bootstd: Support ChromiumOS better
Subsystems (4)
cover bootstd: Support ChromiumOS better
This updates the ChromiumOS bootmeth to detect multiple kernel partitions on a disk.
It also includes minor code improvements to the partition drivers, including accessors for the optional fields.
This series also includes some other related tweaks in testing.
It is available at u-boot-dm/methb-working
Simon Glass (24):
part: Use desc instead of dev_desc
part: amiga: Use desc instead of dev_desc
part: dos: Use desc instead of dev_desc
part: efi: Use desc instead of dev_desc
part: iso: Use desc instead of dev_desc
part: nac: Use desc instead of dev_desc
part: Add comments for static functions
part: Add accessors for struct disk_partition uuid
part: Add accessors for struct disk_partition type_uuid
part: Add an accessor for struct disk_partition sys_ind
part: efi: Add debugging for the signature check fs/erofs: Quieten test for filesystem presence
dm: core: Correct error handling when event fails
uuid: Move function comments to header file
sandbox: Add a way to access persistent test files
test: Move 1MB.fat32.img and 2MB.ext2.img
bootflow: Show an empty filename when there is none
bootstd: test: Allow binding and using any mmc device
bootstd: Add a test for bootmeth_cros
part: Add a fallback for part_get_bootable()
bootstd: Support bootmeths which can scan any partition
uuid: Add ChromiumOS partition types
bootstd: cros: Allow detection of any kernel partition
CI: Add ChromiumOS utilities
arch/sandbox/cpu/os.c | 24 ++++ arch/sandbox/dts/test.dts | 9 ++ boot/Kconfig | 2 + boot/bootdev-uclass.c | 24 +++- boot/bootmeth_cros.c | 48 ++++--- cmd/bootflow.c | 2 +- cmd/gpt.c | 10 +- configs/snow_defconfig | 1 + disk/part.c | 226 +++++++++++++++-------------- disk/part_amiga.c | 34 ++--- disk/part_dos.c | 78 +++++----- disk/part_efi.c | 281 +++++++++++++++++++------------------ disk/part_iso.c | 52 +++---- disk/part_mac.c | 59 ++++---- doc/develop/bootstd.rst | 11 +- drivers/core/device.c | 3 +- fs/erofs/super.c | 4 +- fs/fat/fat.c | 4 +- include/bootmeth.h | 3 + include/os.h | 10 ++ include/part.h | 215 ++++++++++++++++++---------- include/part_efi.h | 14 ++ include/uuid.h | 94 +++++++++++++ lib/uuid.c | 93 +----------- test/boot/bootflow.c | 80 ++++++++--- test/dm/host.c | 44 +++--- test/py/tests/fs_helper.py | 6 +- test/py/tests/test_ut.py | 148 ++++++++++++++++++- tools/docker/Dockerfile | 3 + 29 files changed, 982 insertions(+), 600 deletions(-)
Signature · 1 line
2.41.0.640.ga95def55d0-goog
PATCH 1/24 part: Use desc instead of dev_desc
The dev_ prefix is a hangover from the pre-driver model days. The device is now a different thing, with driver model. Update the partition code to just use 'desc', as is done with driver model.
---
disk/part.c | 178 ++++++++++++++++++++++++------------------------- include/part.h | 128 +++++++++++++++++------------------ 2 files changed, 149 insertions(+), 157 deletions(-)
disk/part.c +86 -92
@@ -42,25 +42,25 @@ static struct part_driver *part_driver_get_type(int part_type)return NULL ; } -static struct part_driver *part_driver_lookup_type (struct blk_desc *dev_desc) +static struct part_driver *part_driver_lookup_type (struct blk_desc *desc) {struct part_driver *drv = ll_entry_start(struct part_driver, part_driver); const int n_ents = ll_entry_count(struct part_driver, part_driver);struct part_driver *entry; -if (dev_desc->part_type ==PART_TYPE_UNKNOWN ) { +if (desc->part_type ==PART_TYPE_UNKNOWN ) {for (entry = drv; entry != drv + n_ents; entry++) {int ret; - ret = entry->test (dev_desc); + ret = entry->test (desc);if (!ret) { - dev_desc->part_type = entry->part_type; + desc->part_type = entry->part_type;return entry; } } }else { -return part_driver_get_type (dev_desc->part_type); +return part_driver_get_type (desc->part_type); }/* Not found */
@@ -85,25 +85,25 @@ int part_get_type_by_name(const char *name)static struct blk_desc *get_dev_hwpart (const char *ifname,int dev,int hwpart) { -struct blk_desc *dev_desc; +struct blk_desc *desc;int ret;if (!blk_enabled ())return NULL ; - dev_desc =blk_get_devnum_by_uclass_idname (ifname, dev); -if (!dev_desc) { + desc =blk_get_devnum_by_uclass_idname (ifname, dev); +if (!desc) {debug ("%s: No device for iface '%s', dev %d\n" , __func__, ifname, dev);return NULL ; } - ret =blk_dselect_hwpart (dev_desc, hwpart); + ret =blk_dselect_hwpart (desc, hwpart);if (ret) {debug ("%s: Failed to select h/w partition: err-%d\n" , __func__, ret);return NULL ; } -return dev_desc; +return desc; }struct blk_desc *blk_get_dev (const char *ifname,int dev)
@@ -140,29 +140,24 @@ static lba512_t lba512_muldiv(lba512_t block_count, lba512_t mul_by,return bc_quot * mul_by + ((bc_rem * mul_by) >> right_shift); } -void dev_print (struct blk_desc *dev_desc) +void dev_print (struct blk_desc *desc) {lba512_t lba512;/* number of blocks if 512bytes block size */ -if (dev_desc->type ==DEV_TYPE_UNKNOWN ) { +if (desc->type ==DEV_TYPE_UNKNOWN ) {puts ("not available\n" );return ; } -switch (dev_desc->uclass_id) { +switch (desc->uclass_id) {case UCLASS_SCSI : -printf ("(%d:%d) Vendor: %s Prod.: %s Rev: %s\n" , - dev_desc->target,dev_desc->lun, - dev_desc->vendor, - dev_desc->product, - dev_desc->revision); +printf ("(%d:%d) Vendor: %s Prod.: %s Rev: %s\n" , desc->target, + desc->lun, desc->vendor, desc->product, desc->revision);break ;case UCLASS_IDE :case UCLASS_AHCI : -printf ("Model: %s Firm: %s Ser#: %s\n" , - dev_desc->vendor, - dev_desc->revision, - dev_desc->product); +printf ("Model: %s Firm: %s Ser#: %s\n" , desc->vendor, + desc->revision, desc->product);break ;case UCLASS_MMC :case UCLASS_USB :
@@ -171,27 +166,27 @@ void dev_print(struct blk_desc *dev_desc)case UCLASS_HOST :case UCLASS_BLKMAP :printf ("Vendor: %s Rev: %s Prod: %s\n" , - dev_desc->vendor, - dev_desc->revision, - dev_desc->product); + desc->vendor, + desc->revision, + desc->product);break ;case UCLASS_VIRTIO : -printf ("%s VirtIO Block Device\n" , dev_desc->vendor); +printf ("%s VirtIO Block Device\n" , desc->vendor);break ;case UCLASS_EFI_MEDIA : -printf ("EFI media Block Device %d\n" , dev_desc->devnum); +printf ("EFI media Block Device %d\n" , desc->devnum);break ;case UCLASS_INVALID :puts ("device type unknown\n" );return ;default : -printf ("Unhandled device type: %i\n" , dev_desc->uclass_id); +printf ("Unhandled device type: %i\n" , desc->uclass_id);return ; }puts (" Type: " ); -if (dev_desc->removable) +if (desc->removable)puts ("Removable " ); -switch (dev_desc->type &0x1F ) { +switch (desc->type &0x1F ) {case DEV_TYPE_HARDDISK :puts ("Hard Disk" );break ;
@@ -205,17 +200,17 @@ void dev_print(struct blk_desc *dev_desc)puts ("Tape" );break ;default : -printf ("# %02X #" , dev_desc->type &0x1F ); +printf ("# %02X #" , desc->type &0x1F );break ; }puts ("\n" ); -if (dev_desc->lba >0L && dev_desc->blksz >0L ) { +if (desc->lba >0L && desc->blksz >0L ) {ulong mb, mb_quot, mb_rem, gb, gb_quot, gb_rem;lbaint_t lba; - lba = dev_desc->lba; + lba = desc->lba; - lba512 = (lba * (dev_desc->blksz/512 )); + lba512 = lba * (desc->blksz /512 );/* round to 1 digit */ /* 2048 = (1024 * 1024) / 512 MB */ mb =lba512_muldiv (lba512,10 ,11 );
@@ -227,7 +222,7 @@ void dev_print(struct blk_desc *dev_desc) gb_quot = gb /10 ; gb_rem = gb - (10 * gb_quot);#ifdef CONFIG_LBA48 -if (dev_desc->lba48) +if (desc->lba48)printf (" Supports 48-bit addressing\n" );#endif #if defined(CONFIG_SYS_64BIT_LBA )
@@ -235,42 +230,42 @@ void dev_print(struct blk_desc *dev_desc) mb_quot, mb_rem, gb_quot, gb_rem, lba, - dev_desc->blksz); + desc->blksz);#else printf (" Capacity: %lu.%lu MB = %lu.%lu GB (%lu x %lu)\n" , mb_quot, mb_rem, gb_quot, gb_rem, (ulong )lba, - dev_desc->blksz); + desc->blksz);#endif }else {puts (" Capacity: not available\n" ); } } -void part_init (struct blk_desc *dev_desc) +void part_init (struct blk_desc *desc) {struct part_driver *drv = ll_entry_start(struct part_driver, part_driver); const int n_ents = ll_entry_count(struct part_driver, part_driver);struct part_driver *entry; -blkcache_invalidate (dev_desc->uclass_id, dev_desc->devnum); +blkcache_invalidate (desc->uclass_id, desc->devnum); - dev_desc->part_type =PART_TYPE_UNKNOWN ; + desc->part_type =PART_TYPE_UNKNOWN ;for (entry = drv; entry != drv + n_ents; entry++) {int ret; - ret = entry->test (dev_desc); + ret = entry->test (desc);debug ("%s: try '%s': ret=%d\n" , __func__, entry->name, ret);if (!ret) { - dev_desc->part_type = entry->part_type; + desc->part_type = entry->part_type;break ; } } } -static void print_part_header (const char *type,struct blk_desc *dev_desc) +static void print_part_header (const char *type,struct blk_desc *desc) { #if CONFIG_IS_ENABLED(MAC_PARTITION) || \ CONFIG_IS_ENABLED(DOS_PARTITION) || \
@@ -278,7 +273,7 @@ static void print_part_header(const char *type, struct blk_desc *dev_desc)CONFIG_IS_ENABLED (AMIGA_PARTITION ) || \CONFIG_IS_ENABLED (EFI_PARTITION ) puts ("\nPartition Map for "); -switch (dev_desc->uclass_id) { +switch (desc->uclass_id) {case UCLASS_IDE :puts ("IDE" );break ;
@@ -314,28 +309,28 @@ static void print_part_header(const char *type, struct blk_desc *dev_desc) break; }printf (" device %d -- Partition Type: %s\n\n" , - dev_desc->devnum, type); + desc->devnum, type);#endif /* any CONFIG_..._PARTITION */ } -void part_print (struct blk_desc *dev_desc) +void part_print (struct blk_desc *desc) {struct part_driver *drv; - drv =part_driver_lookup_type (dev_desc); + drv =part_driver_lookup_type (desc);if (!drv) {printf ("## Unknown partition table type %x\n" , - dev_desc->part_type); + desc->part_type);return ; }PRINTF ("## Testing for valid %s partition ##\n" , drv->name); -print_part_header (drv->name, dev_desc); +print_part_header (drv->name, desc);if (drv->print) - drv->int part_get_info_by_type (struct blk_desc *dev_desc,int part,int part_type, +int part_get_info_by_type (struct blk_desc *desc,int part,int part_type,struct disk_partition *info) {struct part_driver *drv;
@@ -350,14 +345,14 @@ int part_get_info_by_type(struct blk_desc *dev_desc, int part, int part_type,#endif if (part_type ==PART_TYPE_UNKNOWN ) { - drv =part_driver_lookup_type (dev_desc); + drv =part_driver_lookup_type (desc); }else { drv =part_driver_get_type (part_type); }if (!drv) {debug ("## Unknown partition table type %x\n" , - dev_desc->part_type); + desc->part_type);return -EPROTONOSUPPORT ; }if (!drv->get_info) {
@@ -365,7 +360,7 @@ int part_get_info_by_type(struct blk_desc *dev_desc, int part, int part_type, drv->name);return -ENOSYS ; } -if (drv->get_info (dev_desc, part, info) ==0 ) { +if (drv->get_info (desc, part, info) ==0 ) {PRINTF ("## Valid %s partition found ##\n" , drv->name);return 0 ; }
@@ -374,18 +369,18 @@ int part_get_info_by_type(struct blk_desc *dev_desc, int part, int part_type,return -ENOENT ; } -int part_get_info (struct blk_desc *dev_desc,int part, +int part_get_info (struct blk_desc *desc,int part,struct disk_partition *info) { -return part_get_info_by_type (dev_desc, part,PART_TYPE_UNKNOWN , info); +return part_get_info_by_type (desc, part,PART_TYPE_UNKNOWN , info); } -int part_get_info_whole_disk (struct blk_desc *dev_desc, +int part_get_info_whole_disk (struct blk_desc *desc,struct disk_partition *info) { info->start =0 ; - info->size = dev_desc->lba; - info->blksz = dev_desc->blksz; + info->size = desc->lba; + info->blksz = desc->blksz; info->bootable =0 ;strcpy ((char *)info->type,BOOT_PART_TYPE );strcpy ((char *)info->name,"Whole Disk" );
@@ -400,7 +395,7 @@ int part_get_info_whole_disk(struct blk_desc *dev_desc, }int blk_get_device_by_str (const char *ifname,const char *dev_hwpart_str, -struct blk_desc **dev_desc) +struct blk_desc **desc) {char *ep;char *dup_str =NULL ;
@@ -436,8 +431,8 @@ int blk_get_device_by_str(const char *ifname, const char *dev_hwpart_str, } } - *dev_desc =get_dev_hwpart (ifname, dev, hwpart); -if (!(*dev_desc) || ((*dev_desc)->type ==DEV_TYPE_UNKNOWN )) { + *desc =get_dev_hwpart (ifname, dev, hwpart); +if (!(*desc) || ((*desc)->type ==DEV_TYPE_UNKNOWN )) {debug ("** Bad device %s %s **\n" , ifname, dev_hwpart_str); dev = -ENODEV ; goto cleanup;
@@ -449,8 +444,8 @@ int blk_get_device_by_str(const char *ifname, const char *dev_hwpart_str,* Always should be done, otherwise hw partition 0 will return * stale data after displaying a non-zero hw partition. */ -if ((*dev_desc)->uclass_id ==UCLASS_MMC ) -part_init (*dev_desc); +if ((*desc)->uclass_id ==UCLASS_MMC ) +part_init (*desc); } cleanup:
@@ -461,7 +456,7 @@ cleanup:#define PART_UNSPECIFIED -2#define PART_AUTO -1int blk_get_device_part_str (const char *ifname,const char *dev_part_str, -struct blk_desc **dev_desc, +struct blk_desc **desc,struct disk_partition *info,int allow_whole_dev) {int ret;
@@ -474,7 +469,7 @@ int blk_get_device_part_str(const char *ifname, const char *dev_part_str,int part;struct disk_partition tmpinfo; - *dev_desc =NULL ; + *desc =NULL ;memset (info,0 ,sizeof (*info));#if IS_ENABLED (CONFIG_SANDBOX ) ||IS_ENABLED (CONFIG_SEMIHOSTING )
@@ -533,7 +528,7 @@ int blk_get_device_part_str(const char *ifname, const char *dev_part_str, }/* Look up the device */ - dev =blk_get_device_by_str (ifname, dev_str, dev_desc); + dev =blk_get_device_by_str (ifname, dev_str, desc);if (dev <0 ) {printf ("** Bad device specification %s %s **\n" , ifname, dev_str);
@@ -565,9 +560,8 @@ int blk_get_device_part_str(const char *ifname, const char *dev_part_str,* No partition table on device, * or user requested partition 0 (entire device). */ -if (((*dev_desc)->part_type ==PART_TYPE_UNKNOWN ) || - (part ==0 )) { -if (!(*dev_desc)->lba) { +if (((*desc)->part_type ==PART_TYPE_UNKNOWN ) || !part) { +if (!(*desc)->lba) {printf ("** Bad device size - %s %s **\n" , ifname, dev_str); ret = -EINVAL ;
@@ -586,9 +580,9 @@ int blk_get_device_part_str(const char *ifname, const char *dev_part_str, goto cleanup; } - (*dev_desc)->log2blksz =LOG2 ((*dev_desc)->blksz); + (*desc)->log2blksz =LOG2 ((*desc)->blksz); -part_get_info_whole_disk (*dev_desc, info); +part_get_info_whole_disk (*desc, info); ret =0 ; goto cleanup;
@@ -606,7 +600,7 @@ int blk_get_device_part_str(const char *ifname, const char *dev_part_str,* other than "auto", use that partition number directly. */ if (part !=PART_AUTO ) { - ret =part_get_info (*dev_desc, part, info); + ret =part_get_info (*desc, part, info);if (ret) {printf ("** Invalid partition %d **\n" , part); goto cleanup;
@@ -618,7 +612,7 @@ int blk_get_device_part_str(const char *ifname, const char *dev_part_str,*/ part =0 ;for (p =1 ; p <=MAX_SEARCH_PARTITIONS ; p++) { - ret =part_get_info (*dev_desc, p, info); + ret =part_get_info (*desc, p, info);if (ret)continue ;
@@ -662,7 +656,7 @@ int blk_get_device_part_str(const char *ifname, const char *dev_part_str, goto cleanup; } - (*dev_desc)->log2blksz =LOG2 ((*dev_desc)->blksz); + (*desc)->log2blksz =LOG2 ((*desc)->blksz); ret = part; goto cleanup;
@@ -672,14 +666,14 @@ cleanup:return ret; } -int part_get_info_by_name (struct blk_desc *dev_desc,const char *name, +int part_get_info_by_name (struct blk_desc *desc,const char *name,struct disk_partition *info) {struct part_driver *part_drv;int ret;int i; - part_drv =part_driver_lookup_type (dev_desc); + part_drv =part_driver_lookup_type (desc);if (!part_drv)return -1 ;
@@ -690,7 +684,7 @@ int part_get_info_by_name(struct blk_desc *dev_desc, const char *name, }for (i =1 ; i < part_drv->max_entries; i++) { - ret = part_drv->get_info (dev_desc, i, info); + ret = part_drv->get_info (desc, i, info);if (ret !=0 ) {/* no more entries in table */ break ;
@@ -710,18 +704,18 @@ int part_get_info_by_name(struct blk_desc *dev_desc, const char *name,* Parse a device number and partition name string in the form of * "devicenum.hwpartnum#partition_name", for example "0.1#misc". devicenum and * hwpartnum are both optional, defaulting to 0. If the partition is found, -* sets dev_desc and part_info accordingly with the information of the +* sets desc and part_info accordingly with the information of the * partition with the given partition_name. * * @param[in] dev_iface Device interface * @param[in] dev_part_str Input string argument, like "0.1#misc" -* @param[out] dev_desc Place to store the device description pointer +* @param[out] desc Place to store the device description pointer * @param[out] part_info Place to store the partition information * Return: 0 on success, or a negative on error */ static int part_get_info_by_dev_and_name (const char *dev_iface,const char *dev_part_str, -struct blk_desc **dev_desc, +struct blk_desc **desc,struct disk_partition *part_info) {char *dup_str =NULL ;
@@ -743,11 +737,11 @@ static int part_get_info_by_dev_and_name(const char *dev_iface,return -EINVAL ; } - ret =blk_get_device_by_str (dev_iface, dev_str, dev_desc); + ret =blk_get_device_by_str (dev_iface, dev_str, desc);if (ret <0 ) goto cleanup; - ret =part_get_info_by_name (*dev_desc, part_str, part_info); + ret =part_get_info_by_name (*desc, part_str, part_info);if (ret <0 )printf ("Could not find \"%s\" partition\n" , part_str);
@@ -758,35 +752,35 @@ cleanup:int part_get_info_by_dev_and_name_or_num (const char *dev_iface,const char *dev_part_str, -struct blk_desc **dev_desc, +struct blk_desc **desc,struct disk_partition *part_info,int allow_whole_dev) {int ret;/* Split the part_name if passed as "$dev_num#part_name". */ - ret =part_get_info_by_dev_and_name (dev_iface, dev_part_str, - dev_desc, part_info); + ret =part_get_info_by_dev_and_name (dev_iface, dev_part_str, desc, + part_info);if (ret >=0 )return ret;/* * Couldn't lookup by name, try looking up the partition description * directly. */ - ret =blk_get_device_part_str (dev_iface, dev_part_str, - dev_desc, part_info, allow_whole_dev); + ret =blk_get_device_part_str (dev_iface, dev_part_str, desc, part_info, + allow_whole_dev);if (ret <0 )printf ("Couldn't find partition %s %s\n" , dev_iface, dev_part_str);return ret; } -void part_set_generic_name (const struct blk_desc *dev_desc, -int part_num,char *name) +void part_set_generic_name (const struct blk_desc *desc,int part_num, +char *name) {char *devtype; -switch (dev_desc->uclass_id) { +switch (desc->uclass_id) {case UCLASS_IDE :case UCLASS_AHCI : devtype ="hd" ;
@@ -805,7 +799,7 @@ void part_set_generic_name(const struct blk_desc *dev_desc,break ; } -sprintf (name,"%s%c%d" , devtype,'a' + dev_desc->devnum, part_num); +sprintf (name,"%s%c%d" , devtype,'a' + desc->devnum, part_num); }int part_get_bootable (struct blk_desc *desc)
include/part.h +63 -65
363 lines not on this page · raw message
Signature · 1 line
2.41.0.640.ga95def55d0-goog
PATCH 2/24 part: amiga: Use desc instead of dev_desc
In reply to Simon GlassThe dev_ prefix is a hangover from the pre-driver model days. The device is now a different thing, with driver model. Update the amiga code to just use 'desc'.
---
disk/part_amiga.c | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-)
disk/part_amiga.c +17 -17
@@ -125,7 +125,7 @@ static void print_part_info(struct partition_block *p)* the ID AMIGA_ID_RDISK ('RDSK') and needs to have a valid * sum-to-zero checksum */ -struct rigid_disk_block *get_rdisk (struct blk_desc *dev_desc) +struct rigid_disk_block *get_rdisk (struct blk_desc *desc) {int i;int limit;
@@ -139,7 +139,7 @@ struct rigid_disk_block *get_rdisk(struct blk_desc *dev_desc)for (i=0 ; i<limit; i++) { -ulong res =blk_dread (dev_desc, i,1 , (ulong *)block_buffer); +ulong res =blk_dread (desc, i,1 , (ulong *)block_buffer);if (res ==1 ) {struct rigid_disk_block *trdb = (struct rigid_disk_block *)block_buffer;
@@ -165,7 +165,7 @@ struct rigid_disk_block *get_rdisk(struct blk_desc *dev_desc)* Ridgid disk block */ -struct bootcode_block *get_bootcode (struct blk_desc *dev_desc) +struct bootcode_block *get_bootcode (struct blk_desc *desc) {int i;int limit;
@@ -181,7 +181,7 @@ struct bootcode_block *get_bootcode(struct blk_desc *dev_desc)for (i =0 ; i < limit; i++) { -ulong res =blk_dread (dev_desc, i,1 , (ulong *)block_buffer); +ulong res =blk_dread (desc, i,1 , (ulong *)block_buffer);if (res ==1 ) {struct bootcode_block *boot = (struct bootcode_block *)block_buffer;
@@ -206,17 +206,17 @@ struct bootcode_block *get_bootcode(struct blk_desc *dev_desc)* Test if the given partition has an Amiga partition table/Rigid * Disk block */ -static int part_test_amiga (struct blk_desc *dev_desc) +static int part_test_amiga (struct blk_desc *desc) {struct rigid_disk_block *rdb;struct bootcode_block *bootcode;PRINTF ("part_test_amiga: Testing for an Amiga RDB partition\n" ); - rdb =get_rdisk (dev_desc); + rdb =get_rdisk (desc);if (rdb) { - bootcode =get_bootcode (dev_desc); + bootcode =get_bootcode (desc);if (bootcode)PRINTF ("part_test_amiga: bootable Amiga disk\n" );else
@@ -235,7 +235,7 @@ static int part_test_amiga(struct blk_desc *dev_desc)/* * Find partition number partnum on the given drive. */ -static struct partition_block *find_partition (struct blk_desc *dev_desc, +static struct partition_block *find_partition (struct blk_desc *desc,int partnum) {struct rigid_disk_block *rdb;
@@ -243,7 +243,7 @@ static struct partition_block *find_partition(struct blk_desc *dev_desc,u32 block;PRINTF ("Trying to find partition block %d\n" , partnum); - rdb =get_rdisk (dev_desc); + rdb =get_rdisk (desc);if (!rdb) {PRINTF ("find_partition: no rdb found\n" );
@@ -257,7 +257,7 @@ static struct partition_block *find_partition(struct blk_desc *dev_desc,while (block !=0xFFFFFFFF ) { -ulong res =blk_dread (dev_desc, block,1 , (ulong *)block_buffer); +ulong res =blk_dread (desc, block,1 , (ulong *)block_buffer);if (res ==1 ) { p = (struct partition_block *)block_buffer;
@@ -289,10 +289,10 @@ static struct partition_block *find_partition(struct blk_desc *dev_desc,/* * Get info about a partition */ -static int part_get_info_amiga (struct blk_desc *dev_desc,int part, -struct disk_partition *info) +static int part_get_info_amiga (struct blk_desc *desc,int part, +struct disk_partition *info) { -struct partition_block *p =find_partition (dev_desc, part-1 ); +struct partition_block *p =find_partition (desc, part -1 );struct amiga_part_geometry *g;u32 disk_type;
@@ -317,7 +317,7 @@ static int part_get_info_amiga(struct blk_desc *dev_desc, int part,return 0 ; } -static void part_print_amiga (struct blk_desc *dev_desc) +static void part_print_amiga (struct blk_desc *desc) {struct rigid_disk_block *rdb;struct bootcode_block *boot;
@@ -325,7 +325,7 @@ static void part_print_amiga(struct blk_desc *dev_desc)u32 block;int i =1 ; - rdb =get_rdisk (dev_desc); + rdb =get_rdisk (desc);if (!rdb) {PRINTF ("part_print_amiga: no rdb found\n" );
@@ -353,7 +353,7 @@ static void part_print_amiga(struct blk_desc *dev_desc)PRINTF ("Trying to load block #0x%X\n" , block); - res =blk_dread (dev_desc, block,1 , (ulong *)block_buffer); + res =blk_dread (desc, block,1 , (ulong *)block_buffer);if (res ==1 ) { p = (struct partition_block *)block_buffer;
@@ -370,7 +370,7 @@ static void part_print_amiga(struct blk_desc *dev_desc) }else block =0xFFFFFFFF ; } - boot =get_bootcode (dev_desc); + boot =get_bootcode (desc);if (boot) {printf ("Disk is bootable\n" );
Signature · 1 line
2.41.0.640.ga95def55d0-goog
PATCH 3/24 part: dos: Use desc instead of dev_desc
In reply to Simon GlassThe dev_ prefix is a hangover from the pre-driver model days. The device is now a different thing, with driver model. Update the dos code to just use 'desc'.
---
disk/part_dos.c | 61 ++++++++++++++++++++++++------------------------- 1 file changed, 30 insertions(+), 31 deletions(-)
disk/part_dos.c +30 -31
@@ -98,27 +98,26 @@ static int test_block_type(unsigned char *buffer)return -1 ; } -static int part_test_dos (struct blk_desc *dev_desc) +static int part_test_dos (struct blk_desc *desc) {#ifndef CONFIG_SPL_BUILD ALLOC_CACHE_ALIGN_BUFFER (legacy_mbr, mbr, -DIV_ROUND_UP (dev_desc->blksz,sizeof (legacy_mbr))); +DIV_ROUND_UP (desc->blksz,sizeof (legacy_mbr))); -if (blk_dread (dev_desc,0 ,1 , (ulong *)mbr) !=1 ) +if (blk_dread (desc,0 ,1 , (ulong *)mbr) !=1 )return -1 ;if (test_block_type ((unsigned char *)mbr) !=DOS_MBR )return -1 ; -if (dev_desc->sig_type ==SIG_TYPE_NONE && - mbr->unique_mbr_signature !=0 ) { - dev_desc->sig_type =SIG_TYPE_MBR ; - dev_desc->mbr_sig = mbr->unique_mbr_signature; +if (desc->sig_type ==SIG_TYPE_NONE && mbr->unique_mbr_signature) { + desc->sig_type =SIG_TYPE_MBR ; + desc->mbr_sig = mbr->unique_mbr_signature; }#else - ALLOC_CACHE_ALIGN_BUFFER(unsigned char, buffer, dev_desc->blksz); + ALLOC_CACHE_ALIGN_BUFFER(unsigned char, buffer, desc->blksz); -if (blk_dread (dev_desc,0 ,1 , (ulong *)buffer) !=1 ) +if (blk_dread (desc,0 ,1 , (ulong *)buffer) !=1 )return -1 ;if (test_block_type (buffer) !=DOS_MBR )
@@ -130,12 +129,12 @@ static int part_test_dos(struct blk_desc *dev_desc)/* Print a partition that is relative to its Extended partition table */ -static void print_partition_extended (struct blk_desc *dev_desc, +static void print_partition_extended (struct blk_desc *desc,lbaint_t ext_part_sector,lbaint_t relative,int part_num,unsigned int disksig) { - ALLOC_CACHE_ALIGN_BUFFER(unsigned char, buffer, dev_desc->blksz); + ALLOC_CACHE_ALIGN_BUFFER(unsigned char, buffer, desc->blksz);dos_partition_t *pt;int i;
@@ -146,9 +145,9 @@ static void print_partition_extended(struct blk_desc *dev_desc,return ; } -if (blk_dread (dev_desc, ext_part_sector,1 , (ulong *)buffer) !=1 ) { +if (blk_dread (desc, ext_part_sector,1 , (ulong *)buffer) !=1 ) {printf ("** Can't read partition table on %d:" LBAFU " **\n" , - dev_desc->devnum, ext_part_sector); + desc->devnum, ext_part_sector);return ; } i=test_block_type (buffer);
@@ -189,9 +188,9 @@ static void print_partition_extended(struct blk_desc *dev_desc,lbaint_t lba_start =get_unaligned_le32 (pt->start4) + relative; -print_partition_extended (dev_desc, lba_start, - ext_part_sector ==0 ? lba_start : relative, - part_num, disksig); +print_partition_extended (desc, lba_start, + !ext_part_sector ? lba_start : + relative, part_num, disksig); } }
@@ -201,12 +200,12 @@ static void print_partition_extended(struct blk_desc *dev_desc,/* Print a partition that is relative to its Extended partition table */ -static int part_get_info_extended (struct blk_desc *dev_desc, +static int part_get_info_extended (struct blk_desc *desc,lbaint_t ext_part_sector,lbaint_t relative,int part_num,int which_part,struct disk_partition *info,uint disksig) { - ALLOC_CACHE_ALIGN_BUFFER(unsigned char, buffer, dev_desc->blksz); + ALLOC_CACHE_ALIGN_BUFFER(unsigned char, buffer, desc->blksz);dos_partition_t *pt;int i;int dos_type;
@@ -218,9 +217,9 @@ static int part_get_info_extended(struct blk_desc *dev_desc,return -1 ; } -if (blk_dread (dev_desc, ext_part_sector,1 , (ulong *)buffer) !=1 ) { +if (blk_dread (desc, ext_part_sector,1 , (ulong *)buffer) !=1 ) {printf ("** Can't read partition table on %d:" LBAFU " **\n" , - dev_desc->devnum, ext_part_sector); + desc->devnum, ext_part_sector);return -1 ; } if (buffer[DOS_PART_MAGIC_OFFSET] != 0x55 ||
@@ -251,7 +250,7 @@ static int part_get_info_extended(struct blk_desc *dev_desc, info->start = (lbaint_t)(ext_part_sector +get_unaligned_le32 (pt->start4)); info->size = (lbaint_t )get_unaligned_le32 (pt->size4); -part_set_generic_name (dev_desc, part_num, +part_set_generic_name (desc, part_num, (char *)info->name);/* sprintf(info->type, "%d, pt->sys_ind); */ strcpy ((char *)info->type,"U-Boot" );
@@ -277,7 +276,7 @@ static int part_get_info_extended(struct blk_desc *dev_desc,lbaint_t lba_start =get_unaligned_le32 (pt->start4) + relative; -return part_get_info_extended (dev_desc, lba_start, +return part_get_info_extended (desc, lba_start, ext_part_sector ==0 ? lba_start : relative, part_num, which_part, info, disksig); }
@@ -288,7 +287,7 @@ static int part_get_info_extended(struct blk_desc *dev_desc,if (dos_type ==DOS_PBR ) { info->start =0 ; - info->size = dev_desc->lba; + info->size = desc->lba; info->blksz =DOS_PART_DEFAULT_SECTOR ; info->bootable =0 ;strcpy ((char *)info->type,"U-Boot" );
@@ -301,16 +300,16 @@ static int part_get_info_extended(struct blk_desc *dev_desc,return -1 ; } -static void __maybe_unused part_print_dos (struct blk_desc *dev_desc) +static void __maybe_unused part_print_dos (struct blk_desc *desc) {printf ("Part\tStart Sector\tNum Sectors\tUUID\t\tType\n" ); -print_partition_extended (dev_desc,0 ,0 ,1 ,0 ); +print_partition_extended (desc,0 ,0 ,1 ,0 ); } -static int __maybe_unused part_get_info_dos (struct blk_desc *dev_desc,int part, -struct disk_partition *info) +static int __maybe_unused part_get_info_dos (struct blk_desc *desc,int part, +struct disk_partition *info) { -return part_get_info_extended (dev_desc,0 ,0 ,1 , part, info,0 ); +return part_get_info_extended (desc,0 ,0 ,1 , part, info,0 ); }int is_valid_dos_buf (void *buf)
@@ -490,20 +489,20 @@ int layout_mbr_partitions(struct disk_partition *p, int count, }#endif -int write_mbr_sector (struct blk_desc *dev_desc,void *buf) +int write_mbr_sector (struct blk_desc *desc,void *buf) {if (is_valid_dos_buf (buf))return -1 ;/* write MBR */ -if (blk_dwrite (dev_desc,0 ,1 , buf) !=1 ) { +if (blk_dwrite (desc,0 ,1 , buf) !=1 ) {printf ("%s: failed writing '%s' (1 blks at 0x0)\n" , __func__,"MBR" );return 1 ; }/* Update the partition table entries*/ -part_init (dev_desc); +part_init (desc);return 0 ; }
Signature · 1 line
2.41.0.640.ga95def55d0-goog
PATCH 4/24 part: efi: Use desc instead of dev_desc
In reply to Simon GlassThe dev_ prefix is a hangover from the pre-driver model days. The device is now a different thing, with driver model. Update the efi code to just use 'desc'.
---
disk/part_efi.c | 228 ++++++++++++++++++++++++------------------------ 1 file changed, 112 insertions(+), 116 deletions(-)
disk/part_efi.c +112 -116
@@ -51,12 +51,12 @@ static inline u32 efi_crc32(const void *buf, u32 len)static int pmbr_part_valid (struct partition *part);static int is_pmbr_valid (legacy_mbr * mbr); -static int is_gpt_valid (struct blk_desc *dev_desc,u64 lba, -gpt_header *pgpt_head,gpt_entry **pgpt_pte); -static gpt_entry *alloc_read_gpt_entries (struct blk_desc *dev_desc, +static int is_gpt_valid (struct blk_desc *desc,u64 lba,gpt_header *pgpt_head, +gpt_entry **pgpt_pte); +static gpt_entry *alloc_read_gpt_entries (struct blk_desc *desc,gpt_header *pgpt_head);static int is_pte_valid (gpt_entry * pte); -static int find_valid_gpt (struct blk_desc *dev_desc,gpt_header *gpt_head, +static int find_valid_gpt (struct blk_desc *desc,gpt_header *gpt_head,gpt_entry **pgpt_pte);static char *print_efiname (gpt_entry *pte)
@@ -195,14 +195,14 @@ static void prepare_backup_gpt_header(gpt_header *gpt_h)* UUID is displayed as 32 hexadecimal digits, in 5 groups, * separated by hyphens, in the form 8-4-4-4-12 for a total of 36 characters */ -int get_disk_guid (struct blk_desc * dev_desc,char *guid) +int get_disk_guid (struct blk_desc *desc,char *guid) { -ALLOC_CACHE_ALIGN_BUFFER_PAD (gpt_header, gpt_head,1 , dev_desc->blksz); +ALLOC_CACHE_ALIGN_BUFFER_PAD (gpt_header, gpt_head,1 , desc->blksz);gpt_entry *gpt_pte =NULL ;unsigned char *guid_bin;/* This function validates AND fills in the GPT header and PTE */ -if (find_valid_gpt (dev_desc, gpt_head, &gpt_pte) !=1 ) +if (find_valid_gpt (desc, gpt_head, &gpt_pte) !=1 )return -EINVAL ; guid_bin = gpt_head->disk_guid.b;
@@ -213,15 +213,15 @@ int get_disk_guid(struct blk_desc * dev_desc, char *guid)return 0 ; } -void part_print_efi (struct blk_desc *dev_desc) +void part_print_efi (struct blk_desc *desc) { -ALLOC_CACHE_ALIGN_BUFFER_PAD (gpt_header, gpt_head,1 , dev_desc->blksz); +ALLOC_CACHE_ALIGN_BUFFER_PAD (gpt_header, gpt_head,1 , desc->blksz);gpt_entry *gpt_pte =NULL ;int i =0 ;unsigned char *uuid;/* This function validates AND fills in the GPT header and PTE */ -if (find_valid_gpt (dev_desc, gpt_head, &gpt_pte) !=1 ) +if (find_valid_gpt (desc, gpt_head, &gpt_pte) !=1 )return ;debug ("%s: gpt-entry at %p\n" , __func__, gpt_pte);
@@ -255,10 +255,10 @@ void part_print_efi(struct blk_desc *dev_desc)return ; } -int part_get_info_efi (struct blk_desc *dev_desc,int part, +int part_get_info_efi (struct blk_desc *desc,int part,struct disk_partition *info) { -ALLOC_CACHE_ALIGN_BUFFER_PAD (gpt_header, gpt_head,1 , dev_desc->blksz); +ALLOC_CACHE_ALIGN_BUFFER_PAD (gpt_header, gpt_head,1 , desc->blksz);gpt_entry *gpt_pte =NULL ;/* "part" argument must be at least 1 */
@@ -268,7 +268,7 @@ int part_get_info_efi(struct blk_desc *dev_desc, int part, }/* This function validates AND fills in the GPT header and PTE */ -if (find_valid_gpt (dev_desc, gpt_head, &gpt_pte) !=1 ) +if (find_valid_gpt (desc, gpt_head, &gpt_pte) !=1 )return -EINVAL ; if (part > le32_to_cpu(gpt_head->num_partition_entries) ||
@@ -283,7 +283,7 @@ int part_get_info_efi(struct blk_desc *dev_desc, int part,/* The ending LBA is inclusive, to calculate size, add 1 to it */ info->size = (lbaint_t )le64_to_cpu (gpt_pte[part -1 ].ending_lba) +1 - info->start; - info->blksz = dev_desc->blksz; + info->blksz = desc->blksz;snprintf ((char *)info->name,sizeof (info->name),"%s" ,print_efiname (&gpt_pte[part -1 ]));
@@ -306,12 +306,12 @@ int part_get_info_efi(struct blk_desc *dev_desc, int part,return 0 ; } -static int part_test_efi (struct blk_desc *dev_desc) +static int part_test_efi (struct blk_desc *desc) { -ALLOC_CACHE_ALIGN_BUFFER_PAD (legacy_mbr, legacymbr,1 , dev_desc->blksz); +ALLOC_CACHE_ALIGN_BUFFER_PAD (legacy_mbr, legacymbr,1 , desc->blksz);/* Read legacy MBR from block 0 and validate it */ -if ((blk_dread (dev_desc,0 ,1 , (ulong *)legacymbr) !=1 ) +if ((blk_dread (desc,0 ,1 , (ulong *)legacymbr) !=1 ) || (is_pmbr_valid (legacymbr) !=1 )) {return -1 ; }
@@ -320,23 +320,23 @@ static int part_test_efi(struct blk_desc *dev_desc)/** * set_protective_mbr(): Set the EFI protective MBR -* @param dev_desc - block device descriptor +* @param desc - block device descriptor * * Return: - zero on success, otherwise error */ -static int set_protective_mbr (struct blk_desc *dev_desc) +static int set_protective_mbr (struct blk_desc *desc) {/* Setup the Protective MBR */ -ALLOC_CACHE_ALIGN_BUFFER_PAD (legacy_mbr, p_mbr,1 , dev_desc->blksz); +ALLOC_CACHE_ALIGN_BUFFER_PAD (legacy_mbr, p_mbr,1 , desc->blksz);if (p_mbr ==NULL ) {log_debug ("calloc failed!\n" );return -ENOMEM ; }/* Read MBR to backup boot code if it exists */ -if (blk_dread (dev_desc,0 ,1 , p_mbr) !=1 ) { +if (blk_dread (desc,0 ,1 , p_mbr) !=1 ) {log_debug ("** Can't read from device %d **\n" , - dev_desc->devnum); + desc->devnum);return -EIO ; }
@@ -348,27 +348,26 @@ static int set_protective_mbr(struct blk_desc *dev_desc) p_mbr->signature =MSDOS_MBR_SIGNATURE ; p_mbr->partition_record[0 ].sys_ind =EFI_PMBR_OSTYPE_EFI_GPT ; p_mbr->partition_record[0 ].start_sect =1 ; - p_mbr->partition_record[0 ].nr_sects = (u32 ) dev_desc->lba -1 ; + p_mbr->partition_record[0 ].nr_sects = (u32 )desc->lba -1 ;/* Write MBR sector to the MMC device */ -if (blk_dwrite (dev_desc,0 ,1 , p_mbr) !=1 ) { -log_debug ("** Can't write to device %d **\n" , dev_desc->devnum); +if (blk_dwrite (desc,0 ,1 , p_mbr) !=1 ) { +log_debug ("** Can't write to device %d **\n" , desc->devnum);return -EIO ; }return 0 ; } -int write_gpt_table (struct blk_desc *dev_desc, -gpt_header *gpt_h,gpt_entry *gpt_e) +int write_gpt_table (struct blk_desc *desc,gpt_header *gpt_h,gpt_entry *gpt_e) {const int pte_blk_cnt =BLOCK_CNT ((gpt_h->num_partition_entries - *sizeof (gpt_entry)), dev_desc); + *sizeof (gpt_entry)), desc);u32 calc_crc32; -debug ("max lba: %x\n" , (u32 ) dev_desc->lba); +debug ("max lba: %x\n" , (u32 )desc->lba);/* Setup the Protective MBR */ -if (set_protective_mbr (dev_desc) <0 ) +if (set_protective_mbr (desc) <0 ) goto err;/* Generate CRC for the Primary GPT Header */
@@ -382,20 +381,20 @@ int write_gpt_table(struct blk_desc *dev_desc, gpt_h->header_crc32 =cpu_to_le32 (calc_crc32);/* Write the First GPT to the block right after the Legacy MBR */ -if (blk_dwrite (dev_desc,1 ,1 , gpt_h) !=1 ) +if (blk_dwrite (desc,1 ,1 , gpt_h) !=1 ) goto err; -if (blk_dwrite (dev_desc,le64_to_cpu (gpt_h->partition_entry_lba), +if (blk_dwrite (desc,le64_to_cpu (gpt_h->partition_entry_lba), pte_blk_cnt, gpt_e) != pte_blk_cnt) goto err;prepare_backup_gpt_header (gpt_h); -if (blk_dwrite (dev_desc, (lbaint_t )le64_to_cpu (gpt_h->last_usable_lba) +if (blk_dwrite (desc, (lbaint_t )le64_to_cpu (gpt_h->last_usable_lba) +1 , pte_blk_cnt, gpt_e) != pte_blk_cnt) goto err; -if (blk_dwrite (dev_desc, (lbaint_t )le64_to_cpu (gpt_h->my_lba),1 , +if (blk_dwrite (desc, (lbaint_t )le64_to_cpu (gpt_h->my_lba),1 , gpt_h) !=1 ) goto err;
@@ -403,11 +402,11 @@ int write_gpt_table(struct blk_desc *dev_desc,return 0 ; err: -log_debug ("** Can't write to device %d **\n" , dev_desc->devnum); +log_debug ("** Can't write to device %d **\n" , desc->devnum);return -EIO ; } -int gpt_fill_pte (struct blk_desc *dev_desc, +int gpt_fill_pte (struct blk_desc *desc,gpt_header *gpt_h,gpt_entry *gpt_e,struct disk_partition *partitions,int parts) {
@@ -430,7 +429,7 @@ int gpt_fill_pte(struct blk_desc *dev_desc,size_t pte_start = gpt_h->partition_entry_lba;size_t pte_end = pte_start + gpt_h->num_partition_entries * gpt_h->sizeof_partition_entry / - dev_desc->blksz; + desc->blksz;for (i =0 ; i < parts; i++) {/* partition starting lba */
@@ -527,7 +526,7 @@ int gpt_fill_pte(struct blk_desc *dev_desc,return 0 ; } -static uint32_t partition_entries_offset (struct blk_desc *dev_desc) +static uint32_t partition_entries_offset (struct blk_desc *desc) {uint32_t offset_blks =2 ;uint32_t __maybe_unused offset_bytes;
@@ -543,8 +542,8 @@ static uint32_t partition_entries_offset(struct blk_desc *dev_desc)* CONFIG_EFI_PARTITION_ENTRIES_OFF. */ offset_bytes = -PAD_TO_BLOCKSIZE (CONFIG_EFI_PARTITION_ENTRIES_OFF , dev_desc); - offset_blks = offset_bytes / dev_desc->blksz; +PAD_TO_BLOCKSIZE (CONFIG_EFI_PARTITION_ENTRIES_OFF , desc); + offset_blks = offset_bytes / desc->blksz;#endif #if defined(CONFIG_OF_CONTROL )
@@ -556,8 +555,8 @@ static uint32_t partition_entries_offset(struct blk_desc *dev_desc) config_offset =ofnode_conf_read_int ("u-boot,efi-partition-entries-offset" , -EINVAL );if (config_offset != -EINVAL ) { - offset_bytes =PAD_TO_BLOCKSIZE (config_offset, dev_desc); - offset_blks = offset_bytes / dev_desc->blksz; + offset_bytes =PAD_TO_BLOCKSIZE (config_offset, desc); + offset_blks = offset_bytes / desc->blksz; }#endif
@@ -573,17 +572,17 @@ static uint32_t partition_entries_offset(struct blk_desc *dev_desc)return offset_blks; } -int gpt_fill_header (struct blk_desc *dev_desc,gpt_header *gpt_h, -char *str_guid,int parts_count) +int gpt_fill_header (struct blk_desc *desc,gpt_header *gpt_h,char *str_guid, +int parts_count) { gpt_h->signature =cpu_to_le64 (GPT_HEADER_SIGNATURE_UBOOT ); gpt_h->revision =cpu_to_le32 (GPT_HEADER_REVISION_V1 ); gpt_h->header_size =cpu_to_le32 (sizeof (gpt_header)); gpt_h->my_lba =cpu_to_le64 (1 ); - gpt_h->alternate_lba =cpu_to_le64 (dev_desc->lba -1 ); - gpt_h->last_usable_lba =cpu_to_le64 (dev_desc->lba -34 ); + gpt_h->alternate_lba =cpu_to_le64 (desc->lba -1 ); + gpt_h->last_usable_lba =cpu_to_le64 (desc->lba -34 ); gpt_h->partition_entry_lba = -cpu_to_le64 (partition_entries_offset (dev_desc)); +cpu_to_le64 (partition_entries_offset (desc)); gpt_h->first_usable_lba =cpu_to_le64 (le64_to_cpu (gpt_h->partition_entry_lba) +32 ); gpt_h->num_partition_entries =cpu_to_le32 (GPT_ENTRY_NUMBERS );
@@ -597,14 +596,14 @@ int gpt_fill_header(struct blk_desc *dev_desc, gpt_header *gpt_h,return 0 ; } -int gpt_restore (struct blk_desc *dev_desc,char *str_disk_guid, +int gpt_restore (struct blk_desc *desc,char *str_disk_guid,struct disk_partition *partitions,int parts_count) {gpt_header *gpt_h;gpt_entry *gpt_e;int ret, size; - size =PAD_TO_BLOCKSIZE (sizeof (gpt_header), dev_desc); + size =PAD_TO_BLOCKSIZE (sizeof (gpt_header), desc); gpt_h =malloc_cache_aligned (size);if (gpt_h ==NULL ) {log_debug ("calloc failed!\n" );
@@ -613,7 +612,7 @@ int gpt_restore(struct blk_desc *dev_desc, char *str_disk_guid,memset (gpt_h,0 , size); size =PAD_TO_BLOCKSIZE (GPT_ENTRY_NUMBERS *sizeof (gpt_entry), - dev_desc); + desc); gpt_e =malloc_cache_aligned (size);if (gpt_e ==NULL ) {log_debug ("calloc failed!\n" );
@@ -623,17 +622,17 @@ int gpt_restore(struct blk_desc *dev_desc, char *str_disk_guid,memset (gpt_e,0 , size);/* Generate Primary GPT header (LBA1) */ - ret =gpt_fill_header (dev_desc, gpt_h, str_disk_guid, parts_count); + ret =gpt_fill_header (desc, gpt_h, str_disk_guid, parts_count);if (ret) goto err;/* Generate partition entries */ - ret =gpt_fill_pte (dev_desc, gpt_h, gpt_e, partitions, parts_count); + ret =gpt_fill_pte (desc, gpt_h, gpt_e, partitions, parts_count);if (ret) goto err;/* Write GPT partition table */ - ret =write_gpt_table (dev_desc, gpt_h, gpt_e); + ret =write_gpt_table (desc, gpt_h, gpt_e); err:free (gpt_e);
@@ -664,14 +663,14 @@ static void gpt_convert_efi_name_to_char(char *s, void *es, int n) } } -int gpt_verify_headers (struct blk_desc *dev_desc,gpt_header *gpt_head, +int gpt_verify_headers (struct blk_desc *desc,gpt_header *gpt_head,gpt_entry **gpt_pte) {/* * This function validates AND * fills in the GPT header and PTE */ -if (is_gpt_valid (dev_desc, +if (is_gpt_valid (desc,GPT_PRIMARY_PARTITION_TABLE_LBA , gpt_head, gpt_pte) !=1 ) {log_debug ("Invalid GPT\n" );
@@ -684,12 +683,12 @@ int gpt_verify_headers(struct blk_desc *dev_desc, gpt_header *gpt_head,/* * Check that the alternate_lba entry points to the last LBA */ -if (le64_to_cpu (gpt_head->alternate_lba) != (dev_desc->lba -1 )) { +if (le64_to_cpu (gpt_head->alternate_lba) != (desc->lba -1 )) {log_debug ("Misplaced Backup GPT\n" );return -1 ; } -if (is_gpt_valid (dev_desc, (dev_desc->lba -1 ), +if (is_gpt_valid (desc, (desc->lba -1 ), gpt_head, gpt_pte) !=1 ) {log_debug ("Invalid Backup GPT\n" );return -1 ;
@@ -698,7 +697,7 @@ int gpt_verify_headers(struct blk_desc *dev_desc, gpt_header *gpt_head,return 0 ; } -static void restore_primary_gpt_header (gpt_header *gpt_h,struct blk_desc *dev_desc) +static void restore_primary_gpt_header (gpt_header *gpt_h,struct blk_desc *desc) {u32 calc_crc32;u64 val;
@@ -707,7 +706,7 @@ static void restore_primary_gpt_header(gpt_header *gpt_h, struct blk_desc *dev_d val =le64_to_cpu (gpt_h->my_lba); gpt_h->my_lba = gpt_h->alternate_lba; gpt_h->alternate_lba =cpu_to_le64 (val); - gpt_h->partition_entry_lba =cpu_to_le64 (partition_entries_offset (dev_desc)); + gpt_h->partition_entry_lba =cpu_to_le64 (partition_entries_offset (desc)); gpt_h->header_crc32 =0 ;
@@ -716,22 +715,22 @@ static void restore_primary_gpt_header(gpt_header *gpt_h, struct blk_desc *dev_d gpt_h->header_crc32 =cpu_to_le32 (calc_crc32); } -static int write_one_gpt_table (struct blk_desc *dev_desc, -gpt_header *gpt_h,gpt_entry *gpt_e) +static int write_one_gpt_table (struct blk_desc *desc,gpt_header *gpt_h, +gpt_entry *gpt_e) {const int pte_blk_cnt =BLOCK_CNT ((gpt_h->num_partition_entries - *sizeof (gpt_entry)), dev_desc); + *sizeof (gpt_entry)), desc);lbaint_t start;int ret =0 ; start =le64_to_cpu (gpt_h->my_lba); -if (blk_dwrite (dev_desc, start,1 , gpt_h) !=1 ) { +if (blk_dwrite (desc, start,1 , gpt_h) !=1 ) { ret =-1 ; goto out; } start =le64_to_cpu (gpt_h->partition_entry_lba); -if (blk_dwrite (dev_desc, start, pte_blk_cnt, gpt_e) != pte_blk_cnt) { +if (blk_dwrite (desc, start, pte_blk_cnt, gpt_e) != pte_blk_cnt) { ret =-1 ; goto out; }
@@ -740,17 +739,17 @@ static int write_one_gpt_table(struct blk_desc *dev_desc,return ret; } -int gpt_repair_headers (struct blk_desc *dev_desc) +int gpt_repair_headers (struct blk_desc *desc) { -ALLOC_CACHE_ALIGN_BUFFER_PAD (gpt_header, gpt_h1,1 , dev_desc->blksz); -ALLOC_CACHE_ALIGN_BUFFER_PAD (gpt_header, gpt_h2,1 , dev_desc->blksz); +ALLOC_CACHE_ALIGN_BUFFER_PAD (gpt_header, gpt_h1,1 , desc->blksz); +ALLOC_CACHE_ALIGN_BUFFER_PAD (gpt_header, gpt_h2,1 , desc->blksz);gpt_entry *gpt_e1 =NULL , *gpt_e2 =NULL ;int is_gpt1_valid, is_gpt2_valid;int ret =-1 ; - is_gpt1_valid =is_gpt_valid (dev_desc,GPT_PRIMARY_PARTITION_TABLE_LBA , + is_gpt1_valid =is_gpt_valid (desc,GPT_PRIMARY_PARTITION_TABLE_LBA , gpt_h1, &gpt_e1); - is_gpt2_valid =is_gpt_valid (dev_desc, dev_desc->lba -1 , + is_gpt2_valid =is_gpt_valid (desc, desc->lba -1 , gpt_h2, &gpt_e2);if (is_gpt1_valid && is_gpt2_valid) {
@@ -760,13 +759,13 @@ int gpt_repair_headers(struct blk_desc *dev_desc)if (is_gpt1_valid && !is_gpt2_valid) {prepare_backup_gpt_header (gpt_h1); - ret =write_one_gpt_table (dev_desc, gpt_h1, gpt_e1); + ret =write_one_gpt_table (desc, gpt_h1, gpt_e1); goto out; }if (!is_gpt1_valid && is_gpt2_valid) { -restore_primary_gpt_header (gpt_h2, dev_desc); - ret =write_one_gpt_table (dev_desc, gpt_h2, gpt_e2); +restore_primary_gpt_header (gpt_h2, desc); + ret =write_one_gpt_table (desc, gpt_h2, gpt_e2); goto out; }
@@ -784,7 +783,7 @@ int gpt_repair_headers(struct blk_desc *dev_desc)return ret; } -int gpt_verify_partitions (struct blk_desc *dev_desc, +int gpt_verify_partitions (struct blk_desc *desc,struct disk_partition *partitions,int parts,gpt_header *gpt_head,gpt_entry **gpt_pte) {
@@ -793,7 +792,7 @@ int gpt_verify_partitions(struct blk_desc *dev_desc,gpt_entry *gpt_e;int ret, i; - ret =gpt_verify_headers (dev_desc, gpt_head, gpt_pte); + ret =gpt_verify_headers (desc, gpt_head, gpt_pte);if (ret)return ret;
@@ -862,28 +861,27 @@ int gpt_verify_partitions(struct blk_desc *dev_desc,return 0 ; } -int is_valid_gpt_buf (struct blk_desc *dev_desc,void *buf) +int is_valid_gpt_buf (struct blk_desc *desc,void *buf) {gpt_header *gpt_h;gpt_entry *gpt_e;/* determine start of GPT Header in the buffer */ - gpt_h = buf + (GPT_PRIMARY_PARTITION_TABLE_LBA * - dev_desc->blksz); + gpt_h = buf + (GPT_PRIMARY_PARTITION_TABLE_LBA * desc->blksz);if (validate_gpt_header (gpt_h,GPT_PRIMARY_PARTITION_TABLE_LBA , - dev_desc->lba)) + desc->lba))return -1 ;/* determine start of GPT Entries in the buffer */ gpt_e = buf + (le64_to_cpu (gpt_h->partition_entry_lba) * - dev_desc->blksz); + desc->blksz);if (validate_gpt_entries (gpt_h, gpt_e))return -1 ;return 0 ; } -int write_mbr_and_gpt_partitions (struct blk_desc *dev_desc,void *buf) +int write_mbr_and_gpt_partitions (struct blk_desc *desc,void *buf) {gpt_header *gpt_h;gpt_entry *gpt_e;
@@ -891,24 +889,22 @@ int write_mbr_and_gpt_partitions(struct blk_desc *dev_desc, void *buf)lbaint_t lba;int cnt; -if (is_valid_gpt_buf (dev_desc, buf)) +if (is_valid_gpt_buf (desc, buf))return -1 ;/* determine start of GPT Header in the buffer */ - gpt_h = buf + (GPT_PRIMARY_PARTITION_TABLE_LBA * - dev_desc->blksz); + gpt_h = buf + (GPT_PRIMARY_PARTITION_TABLE_LBA * desc->blksz);/* determine start of GPT Entries in the buffer */ - gpt_e = buf + (le64_to_cpu (gpt_h->partition_entry_lba) * - dev_desc->blksz); + gpt_e = buf + (le64_to_cpu (gpt_h->partition_entry_lba) * desc->blksz); gpt_e_blk_cnt =BLOCK_CNT ((le32_to_cpu (gpt_h->num_partition_entries) *le32_to_cpu (gpt_h->sizeof_partition_entry)), - dev_desc); + desc);/* write MBR */ lba =0 ;/* MBR is always at 0 */ cnt =1 ;/* MBR (1 block) */ -if (blk_dwrite (dev_desc, lba, cnt, buf) != cnt) { +if (blk_dwrite (desc, lba, cnt, buf) != cnt) {log_debug ("failed writing '%s' (%d blks at 0x" LBAF ")\n" ,"MBR" , cnt, lba);return 1 ;
@@ -917,7 +913,7 @@ int write_mbr_and_gpt_partitions(struct blk_desc *dev_desc, void *buf)/* write Primary GPT */ lba =GPT_PRIMARY_PARTITION_TABLE_LBA ; cnt =1 ;/* GPT Header (1 block) */ -if (blk_dwrite (dev_desc, lba, cnt, gpt_h) != cnt) { +if (blk_dwrite (desc, lba, cnt, gpt_h) != cnt) {log_debug ("failed writing '%s' (%d blks at 0x" LBAF ")\n" ,"Primary GPT Header" , cnt, lba);return 1 ;
@@ -925,7 +921,7 @@ int write_mbr_and_gpt_partitions(struct blk_desc *dev_desc, void *buf) lba =le64_to_cpu (gpt_h->partition_entry_lba); cnt = gpt_e_blk_cnt; -if (blk_dwrite (dev_desc, lba, cnt, gpt_e) != cnt) { +if (blk_dwrite (desc, lba, cnt, gpt_e) != cnt) {log_debug ("failed writing '%s' (%d blks at 0x" LBAF ")\n" ,"Primary GPT Entries" , cnt, lba);return 1 ;
@@ -936,7 +932,7 @@ int write_mbr_and_gpt_partitions(struct blk_desc *dev_desc, void *buf)/* write Backup GPT */ lba =le64_to_cpu (gpt_h->partition_entry_lba); cnt = gpt_e_blk_cnt; -if (blk_dwrite (dev_desc, lba, cnt, gpt_e) != cnt) { +if (blk_dwrite (desc, lba, cnt, gpt_e) != cnt) {log_debug ("failed writing '%s' (%d blks at 0x" LBAF ")\n" ,"Backup GPT Entries" , cnt, lba);return 1 ;
@@ -944,14 +940,14 @@ int write_mbr_and_gpt_partitions(struct blk_desc *dev_desc, void *buf) lba =le64_to_cpu (gpt_h->my_lba); cnt =1 ;/* GPT Header (1 block) */ -if (blk_dwrite (dev_desc, lba, cnt, gpt_h) != cnt) { +if (blk_dwrite (desc, lba, cnt, gpt_h) != cnt) {log_debug ("failed writing '%s' (%d blks at 0x" LBAF ")\n" ,"Backup GPT Header" , cnt, lba);return 1 ; }/* Update the partition table entries*/ -part_init (dev_desc); +part_init (desc);return 0 ; }
@@ -1008,25 +1004,25 @@ static int is_pmbr_valid(legacy_mbr * mbr)* Description: returns 1 if valid, 0 on error, 2 if ignored header * If valid, returns pointers to PTEs. */ -static int is_gpt_valid (struct blk_desc *dev_desc,u64 lba, -gpt_header *pgpt_head,gpt_entry **pgpt_pte) +static int is_gpt_valid (struct blk_desc *desc,u64 lba,gpt_header *pgpt_head, +gpt_entry **pgpt_pte) {/* Confirm valid arguments prior to allocation. */ -if (!dev_desc || !pgpt_head) { +if (!desc || !pgpt_head) {log_debug ("Invalid Argument(s)\n" );return 0 ; } -ALLOC_CACHE_ALIGN_BUFFER_PAD (legacy_mbr, mbr,1 , dev_desc->blksz); +ALLOC_CACHE_ALIGN_BUFFER_PAD (legacy_mbr, mbr,1 , desc->blksz);/* Read MBR Header from device */ -if (blk_dread (dev_desc,0 ,1 , (ulong *)mbr) !=1 ) { +if (blk_dread (desc,0 ,1 , (ulong *)mbr) !=1 ) {log_debug ("Can't read MBR header\n" );return 0 ; }/* Read GPT Header from device */ -if (blk_dread (dev_desc, (lbaint_t )lba,1 , pgpt_head) !=1 ) { +if (blk_dread (desc, (lbaint_t )lba,1 , pgpt_head) !=1 ) {log_debug ("Can't read GPT header\n" );return 0 ; }
@@ -1037,23 +1033,23 @@ static int is_gpt_valid(struct blk_desc *dev_desc, u64 lba,return 2 ; } -if (validate_gpt_header (pgpt_head, (lbaint_t )lba, dev_desc->lba)) +if (validate_gpt_header (pgpt_head, (lbaint_t )lba, desc->lba))return 0 ; -if (dev_desc->sig_type ==SIG_TYPE_NONE ) { +if (desc->sig_type ==SIG_TYPE_NONE ) {efi_guid_t empty = {};if (memcmp (&pgpt_head->disk_guid, &empty,sizeof (empty))) { - dev_desc->sig_type =SIG_TYPE_GUID ; -memcpy (&dev_desc->guid_sig, &pgpt_head->disk_guid, -sizeof (empty)); + desc->sig_type =SIG_TYPE_GUID ; +memcpy (&desc->guid_sig, &pgpt_head->disk_guid, +sizeof (empty)); }else if (mbr->unique_mbr_signature !=0 ) { - dev_desc->sig_type =SIG_TYPE_MBR ; - dev_desc->mbr_sig = mbr->unique_mbr_signature; + desc->sig_type =SIG_TYPE_MBR ; + desc->mbr_sig = mbr->unique_mbr_signature; } }/* Read and allocate Partition Table Entries */ - *pgpt_pte =alloc_read_gpt_entries (dev_desc, pgpt_head); + *pgpt_pte =alloc_read_gpt_entries (desc, pgpt_head);if (!*pgpt_pte)return 0 ;
@@ -1075,20 +1071,20 @@ static int is_gpt_valid(struct blk_desc *dev_desc, u64 lba,* Description: returns 1 if found a valid gpt, 0 on error. * If valid, returns pointers to PTEs. */ -static int find_valid_gpt (struct blk_desc *dev_desc,gpt_header *gpt_head, +static int find_valid_gpt (struct blk_desc *desc,gpt_header *gpt_head,gpt_entry **pgpt_pte) {int r; - r =is_gpt_valid (dev_desc,GPT_PRIMARY_PARTITION_TABLE_LBA , gpt_head, + r =is_gpt_valid (desc,GPT_PRIMARY_PARTITION_TABLE_LBA , gpt_head, pgpt_pte);if (r !=1 ) {if (r !=2 )log_debug ("Invalid GPT\n" ); -if (is_gpt_valid (dev_desc, (dev_desc->lba -1 ), gpt_head, - pgpt_pte) !=1 ) { +if (is_gpt_valid (desc, desc->lba -1 , gpt_head, pgpt_pte) + !=1 ) {log_debug ("Invalid Backup GPT\n" );return 0 ; }
@@ -1100,21 +1096,21 @@ static int find_valid_gpt(struct blk_desc *dev_desc, gpt_header *gpt_head,/** * alloc_read_gpt_entries(): reads partition entries from disk -* @dev_desc +* @desc * @gpt - GPT header * * Description: Returns ptes on success, NULL on error. * Allocates space for PTEs based on information found in @gpt. * Notes: remember to free pte when you're done! */ -static gpt_entry *alloc_read_gpt_entries (struct blk_desc *dev_desc, +static gpt_entry *alloc_read_gpt_entries (struct blk_desc *desc,gpt_header *pgpt_head) {size_t count =0 , blk_cnt;lbaint_t blk;gpt_entry *pte =NULL ; -if (!dev_desc || !pgpt_head) { +if (!desc || !pgpt_head) {log_debug ("Invalid Argument(s)\n" );return NULL ; }
@@ -1130,7 +1126,7 @@ static gpt_entry *alloc_read_gpt_entries(struct blk_desc *dev_desc,/* Allocate memory for PTE, remember to FREE */ if (count !=0 ) { pte =memalign (ARCH_DMA_MINALIGN , -PAD_TO_BLOCKSIZE (count, dev_desc)); +PAD_TO_BLOCKSIZE (count, desc)); }if (count ==0 || pte ==NULL ) {
@@ -1141,8 +1137,8 @@ static gpt_entry *alloc_read_gpt_entries(struct blk_desc *dev_desc,/* Read GPT Entries from device */ blk =le64_to_cpu (pgpt_head->partition_entry_lba); - blk_cnt =BLOCK_CNT (count, dev_desc); -if (blk_dread (dev_desc, blk, (lbaint_t )blk_cnt, pte) != blk_cnt) { + blk_cnt =BLOCK_CNT (count, desc); +if (blk_dread (desc, blk, (lbaint_t )blk_cnt, pte) != blk_cnt) {log_debug ("Can't read GPT Entries\n" );free (pte);return NULL ;
Signature · 1 line
2.41.0.640.ga95def55d0-goog
PATCH 5/24 part: iso: Use desc instead of dev_desc
In reply to Simon GlassThe dev_ prefix is a hangover from the pre-driver model days. The device is now a different thing, with driver model. Update the iso code to just use 'desc'.
---
disk/part_iso.c | 52 ++++++++++++++++++++++++------------------------- 1 file changed, 26 insertions(+), 26 deletions(-)
disk/part_iso.c +26 -26
@@ -46,7 +46,7 @@ unsigned long iso_dread(struct blk_desc *block_dev, lbaint_t start, }/* only boot records will be listed as valid partitions */ -int part_get_info_iso_verb (struct blk_desc *dev_desc,int part_num, +int part_get_info_iso_verb (struct blk_desc *desc,int part_num,struct disk_partition *info,int verb) {int i,offset,entry_num;
@@ -58,23 +58,23 @@ int part_get_info_iso_verb(struct blk_desc *dev_desc, int part_num,iso_val_entry_t *pve = (iso_val_entry_t *)tmpbuf;iso_init_def_entry_t *pide; -if ((dev_desc->blksz !=CD_SECTSIZE ) && (dev_desc->blksz !=512 )) +if (desc->blksz !=CD_SECTSIZE && desc->blksz !=512 )return -1 ;/* the first sector (sector 0x10) must be a primary volume desc */ blkaddr=PVD_OFFSET ; -if (iso_dread (dev_desc,PVD_OFFSET ,1 , (ulong *)tmpbuf) !=1 ) +if (iso_dread (desc,PVD_OFFSET ,1 , (ulong *)tmpbuf) !=1 )return -1 ;if (ppr->desctype!=0x01 ) {if (verb)printf ("** First descriptor is NOT a primary desc on %d:%d **\n" , - dev_desc->devnum, part_num); + desc->devnum, part_num);return (-1 ); }if (strncmp ((char *)ppr->stand_ident,"CD001" ,5 )!=0 ) {if (verb)printf ("** Wrong ISO Ident: %s on %d:%d **\n" , - ppr->stand_ident, dev_desc->devnum, part_num); + ppr->stand_ident, desc->devnum, part_num);return (-1 ); } lastsect =le32_to_cpu (ppr->firstsek_LEpathtab1_LE);
@@ -83,14 +83,14 @@ int part_get_info_iso_verb(struct blk_desc *dev_desc, int part_num,PRINTF (" Lastsect:%08lx\n" ,lastsect);for (i=blkaddr;i<lastsect;i++) {PRINTF ("Reading block %d\n" , i); -if (iso_dread (dev_desc, i,1 , (ulong *)tmpbuf) !=1 ) +if (iso_dread (desc, i,1 , (ulong *)tmpbuf) !=1 )return -1 ;if (ppr->desctype==0x00 )break ;/* boot entry found */ if (ppr->desctype==0xff ) {if (verb)printf ("** No valid boot catalog found on %d:%d **\n" , - dev_desc->devnum, part_num); + desc->devnum, part_num);return (-1 ); } }
@@ -98,15 +98,15 @@ int part_get_info_iso_verb(struct blk_desc *dev_desc, int part_num,if (strncmp (pbr->ident_str,"EL TORITO SPECIFICATION" ,23 )!=0 ) {if (verb)printf ("** Wrong El Torito ident: %s on %d:%d **\n" , - pbr->ident_str, dev_desc->devnum, part_num); + pbr->ident_str, desc->devnum, part_num);return (-1 ); } bootaddr =get_unaligned_le32 (pbr->pointer);PRINTF (" Boot Entry at: %08lX\n" ,bootaddr); -if (iso_dread (dev_desc, bootaddr,1 , (ulong *)tmpbuf) !=1 ) { +if (iso_dread (desc, bootaddr,1 , (ulong *)tmpbuf) !=1 ) {if (verb)printf ("** Can't read Boot Entry at %lX on %d:%d **\n" , - bootaddr, dev_desc->devnum, part_num); + bootaddr, desc->devnum, part_num);return (-1 ); } chksum=0 ;
@@ -116,20 +116,20 @@ int part_get_info_iso_verb(struct blk_desc *dev_desc, int part_num,if (chksum!=0 ) {if (verb)printf ("** Checksum Error in booting catalog validation entry on %d:%d **\n" , - dev_desc->devnum, part_num); + desc->devnum, part_num);return (-1 ); }if ((pve->key[0 ]!=0x55 )||(pve->key[1 ]!=0xAA )) {if (verb)printf ("** Key 0x55 0xAA error on %d:%d **\n" , - dev_desc->devnum, part_num); + desc->devnum, part_num);return (-1 ); }#ifdef CHECK_FOR_POWERPC_PLATTFORM if (pve->platform!=0x01 ) {if (verb)printf ("** No PowerPC platform CD on %d:%d **\n" , - dev_desc->devnum, part_num); + desc->devnum, part_num);return (-1 ); }#endif
@@ -137,7 +137,7 @@ int part_get_info_iso_verb(struct blk_desc *dev_desc, int part_num, entry_num=1 ; offset=0x20 ;strcpy ((char *)info->type,"U-Boot" ); -part_set_generic_name (dev_desc, part_num, (char *)info->name); +part_set_generic_name (desc, part_num, (char *)info->name);/* the bootcatalog (including validation Entry) is limited to 2048Bytes * (63 boot entries + validation entry) */ while (offset<2048 ) {
@@ -159,7 +159,7 @@ int part_get_info_iso_verb(struct blk_desc *dev_desc, int part_num,else {if (verb)printf ("** Partition %d not found on device %d **\n" , - part_num, dev_desc->devnum); + part_num, desc->devnum);return (-1 ); } }
@@ -167,13 +167,13 @@ int part_get_info_iso_verb(struct blk_desc *dev_desc, int part_num,* searched w/o succsess */ if (verb)printf ("** Partition %d not found on device %d **\n" , - part_num, dev_desc->devnum); + part_num, desc->devnum);return (-1 ); found:if (pide->boot_ind!=0x88 ) {if (verb)printf ("** Partition %d is not bootable on device %d **\n" , - part_num, dev_desc->devnum); + part_num, desc->devnum);return (-1 ); }switch (pide->boot_media) {
@@ -189,7 +189,7 @@ found: newblkaddr =get_unaligned_le32 (pide->rel_block_addr); info->start=newblkaddr; -if (dev_desc->blksz ==512 ) { +if (desc->blksz ==512 ) { info->size *=4 ; info->start *=4 ; info->blksz =512 ;
@@ -199,20 +199,20 @@ found:return 0 ; } -static int part_get_info_iso (struct blk_desc *dev_desc,int part_num, +static int part_get_info_iso (struct blk_desc *desc,int part_num,struct disk_partition *info) { -return part_get_info_iso_verb (dev_desc, part_num, info,0 ); +return part_get_info_iso_verb (desc, part_num, info,0 ); } -static void part_print_iso (struct blk_desc *dev_desc) +static void part_print_iso (struct blk_desc *desc) {struct disk_partition info;int i; -if (part_get_info_iso_verb (dev_desc,1 , &info,0 ) ==-1 ) { +if (part_get_info_iso_verb (desc,1 , &info,0 ) ==-1 ) {printf ("** No boot partition found on device %d **\n" , - dev_desc->devnum); + desc->devnum);return ; }printf ("Part Start Sect x Size Type\n" );
@@ -221,14 +221,14 @@ static void part_print_iso(struct blk_desc *dev_desc)printf (" %2d %8" LBAFlength"u %8" LBAFlength"u %6ld %.32s\n" , i, info.start, info.size, info.blksz, info.type); i++; - }while (part_get_info_iso_verb (dev_desc, i, &info,0 ) !=-1 ); + }while (part_get_info_iso_verb (desc, i, &info,0 ) !=-1 ); } -static int part_test_iso (struct blk_desc *dev_desc) +static int part_test_iso (struct blk_desc *desc) {struct disk_partition info; -return part_get_info_iso_verb (dev_desc,1 , &info,0 ); +return part_get_info_iso_verb (desc,1 , &info,0 ); }U_BOOT_PART_TYPE (iso) = {
Signature · 1 line
2.41.0.640.ga95def55d0-goog
PATCH 6/24 part: nac: Use desc instead of dev_desc
In reply to Simon GlassThe dev_ prefix is a hangover from the pre-driver model days. The device is now a different thing, with driver model. Update the mac code to just use 'desc'.
---
disk/part_mac.c | 59 ++++++++++++++++++++++--------------------------- 1 file changed, 27 insertions(+), 32 deletions(-)
disk/part_mac.c +27 -32
@@ -31,21 +31,20 @@ extern ldiv_t ldiv (long int __numer, long int __denom);#endif -static int part_mac_read_ddb (struct blk_desc *dev_desc, -mac_driver_desc_t *ddb_p); -static int part_mac_read_pdb (struct blk_desc *dev_desc,int part, +static int part_mac_read_ddb (struct blk_desc *desc,mac_driver_desc_t *ddb_p); +static int part_mac_read_pdb (struct blk_desc *desc,int part,mac_partition_t *pdb_p);/* * Test for a valid MAC partition */ -static int part_test_mac (struct blk_desc *dev_desc) +static int part_test_mac (struct blk_desc *desc) {ALLOC_CACHE_ALIGN_BUFFER (mac_driver_desc_t, ddesc,1 );ALLOC_CACHE_ALIGN_BUFFER (mac_partition_t, mpart,1 );ulong i, n; -if (part_mac_read_ddb (dev_desc, ddesc)) { +if (part_mac_read_ddb (desc, ddesc)) {/* * error reading Driver Descriptor Block, * or no valid Signature
@@ -55,8 +54,8 @@ static int part_test_mac(struct blk_desc *dev_desc) n =1 ;/* assuming at least one partition */ for (i=1 ; i<=n; ++i) { -if ((blk_dread (dev_desc, i,1 , (ulong *)mpart) !=1 ) || - (mpart->signature !=MAC_PARTITION_MAGIC ) ) { +if ((blk_dread (desc, i,1 , (ulong *)mpart) !=1 ) || + mpart->signature !=MAC_PARTITION_MAGIC ) {return (-1 ); }/* update partition count */
@@ -65,14 +64,14 @@ static int part_test_mac(struct blk_desc *dev_desc)return (0 ); } -static void part_print_mac (struct blk_desc *dev_desc) +static void part_print_mac (struct blk_desc *desc) {ulong i, n;ALLOC_CACHE_ALIGN_BUFFER (mac_driver_desc_t, ddesc,1 );ALLOC_CACHE_ALIGN_BUFFER (mac_partition_t, mpart,1 );ldiv_t mb, gb; -if (part_mac_read_ddb (dev_desc, ddesc)) { +if (part_mac_read_ddb (desc, ddesc)) {/* * error reading Driver Descriptor Block, * or no valid Signature
@@ -110,15 +109,15 @@ static void part_print_mac(struct blk_desc *dev_desc)char c;printf ("%4ld: " , i); -if (blk_dread (dev_desc, i,1 , (ulong *)mpart) !=1 ) { +if (blk_dread (desc, i,1 , (ulong *)mpart) !=1 ) {printf ("** Can't read Partition Map on %d:%ld **\n" , - dev_desc->devnum, i); + desc->devnum, i);return ; }if (mpart->signature !=MAC_PARTITION_MAGIC ) {printf ("** Bad Signature on %d:%ld - expected 0x%04x, got 0x%04x\n" , - dev_desc->devnum, i,MAC_PARTITION_MAGIC , + desc->devnum, i,MAC_PARTITION_MAGIC , mpart->signature);return ; }
@@ -154,10 +153,9 @@ static void part_print_mac(struct blk_desc *dev_desc)/* * Read Device Descriptor Block */ -static int part_mac_read_ddb (struct blk_desc *dev_desc, -mac_driver_desc_t *ddb_p) +static int part_mac_read_ddb (struct blk_desc *desc,mac_driver_desc_t *ddb_p) { -if (blk_dread (dev_desc,0 ,1 , (ulong *)ddb_p) !=1 ) { +if (blk_dread (desc,0 ,1 , (ulong *)ddb_p) !=1 ) {debug ("** Can't read Driver Descriptor Block **\n" );return (-1 ); }
@@ -171,7 +169,7 @@ static int part_mac_read_ddb(struct blk_desc *dev_desc,/* * Read Partition Descriptor Block */ -static int part_mac_read_pdb (struct blk_desc *dev_desc,int part, +static int part_mac_read_pdb (struct blk_desc *desc,int part,mac_partition_t *pdb_p) {int n =1 ;
@@ -182,15 +180,15 @@ static int part_mac_read_pdb(struct blk_desc *dev_desc, int part,* partition 1 first since this is the only way to * know how many partitions we have. */ -if (blk_dread (dev_desc, n,1 , (ulong *)pdb_p) !=1 ) { -printf ("** Can't read Partition Map on %d:%d **\n" , - dev_desc->devnum, n); +if (blk_dread (desc, n,1 , (ulong *)pdb_p) !=1 ) { +printf ("** Can't read Partition Map on %d:%d **\n" , + desc->devnum, n);return (-1 ); }if (pdb_p->signature !=MAC_PARTITION_MAGIC ) {printf ("** Bad Signature on %d:%d: expected 0x%04x, got 0x%04x\n" , - dev_desc->devnum, n,MAC_PARTITION_MAGIC , + desc->devnum, n,MAC_PARTITION_MAGIC , pdb_p->signature);return (-1 ); }
@@ -199,10 +197,9 @@ static int part_mac_read_pdb(struct blk_desc *dev_desc, int part,return (0 );if ((part <1 ) || (part > pdb_p->map_count)) { -printf ("** Invalid partition %d:%d [%d:1...%d:%d only]\n" , - dev_desc->devnum, part, - dev_desc->devnum, - dev_desc->devnum, pdb_p->map_count); +printf ("** Invalid partition %d:%d [%d:1...%d:%d only]\n" , + desc->devnum, part, desc->devnum, desc->devnum, + pdb_p->map_count);return (-1 ); }
@@ -213,21 +210,19 @@ static int part_mac_read_pdb(struct blk_desc *dev_desc, int part,/* NOTREACHED */ } -static int part_get_info_mac (struct blk_desc *dev_desc,int part, -struct disk_partition *info) +static int part_get_info_mac (struct blk_desc *desc,int part, +struct disk_partition *info) {ALLOC_CACHE_ALIGN_BUFFER (mac_driver_desc_t, ddesc,1 );ALLOC_CACHE_ALIGN_BUFFER (mac_partition_t, mpart,1 ); -if (part_mac_read_ddb (dev_desc, ddesc)) { -return (-1 ); - } +if (part_mac_read_ddb (desc, ddesc)) +return -1 ; info->blksz = ddesc->blk_size; -if (part_mac_read_pdb (dev_desc, part, mpart)) { -return (-1 ); - } +if (part_mac_read_pdb (desc, part, mpart)) +return -1 ; info->start = mpart->start_block; info->size = mpart->block_count;
Signature · 1 line
2.41.0.640.ga95def55d0-goog
PATCH 7/24 part: Add comments for static functions
In reply to Simon GlassSome internal functions could do with a few comments, to explain what they do. Add these, to make the code easier to follow.
---
disk/part.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+)
disk/part.c +32 -0
@@ -26,6 +26,12 @@/* Check all partition types */ #define PART_TYPE_ALL -1 +/** +* part_driver_get_type() - Get a driver given its type +* +* @part_type: Partition type to find the driver for +* Return: Driver for that type, or NULL if none +*/ static struct part_driver *part_driver_get_type (int part_type) { struct part_driver *drv =
@@ -42,6 +48,22 @@ static struct part_driver *part_driver_get_type(int part_type)return NULL ; } +/** +* part_driver_lookup_type() - Look up the partition driver for a blk device +* +* If @desc->part_type is PART_TYPE_UNKNOWN, this checks each parition driver +* against the blk device to see if there is a valid partition table acceptable +* to that driver. +* +* If @desc->part_type is already set, it just returns the driver for that +* type, without testing if the driver can find a valid partition on the +* descriptor. +* +* On success it updates @desc->part_type if set to PART_TYPE_UNKNOWN on entry +* +* @dev_desc: Device descriptor +* Return: Driver found, or NULL if none +*/ static struct part_driver *part_driver_lookup_type (struct blk_desc *desc) { struct part_driver *drv =
@@ -83,6 +105,16 @@ int part_get_type_by_name(const char *name)return PART_TYPE_UNKNOWN ; } +/** +* get_dev_hwpart() - Get the descriptor for a device with hardware partitions +* +* @ifname: Interface name (e.g. "ide", "scsi") +* @dev: Device number (0 for first device on that interface, 1 for +* second, etc. +* @hwpart: Hardware partition, or 0 if none (used for MMC) +* Return: pointer to the block device, or NULL if not available, or an +* error occurred. +*/ static struct blk_desc *get_dev_hwpart (const char *ifname,int dev,int hwpart) {struct blk_desc *desc;
Signature · 1 line
2.41.0.640.ga95def55d0-goog
PATCH 8/24 part: Add accessors for struct disk_partition uuid
In reply to Simon GlassThis field is only present when a CONFIG is set. To avoid annoying #ifdefs in the source code, add accessors. Update all code to use it.
Note that the accessor is optional. It can be omitted if it is known that the option is enabled.
---
cmd/gpt.c | 10 ++++------ disk/part.c | 8 ++------ disk/part_dos.c | 17 ++++++++--------- disk/part_efi.c | 31 ++++++++++++++++--------------- fs/fat/fat.c | 4 +--- include/part.h | 27 +++++++++++++++++++++++++++ 6 files changed, 58 insertions(+), 39 deletions(-)
cmd/gpt.c +4 -6
@@ -211,12 +211,10 @@ static struct disk_part *allocate_disk_part(struct disk_partition *info, PART_TYPE_LEN); newpart->gpt_part_info.type[PART_TYPE_LEN -1 ] ='\0' ; newpart->gpt_part_info.bootable = info->bootable; -#ifdef CONFIG_PARTITION_UUIDS -strncpy (newpart->gpt_part_info.uuid, (const char *)info->uuid, -UUID_STR_LEN ); -/* UUID_STR_LEN is correct, as uuid[]'s length is UUID_STR_LEN+1 chars */ - newpart->gpt_part_info.uuid[UUID_STR_LEN ] ='\0' ; -#endif +if (IS_ENABLED (CONFIG_PARTITION_UUIDS )) { +strlcpy (newpart->gpt_part_info.uuid,disk_partition_uuid (info), +UUID_STR_LEN +1 ); + } newpart->partnum = partnum;return newpart;
disk/part.c +2 -6
@@ -368,10 +368,8 @@ int part_get_info_by_type(struct blk_desc *desc, int part, int part_type,struct part_driver *drv;if (blk_enabled ()) { -#if CONFIG_IS_ENABLED (PARTITION_UUIDS )/* The common case is no UUID support */ - info->uuid[0 ] =0 ; -#endif +disk_partition_clr_uuid (info);#ifdef CONFIG_PARTITION_TYPE_GUID info->type_guid[0 ] =0 ;#endif
@@ -416,9 +414,7 @@ int part_get_info_whole_disk(struct blk_desc *desc, info->bootable =0 ;strcpy ((char *)info->type,BOOT_PART_TYPE );strcpy ((char *)info->name,"Whole Disk" ); -#if CONFIG_IS_ENABLED (PARTITION_UUIDS ) - info->uuid[0 ] =0 ; -#endif +disk_partition_clr_uuid (info);#ifdef CONFIG_PARTITION_TYPE_GUID info->type_guid[0 ] =0 ;#endif
disk/part_dos.c +8 -9
@@ -230,10 +230,8 @@ static int part_get_info_extended(struct blk_desc *desc,return -1 ; } -#if CONFIG_IS_ENABLED (PARTITION_UUIDS ) -if (!ext_part_sector) +if (CONFIG_IS_ENABLED (PARTITION_UUIDS ) && !ext_part_sector) disksig =get_unaligned_le32 (&buffer[DOS_PART_DISKSIG_OFFSET ]); -#endif /* Print all primary/logical partitions */ pt = (dos_partition_t *) (buffer +DOS_PART_TBL_OFFSET );
@@ -255,9 +253,12 @@ static int part_get_info_extended(struct blk_desc *desc,/* sprintf(info->type, "%d, pt->sys_ind); */ strcpy ((char *)info->type,"U-Boot" ); info->bootable =get_bootable (pt); -#if CONFIG_IS_ENABLED (PARTITION_UUIDS ) -sprintf (info->uuid,"%08x-%02x" , disksig, part_num); -#endif +if (CONFIG_IS_ENABLED (PARTITION_UUIDS )) { +char str[12 ]; + +sprintf (str,"%08x-%02x" , disksig, part_num); +disk_partition_set_uuid (info, str); + } info->sys_ind = pt->sys_ind;return 0 ; }
@@ -291,9 +292,7 @@ static int part_get_info_extended(struct blk_desc *desc, info->blksz =DOS_PART_DEFAULT_SECTOR ; info->bootable =0 ;strcpy ((char *)info->type,"U-Boot" ); -#if CONFIG_IS_ENABLED (PARTITION_UUIDS ) - info->uuid[0 ] =0 ; -#endif +disk_partition_clr_uuid (info);return 0 ; }
disk/part_efi.c +16 -15
@@ -289,10 +289,11 @@ int part_get_info_efi(struct blk_desc *desc, int part, print_efiname(&gpt_pte[part - 1]));strcpy ((char *)info->type,"U-Boot" ); info->bootable =get_bootable (&gpt_pte[part -1 ]); -#if CONFIG_IS_ENABLED (PARTITION_UUIDS ) -uuid_bin_to_str (gpt_pte[part -1 ].unique_partition_guid.b, info->uuid, -UUID_STR_FORMAT_GUID ); -#endif +if (CONFIG_IS_ENABLED (PARTITION_UUIDS )) { +uuid_bin_to_str (gpt_pte[part -1 ].unique_partition_guid.b, + (char *)disk_partition_uuid (info), +UUID_STR_FORMAT_GUID ); + }#ifdef CONFIG_PARTITION_TYPE_GUID uuid_bin_to_str (gpt_pte[part -1 ].partition_type_guid.b, info->type_guid,UUID_STR_FORMAT_GUID );
@@ -415,10 +416,7 @@ int gpt_fill_pte(struct blk_desc *desc,le64_to_cpu (gpt_h->last_usable_lba);int i, k;size_t efiname_len, dosname_len; -#if CONFIG_IS_ENABLED (PARTITION_UUIDS ) -char *str_uuid;unsigned char *bin_uuid; -#endif #ifdef CONFIG_PARTITION_TYPE_GUID char *str_type_guid;unsigned char *bin_type_guid;
@@ -487,16 +485,19 @@ int gpt_fill_pte(struct blk_desc *desc, &partition_basic_data_guid, 16);#endif -#if CONFIG_IS_ENABLED (PARTITION_UUIDS ) - str_uuid = partitions[i].uuid; - bin_uuid = gpt_e[i].unique_partition_guid.b; +if (CONFIG_IS_ENABLED (PARTITION_UUIDS )) { +const char *str_uuid; + + str_uuid =disk_partition_uuid (&partitions[i]); + bin_uuid = gpt_e[i].unique_partition_guid.b; -if (uuid_str_to_bin (str_uuid, bin_uuid,UUID_STR_FORMAT_GUID )) { -log_debug ("Partition no. %d: invalid guid: %s\n" , - i, str_uuid); -return -EINVAL ; +if (uuid_str_to_bin (str_uuid, bin_uuid, +UUID_STR_FORMAT_GUID )) { +log_debug ("Partition no. %d: invalid guid: %s\n" , + i, str_uuid); +return -EINVAL ; + } } -#endif /* partition attributes */ memset(&gpt_e[i].attributes, 0,
fs/fat/fat.c +1 -3
@@ -110,9 +110,7 @@ int fat_register_device(struct blk_desc *dev_desc, int part_no) info.name[0 ] =0 ; info.type[0 ] =0 ; info.bootable =0 ; -#if CONFIG_IS_ENABLED (PARTITION_UUIDS ) - info.uuid[0 ] =0 ; -#endif +disk_partition_clr_uuid (&info); }return fat_set_blk_dev (dev_desc, &info);
include/part.h +27 -0
@@ -80,6 +80,33 @@ struct disk_partition {#endif }; +/* Accessors for struct disk_partition field ->uuid */ +extern char *__invalid_use_of_disk_partition_uuid; + +static inline const char *disk_partition_uuid (const struct disk_partition *info) +{ +#if CONFIG_IS_ENABLED (PARTITION_UUIDS ) +return info->uuid; +#else +return __invalid_use_of_disk_partition_uuid; +#endif +} + +static inline void disk_partition_set_uuid (struct disk_partition *info, +const char *val) +{ +#if CONFIG_IS_ENABLED (PARTITION_UUIDS ) +strlcpy (info->uuid, val,UUID_STR_LEN +1 ); +#endif +} + +static inline void disk_partition_clr_uuid (struct disk_partition *info) +{ +#if CONFIG_IS_ENABLED (PARTITION_UUIDS ) + *info->uuid ='\0' ; +#endif +} +struct disk_part {int partnum;struct disk_partition gpt_part_info;
Signature · 1 line
2.41.0.640.ga95def55d0-goog
PATCH 9/24 part: Add accessors for struct disk_partition type_uuid
In reply to Simon GlassThis field is only present when a CONFIG is set. To avoid annoying #ifdefs in the source code, add accessors. Update all code to use it.
Note that the accessor is optional. It can be omitted if it is known that the option is enabled.
---
disk/part.c | 8 ++------ disk/part_efi.c | 9 +++++---- include/part.h | 28 ++++++++++++++++++++++++++++ 3 files changed, 35 insertions(+), 10 deletions(-)
disk/part.c +2 -6
@@ -370,9 +370,7 @@ int part_get_info_by_type(struct blk_desc *desc, int part, int part_type,if (blk_enabled ()) {/* The common case is no UUID support */ disk_partition_clr_uuid (info); -#ifdef CONFIG_PARTITION_TYPE_GUID - info->type_guid[0 ] =0 ; -#endif +disk_partition_clr_type_guid (info);if (part_type ==PART_TYPE_UNKNOWN ) { drv =part_driver_lookup_type (desc);
@@ -415,9 +413,7 @@ int part_get_info_whole_disk(struct blk_desc *desc,strcpy ((char *)info->type,BOOT_PART_TYPE );strcpy ((char *)info->name,"Whole Disk" );disk_partition_clr_uuid (info); -#ifdef CONFIG_PARTITION_TYPE_GUID - info->type_guid[0 ] =0 ; -#endif +disk_partition_clr_type_guid (info);return 0 ; }
disk/part_efi.c +5 -4
@@ -294,10 +294,11 @@ int part_get_info_efi(struct blk_desc *desc, int part, (char *)disk_partition_uuid (info), UUID_STR_FORMAT_GUID); } -#ifdef CONFIG_PARTITION_TYPE_GUID -uuid_bin_to_str (gpt_pte[part -1 ].partition_type_guid.b, - info->type_guid,UUID_STR_FORMAT_GUID ); -#endif +if (IS_ENABLED (CONFIG_PARTITION_TYPE_GUID )) { +uuid_bin_to_str (gpt_pte[part -1 ].partition_type_guid.b, + (char *)disk_partition_type_uuid (info), +UUID_STR_FORMAT_GUID ); + }log_debug ("start 0x" LBAF ", size 0x" LBAF ", name %s\n" , info->start, info->size, info->name);
include/part.h +28 -0
@@ -107,6 +107,34 @@ static inline void disk_partition_clr_uuid(struct disk_partition *info)#endif } +/* Accessors for struct disk_partition field ->type_guid */ +extern char *__invalid_use_of_disk_partition_type_uuid; + +static inline const +char *disk_partition_type_uuid (const struct disk_partition *info) +{ +#ifdef CONFIG_PARTITION_TYPE_GUID +return info->type_guid; +#else +return __invalid_use_of_disk_partition_type_uuid; +#endif +} + +static inline void disk_partition_set_type_guid (struct disk_partition *info, +const char *val) +{ +#ifdef CONFIG_PARTITION_TYPE_GUID +strlcpy (info->type_guid, val,UUID_STR_LEN +1 ); +#endif +} + +static inline void disk_partition_clr_type_guid (struct disk_partition *info) +{ +#ifdef CONFIG_PARTITION_TYPE_GUID + *info->type_guid ='\0' ; +#endif +} +struct disk_part {int partnum;struct disk_partition gpt_part_info;
Signature · 1 line
2.41.0.640.ga95def55d0-goog
PATCH 10/24 part: Add an accessor for struct disk_partition sys_ind
In reply to Simon GlassThis field is only present when a CONFIG is set. To avoid annoying #ifdefs in the source code, add an accessor. Update the only usage.
Note that the accessor is optional. It can be omitted if it is known that the option is enabled.
---
boot/bootdev-uclass.c | 7 +++---- include/part.h | 12 ++++++++++++ 2 files changed, 15 insertions(+), 4 deletions(-)
boot/bootdev-uclass.c +3 -4
@@ -184,12 +184,11 @@ int bootdev_find_in_blk(struct udevice *dev, struct udevice *blk,if (ret)return log_msg_ret ("fs" , ret); -/* Use an #ifdef due to info.sys_ind */ -#ifdef CONFIG_DOS_PARTITION log_debug ("%s: Found partition %x type %x fstype %d\n" , - blk->name, bflow->part, info.sys_ind, + blk->name, bflow->part, +IS_ENABLED (CONFIG_DOS_PARTITION ) ? +disk_partition_sys_ind (&info) :0 , ret ?-1 :fs_get_type ()); -#endif bflow->blk = blk; bflow->state =BOOTFLOWST_FS ; }
include/part.h +12 -0
@@ -135,6 +135,18 @@ static inline void disk_partition_clr_type_guid(struct disk_partition *info)#endif } +/* Accessors for struct disk_partition field ->sys_ind */ +extern int __invalid_use_of_disk_partition_sys_ind; + +static inline uint disk_partition_sys_ind (const struct disk_partition *info) +{ +#ifdef CONFIG_DOS_PARTITION +return info->sys_ind; +#else +return __invalid_use_of_disk_partition_sys_ind; +#endif +} +struct disk_part {int partnum;struct disk_partition gpt_part_info;
Signature · 1 line
2.41.0.640.ga95def55d0-goog
PATCH 11/24 part: efi: Add debugging for the signature check
In reply to Simon GlassAdd a little more debugging for the initial signature check. Drop the pointless check for NULL. Also set a log category while we are here.
---
disk/part_efi.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-)
disk/part_efi.c +11 -2
@@ -9,6 +9,9 @@* when CONFIG_SYS_64BIT_LBA is not defined, lbaint_t is 32 bits; this * limits the maximum size of addressable storage to < 2 tebibytes */ + +#define LOG_CATEGORY LOGC_FS +#include <common.h> #include <blk.h> #include <log.h>
@@ -976,17 +979,23 @@ static int pmbr_part_valid(struct partition *part)/* * is_pmbr_valid(): test Protective MBR for validity * +* @mbr: Pointer to Master Boot-Record data +* * Returns: 1 if PMBR is valid, 0 otherwise. * Validity depends on two things: * 1) MSDOS signature is in the last two bytes of the MBR * 2) One partition of type 0xEE is found, checked by pmbr_part_valid() */ -static int is_pmbr_valid (legacy_mbr * mbr) +static int is_pmbr_valid (legacy_mbr *mbr) { +uint sig =le16_to_cpu (mbr->signature);int i =0 ; -if (!mbr ||le16_to_cpu (mbr->signature) !=MSDOS_MBR_SIGNATURE ) +if (sig !=MSDOS_MBR_SIGNATURE ) { +log_debug ("Invalid signature %x\n" , sig);return 0 ; + } +log_debug ("Signature %x valid\n" , sig);for (i =0 ; i <4 ; i++) {if (pmbr_part_valid (&mbr->partition_record[i])) {
Signature · 1 line
2.41.0.640.ga95def55d0-goog
PATCH 12/24 fs/erofs: Quieten test for filesystem presence
In reply to Simon GlassAt present listing a partition produces lots of errors about this filesystem:
=> part list mmc 4
cannot find valid erofs superblock
cannot find valid erofs superblock
cannot read erofs superblock: -5
[9 more similar lines]
Use debugging rather than errors when unable to find a signature, as is done with other filesystems.
---
fs/erofs/super.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
fs/erofs/super.c +2 -2
@@ -68,14 +68,14 @@ int erofs_read_superblock(void) ret =erofs_blk_read (data,0 ,erofs_blknr (sizeof (data)));if (ret <0 ) { -erofs_err ("cannot read erofs superblock: %d" , ret); +erofs_dbg ("cannot read erofs superblock: %d" , ret);return -EIO ; } dsb = (struct erofs_super_block *)(data +EROFS_SUPER_OFFSET ); ret = -EINVAL ;if (le32_to_cpu (dsb->magic) !=EROFS_SUPER_MAGIC_V1 ) { -erofs_err ("cannot find valid erofs superblock" ); +erofs_dbg ("cannot find valid erofs superblock" );return ret; }
Signature · 1 line
2.41.0.640.ga95def55d0-goog
Re: [PATCH 12/24] fs/erofs: Quieten test for filesystem presence
Quoted 9 lines · Simon Glass
At present listing a partition produces lots of errors about this filesystem:
=> part list mmc 4
cannot find valid erofs superblock
cannot find valid erofs superblock
cannot read erofs superblock: -5
[9 more similar lines]
Quoted 4 lines
Use debugging rather than errors when unable to find a signature, as is done with other filesystems.
Signed-off-by Simon Glass <[email protected]>
Thanks,
Gao Xiang
PATCH 13/24 dm: core: Correct error handling when event fails
In reply to Simon GlassFollow the correct path in device_probe() when and event handler fails. This avoids getting into a strange state where the device appears to be activated but is not.
---
drivers/core/device.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/core/device.c +2 -1
@@ -598,9 +598,10 @@ int device_probe(struct udevice *dev) ret =device_notify (dev,EVT_DM_POST_PROBE );if (ret) -return ret; + goto fail_event;return 0 ; +fail_event: fail_uclass:if (device_remove (dev,DM_REMOVE_NORMAL )) { dm_warn("%s: Device '%s' failed to remove on error path\n",
Signature · 1 line
2.41.0.640.ga95def55d0-goog
PATCH 14/24 uuid: Move function comments to header file
In reply to Simon GlassThese should be in the header file for easy browsing, not in the source code. Move them and add a missing Return on one of the functions.
---
include/uuid.h | 94 ++++++++++++++++++++++++++++++++++++++++++++++++++ lib/uuid.c | 86 --------------------------------------------- 2 files changed, 94 insertions(+), 86 deletions(-)
include/uuid.h +94 -0
@@ -8,6 +8,51 @@#include <linux/bitops.h> +/* +* UUID - Universally Unique IDentifier - 128 bits unique number. +* There are 5 versions and one variant of UUID defined by RFC4122 +* specification. A UUID contains a set of fields. The set varies +* depending on the version of the UUID, as shown below: +* - time, MAC address(v1), +* - user ID(v2), +* - MD5 of name or URL(v3), +* - random data(v4), +* - SHA-1 of name or URL(v5), +* +* Layout of UUID: +* timestamp - 60-bit: time_low, time_mid, time_hi_and_version +* version - 4 bit (bit 4 through 7 of the time_hi_and_version) +* clock seq - 14 bit: clock_seq_hi_and_reserved, clock_seq_low +* variant: - bit 6 and 7 of clock_seq_hi_and_reserved +* node - 48 bit +* +* source: https://www.ietf.org/rfc/rfc4122.txt +* +* UUID binary format (16 bytes): +* +* 4B-2B-2B-2B-6B (big endian - network byte order) +* +* UUID string is 36 length of characters (36 bytes): +* +* 0 9 14 19 24 +* xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx +* be be be be be +* +* where x is a hexadecimal character. Fields are separated by '-'s. +* When converting to a binary UUID, le means the field should be converted +* to little endian and be means it should be converted to big endian. +* +* UUID is also used as GUID (Globally Unique Identifier) with the same binary +* format but it differs in string format like below. +* +* GUID: +* 0 9 14 19 24 +* xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx +* le le le be be +* +* GUID is used e.g. in GPT (GUID Partition Table) as a partiions unique id. +*/ +/* This is structure is in big-endian */ struct uuid {unsigned int time_low;
@@ -36,12 +81,61 @@ struct uuid {#define UUID_VARIANT 0x1int uuid_str_valid (const char *uuid); + +/* +* uuid_str_to_bin() - convert string UUID or GUID to big endian binary data. +* +* @param uuid_str - pointer to UUID or GUID string [37B] or GUID shorcut +* @param uuid_bin - pointer to allocated array for big endian output [16B] +* @str_format - UUID string format: 0 - UUID; 1 - GUID +* Return: 0 if OK, -EINVAL if the string is not a valid UUID +*/ int uuid_str_to_bin (const char *uuid_str,unsigned char *uuid_bin,int str_format); + +/* +* uuid_bin_to_str() - convert big endian binary data to string UUID or GUID. +* +* @param uuid_bin: pointer to binary data of UUID (big endian) [16B] +* @param uuid_str: pointer to allocated array for output string [37B] +* @str_format: bit 0: 0 - UUID; 1 - GUID +* bit 1: 0 - lower case; 2 - upper case +*/ void uuid_bin_to_str (const unsigned char *uuid_bin,char *uuid_str,int str_format); + +/* +* uuid_guid_get_bin() - this function get GUID bin for string +* +* @param guid_str - pointer to partition type string +* @param guid_bin - pointer to allocated array for big endian output [16B] +*/ int uuid_guid_get_bin (const char *guid_str,unsigned char *guid_bin); + +/* +* uuid_guid_get_str() - this function get string for GUID. +* +* @param guid_bin - pointer to string with partition type guid [16B] +* +* Returns NULL if the type GUID is not known. +*/ const char *uuid_guid_get_str (const unsigned char *guid_bin); + +/* +* gen_rand_uuid() - this function generates a random binary UUID version 4. +* In this version all fields beside 4 bits of version and +* 2 bits of variant are randomly generated. +* +* @param uuid_bin - pointer to allocated array [16B]. Output is in big endian. +*/ void gen_rand_uuid (unsigned char *uuid_bin); + +/* +* gen_rand_uuid_str() - this function generates UUID v4 (random) in two string +* formats UUID or GUID. +* +* @param uuid_str - pointer to allocated array [37B]. +* @param - uuid output type: UUID - 0, GUID - 1 +*/ void gen_rand_uuid_str (char *uuid_str,int str_format);#endif
lib/uuid.c +0 -86
128 lines not on this page · raw message
Signature · 1 line
2.41.0.640.ga95def55d0-goog
PATCH 15/24 sandbox: Add a way to access persistent test files
In reply to Simon GlassSome pytests create files in the persistent-data directory. It is useful to be able to access these files in C tests. Add a function which can locate a file given its leaf name, using the environment variable set up in test/py/conftest.py
---
arch/sandbox/cpu/os.c | 24 ++++++++++++++++++++++++ include/os.h | 10 ++++++++++ 2 files changed, 34 insertions(+)
arch/sandbox/cpu/os.c +24 -0
@@ -258,6 +258,30 @@ int os_unmap(void *buf, int size)return 0 ; } +int os_persistent_file (char *buf,int maxsize,const char *fname) +{ +const char *dirname =getenv ("U_BOOT_PERSISTENT_DATA_DIR" ); +char *ptr; +int len; + + len =strlen (fname) + (dirname ?strlen (dirname) +1 :0 ) +1 ; +if (len > maxsize) +return -ENOSPC ; + + ptr = buf; +if (dirname) { +strcpy (ptr, dirname); + ptr +=strlen (dirname); + *ptr++ ='/' ; + } +strcpy (ptr, fname); + +if (access (buf,F_OK ) ==-1 ) +return -ENOENT ; + +return 0 ; +} +/* Restore tty state when we exit */ static struct termios orig_term;static bool term_setup;
include/os.h +10 -0
@@ -98,6 +98,16 @@ int os_close(int fd);*/ int os_unlink (const char *pathname); +/** os_persistent_fname() - Find the path to a test file +* +* @buf: Buffer to hold path +* @maxsize: Maximum size of buffer +* @fname: Leaf filename to find +* Returns: 0 on success, -ENOENT if file is not found, -ENOSPC if the buffer is +* too small +*/ +int os_persistent_file (char *buf,int maxsize,const char *fname); +/** * os_exit() - access to the OS exit() system call *
Signature · 1 line
2.41.0.640.ga95def55d0-goog
PATCH 16/24 test: Move 1MB.fat32.img and 2MB.ext2.img
In reply to Simon GlassThese are currently created in the source directory, which is not ideal. Move them to the persistent-data directory instead. Update the test so skip validating the filename, since it now includes a full path.
---
test/dm/host.c | 44 ++++++++++++++++++++++---------------- test/py/tests/fs_helper.py | 6 ++---- test/py/tests/test_ut.py | 6 ++---- 3 files changed, 30 insertions(+), 26 deletions(-)
test/dm/host.c +26 -18
@@ -8,6 +8,7 @@#include <blk.h> #include <dm.h> #include <fs.h> +#include <os.h> #include <sandbox_host.h> #include <asm/test.h> #include <dm/device-internal.h>
@@ -15,9 +16,6 @@#include <test/test.h> #include <test/ut.h> -static const char filename[] ="2MB.ext2.img" ; -static const char filename2[] ="1MB.fat32.img" ; -/* Basic test of host interface */ static int dm_test_host (struct unit_test_state *uts) {
@@ -25,6 +23,7 @@ static int dm_test_host(struct unit_test_state *uts)struct udevice *dev, *part, *chk, *blk;struct host_sb_plat *plat;struct blk_desc *desc; +char fname[256 ];ulong mem_start;loff_t actwrite;
@@ -40,13 +39,15 @@ static int dm_test_host(struct unit_test_state *uts)ut_assert (label != plat->label);ut_asserteq (0 , plat->fd); -/* Attach a file created in test_host.py */ -ut_assertok (host_attach_file (dev, filename)); +/* Attach a file created in test_ut_dm_init */ +ut_assertok (os_persistent_file (fname,sizeof (fname),"2MB.ext2.img" )); + +ut_assertok (host_attach_file (dev, fname));ut_assertok (uclass_first_device_err (UCLASS_HOST , &chk));ut_asserteq_ptr (chk, dev); -ut_asserteq_str (filename, plat->filename); -ut_assert (filename != plat->filename); +ut_asserteq_str (fname, plat->filename); +ut_assert (fname != plat->filename);ut_assert (plat->fd !=0 );/* Get the block device */
@@ -79,12 +80,14 @@ static int dm_test_host_dup(struct unit_test_state *uts) {static char label[] ="test" ;struct udevice *dev, *chk; +char fname[256 ];ut_asserteq (0 ,uclass_id_count (UCLASS_HOST ));ut_assertok (host_create_device (label, true, &dev)); -/* Attach a file created in test_host.py */ -ut_assertok (host_attach_file (dev, filename)); +/* Attach a file created in test_ut_dm_init */ +ut_assertok (os_persistent_file (fname,sizeof (fname),"2MB.ext2.img" )); +ut_assertok (host_attach_file (dev, fname));ut_assertok (uclass_first_device_err (UCLASS_HOST , &chk));ut_asserteq_ptr (chk, dev);ut_asserteq (1 ,uclass_id_count (UCLASS_HOST ));
@@ -92,8 +95,10 @@ static int dm_test_host_dup(struct unit_test_state *uts)/* Create another device with the same label (should remove old one) */ ut_assertok (host_create_device (label, true, &dev)); -/* Attach a different file created in test_host.py */ -ut_assertok (host_attach_file (dev, filename2)); +/* Attach a different file created in test_ut_dm_init */ +ut_assertok (os_persistent_file (fname,sizeof (fname),"1MB.fat32.img" )); +ut_assertok (host_attach_file (dev, fname)); +ut_assertok (uclass_first_device_err (UCLASS_HOST , &chk));ut_asserteq_ptr (chk, dev);
@@ -109,6 +114,7 @@ static int dm_test_cmd_host(struct unit_test_state *uts) {struct udevice *dev, *blk;struct blk_desc *desc; +char fname[256 ];console_record_reset ();
@@ -117,7 +123,8 @@ static int dm_test_cmd_host(struct unit_test_state *uts)ut_assert_nextline ("dev blocks label path" );ut_assert_console_end (); -ut_assertok (run_commandf ("host bind -r test2 %s" , filename)); +ut_assertok (os_persistent_file (fname,sizeof (fname),"2MB.ext2.img" )); +ut_assertok (run_commandf ("host bind -r test2 %s" , fname));/* Check the -r flag worked */ ut_assertok (uclass_first_device_err (UCLASS_HOST , &dev));
@@ -127,10 +134,11 @@ static int dm_test_cmd_host(struct unit_test_state *uts)ut_assertok (run_command ("host info" ,0 ));ut_assert_nextline ("dev blocks label path" ); -ut_assert_nextline (" 0 4096 test2 2MB.ext2.img" ); +ut_assert_nextlinen (" 0 4096 test2" );ut_assert_console_end (); -ut_assertok (run_commandf ("host bind fat %s" , filename2)); +ut_assertok (os_persistent_file (fname,sizeof (fname),"1MB.fat32.img" )); +ut_assertok (run_commandf ("host bind fat %s" , fname));/* Check it is not removable (no '-r') */ ut_assertok (uclass_next_device_err (&dev));
@@ -140,8 +148,8 @@ static int dm_test_cmd_host(struct unit_test_state *uts)ut_assertok (run_command ("host info" ,0 ));ut_assert_nextline ("dev blocks label path" ); -ut_assert_nextline (" 0 4096 test2 2MB.ext2.img" ); -ut_assert_nextline (" 1 2048 fat 1MB.fat32.img" ); +ut_assert_nextlinen (" 0 4096 test2" ); +ut_assert_nextlinen (" 1 2048 fat" );ut_assert_console_end ();ut_asserteq (1 ,run_command ("host info test" ,0 ));
@@ -150,7 +158,7 @@ static int dm_test_cmd_host(struct unit_test_state *uts)ut_assertok (run_command ("host info fat" ,0 ));ut_assert_nextline ("dev blocks label path" ); -ut_assert_nextline (" 1 2048 fat 1MB.fat32.img" ); +ut_assert_nextlinen (" 1 2048 fat" );ut_assert_console_end ();/* check 'host dev' */
@@ -187,7 +195,7 @@ static int dm_test_cmd_host(struct unit_test_state *uts)ut_assertok (run_command ("host info" ,0 ));ut_assert_nextline ("dev blocks label path" ); -ut_assert_nextline (" 1 2048 fat 1MB.fat32.img" ); +ut_assert_nextlinen (" 1 2048 fat" );ut_assert_console_end ();return 0 ;
test/py/tests/fs_helper.py +2 -4
@@ -9,7 +9,7 @@ import re import os from subprocess import call, check_call, check_output, CalledProcessError -def mk_fs(config, fs_type, size, prefix, use_src_dir=False): +def mk_fs(config, fs_type, size, prefix): """Create a file system volume Args:
@@ -17,14 +17,12 @@ def mk_fs(config, fs_type, size, prefix, use_src_dir=False): fs_type (str): File system type, e.g. 'ext4' size (int): Size of file system in bytes prefix (str): Prefix string of volume's file name - use_src_dir (bool): true to put the file in the source directory Raises: CalledProcessError: if any error occurs when creating the filesystem """ fs_img = f'{prefix}.{fs_type}.img' - fs_img = os.path.join(config.source_dir if use_src_dir - else config.persistent_data_dir, fs_img) + fs_img = os.path.join(config.persistent_data_dir, fs_img) if fs_type == 'fat16': mkfs_opt = '-F 16'
test/py/tests/test_ut.py +2 -4
@@ -317,10 +317,8 @@ def test_ut_dm_init(u_boot_console): u_boot_utils.run_and_log( u_boot_console, f'sfdisk {fn}', stdin=b'type=83') - fs_helper.mk_fs(u_boot_console.config, 'ext2', 0x200000, '2MB', - use_src_dir=True) - fs_helper.mk_fs(u_boot_console.config, 'fat32', 0x100000, '1MB', - use_src_dir=True) + fs_helper.mk_fs(u_boot_console.config, 'ext2', 0x200000, '2MB') + fs_helper.mk_fs(u_boot_console.config, 'fat32', 0x100000, '1MB') @pytest.mark.buildconfigspec('cmd_bootflow') def test_ut_dm_init_bootstd(u_boot_console):
Signature · 1 line
2.41.0.640.ga95def55d0-goog
PATCH 17/24 bootflow: Show an empty filename when there is none
In reply to Simon GlassAt present 'bootflow list' shows <NULL> for the filename when it is not present. Show an empty string instead, since that is more user-friendly.
---
cmd/bootflow.c | 2 +- test/boot/bootflow.c | 22 ++++++++++++---------- 2 files changed, 13 insertions(+), 11 deletions(-)
cmd/bootflow.c +1 -1
@@ -71,7 +71,7 @@ static void show_bootflow(int index, struct bootflow *bflow, bool errors)printf ("%3x %-11s %-6s %-9.9s %4x %-25.25s %s\n" , index, bflow->method->name,bootflow_state_get_name (bflow->state), bflow->dev ?dev_get_uclass_name (dev_get_parent (bflow->dev)) : -"(none)" , bflow->part, bflow->name, bflow->fname); +"(none)" , bflow->part, bflow->name, bflow->fname ?:"" );if (errors)report_bootflow_err (bflow, bflow->err); }
test/boot/bootflow.c +12 -10
@@ -167,21 +167,22 @@ static int bootflow_cmd_scan_e(struct unit_test_state *uts)ut_assert_nextline ("Seq Method State Uclass Part Name Filename" );ut_assert_nextlinen ("---" );ut_assert_nextline ("Scanning bootdev 'mmc2.bootdev':" ); -ut_assert_nextline (" 0 extlinux media mmc 0 mmc2.bootdev.whole <NULL>" ); +ut_assert_nextline (" 0 extlinux media mmc 0 mmc2.bootdev.whole " );ut_assert_nextline (" ** No partition found, err=-93: Protocol not supported" ); -ut_assert_nextline (" 1 efi media mmc 0 mmc2.bootdev.whole <NULL>" ); +ut_assert_nextline (" 1 efi media mmc 0 mmc2.bootdev.whole " );ut_assert_nextline (" ** No partition found, err=-93: Protocol not supported" );ut_assert_nextline ("Scanning bootdev 'mmc1.bootdev':" ); -ut_assert_nextline (" 2 extlinux media mmc 0 mmc1.bootdev.whole <NULL>" ); +ut_assert_nextline (" 2 extlinux media mmc 0 mmc1.bootdev.whole " );ut_assert_nextline (" ** No partition found, err=-2: No such file or directory" ); -ut_assert_nextline (" 3 efi media mmc 0 mmc1.bootdev.whole <NULL>" ); +ut_assert_nextline (" 3 efi media mmc 0 mmc1.bootdev.whole " );ut_assert_nextline (" ** No partition found, err=-2: No such file or directory" );ut_assert_nextline (" 4 extlinux ready mmc 1 mmc1.bootdev.part_1 /extlinux/extlinux.conf" );ut_assert_nextline (" 5 efi fs mmc 1 mmc1.bootdev.part_1 efi/boot/bootsbox.efi" );ut_assert_skip_to_line ("Scanning bootdev 'mmc0.bootdev':" ); -ut_assert_skip_to_line (" 3f efi media mmc 0 mmc0.bootdev.whole <NULL>" ); +ut_assert_skip_to_line ( +" 3f efi media mmc 0 mmc0.bootdev.whole " );ut_assert_nextline (" ** No partition found, err=-93: Protocol not supported" );ut_assert_nextline ("No more bootdevs" );ut_assert_nextlinen ("---" );
@@ -192,10 +193,11 @@ static int bootflow_cmd_scan_e(struct unit_test_state *uts)ut_assert_nextline ("Showing all bootflows" );ut_assert_nextline ("Seq Method State Uclass Part Name Filename" );ut_assert_nextlinen ("---" ); -ut_assert_nextline (" 0 extlinux media mmc 0 mmc2.bootdev.whole <NULL>" ); -ut_assert_nextline (" 1 efi media mmc 0 mmc2.bootdev.whole <NULL>" ); -ut_assert_skip_to_line (" 4 extlinux ready mmc 1 mmc1.bootdev.part_1 /extlinux/extlinux.conf" ); -ut_assert_skip_to_line (" 3f efi media mmc 0 mmc0.bootdev.whole <NULL>" ); +ut_assert_nextline (" 0 extlinux media mmc 0 mmc2.bootdev.whole " ); +ut_assert_nextline (" 1 efi media mmc 0 mmc2.bootdev.whole " ); +ut_assert_skip_to_line ( +" 4 extlinux ready mmc 1 mmc1.bootdev.part_1 /extlinux/extlinux.conf" ); +ut_assert_skip_to_line (" 3f efi media mmc 0 mmc0.bootdev.whole " );ut_assert_nextlinen ("---" );ut_assert_nextline ("(64 bootflows, 1 valid)" );ut_assert_console_end ();
@@ -384,7 +386,7 @@ static int bootflow_system(struct unit_test_state *uts)console_record_reset_enable ();ut_assertok (run_command ("bootflow scan -lH" ,0 ));ut_assert_skip_to_line ( -" 0 efi_mgr ready (none) 0 <NULL> <NULL>" ); +" 0 efi_mgr ready (none) 0 <NULL> " );ut_assert_skip_to_line ("No more bootdevs" );ut_assert_skip_to_line ("(2 bootflows, 2 valid)" );ut_assert_console_end ();
Signature · 1 line
2.41.0.640.ga95def55d0-goog
PATCH 18/24 bootstd: test: Allow binding and using any mmc device
In reply to Simon GlassWe currently use mmc4 for tests. Update the function which sets this up so that it can handle any device.
---
test/boot/bootflow.c | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-)
test/boot/bootflow.c +22 -6
@@ -508,21 +508,24 @@ static int bootflow_cmd_boot(struct unit_test_state *uts)BOOTSTD_TEST (bootflow_cmd_boot,UT_TESTF_DM |UT_TESTF_SCAN_FDT );/** -* prep_mmc4_bootdev() - Set up the mmc4 bootdev so we can access a fake Armbian +* prep_mmc_bootdev() - Set up an mmc bootdev so we can access other distros * * @uts: Unit test state +* @mmc_dev: MMC device to use, e.g. "mmc4" * Returns 0 on success, -ve on failure */ -static int prep_mmc4_bootdev (struct unit_test_state *uts) +static int prep_mmc_bootdev (struct unit_test_state *uts,const char *mmc_dev) { -static const char *order[] = {"mmc2" ,"mmc1" ,"mmc4" ,NULL }; +const char *order[] = {"mmc2" ,"mmc1" , mmc_dev,NULL };struct udevice *dev, *bootstd;struct bootstd_priv *std;const char **old_order; -ofnode node; +ofnode root, node;/* Enable the mmc4 node since we need a second bootflow */ - node =ofnode_path ("/mmc4" ); + root =oftree_root (oftree_default ()); + node =ofnode_find_subnode (root, mmc_dev); +ut_assert (ofnode_valid (node));ut_assertok (lists_bind_fdt (gd->dm_root, node, &dev,NULL , false));/* Enable the script bootmeth too */
@@ -530,7 +533,7 @@ static int prep_mmc4_bootdev(struct unit_test_state *uts)ut_assertok (device_bind (bootstd,DM_DRIVER_REF (bootmeth_script),"bootmeth_script" ,0 ,ofnode_null (), &dev)); -/* Change the order to include mmc4 */ +/* Change the order to include the device */ std =dev_get_priv (bootstd); old_order = std->bootdev_order; std->bootdev_order = order;
@@ -545,6 +548,19 @@ static int prep_mmc4_bootdev(struct unit_test_state *uts)return 0 ; } +/** +* prep_mmc4_bootdev() - Set up the mmc4 bootdev so we can access a fake Armbian +* +* @uts: Unit test state +* Returns 0 on success, -ve on failure +*/ +static int prep_mmc4_bootdev (struct unit_test_state *uts) +{ +ut_assertok (prep_mmc_bootdev (uts,"mmc4" )); + +return 0 ; +} +/* Check 'bootflow menu' to select a bootflow */ static int bootflow_cmd_menu (struct unit_test_state *uts) {
Signature · 1 line
2.41.0.640.ga95def55d0-goog
PATCH 19/24 bootstd: Add a test for bootmeth_cros
In reply to Simon GlassThe ChromiumOS bootmeth has no tests at present. Before adding more features. add a basic test.
This creates a disk which can be scanned by the bootmeth, so make sure things work. It is quite rudimentary, since the kernel is faked, the root disk is missing and there is no cmdline stored.
Enable the bootmeth for snow so it can build the unit test.
---
arch/sandbox/dts/test.dts | 9 +++ configs/snow_defconfig | 1 + test/boot/bootflow.c | 33 ++++++++- test/py/tests/test_ut.py | 142 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 183 insertions(+), 2 deletions(-)
arch/sandbox/dts/test.dts +9 -0
@@ -39,6 +39,8 @@ mmc1 = "/mmc1"; mmc2 = "/mmc2"; mmc3 = "/mmc3"; + mmc4 = "/mmc4"; + mmc5 = "/mmc5"; pci0 = &pci0; pci1 = &pci1; pci2 = &pci2;
@@ -1055,6 +1057,13 @@ filename = "mmc4.img"; }; + /* This is used for ChromiumOS tests */ + mmc5 { + status = "disabled"; + compatible = "sandbox,mmc"; + filename = "mmc5.img"; + }; + pch { compatible = "sandbox,pch"; };
configs/snow_defconfig +1 -0
@@ -29,6 +29,7 @@ CONFIG_DEBUG_UART=y CONFIG_FIT=y CONFIG_FIT_BEST_MATCH=y CONFIG_BOOTSTD_FULL=y +CONFIG_BOOTMETH_CROS=y CONFIG_DISTRO_DEFAULTS=y CONFIG_SILENT_CONSOLE=y CONFIG_BLOBLIST=y
test/boot/bootflow.c +31 -2
@@ -27,6 +27,7 @@DECLARE_GLOBAL_DATA_PTR ; +extern U_BOOT_DRIVER (bootmeth_cros);extern U_BOOT_DRIVER (bootmeth_script);static int inject_response (struct unit_test_state *uts)
@@ -514,7 +515,8 @@ BOOTSTD_TEST(bootflow_cmd_boot, UT_TESTF_DM | UT_TESTF_SCAN_FDT);* @mmc_dev: MMC device to use, e.g. "mmc4" * Returns 0 on success, -ve on failure */ -static int prep_mmc_bootdev (struct unit_test_state *uts,const char *mmc_dev) +static int prep_mmc_bootdev (struct unit_test_state *uts,const char *mmc_dev, +bool bind_cros) {const char *order[] = {"mmc2" ,"mmc1" , mmc_dev,NULL };struct udevice *dev, *bootstd;
@@ -533,6 +535,13 @@ static int prep_mmc_bootdev(struct unit_test_state *uts, const char *mmc_dev)ut_assertok (device_bind (bootstd,DM_DRIVER_REF (bootmeth_script),"bootmeth_script" ,0 ,ofnode_null (), &dev)); +/* Enable the cros bootmeth if needed */ +if (bind_cros) { +ut_assertok (uclass_first_device_err (UCLASS_BOOTSTD , &bootstd)); +ut_assertok (device_bind (bootstd,DM_DRIVER_REF (bootmeth_cros), +"cros" ,0 ,ofnode_null (), &dev)); + } +/* Change the order to include the device */ std =dev_get_priv (bootstd); old_order = std->bootdev_order;
@@ -556,7 +565,7 @@ static int prep_mmc_bootdev(struct unit_test_state *uts, const char *mmc_dev)*/ static int prep_mmc4_bootdev (struct unit_test_state *uts) { -ut_assertok (prep_mmc_bootdev (uts,"mmc4" )); +ut_assertok (prep_mmc_bootdev (uts,"mmc4" , false));return 0 ; }
@@ -963,3 +972,23 @@ static int bootflow_cmdline(struct unit_test_state *uts)return 0 ; }BOOTSTD_TEST (bootflow_cmdline,0 ); + +/* Test ChromiumOS bootmeth */ +static int bootflow_cros (struct unit_test_state *uts) +{ +ut_assertok (prep_mmc_bootdev (uts,"mmc5" , true)); +ut_assertok (run_command ("bootflow list" ,0 )); + +ut_assert_nextlinen ("Showing all" ); +ut_assert_nextlinen ("Seq" ); +ut_assert_nextlinen ("---" ); +ut_assert_nextlinen (" 0 extlinux" ); +ut_assert_nextlinen (" 1 cros ready mmc 2 mmc5.bootdev.whole " ); +ut_assert_nextlinen ("---" ); +ut_assert_skip_to_line ("(2 bootflows, 2 valid)" ); + +ut_assert_console_end (); + +return 0 ; +} +BOOTSTD_TEST (bootflow_cros,0 );
test/py/tests/test_ut.py +142 -0
160 lines not on this page · raw message
Signature · 1 line
2.41.0.640.ga95def55d0-goog
PATCH 20/24 part: Add a fallback for part_get_bootable()
In reply to Simon GlassThis function can be called when partition support is disabled. Add a static inline to handle this.
---
include/part.h | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-)
include/part.h +12 -8
@@ -364,14 +364,6 @@ part_get_info_by_dev_and_name_or_num(const char *dev_iface, }#endif -/** -* part_get_bootable() - Find the first bootable partition -* -* @desc: Block-device descriptor -* @return first bootable partition, or 0 if there is none -*/ -int part_get_bootable (struct blk_desc *desc); -struct udevice ;/** * part_create_block_devices - Create block devices for disk partitions
@@ -666,12 +658,24 @@ static inline struct part_driver *part_driver_get_first(void)*/ int part_get_type_by_name (const char *name); +/** +* part_get_bootable() - Find the first bootable partition +* +* @desc: Block-device descriptor +* @return first bootable partition, or 0 if there is none +*/ +int part_get_bootable (struct blk_desc *desc); +#else static inline int part_driver_get_count (void ) {return 0 ; }static inline struct part_driver *part_driver_get_first (void ) {return NULL ; } + +static inline bool part_get_bootable (struct blk_desc *desc) +{return false; } +#endif /* CONFIG_PARTITIONS */ #endif /* _PART_H */
Signature · 1 line
2.41.0.640.ga95def55d0-goog
PATCH 21/24 bootstd: Support bootmeths which can scan any partition
In reply to Simon GlassSome bootmeths support scanning a partition without a filesystem on it. Add a flag to support this.
This will allow the ChromiumOS bootmeth to find kernel partition, which are stored in a special format, without a filesystem.
---
boot/bootdev-uclass.c | 17 ++++++++++++++--- doc/develop/bootstd.rst | 11 ++++++----- include/bootmeth.h | 3 +++ 3 files changed, 23 insertions(+), 8 deletions(-)
boot/bootdev-uclass.c +14 -3
@@ -111,6 +111,8 @@ int bootdev_bind(struct udevice *parent, const char *drv_name, const char *name,int bootdev_find_in_blk (struct udevice *dev,struct udevice *blk,struct bootflow_iter *iter,struct bootflow *bflow) { +struct bootmeth_uc_plat *plat =dev_get_uclass_plat (bflow->method); +bool allow_any_part = plat->flags &BOOTMETHF_ANY_PART ;struct blk_desc *desc =dev_get_uclass_plat (blk);struct disk_partition info;char partstr[20 ];
@@ -142,6 +144,7 @@ int bootdev_find_in_blk(struct udevice *dev, struct udevice *blk,* us whether there is valid media there */ ret =part_get_info (desc, iter->part, &info); +log_debug ("part_get_info() returned %d\n" , ret);if (!iter->part && ret == -ENOENT ) ret =0 ;
@@ -154,7 +157,7 @@ int bootdev_find_in_blk(struct udevice *dev, struct udevice *blk, ret = -ESHUTDOWN ; else bflow->state = BOOTFLOWST_MEDIA; -if (ret) { +if (ret && !allow_any_part) {/* allow partition 1 to be missing */ if (iter->part ==1 ) { iter->max_part =3 ;
@@ -174,9 +177,15 @@ int bootdev_find_in_blk(struct udevice *dev, struct udevice *blk,if (!iter->part) { iter->first_bootable =part_get_bootable (desc);log_debug ("checking bootable=%d\n" , iter->first_bootable); + }else if (allow_any_part) { +/* +* allow any partition to be scanned, by skipping any checks +* for filesystems or partition contents on this disk +*/ /* if there are bootable partitions, scan only those */ - }else if (iter->first_bootable ? !info.bootable : iter->part !=1 ) { + }else if (iter->first_bootable >=0 && + (iter->first_bootable ? !info.bootable : iter->part !=1 )) {return log_msg_ret ("boot" , -EINVAL ); }else { ret =fs_set_blk_dev_with_part (desc, bflow->part);
@@ -193,6 +202,7 @@ int bootdev_find_in_blk(struct udevice *dev, struct udevice *blk, bflow->state =BOOTFLOWST_FS ; } +log_debug ("method %s\n" , bflow->method->name); ret =bootmeth_read_bootflow (bflow->method, bflow);if (ret)return log_msg_ret ("method" , ret);
@@ -555,7 +565,8 @@ int bootdev_get_bootflow(struct udevice *dev, struct bootflow_iter *iter, {const struct bootdev_ops *ops =bootdev_get_ops (dev); -log_debug ("->get_bootflow %s=%p\n" , dev->name, ops->get_bootflow); +log_debug ("->get_bootflow %s,%x=%p\n" , dev->name, iter->part, + ops->get_bootflow);bootflow_init (bflow, dev, iter->method);if (!ops->get_bootflow)return default_get_bootflow (dev, iter, bflow);
doc/develop/bootstd.rst +6 -5
@@ -677,11 +677,12 @@ Assuming the bootmeth is happy, or at least indicates that it is willing to try partition. If that works it tries to detect a file system. If that works then it calls the bootmeth device once more, this time to read the bootflow. -Note: At present a filesystem is needed for the bootmeth to be called on block -devices, simply because we don't have any examples where this is not the case. -This feature can be added as needed. Note that sandbox is a special case, since -in that case the host filesystem can be accessed even though the block device -is NULL. +Note: Normally a filesystem is needed for the bootmeth to be called on block +devices, but bootmeths which don't need that can set the BOOTMETHF_ANY_PART +flag to indicate that they can scan any partition. An example is the ChromiumOS +bootmeth which can store a kernel in a raw partition. Note also that sandbox is +a special case, since in that case the host filesystem can be accessed even +though the block device is NULL. If we take the example of the `bootmeth_extlinux` driver, this call ends up at `extlinux_read_bootflow()`. It has the filesystem ready, so tries various
include/bootmeth.h +3 -0
@@ -16,9 +16,12 @@ struct udevice;* enum bootmeth_flags - Flags for bootmeths * * @BOOTMETHF_GLOBAL: bootmeth handles bootdev selection automatically +* @BOOTMETHF_ANY_PART: bootmeth is willing to check any partition, even if it +* has no filesystem */ enum bootmeth_flags {BOOTMETHF_GLOBAL =BIT (0 ), +BOOTMETHF_ANY_PART =BIT (1 ), };/**
Signature · 1 line
2.41.0.640.ga95def55d0-goog
PATCH 22/24 uuid: Add ChromiumOS partition types
In reply to Simon GlassAdd some GUIDs for ChromiumOS so we can detect the partitions.
---
include/part_efi.h | 14 ++++++++++++++ lib/uuid.c | 7 +++++++ 2 files changed, 21 insertions(+)
include/part_efi.h +14 -0
@@ -60,6 +60,20 @@EFI_GUID (0x3de21764 ,0x95bd ,0x54bd , \0xa5 ,0xc3 ,0x4a ,0xbe ,0x78 ,0x6f ,0x38 ,0xa8 ) +/* Special ChromiumOS things */ +#define PARTITION_CROS_KERNEL \ + EFI_GUID(0xfe3a2a5d, 0x4f32, 0x41a7, \ + 0xb7, 0x25, 0xac, 0xcc, 0x32, 0x85, 0xa3, 0x09) +#define PARTITION_CROS_ROOT \ + EFI_GUID(0x3cb8e202, 0x3b7e, 0x47dd, \ + 0x8a, 0x3c, 0x7f, 0xf2, 0xa1, 0x3c, 0xfc, 0xec) +#define PARTITION_CROS_FIRMWARE \ + EFI_GUID(0xcab6e88e, 0xabf3, 0x4102, \ + 0xa0, 0x7a, 0xd4, 0xbb, 0x9b, 0xe3, 0xc1, 0xd3) +#define PARTITION_CROS_RESERVED \ + EFI_GUID(0x2e0a753d, 0x9e48, 0x43b0, \ + 0x83, 0x37, 0xb1, 0x51, 0x92, 0xcb, 0x1b, 0x5e) +/* linux/include/efi.h */ typedef u16 efi_char16_t ;
lib/uuid.c +7 -0
@@ -3,6 +3,8 @@* Copyright 2011 Calxeda, Inc. */ +#define LOG_CATEGOT LOGC_CORE +#include <common.h> #include <command.h> #include <efi_api.h>
@@ -57,6 +59,10 @@ static const struct { {"swap", PARTITION_LINUX_SWAP_GUID}, {"lvm", PARTITION_LINUX_LVM_GUID}, {"u-boot-env", PARTITION_U_BOOT_ENVIRONMENT}, + {"cros-kern", PARTITION_CROS_KERNEL}, + {"cros-root", PARTITION_CROS_ROOT}, + {"cros-fw", PARTITION_CROS_FIRMWARE}, + {"cros-rsrv", PARTITION_CROS_RESERVED}, #endif #if defined(CONFIG_CMD_EFIDEBUG) || defined(CONFIG_EFI) {
@@ -254,6 +260,7 @@ int uuid_str_to_bin(const char *uuid_str, unsigned char *uuid_bin,uint64_t tmp64;if (!uuid_str_valid (uuid_str)) { +log_debug ("not valid\n" );#ifdef CONFIG_PARTITION_TYPE_GUID if (!uuid_guid_get_bin (uuid_str, uuid_bin))return 0 ;
Signature · 1 line
2.41.0.640.ga95def55d0-goog
PATCH 23/24 bootstd: cros: Allow detection of any kernel partition
In reply to Simon GlassThe existing ChromiumOS bootmeth only supports reading a single kernel partition, either 2 or 4. In fact there are normally two options available.
Use the GUID to detect kernel partitions, with the BOOTMETHF_ANY_PART flag, so that bootstd does not require a valid filesystem before calling the bootmeth.
Tidy up and improve the logging while we are here.
---
boot/Kconfig | 2 ++ boot/bootmeth_cros.c | 48 +++++++++++++++++++++++++++----------------- test/boot/bootflow.c | 5 +++-- 3 files changed, 35 insertions(+), 20 deletions(-)
boot/Kconfig +2 -0
@@ -466,6 +466,8 @@ config BOOTMETH_CROS bool "Bootdev support for Chromium OS" depends on X86 || ARM || SANDBOX default y if !ARM + select PARTITION_TYPE_GUID + select PARTITION_UUIDS help Enables support for booting Chromium OS using bootdevs. This uses the kernel A slot and obtains the kernel command line from the parameters
boot/bootmeth_cros.c +30 -18
111 lines not on this page · raw message
test/boot/bootflow.c +3 -2
@@ -983,9 +983,10 @@ static int bootflow_cros(struct unit_test_state *uts)ut_assert_nextlinen ("Seq" );ut_assert_nextlinen ("---" );ut_assert_nextlinen (" 0 extlinux" ); -ut_assert_nextlinen (" 1 cros ready mmc 2 mmc5.bootdev.whole " ); +ut_assert_nextlinen (" 1 cros ready mmc 2 mmc5.bootdev.part_2 " ); +ut_assert_nextlinen (" 2 cros ready mmc 4 mmc5.bootdev.part_4 " );ut_assert_nextlinen ("---" ); -ut_assert_skip_to_line ("(2 bootflows, 2 valid)" ); +ut_assert_skip_to_line ("(3 bootflows, 3 valid)" );ut_assert_console_end ();
Signature · 1 line
2.41.0.640.ga95def55d0-goog
PATCH 24/24 CI: Add ChromiumOS utilities
In reply to Simon GlassWe need cgpt and futility for building test images. Add them.
---
tools/docker/Dockerfile | 3 +++ 1 file changed, 3 insertions(+)
tools/docker/Dockerfile +3 -0
@@ -39,6 +39,7 @@ RUN apt-get update && apt-get install -y \ binutils-dev \ bison \ build-essential \ + cgpt \ clang-16 \ coreutils \ cpio \
@@ -115,6 +116,8 @@ RUN apt-get update && apt-get install -y \ util-linux \ uuid-dev \ virtualenv \ + vboot-kernel-utils \ + vboot-utils \ xxd \ zip \ && rm -rf /var/lib/apt/lists/*
Signature · 1 line
2.41.0.640.ga95def55d0-goog
Quoted 9 lines · Simon Glass
This updates the ChromiumOS bootmeth to detect multiple kernel partitions on a disk.
It also includes minor code improvements to the partition drivers, including accessors for the optional fields.
This series also includes some other related tweaks in testing.
It is available at u-boot-dm/methb-working
Please rebase this on top of current next, thanks.
Signature · 1 line
Tom