[lib][ptable] Modify ptable to respect erase geometries.
Modify the existing ptable code to pay attention to bio device erase geometry if present. Significant changes include... + Partitions must be allocated on both program and erase block boundaries. + Partitions lengths must be multiples of both program and erase block sizes. + Partitions may not span non-homogeneous regions of erase geometry. + ptable_allocate as been made private. + Users may no longer explicitly select a position for partitions to be added, they may only ask for the partition to be allocated at the begining or the end of the block device. + A bio subdevice will be registered for each active partition in the system. Users are encouraged to add their partition using ptable_add, and then open a handle to the subdevice using bio_open. The bio subdevice will prevent accidental scribbling outside of the partition lines, and also advertise the partition erase size. Signed-off-by: John Grossman <johngro@google.com> Change-Id: I09bf9038d210ff8be42d44166ab92c789872e036
This commit is contained in:
committed by
Travis Geiselbrecht
parent
8a7219ddb1
commit
eab2816302
@@ -295,17 +295,7 @@ int lkb_handle_command(lkb_t *lkb, const char *cmd, const char *arg, size_t len,
|
||||
if (ptable_find(arg, &entry) < 0) {
|
||||
size_t plen = len;
|
||||
/* doesn't exist, make one */
|
||||
#if PLATFORM_ZYNQ
|
||||
/* XXX not really the right place, should be in the ptable/bio layer */
|
||||
plen = ROUNDUP(plen, 256*1024);
|
||||
#endif
|
||||
off_t off = ptable_allocate(plen, 0);
|
||||
if (off < 0) {
|
||||
*result = "no space to allocate partition";
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (ptable_add(arg, off, plen, 0) < 0) {
|
||||
if (ptable_add(arg, plen, 0) < 0) {
|
||||
*result = "error creating partition";
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -42,6 +42,8 @@
|
||||
#include <lib/minip.h>
|
||||
#endif
|
||||
|
||||
#define BLOCK_DEVICE_NAME "spi0"
|
||||
|
||||
static void zynq_common_target_init(uint level)
|
||||
{
|
||||
status_t err;
|
||||
@@ -49,11 +51,11 @@ static void zynq_common_target_init(uint level)
|
||||
/* zybo has a spiflash on qspi */
|
||||
spiflash_detect();
|
||||
|
||||
bdev_t *spi = bio_open("spi0");
|
||||
bdev_t *spi = bio_open(BLOCK_DEVICE_NAME);
|
||||
if (spi) {
|
||||
/* find or create a partition table at the start of flash */
|
||||
if (ptable_scan(spi, 0) < 0) {
|
||||
ptable_create_default(spi, 0);
|
||||
if (ptable_scan(BLOCK_DEVICE_NAME, 0) < 0) {
|
||||
ptable_create_default(BLOCK_DEVICE_NAME, 0);
|
||||
}
|
||||
|
||||
struct ptable_entry entry = { 0 };
|
||||
@@ -61,7 +63,7 @@ static void zynq_common_target_init(uint level)
|
||||
/* find and recover sysparams */
|
||||
if (ptable_find("sysparam", &entry) < 0) {
|
||||
/* didn't find sysparam partition, create it */
|
||||
ptable_add("sysparam", 0x1000, 0x1000, 0);
|
||||
ptable_add("sysparam", 0x1000, 0);
|
||||
ptable_find("sysparam", &entry);
|
||||
}
|
||||
|
||||
@@ -81,7 +83,7 @@ static void zynq_common_target_init(uint level)
|
||||
}
|
||||
|
||||
/* create bootloader partition if it does not exist */
|
||||
ptable_add("bootloader", 0x20000, 0x40000, 0);
|
||||
ptable_add("bootloader", 0x40000, 0);
|
||||
|
||||
#if LK_DEBUGLEVEL > 1
|
||||
printf("flash partition table:\n");
|
||||
@@ -111,7 +113,7 @@ static void zynq_common_target_init(uint level)
|
||||
if (ptr) {
|
||||
bootimage_open(ptr, bootimage_size, &bi);
|
||||
}
|
||||
} else if (!strcmp(device, "spi0")) {
|
||||
} else if (!strcmp(device, BLOCK_DEVICE_NAME)) {
|
||||
/* we were loaded from spi flash, go look at it to see if we can find it */
|
||||
if (spi) {
|
||||
void *ptr = 0;
|
||||
|
||||
Reference in New Issue
Block a user