]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
android_ab: Add option to skip decrementing tries
authorJoshua Watt <jpewhacker@gmail.com>
Fri, 23 Jun 2023 22:05:48 +0000 (17:05 -0500)
committerTom Rini <trini@konsulko.com>
Mon, 17 Jul 2023 19:39:55 +0000 (15:39 -0400)
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 <JPEWhacker@gmail.com>
boot/android_ab.c
cmd/ab_select.c
include/android_ab.h

index 2d7b392666563d5c1ab96cbdc539c28fc391500f..60ae002978f1af0db04b49d7cb6cf6bd51bd97cf 100644 (file)
@@ -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) {
index 3e46663d6ea543a59d9c01db2bc0f51a51a3cdcc..bfb67b8236b62b56a81869fcebe46dd13fdcb60c 100644 (file)
@@ -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.",
-          "<slot_var_name> <interface> <dev[:part|#part_name]>\n"
+          "<slot_var_name> <interface> <dev[:part|#part_name]> [--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"
 );
index 3eb61125c661ab640df96ede71a3d10c5de96a24..1fee7582b90adc91e4b39b9b3720806d1cc277db 100644 (file)
@@ -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 */