lk中的partition.c

lk中的partition.c中是讲的是将flashlayout保持在flash中的case,之前我们将的ptable的case是将flashlayout信息buildin到lk中。
例如:
static struct ptentry board_part_list_sku3[] = {
{
.start = 0,
.length = 10 /* In MB */ ,
.name = "boot",
},
{
.start = DIFF_START_ADDR,
.length = 253 /* In MB */ ,
.name = "system",
},
};
而partition.c将flashlayout保持在flash,具体的函数就只有partition_publish


int partition_publish(const char *device, off_t offset)
{
int err = 0;
int count = 0;


// clear any partitions that may have already existed
partition_unpublish(device);


打开保持flashlayout的block dev。
bdev_t *dev = bio_open(device);
if (!dev) {
printf("partition_publish: unable to open device\n");
return -1;
}


将buf按照block_size对其
STACKBUF_DMA_ALIGN(buf, dev->block_size);

/* sniff for MBR partition types */
do {
int i;
开始读数据
err = bio_read(dev, buf, offset, 512);
if (err < 0)
goto err;
flashlayout的保存有一定的格式,我们这个例子中只有四个partition信息,因此会在buf[510]和buf[511]保存tag
/* look for the aa55 tag */
if (buf[510] != 0x55 || buf[511] != 0xaa)
break;


从446开始读取flashlayout信息
struct mbr_part part[4];
memcpy(part, buf + 446, sizeof(part));


/* validate each of the partition entries */
for (i=0; i < 4; i++) {
if (validate_mbr_partition(dev, &part[i]) >= 0) {
// publish it
char subdevice[128];


sprintf(subdevice, "%sp%d", device, i); 
确认是flashlayout信息后通过bio_publish_subdevice发布出去。
err = bio_publish_subdevice(device, subdevice, part[i].lba_start, part[i].lba_length);
if (err < 0) {
dprintf(INFO, "error publishing subdevice '%s'\n", subdevice);
continue;
}
count++;
}
}
} while(0);


bio_close(dev);


err:
return (err < 0) ? err : count;
}


在lk中没有搜到直接使用partition_publish的case,实际开发中的flashlayout也不止四个,这个就是给大家一个例子,可以参考这个格式写自己的partition_publish
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值