Ruslan Trofymenko | 17030c7 | 2019-07-05 15:37:33 +0300 | [diff] [blame] | 1 | // SPDX-License-Identifier: BSD-2-Clause |
| 2 | /* |
| 3 | * Copyright (C) 2017 The Android Open Source Project |
| 4 | */ |
| 5 | |
Simon Glass | e6f6f9e | 2020-05-10 11:39:58 -0600 | [diff] [blame^] | 6 | #include <common.h> |
Ruslan Trofymenko | 17030c7 | 2019-07-05 15:37:33 +0300 | [diff] [blame] | 7 | #include <android_ab.h> |
| 8 | #include <command.h> |
Simon Glass | e6f6f9e | 2020-05-10 11:39:58 -0600 | [diff] [blame^] | 9 | #include <part.h> |
Ruslan Trofymenko | 17030c7 | 2019-07-05 15:37:33 +0300 | [diff] [blame] | 10 | |
| 11 | static int do_ab_select(cmd_tbl_t *cmdtp, int flag, int argc, |
| 12 | char * const argv[]) |
| 13 | { |
| 14 | int ret; |
| 15 | struct blk_desc *dev_desc; |
Simon Glass | 0528979 | 2020-05-10 11:39:57 -0600 | [diff] [blame] | 16 | struct disk_partition part_info; |
Ruslan Trofymenko | 17030c7 | 2019-07-05 15:37:33 +0300 | [diff] [blame] | 17 | char slot[2]; |
| 18 | |
| 19 | if (argc != 4) |
| 20 | return CMD_RET_USAGE; |
| 21 | |
| 22 | /* Lookup the "misc" partition from argv[2] and argv[3] */ |
| 23 | if (part_get_info_by_dev_and_name_or_num(argv[2], argv[3], |
| 24 | &dev_desc, &part_info) < 0) { |
| 25 | return CMD_RET_FAILURE; |
| 26 | } |
| 27 | |
| 28 | ret = ab_select_slot(dev_desc, &part_info); |
| 29 | if (ret < 0) { |
| 30 | printf("Android boot failed, error %d.\n", ret); |
| 31 | return CMD_RET_FAILURE; |
| 32 | } |
| 33 | |
| 34 | /* Android standard slot names are 'a', 'b', ... */ |
| 35 | slot[0] = BOOT_SLOT_NAME(ret); |
| 36 | slot[1] = '\0'; |
| 37 | env_set(argv[1], slot); |
| 38 | printf("ANDROID: Booting slot: %s\n", slot); |
| 39 | return CMD_RET_SUCCESS; |
| 40 | } |
| 41 | |
| 42 | U_BOOT_CMD(ab_select, 4, 0, do_ab_select, |
| 43 | "Select the slot used to boot from and register the boot attempt.", |
| 44 | "<slot_var_name> <interface> <dev[:part|#part_name]>\n" |
| 45 | " - Load the slot metadata from the partition 'part' on\n" |
| 46 | " device type 'interface' instance 'dev' and store the active\n" |
| 47 | " slot in the 'slot_var_name' variable. This also updates the\n" |
| 48 | " Android slot metadata with a boot attempt, which can cause\n" |
| 49 | " successive calls to this function to return a different result\n" |
| 50 | " if the returned slot runs out of boot attempts.\n" |
| 51 | " - If 'part_name' is passed, preceded with a # instead of :, the\n" |
| 52 | " partition name whose label is 'part_name' will be looked up in\n" |
| 53 | " the partition table. This is commonly the \"misc\" partition.\n" |
| 54 | ); |