From b7ab6e41f8ec83d58ec74ef7e9c22e42e86ab1a7 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Thu, 12 May 2022 11:32:52 -0500 Subject: [PATCH] cmd: ab_select: Don't count boot-to-recovery as a boot attempt. The slot rollback system is intended for normal boot failures after an OTA, and therefore, we should not attempt to change slots based on a failure to boot to recovery (or any other non-normal boot sequence). Signed-off-by: Ram Muthiah Link: https://android-review.googlesource.com/c/platform/external/u-boot/+/1446441 Signed-off-by: Guillaume La Roque --- cmd/ab_select.c | 2 +- common/android_ab.c | 9 +++++++-- include/android_ab.h | 5 ++++- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/cmd/ab_select.c b/cmd/ab_select.c index 6298fcfb60..689ad39428 100644 --- a/cmd/ab_select.c +++ b/cmd/ab_select.c @@ -26,7 +26,7 @@ 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, true); if (ret < 0) { printf("Android boot failed, error %d.\n", ret); return CMD_RET_FAILURE; diff --git a/common/android_ab.c b/common/android_ab.c index 4943f26d53..80aedfbef8 100644 --- a/common/android_ab.c +++ b/common/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 normal_boot) { struct bootloader_control *abc = NULL; u32 crc32_le; @@ -268,7 +269,11 @@ int ab_select_slot(struct blk_desc *dev_desc, struct disk_partition *part_info) } } - if (slot >= 0 && !abc->slot_info[slot].successful_boot) { + /* Note that we only count the boot attempt as a valid try when performing + * normal boots to Android. Booting to recovery or fastboot does not count + * as a normal boot. + */ + if (slot >= 0 && !abc->slot_info[slot].successful_boot && normal_boot) { log_err("ANDROID: Attempting slot %c, tries remaining %d\n", BOOT_SLOT_NAME(slot), abc->slot_info[slot].tries_remaining); diff --git a/include/android_ab.h b/include/android_ab.h index 0941eb6b9c..6b003889dc 100644 --- a/include/android_ab.h +++ b/include/android_ab.h @@ -28,8 +28,11 @@ struct disk_partition; * * @param[in] dev_desc Place to store the device description pointer * @param[in] part_info Place to store the partition information + * @param[in] normal_boot True if a normal boot, false if booting to recovery. * @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 normal_boot); + #endif /* __ANDROID_AB_H */