From patchwork Wed Dec 12 17:12:31 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ruslan Trofymenko X-Patchwork-Id: 153586 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp2056337ljp; Wed, 12 Dec 2018 09:17:25 -0800 (PST) X-Google-Smtp-Source: AFSGD/W80PS0SPiNQ00klwipwCLtvU2tyrbJjRJxY6bWxqwqc2HujvemImsxIVguS1WkLQE45K38 X-Received: by 2002:a17:906:6011:: with SMTP id o17-v6mr5725360ejj.237.1544635045058; Wed, 12 Dec 2018 09:17:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544635045; cv=none; d=google.com; s=arc-20160816; b=yYZnnBUrijQ/f2fD6kvn5X7w9PVCBFRphj1dbXIDKJVvrJtnt+2GpzH7bDou0LuAwc iqNNboNvdk0dDykDVc8CBSUNUBwyc6bV9o42SFP+Ai0p1mShIlHQxvJ4Q0v0yfEvHvQ2 nmYGgRLEZmLhCw+PzFXXZCYzKr9o0y77gAEcRUUooY2npBZPsFcsVgJjNt+4B+hKyG83 bAm8e3r/8B3o+TDWeZxo7FRT8zDPMDBT9FDykrbMUWywlNzACqmyEYvjiICcks+dbZ6G aaSRnNQ0DT2wqoTQi+zbKJ5oojVBqbnVUm4pCBwtUZCGHFNkibOJwnFAG8idfz4YWRVQ UOCg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:cc:references:in-reply-to:message-id :date:to:from:dkim-signature; bh=511y2B8Fx7rUsg646aI/5TgKMOsQnPhd9YM1/eV/7WE=; b=fYi5HiktPSOPJcW9LbVgQQslYhSFPNkVj7lczlSr7ywc/FPU1RS58q4JpkJ1qyeror jtIhQfUW4q62K73DEoefRGWcJ2nCU7oNTb8oFl1W72DAjaXC4RIH+fUErYAV+9AMpDCT niu71ImXL+wfN2QC9SCJ2Vo2CvXBfDpZQ0SI7JOKH4T1z0krC16OQp/jGgbTQMTjEaYE eFalGVGDxcy2RyAVkk5fcSU6Q+vsh5NRU3xJbe03O88gh7SZkCwIumqSXrup2gcxPEZv BBbNGK1xRH0v952zH3Sh/KEkcORXoqIJbIIJhkKaiR5NqSttZDnXXVKcPMQnwd14544G CpEA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b="GiY/BP8A"; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.denx.de (dione.denx.de. [81.169.180.215]) by mx.google.com with ESMTP id t13si1832029edb.83.2018.12.12.09.17.24; Wed, 12 Dec 2018 09:17:25 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) client-ip=81.169.180.215; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b="GiY/BP8A"; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: by lists.denx.de (Postfix, from userid 105) id 96225C2299F; Wed, 12 Dec 2018 17:15:05 +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 7B7E5C22756; Wed, 12 Dec 2018 17:13:02 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id D86E7C2275C; Wed, 12 Dec 2018 17:12:47 +0000 (UTC) Received: from mail-lf1-f66.google.com (mail-lf1-f66.google.com [209.85.167.66]) by lists.denx.de (Postfix) with ESMTPS id 9A065C22770 for ; Wed, 12 Dec 2018 17:12:42 +0000 (UTC) Received: by mail-lf1-f66.google.com with SMTP id e26so14115058lfc.2 for ; Wed, 12 Dec 2018 09:12:42 -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=0O0mgZ+73RVPMEwA8/6rtHkALhyMH9RudW6GAYt4r6s=; b=GiY/BP8AFclkNfZf+bZvQ3KD1TinUvvR0qDeklWxFiSF8jh5yplskYVVq4MaeWzqXT G1Irof7knMwZYLmLSMrljb01lsCwFR2M6YSuZz+nJ9KVYN9XyhkFAgcXvMPzCJyuyPDk 4ykZ/9K7k8wwReRfe7HOpVunH0uugMuXmvz5Q= 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=0O0mgZ+73RVPMEwA8/6rtHkALhyMH9RudW6GAYt4r6s=; b=OzrZM6TtcffCmUv5rCYRwysfsU52X6caVAPXCAEhLYZydxcxBM6ZUoApkCmSDgSG3J MZs9y3OWXYxOQvtUWGAiODpQX6aPsUSi/dZQJ+fCu1kU6MkobRHYlybGf4jHOBMYq8C5 fjaYB8kbtFXmn6UN7Lyde4KnSzLoDhtlwH8dr9hIhEQgWwZQIFMagAGdRI+q57W/Q7el 9fYCD91Ef4YvwHnb6hQsUClw0hZNtSF4VAJTWSOYjMdSDwnYV0ZZjlG8cQ/9WmtfRr7w 3ebRoY2JaggESLVSjbpHRhkS5XbSRgFzVo4+Sz41XK7dm2oYye1xd+GLy3EDS0Vdm1LH SO4g== X-Gm-Message-State: AA+aEWaMLTWfBXJa7Pn3pL3sd70CqIS1SKVdt/i3emr4Qg+Px9evshKD NjZSavX2Qb85MuCC4qxTDSb5c9xy0Sk= X-Received: by 2002:a19:4402:: with SMTP id r2mr2256102lfa.111.1544634761828; Wed, 12 Dec 2018 09:12:41 -0800 (PST) Received: from kbp1-dhp-f54913.synapse.com ([195.238.92.132]) by smtp.gmail.com with ESMTPSA id t81sm3358020lfe.84.2018.12.12.09.12.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 12 Dec 2018 09:12:41 -0800 (PST) From: Ruslan Trofymenko To: u-boot@lists.denx.de Date: Wed, 12 Dec 2018 19:12:31 +0200 Message-Id: <1544634754-3435-5-git-send-email-ruslan.trofymenko@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1544634754-3435-1-git-send-email-ruslan.trofymenko@linaro.org> References: <1544634754-3435-1-git-send-email-ruslan.trofymenko@linaro.org> Cc: Tom Rini , Praneeth Bajjuri , Alistair Strachan Subject: [U-Boot] [PATCH v2 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" 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 Reviewed-by: Alistair Strachan Reviewed-by: Sam Protsenko Reviewed-by: Igor Opaniuk --- 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 ea1a325..ed60e1e 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 4998643..1d345c1 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" +);