Commit 17030c7c4c99c09f439641628734dfc5840da3ff

Authored by Ruslan Trofymenko
Committed by Tom Rini
1 parent d65e8da92e

cmd: Add 'ab_select' command

For A/B system update support the Android boot process requires to send
'androidboot.slot_suffix' parameter as a command line argument. This
patch implementes 'ab_select' command which allows us to obtain current
slot by processing the A/B metadata.

The patch was extracted from commit [1] with one modification: the
separator for specifying the name of metadata partition was changed
from ';' to '#', because ';' is used for commands separation.

[1] https://android-review.googlesource.com/c/platform/external/u-boot/+/729880/2

Signed-off-by: Ruslan Trofymenko <ruslan.trofymenko@linaro.org>
Signed-off-by: Igor Opaniuk <igor.opaniuk@gmail.com>
Reviewed-by: Alistair Strachan <astrachan@google.com>
Reviewed-by: Sam Protsenko <semen.protsenko@linaro.org>
Reviewed-by: Simon Glass <sjg@chromium.org>

Showing 3 changed files with 68 additions and 0 deletions Side-by-side Diff

... ... @@ -1198,6 +1198,21 @@
1198 1198  
1199 1199 endmenu
1200 1200  
  1201 +menu "Android support commands"
  1202 +
  1203 +config CMD_AB_SELECT
  1204 + bool "ab_select"
  1205 + default n
  1206 + depends on ANDROID_AB
  1207 + help
  1208 + On Android devices with more than one boot slot (multiple copies of
  1209 + the kernel and system images) this provides a command to select which
  1210 + slot should be used to boot from and register the boot attempt. This
  1211 + is used by the new A/B update model where one slot is updated in the
  1212 + background while running from the other slot.
  1213 +
  1214 +endmenu
  1215 +
1201 1216 if NET
1202 1217  
1203 1218 menuconfig CMD_NET
... ... @@ -12,6 +12,7 @@
12 12  
13 13 # command
14 14 obj-$(CONFIG_CMD_AES) += aes.o
  15 +obj-$(CONFIG_CMD_AB_SELECT) += ab_select.o
15 16 obj-$(CONFIG_CMD_ADC) += adc.o
16 17 obj-$(CONFIG_CMD_ARMFLASH) += armflash.o
17 18 obj-y += blk_common.o
  1 +// SPDX-License-Identifier: BSD-2-Clause
  2 +/*
  3 + * Copyright (C) 2017 The Android Open Source Project
  4 + */
  5 +
  6 +#include <android_ab.h>
  7 +#include <command.h>
  8 +
  9 +static int do_ab_select(cmd_tbl_t *cmdtp, int flag, int argc,
  10 + char * const argv[])
  11 +{
  12 + int ret;
  13 + struct blk_desc *dev_desc;
  14 + disk_partition_t part_info;
  15 + char slot[2];
  16 +
  17 + if (argc != 4)
  18 + return CMD_RET_USAGE;
  19 +
  20 + /* Lookup the "misc" partition from argv[2] and argv[3] */
  21 + if (part_get_info_by_dev_and_name_or_num(argv[2], argv[3],
  22 + &dev_desc, &part_info) < 0) {
  23 + return CMD_RET_FAILURE;
  24 + }
  25 +
  26 + ret = ab_select_slot(dev_desc, &part_info);
  27 + if (ret < 0) {
  28 + printf("Android boot failed, error %d.\n", ret);
  29 + return CMD_RET_FAILURE;
  30 + }
  31 +
  32 + /* Android standard slot names are 'a', 'b', ... */
  33 + slot[0] = BOOT_SLOT_NAME(ret);
  34 + slot[1] = '\0';
  35 + env_set(argv[1], slot);
  36 + printf("ANDROID: Booting slot: %s\n", slot);
  37 + return CMD_RET_SUCCESS;
  38 +}
  39 +
  40 +U_BOOT_CMD(ab_select, 4, 0, do_ab_select,
  41 + "Select the slot used to boot from and register the boot attempt.",
  42 + "<slot_var_name> <interface> <dev[:part|#part_name]>\n"
  43 + " - Load the slot metadata from the partition 'part' on\n"
  44 + " device type 'interface' instance 'dev' and store the active\n"
  45 + " slot in the 'slot_var_name' variable. This also updates the\n"
  46 + " Android slot metadata with a boot attempt, which can cause\n"
  47 + " successive calls to this function to return a different result\n"
  48 + " if the returned slot runs out of boot attempts.\n"
  49 + " - If 'part_name' is passed, preceded with a # instead of :, the\n"
  50 + " partition name whose label is 'part_name' will be looked up in\n"
  51 + " the partition table. This is commonly the \"misc\" partition.\n"
  52 +);