Skip to content

Commit 22cdb3f

Browse files
JPEWdevtrini
authored andcommitted
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 <[email protected]>
1 parent 4837a1d commit 22cdb3f

File tree

3 files changed

+24
-8
lines changed

3 files changed

+24
-8
lines changed

boot/android_ab.c

+6-3
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,8 @@ static int ab_compare_slots(const struct slot_metadata *a,
181181
return 0;
182182
}
183183

184-
int ab_select_slot(struct blk_desc *dev_desc, struct disk_partition *part_info)
184+
int ab_select_slot(struct blk_desc *dev_desc, struct disk_partition *part_info,
185+
bool dec_tries)
185186
{
186187
struct bootloader_control *abc = NULL;
187188
u32 crc32_le;
@@ -272,8 +273,10 @@ int ab_select_slot(struct blk_desc *dev_desc, struct disk_partition *part_info)
272273
log_err("ANDROID: Attempting slot %c, tries remaining %d\n",
273274
BOOT_SLOT_NAME(slot),
274275
abc->slot_info[slot].tries_remaining);
275-
abc->slot_info[slot].tries_remaining--;
276-
store_needed = true;
276+
if (dec_tries) {
277+
abc->slot_info[slot].tries_remaining--;
278+
store_needed = true;
279+
}
277280
}
278281

279282
if (slot >= 0) {

cmd/ab_select.c

+16-4
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,28 @@ static int do_ab_select(struct cmd_tbl *cmdtp, int flag, int argc,
1616
struct blk_desc *dev_desc;
1717
struct disk_partition part_info;
1818
char slot[2];
19+
bool dec_tries = true;
1920

20-
if (argc != 4)
21+
if (argc < 4)
2122
return CMD_RET_USAGE;
2223

24+
for (int i = 4; i < argc; i++) {
25+
if (strcmp(argv[i], "--no-dec") == 0) {
26+
dec_tries = false;
27+
} else {
28+
return CMD_RET_USAGE;
29+
}
30+
}
31+
2332
/* Lookup the "misc" partition from argv[2] and argv[3] */
2433
if (part_get_info_by_dev_and_name_or_num(argv[2], argv[3],
2534
&dev_desc, &part_info,
2635
false) < 0) {
2736
return CMD_RET_FAILURE;
2837
}
2938

30-
ret = ab_select_slot(dev_desc, &part_info);
39+
40+
ret = ab_select_slot(dev_desc, &part_info, dec_tries);
3141
if (ret < 0) {
3242
printf("Android boot failed, error %d.\n", ret);
3343
return CMD_RET_FAILURE;
@@ -41,9 +51,9 @@ static int do_ab_select(struct cmd_tbl *cmdtp, int flag, int argc,
4151
return CMD_RET_SUCCESS;
4252
}
4353

44-
U_BOOT_CMD(ab_select, 4, 0, do_ab_select,
54+
U_BOOT_CMD(ab_select, 5, 0, do_ab_select,
4555
"Select the slot used to boot from and register the boot attempt.",
46-
"<slot_var_name> <interface> <dev[:part|#part_name]>\n"
56+
"<slot_var_name> <interface> <dev[:part|#part_name]> [--no-dec]\n"
4757
" - Load the slot metadata from the partition 'part' on\n"
4858
" device type 'interface' instance 'dev' and store the active\n"
4959
" 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,
5363
" - If 'part_name' is passed, preceded with a # instead of :, the\n"
5464
" partition name whose label is 'part_name' will be looked up in\n"
5565
" the partition table. This is commonly the \"misc\" partition.\n"
66+
" - If '--no-dec' is set, the number of tries remaining will not\n"
67+
" decremented for the selected boot slot\n"
5668
);

include/android_ab.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ struct disk_partition;
3030
* @param[in] part_info Place to store the partition information
3131
* Return: The slot number (>= 0) on success, or a negative on error
3232
*/
33-
int ab_select_slot(struct blk_desc *dev_desc, struct disk_partition *part_info);
33+
int ab_select_slot(struct blk_desc *dev_desc, struct disk_partition *part_info,
34+
bool dec_tries);
3435

3536
#endif /* __ANDROID_AB_H */

0 commit comments

Comments
 (0)