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
例如:
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