8953系列----在aboot中读取boot version

本文介绍了一种从设备的Boot分区读取版本信息的方法。通过使用C语言编程,该方法能够在嵌入式系统中确定其运行固件的具体版本。文章详细展示了如何定位Boot分区、读取扇区内容并解析出版本字符串。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

    在aboot.c中

void get_image_version(unsigned char *buf)
{
unsigned long long ptn = 0;
int index = INVALID_PTN;
char *src_ptr;
char *dest_str;
uint32_t ret = 0,blocksize;


src_ptr = malloc(PAGE_SIZE + 1);   //先搞个buffer
memset((void*)src_ptr,0,PAGE_SIZE + 1);


index = partition_get_index("boot");   //获取boot在partition中的位置
if(!index)
{
dprintf(CRITICAL,"get boot index failed!\n");
goto error;
}


mmc_set_lun(partition_get_lun(index));


ptn = partition_get_offset(index);   //获取offset
if(!ptn)
{
dprintf(CRITICAL,"get boot sector offset failed!\n");
goto error;
}


blocksize = mmc_get_device_blocksize();  //获取block大小


if(!src_ptr)
{
dprintf(CRITICAL, "Failed to allocate memory for src_ptr!\n");
goto error;
}


ret = mmc_read(ptn,(uint32_t*)src_ptr,blocksize);  //读取内容
if(ret)
{
dprintf(CRITICAL,"read boot header info failed!\n");
goto error;
}


dest_str = findstr_in_binheader(src_ptr,"buildv=",512);  //找到对应的字符串
if(!dest_str)
{
dprintf(CRITICAL,"get image version failed.\n");
goto error;
}


snprintf((char*)buf, MAX_RSP_SIZE, "%s",dest_str);


error:


free(src_ptr);


return;
}


char* findstr_in_binheader(char* src,const char* target,int src_size)
{
char *head,*tail,*pos,*result;
head = src;
tail = src + src_size;


for(pos = head; pos != tail;pos++)
{
if(!*pos)
continue;
if((result = strstr(pos,target)))
return result + strlen(target);
}
return NULL;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值