From patchwork Mon Feb 18 16:21:54 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Igor Opaniuk X-Patchwork-Id: 1044156 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="Dqowdn/L"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 4438M61Rm7z9s7h for ; Tue, 19 Feb 2019 03:24:01 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id A4BB1C21F93; Mon, 18 Feb 2019 16:23:21 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=RCVD_IN_MSPIKE_H2, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 4EB90C21FC4; Mon, 18 Feb 2019 16:22:20 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id DF39CC21FAF; Mon, 18 Feb 2019 16:22:14 +0000 (UTC) Received: from mail-lj1-f196.google.com (mail-lj1-f196.google.com [209.85.208.196]) by lists.denx.de (Postfix) with ESMTPS id 82C99C21FB5 for ; Mon, 18 Feb 2019 16:22:08 +0000 (UTC) Received: by mail-lj1-f196.google.com with SMTP id r10-v6so14886920ljj.4 for ; Mon, 18 Feb 2019 08:22:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=wyamwwdJAwh7hdQI06EZrQamO96USFEqpVHIuxNezTY=; b=Dqowdn/LlsN8QsRasoch161RMP7dPSCjliCSYZ8NiGGyaGjCipopOXVR68eAPs/+4K ZmLwQiG3iOJ11nVwSVTLCpxjqc4GBRDww6nfvOSwcyKsSDC9oo6sP0MQSWWt/+3sDC6L dGvcztrhV90WJsWfybD0ot4n1X85kyjBJ76dVPy1yy6SqUCSH0yM+X6gsMdW/n4owfl3 VRlAYjy+4ahLM3sOVOv6rUnZCC3ZAz06DqrBuWP2La4KjqWbxv6dHW6+oV/2XM4ko7hM kZlm2BjHNP1Vakruv6ZVONpaVhJxVxenvDtCl4WxA0BK2g/7JUiXK4HD7TVwag/5eavS OP1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=wyamwwdJAwh7hdQI06EZrQamO96USFEqpVHIuxNezTY=; b=pPDe453LPI4WJGpZ0qv5t70l+QaFs55GLITrIYi2OkywZCQCLCVBA4/dW5M++KidWT NIfbL1BIK2zYHPqQnCRm14Zy+jA7ySfjE20Hfaetw3vXj5+CEAybn9DyU9NistSpHn/L xSYVy+FuvVTiZGlRSLne1Hf2sxSfczv38BFadQjNftsAmzVcR4MNnq1Na5cBRt/cjdZj DyVf9I+t9JYY1PsATUV5MvWzRVf+pQ5FG7/H3qW0Az7gHIDLIO4nw/hNXfFO6T5uVloo d267r+OM6DhZPTF2IA56dPFhSPeOFFBcRoMAv1LLHxVhEPVU8ryF/RwO6USYl0o0GHQN bi5w== X-Gm-Message-State: AHQUAuZTiVOF/QXcUAA8LLFIcuLPH0c8yL0ocG3hnSkTzu+IipNIOSNy Oj4Jh1wDo/FuhoM1d469cU88suX9RSk= X-Google-Smtp-Source: AHgI3IasZgzQp66m6JgWM57owH23Un5eOAIUlMnrrdJ5Q20cj4tOKhGY0B5peyOWAuI770sNCnqiQw== X-Received: by 2002:a2e:9595:: with SMTP id w21-v6mr14363277ljh.194.1550506927502; Mon, 18 Feb 2019 08:22:07 -0800 (PST) Received: from localhost ([195.238.92.223]) by smtp.gmail.com with ESMTPSA id v65sm3725554lje.77.2019.02.18.08.22.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 18 Feb 2019 08:22:06 -0800 (PST) From: Igor Opaniuk To: u-boot@lists.denx.de Date: Mon, 18 Feb 2019 18:21:54 +0200 Message-Id: <1550506917-25547-5-git-send-email-igor.opaniuk@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1550506917-25547-1-git-send-email-igor.opaniuk@linaro.org> References: <1550506917-25547-1-git-send-email-igor.opaniuk@linaro.org> Cc: trini@konsulko.com, deymo@google.com, praneeth@ti.com, astrachan@google.com, semen.protsenko@linaro.org Subject: [U-Boot] [PATCH v3 4/7] cmd: Add 'ab_select' command X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" From: Ruslan Trofymenko 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 Signed-off-by: Igor Opaniuk Reviewed-by: Alistair Strachan Reviewed-by: Sam Protsenko Reviewed-by: Simon Glass --- Changes in v3: None Changes in v2: * 'android_ab_select' command is renamed to 'ab_select' command * command is moved to the separate 'Android support commands' menu cmd/Kconfig | 15 +++++++++++++++ cmd/Makefile | 1 + cmd/ab_select.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 68 insertions(+) create mode 100644 cmd/ab_select.c diff --git a/cmd/Kconfig b/cmd/Kconfig index 3ea42e4..290a570 100644 --- a/cmd/Kconfig +++ b/cmd/Kconfig @@ -1123,6 +1123,21 @@ config CMD_SETEXPR endmenu +menu "Android support commands" + +config CMD_AB_SELECT + bool "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 + if NET menuconfig CMD_NET diff --git a/cmd/Makefile b/cmd/Makefile index 15ae4d2..ea03eb0 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_AB_SELECT) += ab_select.o obj-$(CONFIG_CMD_ADC) += adc.o obj-$(CONFIG_CMD_ARMFLASH) += armflash.o obj-y += blk_common.o diff --git a/cmd/ab_select.c b/cmd/ab_select.c new file mode 100644 index 0000000..2a9e524 --- /dev/null +++ b/cmd/ab_select.c @@ -0,0 +1,52 @@ +// SPDX-License-Identifier: BSD-2-Clause +/* + * Copyright (C) 2017 The Android Open Source Project + */ + +#include +#include + +static int do_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(ab_select, 4, 0, do_ab_select, + "Select the slot used to boot from and register the boot attempt.", + " \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" +);