[DESCRIPTION]
自己新建的raw data分区,如何在uboot/LK中读取数据。这里给出一段参考code
[SOLUTION]
这里的code供参考,得根据实际情况进行修改和完善。
printf("[demo_uboot]:read test partition in uboot\n");
unsigned long begin;
#ifdef MTK_EMMC_SUPPORT
unsigned long long start_addr;
unsigned long long length;
#else
unsigned long start_addr;
unsigned long length;
#endif
part_t *part;
part_dev_t *dev;
part_hdr_t *part_hdr;
char part_name[] ="test";
length = 1024;
printf("[demo_uboot] raw data part name[%s]\n",part_name);
dev = mt6577_part_get_device();
if (!dev)
{
printf("[demo_uboot] mt6577 get device() failed\n");
return -1;
}
part = mt6577_part_get_partition(part_name);
if (!part)
{
printf("[demo_uboot]get partition failed\n");
return -1;
}
printf("[demo_uboot]part info name:%s\n",part->name);
printf("[demo_uboot]part info startblk:%ld\n",part->startblk);
printf("[demo_uboot]part info blks:%ld\n",part->blknum);
if (!part)
{
printf("[demo_uboot]get partition failed\n");
return -1;
}
printf("[demo_uboot]part info name:%s\n",part->name);
printf("[demo_uboot]part info startblk:%ld\n",part->startblk);
printf("[demo_uboot]part info blks:%ld\n",part->blknum);
#ifdef MTK_EMMC_SUPPORT
start_addr = (u64)part->startblk * BLK_SIZE;
length = (u64)part->blknum* BLK_SIZE;
#else
start_addr = part->startblk * BLK_SIZE;
length = part->blknum* BLK_SIZE;
#endif
printf("[demo_uboot]partition length:%ld\n",length);
/*
part_hdr = (part_hdr_t*)malloc(sizeof(part_hdr_t));
start_addr = (u64)part->startblk * BLK_SIZE;
length = (u64)part->blknum* BLK_SIZE;
#else
start_addr = part->startblk * BLK_SIZE;
length = part->blknum* BLK_SIZE;
#endif
printf("[demo_uboot]partition length:%ld\n",length);
/*
part_hdr = (part_hdr_t*)malloc(sizeof(part_hdr_t));
if (!part_hdr)
{
printf("[demo_uboot]part_hdr malloc memory faild\n");
return -1;
}
len = mboot_common_load_part_info(dev, part_name, part_hdr);
if (len < 0) {
printf("[demo_uboot]load part info failed\n");
len = -EINVAL;
}
begin = get_timer(0);
*/
//****************
//* read image data
//*
printf("[demo_uboot]read the data of %s\n", part_name);
unsigned char *addr;
length = 512;
addr = (unsigned char *)malloc(length*sizeof(char));
len = dev->read(dev, start_addr, (uchar*)addr, length);
if (len < 0) {
printf("[demo_uboot]read data failed\n");
return -1;
}
int i = 0;
for(i = 0;i<length;i++,addr++)
printf("[demo_uboot] result:%x\n",*addr);
length = 512;
addr = (unsigned char *)malloc(length*sizeof(char));
len = dev->read(dev, start_addr, (uchar*)addr, length);
if (len < 0) {
printf("[demo_uboot]read data failed\n");
return -1;
}
int i = 0;
for(i = 0;i<length;i++,addr++)
printf("[demo_uboot] result:%x\n",*addr);
72上经常有需要在LK/Uboot中读取raw data分区中的一个数据,这里把常用到的几个接口在这里列举下.
这些接口如下:
(1)dev = mt_part_get_device();//获取一个设备
(2)mt_part_get_partition(partition name);//获取设备上的一个分区
(3)mboot_common_load_parition_info(...);//加载分区的数据
(4)dev->read(...);//读取分区上的数据
参考源文件:
(1)mt_partition.c
(2)load_image.c