All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ruslan Trofymenko <ruslan.trofymenko@linaro.org>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 4/7] cmd: Add 'android_ab_select' command
Date: Tue, 27 Nov 2018 21:57:19 +0200	[thread overview]
Message-ID: <1543348642-31045-5-git-send-email-ruslan.trofymenko@linaro.org> (raw)
In-Reply-To: <1543348642-31045-1-git-send-email-ruslan.trofymenko@linaro.org>

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 'android_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>
---
 cmd/Kconfig             | 11 ++++++++++
 cmd/Makefile            |  1 +
 cmd/android_ab_select.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 65 insertions(+)
 create mode 100644 cmd/android_ab_select.c

diff --git a/cmd/Kconfig b/cmd/Kconfig
index e2973b3..e96a5e4 100644
--- a/cmd/Kconfig
+++ b/cmd/Kconfig
@@ -1476,6 +1476,17 @@ config CMD_UUID
 	  The two commands are very similar except for the endianness of the
 	  output.
 
+config CMD_ANDROID_AB_SELECT
+	bool "android_ab_select"
+	default n
+	depends on ANDROID_AB
+	help
+	  On Android devices with more than one boot slot (multiple copies of
+	  the kernel and system images) this provides a command to select which
+	  slot should be used to boot from and register the boot attempt. This
+	  is used by the new A/B update model where one slot is updated in the
+	  background while running from the other slot.
+
 endmenu
 
 source "cmd/ti/Kconfig"
diff --git a/cmd/Makefile b/cmd/Makefile
index 5ec2f9e..23a78c0 100644
--- a/cmd/Makefile
+++ b/cmd/Makefile
@@ -12,6 +12,7 @@ obj-y += version.o
 
 # command
 obj-$(CONFIG_CMD_AES) += aes.o
+obj-$(CONFIG_CMD_ANDROID_AB_SELECT) += android_ab_select.o
 obj-$(CONFIG_CMD_ADC) += adc.o
 obj-$(CONFIG_CMD_ARMFLASH) += armflash.o
 obj-y += blk_common.o
diff --git a/cmd/android_ab_select.c b/cmd/android_ab_select.c
new file mode 100644
index 0000000..7966361
--- /dev/null
+++ b/cmd/android_ab_select.c
@@ -0,0 +1,53 @@
+// SPDX-License-Identifier: BSD-2-Clause
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ */
+
+#include <android_ab.h>
+#include <command.h>
+
+static int do_android_ab_select(cmd_tbl_t *cmdtp, int flag, int argc,
+				char * const argv[])
+{
+	int ret;
+	struct blk_desc *dev_desc;
+	disk_partition_t part_info;
+	char slot[2];
+
+	if (argc != 4)
+		return CMD_RET_USAGE;
+
+	/* Lookup the "misc" partition from argv[2] and argv[3] */
+	if (part_get_info_by_dev_and_name_or_num(argv[2], argv[3],
+						 &dev_desc, &part_info) < 0) {
+		return CMD_RET_FAILURE;
+	}
+
+	ret = ab_select_slot(dev_desc, &part_info);
+	if (ret < 0) {
+		printf("Android boot failed, error %d.\n", ret);
+		return CMD_RET_FAILURE;
+	}
+
+	/* Android standard slot names are 'a', 'b', ... */
+	slot[0] = ANDROID_BOOT_SLOT_NAME(ret);
+	slot[1] = '\0';
+	env_set(argv[1], slot);
+	printf("ANDROID: Booting slot: %s\n", slot);
+	return CMD_RET_SUCCESS;
+}
+
+U_BOOT_CMD(android_ab_select, 4, 0, do_android_ab_select,
+	   "Select the slot used to boot from and register the boot attempt.",
+	   "<slot_var_name> <interface> <dev[:part|#part_name]>\n"
+	   "    - Load the slot metadata from the partition 'part' on\n"
+	   "      device type 'interface' instance 'dev' and store the active\n"
+	   "      slot in the 'slot_var_name' variable. This also updates the\n"
+	   "      Android slot metadata with a boot attempt, which can cause\n"
+	   "      successive calls to this function to return a different result\n"
+	   "      if the returned slot runs out of boot attempts.\n"
+	   "    - If 'part_name' is passed, preceded with a # instead of :, the\n"
+	   "      partition name whose label is 'part_name' will be looked up in\n"
+	   "      the partition table. This is commonly the \"misc\" partition.\n"
+);
+
-- 
2.7.4

  parent reply	other threads:[~2018-11-27 19:57 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-27 19:57 [U-Boot] [PATCH 0/7] android: Implement A/B boot process Ruslan Trofymenko
2018-11-27 19:57 ` [U-Boot] [PATCH 1/7] cmd: part: Add 'number' sub-command Ruslan Trofymenko
2018-12-06  1:31   ` Simon Glass
2018-11-27 19:57 ` [U-Boot] [PATCH 2/7] disk: part: Extend API to get partition info Ruslan Trofymenko
2018-12-06  1:31   ` Simon Glass
2018-11-27 19:57 ` [U-Boot] [PATCH 3/7] common: Implement A/B metadata Ruslan Trofymenko
2018-12-06  1:31   ` Simon Glass
2019-04-03 17:55     ` Eugeniu Rosca
2019-04-07 16:51       ` Eugeniu Rosca
2019-04-07 19:11       ` Igor Opaniuk
2019-04-07 22:22         ` Eugeniu Rosca
2018-11-27 19:57 ` Ruslan Trofymenko [this message]
2018-11-27 19:57 ` [U-Boot] [PATCH 5/7] test/py: Add base test case for A/B updates Ruslan Trofymenko
2018-12-06  1:31   ` Simon Glass
2018-11-27 19:57 ` [U-Boot] [PATCH 6/7] doc: android: Add simple guide " Ruslan Trofymenko
2018-12-06  1:31   ` Simon Glass
2018-12-10 19:10     ` Ruslan Trofymenko
2018-12-11  0:00       ` Simon Glass
2018-11-27 19:57 ` [U-Boot] [PATCH 7/7] env: am57xx: Implement A/B boot process Ruslan Trofymenko
2018-11-27 20:09 ` [U-Boot] [PATCH 0/7] android: " Alistair Strachan
2018-11-28 14:38 ` Sam Protsenko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1543348642-31045-5-git-send-email-ruslan.trofymenko@linaro.org \
    --to=ruslan.trofymenko@linaro.org \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.