]> Git Repo - J-u-boot.git/blame - cmd/ab_select.c
bootm: Drop arguments from do_bootm_states()
[J-u-boot.git] / cmd / ab_select.c
CommitLineData
17030c7c
RT
1// SPDX-License-Identifier: BSD-2-Clause
2/*
3 * Copyright (C) 2017 The Android Open Source Project
4 */
5
e6f6f9e6 6#include <common.h>
17030c7c
RT
7#include <android_ab.h>
8#include <command.h>
09140113 9#include <env.h>
e6f6f9e6 10#include <part.h>
17030c7c 11
09140113
SG
12static int do_ab_select(struct cmd_tbl *cmdtp, int flag, int argc,
13 char *const argv[])
17030c7c
RT
14{
15 int ret;
16 struct blk_desc *dev_desc;
0528979f 17 struct disk_partition part_info;
17030c7c 18 char slot[2];
22cdb3f0 19 bool dec_tries = true;
17030c7c 20
22cdb3f0 21 if (argc < 4)
17030c7c
RT
22 return CMD_RET_USAGE;
23
22cdb3f0
JW
24 for (int i = 4; i < argc; i++) {
25 if (strcmp(argv[i], "--no-dec") == 0) {
26 dec_tries = false;
27 } else {
28 return CMD_RET_USAGE;
29 }
30 }
31
17030c7c
RT
32 /* Lookup the "misc" partition from argv[2] and argv[3] */
33 if (part_get_info_by_dev_and_name_or_num(argv[2], argv[3],
9f7bb282
SA
34 &dev_desc, &part_info,
35 false) < 0) {
17030c7c
RT
36 return CMD_RET_FAILURE;
37 }
38
22cdb3f0
JW
39
40 ret = ab_select_slot(dev_desc, &part_info, dec_tries);
17030c7c
RT
41 if (ret < 0) {
42 printf("Android boot failed, error %d.\n", ret);
43 return CMD_RET_FAILURE;
44 }
45
46 /* Android standard slot names are 'a', 'b', ... */
47 slot[0] = BOOT_SLOT_NAME(ret);
48 slot[1] = '\0';
49 env_set(argv[1], slot);
50 printf("ANDROID: Booting slot: %s\n", slot);
51 return CMD_RET_SUCCESS;
52}
53
22cdb3f0 54U_BOOT_CMD(ab_select, 5, 0, do_ab_select,
17030c7c 55 "Select the slot used to boot from and register the boot attempt.",
22cdb3f0 56 "<slot_var_name> <interface> <dev[:part|#part_name]> [--no-dec]\n"
17030c7c
RT
57 " - Load the slot metadata from the partition 'part' on\n"
58 " device type 'interface' instance 'dev' and store the active\n"
59 " slot in the 'slot_var_name' variable. This also updates the\n"
60 " Android slot metadata with a boot attempt, which can cause\n"
61 " successive calls to this function to return a different result\n"
62 " if the returned slot runs out of boot attempts.\n"
63 " - If 'part_name' is passed, preceded with a # instead of :, the\n"
64 " partition name whose label is 'part_name' will be looked up in\n"
65 " the partition table. This is commonly the \"misc\" partition.\n"
22cdb3f0
JW
66 " - If '--no-dec' is set, the number of tries remaining will not\n"
67 " decremented for the selected boot slot\n"
17030c7c 68);
This page took 0.113659 seconds and 4 git commands to generate.