1 // SPDX-License-Identifier: BSD-2-Clause
3 * Copyright (C) 2017 The Android Open Source Project
6 #include <android_ab.h>
9 static int do_ab_select(cmd_tbl_t *cmdtp, int flag, int argc,
13 struct blk_desc *dev_desc;
14 disk_partition_t part_info;
20 /* Lookup the "misc" partition from argv[2] and argv[3] */
21 if (part_get_info_by_dev_and_name_or_num(argv[2], argv[3],
22 &dev_desc, &part_info) < 0) {
23 return CMD_RET_FAILURE;
26 ret = ab_select_slot(dev_desc, &part_info);
28 printf("Android boot failed, error %d.\n", ret);
29 return CMD_RET_FAILURE;
32 /* Android standard slot names are 'a', 'b', ... */
33 slot[0] = BOOT_SLOT_NAME(ret);
35 env_set(argv[1], slot);
36 printf("ANDROID: Booting slot: %s\n", slot);
37 return CMD_RET_SUCCESS;
40 U_BOOT_CMD(ab_select, 4, 0, do_ab_select,
41 "Select the slot used to boot from and register the boot attempt.",
42 "<slot_var_name> <interface> <dev[:part|#part_name]>\n"
43 " - Load the slot metadata from the partition 'part' on\n"
44 " device type 'interface' instance 'dev' and store the active\n"
45 " slot in the 'slot_var_name' variable. This also updates the\n"
46 " Android slot metadata with a boot attempt, which can cause\n"
47 " successive calls to this function to return a different result\n"
48 " if the returned slot runs out of boot attempts.\n"
49 " - If 'part_name' is passed, preceded with a # instead of :, the\n"
50 " partition name whose label is 'part_name' will be looked up in\n"
51 " the partition table. This is commonly the \"misc\" partition.\n"