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

来源:互联网 发布:黑马程序员 课程表 编辑:程序博客网 时间:2024/04/30 22:14

    在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;
}

0 0
原创粉丝点击