blob: 7a4e51571b6d1b550a7c0d7ed014d89dd58b4c70 [file] [log] [blame]
Ruslan Trofymenko17030c72019-07-05 15:37:33 +03001// SPDX-License-Identifier: BSD-2-Clause
2/*
3 * Copyright (C) 2017 The Android Open Source Project
4 */
5
Simon Glasse6f6f9e2020-05-10 11:39:58 -06006#include <common.h>
Ruslan Trofymenko17030c72019-07-05 15:37:33 +03007#include <android_ab.h>
8#include <command.h>
Simon Glasse6f6f9e2020-05-10 11:39:58 -06009#include <part.h>
Ruslan Trofymenko17030c72019-07-05 15:37:33 +030010
11static 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 Glass05289792020-05-10 11:39:57 -060016 struct disk_partition part_info;
Ruslan Trofymenko17030c72019-07-05 15:37:33 +030017 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
42U_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);