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