From 2c120676bad1ecb6aff51b4309cb61be1dbc0695 Mon Sep 17 00:00:00 2001 From: Julien Delbergue Date: Thu, 13 Jul 2023 11:53:09 +0200 Subject: bootstd: Correct 'bpot' typo Fix it to 'boot' in the header, as it is in the source file. Signed-off-by: Julien Delbergue Reviewed-by: Bin Meng --- include/bootstd.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/bootstd.h b/include/bootstd.h index dddb3e15384..7802564bcc6 100644 --- a/include/bootstd.h +++ b/include/bootstd.h @@ -69,7 +69,7 @@ const char *const *const bootstd_get_bootdev_order(struct udevice *dev, /** * bootstd_get_prefixes() - Get the filename-prefixes list * - * This reads the prefixes, e.g. {"/", "/bpot", NULL} + * This reads the prefixes, e.g. {"/", "/boot", NULL} * * The list is alloced by the bootstd driver so should not be freed. That is the * reason for all the const stuff in the function signature -- cgit v1.3.1 From 22cdb3f0f174e926071975cdc5157aa6526b67a7 Mon Sep 17 00:00:00 2001 From: Joshua Watt Date: Fri, 23 Jun 2023 17:05:48 -0500 Subject: android_ab: Add option to skip decrementing tries It is is sometimes desired to be able to skip decrementing the number of tries remaining in an Android A/B boot, and instead just check which slot will be tried later. This can commonly be be the case for platforms that want to A/B u-boot itself, but are required to boot from a FAT MBR partition. In these cases, u-boot must do an early check that the MBR points to the correct A/B boot partition, and if not rewrite the MBR to point to the correct one and reboot. Decrementing the try count in this case is not desired because it means that each u-boot might constantly ping-pong overwriting the MBR and rebooting until all the retries are used up. Signed-off-by: Joshua Watt --- boot/android_ab.c | 9 ++++++--- cmd/ab_select.c | 20 ++++++++++++++++---- include/android_ab.h | 3 ++- 3 files changed, 24 insertions(+), 8 deletions(-) (limited to 'include') diff --git a/boot/android_ab.c b/boot/android_ab.c index 2d7b3926665..60ae002978f 100644 --- a/boot/android_ab.c +++ b/boot/android_ab.c @@ -181,7 +181,8 @@ static int ab_compare_slots(const struct slot_metadata *a, return 0; } -int ab_select_slot(struct blk_desc *dev_desc, struct disk_partition *part_info) +int ab_select_slot(struct blk_desc *dev_desc, struct disk_partition *part_info, + bool dec_tries) { struct bootloader_control *abc = NULL; u32 crc32_le; @@ -272,8 +273,10 @@ int ab_select_slot(struct blk_desc *dev_desc, struct disk_partition *part_info) log_err("ANDROID: Attempting slot %c, tries remaining %d\n", BOOT_SLOT_NAME(slot), abc->slot_info[slot].tries_remaining); - abc->slot_info[slot].tries_remaining--; - store_needed = true; + if (dec_tries) { + abc->slot_info[slot].tries_remaining--; + store_needed = true; + } } if (slot >= 0) { diff --git a/cmd/ab_select.c b/cmd/ab_select.c index 3e46663d6ea..bfb67b8236b 100644 --- a/cmd/ab_select.c +++ b/cmd/ab_select.c @@ -16,10 +16,19 @@ static int do_ab_select(struct cmd_tbl *cmdtp, int flag, int argc, struct blk_desc *dev_desc; struct disk_partition part_info; char slot[2]; + bool dec_tries = true; - if (argc != 4) + if (argc < 4) return CMD_RET_USAGE; + for (int i = 4; i < argc; i++) { + if (strcmp(argv[i], "--no-dec") == 0) { + dec_tries = false; + } else { + return CMD_RET_USAGE; + } + } + /* Lookup the "misc" partition from argv[2] and argv[3] */ if (part_get_info_by_dev_and_name_or_num(argv[2], argv[3], &dev_desc, &part_info, @@ -27,7 +36,8 @@ static int do_ab_select(struct cmd_tbl *cmdtp, int flag, int argc, return CMD_RET_FAILURE; } - ret = ab_select_slot(dev_desc, &part_info); + + ret = ab_select_slot(dev_desc, &part_info, dec_tries); if (ret < 0) { printf("Android boot failed, error %d.\n", ret); return CMD_RET_FAILURE; @@ -41,9 +51,9 @@ static int do_ab_select(struct cmd_tbl *cmdtp, int flag, int argc, return CMD_RET_SUCCESS; } -U_BOOT_CMD(ab_select, 4, 0, do_ab_select, +U_BOOT_CMD(ab_select, 5, 0, do_ab_select, "Select the slot used to boot from and register the boot attempt.", - " \n" + " [--no-dec]\n" " - Load the slot metadata from the partition 'part' on\n" " device type 'interface' instance 'dev' and store the active\n" " slot in the 'slot_var_name' variable. This also updates the\n" @@ -53,4 +63,6 @@ U_BOOT_CMD(ab_select, 4, 0, do_ab_select, " - If 'part_name' is passed, preceded with a # instead of :, the\n" " partition name whose label is 'part_name' will be looked up in\n" " the partition table. This is commonly the \"misc\" partition.\n" + " - If '--no-dec' is set, the number of tries remaining will not\n" + " decremented for the selected boot slot\n" ); diff --git a/include/android_ab.h b/include/android_ab.h index 3eb61125c66..1fee7582b90 100644 --- a/include/android_ab.h +++ b/include/android_ab.h @@ -30,6 +30,7 @@ struct disk_partition; * @param[in] part_info Place to store the partition information * Return: The slot number (>= 0) on success, or a negative on error */ -int ab_select_slot(struct blk_desc *dev_desc, struct disk_partition *part_info); +int ab_select_slot(struct blk_desc *dev_desc, struct disk_partition *part_info, + bool dec_tries); #endif /* __ANDROID_AB_H */ -- cgit v1.3.1 From 387f8be55b5091c4ed39221ef6a38ea7099d0a36 Mon Sep 17 00:00:00 2001 From: Joshua Watt Date: Mon, 3 Jul 2023 08:39:54 -0500 Subject: disk: part: Add API to get partitions with specific driver Adds part_driver_get_type() API which can be used to force a specific driver to be used when getting partition information instead of relying on auto detection. Signed-off-by: Joshua Watt Reviewed-by: Simon Glass --- disk/part.c | 38 +++++++++++++++++++++++++++++++------- include/part.h | 19 ++++++++++++++++++- 2 files changed, 49 insertions(+), 8 deletions(-) (limited to 'include') diff --git a/disk/part.c b/disk/part.c index 1d2117ab71e..0a03b8213d8 100644 --- a/disk/part.c +++ b/disk/part.c @@ -26,6 +26,22 @@ /* Check all partition types */ #define PART_TYPE_ALL -1 +static struct part_driver *part_driver_get_type(int part_type) +{ + 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; + + for (entry = drv; entry != drv + n_ents; entry++) { + if (part_type == entry->part_type) + return entry; + } + + /* Not found */ + return NULL; +} + static struct part_driver *part_driver_lookup_type(struct blk_desc *dev_desc) { struct part_driver *drv = @@ -44,10 +60,7 @@ static struct part_driver *part_driver_lookup_type(struct blk_desc *dev_desc) } } } else { - for (entry = drv; entry != drv + n_ents; entry++) { - if (dev_desc->part_type == entry->part_type) - return entry; - } + return part_driver_get_type(dev_desc->part_type); } /* Not found */ @@ -322,8 +335,8 @@ void part_print(struct blk_desc *dev_desc) drv->print(dev_desc); } -int part_get_info(struct blk_desc *dev_desc, int part, - struct disk_partition *info) +int part_get_info_by_type(struct blk_desc *dev_desc, int part, int part_type, + struct disk_partition *info) { struct part_driver *drv; @@ -336,7 +349,12 @@ int part_get_info(struct blk_desc *dev_desc, int part, info->type_guid[0] = 0; #endif - drv = part_driver_lookup_type(dev_desc); + if (part_type == PART_TYPE_UNKNOWN) { + drv = part_driver_lookup_type(dev_desc); + } else { + drv = part_driver_get_type(part_type); + } + if (!drv) { debug("## Unknown partition table type %x\n", dev_desc->part_type); @@ -356,6 +374,12 @@ int part_get_info(struct blk_desc *dev_desc, int part, return -ENOENT; } +int part_get_info(struct blk_desc *dev_desc, int part, + struct disk_partition *info) +{ + return part_get_info_by_type(dev_desc, part, PART_TYPE_UNKNOWN, info); +} + int part_get_info_whole_disk(struct blk_desc *dev_desc, struct disk_partition *info) { diff --git a/include/part.h b/include/part.h index 3b1b5398699..b19b33ab89a 100644 --- a/include/part.h +++ b/include/part.h @@ -105,7 +105,24 @@ struct blk_desc *blk_get_dev(const char *ifname, int dev); struct blk_desc *mg_disk_get_dev(int dev); -/* disk/part.c */ +/** + * part_get_info_by_type() - Get partitions from a block device using a specific + * partition driver + * + * Each interface allocates its own devices and typically struct blk_desc is + * contained with the interface's data structure. There is no global + * numbering for block devices, so the interface name must be provided. + * + * @dev_desc: Block device descriptor + * @part: Partition number to read + * @part_type: Partition driver to use, or PART_TYPE_UNKNOWN to automatically + * choose a driver + * @info: Returned partition information + * + * Return: 0 on success, negative errno on failure + */ +int part_get_info_by_type(struct blk_desc *dev_desc, int part, int part_type, + struct disk_partition *info); int part_get_info(struct blk_desc *dev_desc, int part, struct disk_partition *info); /** -- cgit v1.3.1