From patchwork Tue Nov 27 19:57:19 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ruslan Trofymenko X-Patchwork-Id: 152166 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp219976ljp; Tue, 27 Nov 2018 12:14:31 -0800 (PST) X-Google-Smtp-Source: AFSGD/W7nNZZdKX57JrfSVFAWZYwpEakNuQI+ys5hVt7r8rcLCuC36K7FNF8YY0WdPG85x2VhrBK X-Received: by 2002:a50:de49:: with SMTP id a9mr12900457edl.18.1543349671496; Tue, 27 Nov 2018 12:14:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543349671; cv=none; d=google.com; s=arc-20160816; b=T8jkTo8Y9nFr5PbfQE9bkUTc1BuZ9q35HqY+d7OSzxXIBdsP+RzY0AeGBvCNGNTgN9 LzhXNOMuxFxRBPwM49a7W9d5jm33ptPkAWdcgTn2d7puHv1QwrkxvujGU/i1cjsVTiyE MJxdFhXgTZeIt0NYcIZSKa7jWTi6z4sM9j577sL340xeLi0iJ0VsfId1qp3CyjDk4OgM zyM0V/qrwfROuUfQgeS790gHwjR8gJnc5B3cV+XT/SE7qU8N12UrsduwBR4zE7WRYRde rMAzybz93vtK9LjkwRpt5L8bg+X/Qjj8pHwOIrA9SB6RdheYjTffCoRE/sgChR7yuNR8 Zohw== 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=M0S10jw8PPSIEUvkE0Pqv+1J/COeOWmIFlE87tkPdDs=; b=lHkAOrmNoAjnOwUevdnO/OiaU+ar0bSzDN6WuNDKAdZBlD1c68A5l5iAexS13C7kqE shEeeLEEenIptONHt/wvj6JTx0SMmqB1BREgsEuRHP+MQZEiKKHPj0IF82Kezg2ldbMD 4w9jJ1MbAMUXmyKPqQ40iFNasBTU7YEhrBjQZcsw7iR4nnp4qJ+CQ6M4zbmGxBOIKEii 1DJrz5gk9wN3YvSqmMv8YCdjWHBso+up38WWZmb1VD09g1Ejy8RzWvwcpt2NbDRS126H LlDpkUKDW5d+sniy5IoDVl76dU9hWYGMnBsMdXacYQlVmSau3htBGStd1RoekmX5TE/o RMeQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=HpQUdna8; 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 j21-v6si2283882ejt.227.2018.11.27.12.14.31; Tue, 27 Nov 2018 12:14:31 -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=HpQUdna8; 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 20E4FC22149; Tue, 27 Nov 2018 20:12:18 +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 11160C222D8; Tue, 27 Nov 2018 20:10:35 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 16F48C2212B; Tue, 27 Nov 2018 19:57:30 +0000 (UTC) Received: from mail-lf1-f65.google.com (mail-lf1-f65.google.com [209.85.167.65]) by lists.denx.de (Postfix) with ESMTPS id 98CE2C21DD7 for ; Tue, 27 Nov 2018 19:57:30 +0000 (UTC) Received: by mail-lf1-f65.google.com with SMTP id l10so17524921lfh.9 for ; Tue, 27 Nov 2018 11:57:30 -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=so/OLYxawWG64zoe2EMURMJbH5DFH0T0BfqngwSoyqY=; b=HpQUdna8yWuFvhgdpOFEMCrtBQUj37BqySbhKrg+ny4Pemr6Pg2kxyyKOBt8BPufDw NN7R4aJDwHi6ymXd6f8k/6F6cEKuh6AcmkFklK1R9NY5SmqMKWOSD8+HNX6FTKCmLFjh ffJZ1L1PwiVFenWpFcg8ASw5v6DV71l/rNmIQ= 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=so/OLYxawWG64zoe2EMURMJbH5DFH0T0BfqngwSoyqY=; b=U66CCGJiPnfOXAjcZ/Mb6zBPGK7ZWYq3Z6zQpregGTp8Nb4bAyjbxXUoOBa8ErywDr XrFa559PsbmzvlV0qFHAL4GQbAAbcE7thxwGCJpFDzJ9pbx0CVurinVM+qFRneUDQBSa sY2lKP+jF5AFzRgASzFvVrpmL7oTU5yIf/dCQnI1t6+GqOKebw/Jb8+un2763jlbguko Lpll/Y96m6p74PkuDdXfP++2gQOxTasomQqaBmkaXe1/ZCjBPyIksfUaAhLP+ahX+3Dx z//Lh2RmCR948Cl2Q7batqQGBxzY/kA+zMcpj5q0nR6StpMDiM7m1+4jq8Vug25AYh3T 4uNQ== X-Gm-Message-State: AA+aEWZmIlVZhsg8bZthchFI/+olJXyzO1AqvDldp83F7MvyHqDFWwrG X26gH7UB524/TtEx8D7r7q0HQ9bdUII= X-Received: by 2002:a19:48d0:: with SMTP id v199mr3998925lfa.104.1543348649727; Tue, 27 Nov 2018 11:57:29 -0800 (PST) Received: from kbp1-dhp-f54913.synapse.com ([195.238.92.132]) by smtp.gmail.com with ESMTPSA id g12-v6sm738725lja.74.2018.11.27.11.57.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 27 Nov 2018 11:57:28 -0800 (PST) From: Ruslan Trofymenko To: u-boot@lists.denx.de Date: Tue, 27 Nov 2018 21:57:19 +0200 Message-Id: <1543348642-31045-5-git-send-email-ruslan.trofymenko@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1543348642-31045-1-git-send-email-ruslan.trofymenko@linaro.org> References: <1543348642-31045-1-git-send-email-ruslan.trofymenko@linaro.org> X-Mailman-Approved-At: Tue, 27 Nov 2018 20:10:30 +0000 Cc: Tom Rini , Praneeth Bajjuri , Alistair Strachan Subject: [U-Boot] [PATCH 4/7] cmd: Add 'android_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 '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 --- 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 +#include + +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.", + " \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" +); +