blob: 3e46663d6ea543a59d9c01db2bc0f51a51a3cdcc [file] [log] [blame]
Ruslan Trofymenkoa24f9b42019-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 Glass655306c2020-05-10 11:39:58 -06006#include <common.h>
Ruslan Trofymenkoa24f9b42019-07-05 15:37:33 +03007#include <android_ab.h>
8#include <command.h>
Simon Glassed38aef2020-05-10 11:40:03 -06009#include <env.h>
Simon Glass655306c2020-05-10 11:39:58 -060010#include <part.h>
Ruslan Trofymenkoa24f9b42019-07-05 15:37:33 +030011
Simon Glassed38aef2020-05-10 11:40:03 -060012static int do_ab_select(struct cmd_tbl *cmdtp, int flag, int argc,
13 char *const argv[])
Ruslan Trofymenkoa24f9b42019-07-05 15:37:33 +030014{
15 int ret;
16 struct blk_desc *dev_desc;
Simon Glassc1c4a8f2020-05-10 11:39:57 -060017 struct disk_partition part_info;
Ruslan Trofymenkoa24f9b42019-07-05 15:37:33 +030018 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],
Sean Andersonc81028d2021-02-05 09:38:56 -050025 &dev_desc, &part_info,
26 false) < 0) {
Ruslan Trofymenkoa24f9b42019-07-05 15:37:33 +030027 return CMD_RET_FAILURE;
28 }
29
30 ret = ab_select_slot(dev_desc, &part_info);
31 if (ret < 0) {
32 printf("Android boot failed, error %d.\n", ret);
33 return CMD_RET_FAILURE;
34 }
35
36 /* Android standard slot names are 'a', 'b', ... */
37 slot[0] = BOOT_SLOT_NAME(ret);
38 slot[1] = '\0';
39 env_set(argv[1], slot);
40 printf("ANDROID: Booting slot: %s\n", slot);
41 return CMD_RET_SUCCESS;
42}
43
44U_BOOT_CMD(ab_select, 4, 0, do_ab_select,
45 "Select the slot used to boot from and register the boot attempt.",
46 "<slot_var_name> <interface> <dev[:part|#part_name]>\n"
47 " - Load the slot metadata from the partition 'part' on\n"
48 " device type 'interface' instance 'dev' and store the active\n"
49 " slot in the 'slot_var_name' variable. This also updates the\n"
50 " Android slot metadata with a boot attempt, which can cause\n"
51 " successive calls to this function to return a different result\n"
52 " if the returned slot runs out of boot attempts.\n"
53 " - If 'part_name' is passed, preceded with a # instead of :, the\n"
54 " partition name whose label is 'part_name' will be looked up in\n"
55 " the partition table. This is commonly the \"misc\" partition.\n"
56);