From patchwork Tue Nov 27 19:57:16 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ruslan Trofymenko X-Patchwork-Id: 152163 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp216408ljp; Tue, 27 Nov 2018 12:11:16 -0800 (PST) X-Google-Smtp-Source: AFSGD/UKB8sXdgbiU1e18z7/3fdCht2i+jGgMVOztA475i9jleqcfeu6k68A29suX0Hb1uRK3ySX X-Received: by 2002:a50:c2d9:: with SMTP id u25mr23840782edf.280.1543349476244; Tue, 27 Nov 2018 12:11:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543349476; cv=none; d=google.com; s=arc-20160816; b=XoRYmxLpTqmpYWy4uGSZ4tZQdvW6/PzX4a38B8gg6EOJUPqwJidEAwIaU34oKezjAQ 8xugtfuco2froIia8MJw8ba8Zs5MG8VMFS9DtKx70Yrf1hJLlE2ES731FISDsxyQPwdg Z/6NhYnAeOTVPJo5r1CSHVcmvMOqOKKQCU5sELL+L1Rg/N3q1+zXcuVK7O0NtTiL6nWW 8Vu9pKDeGvpAkGTjwjpA/PRUcq0dQWFjVbNrMshCowltUAKKby1nDxD3WPlL2TzD63Ai Su9OvdNGoFgfd5lSgj77R52Dv7QCH87snRuc5db0TFHWkMbLnJJ5gj+tm2pnwjPMJ1kN 9rsQ== 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=ZRxvQRAnOnWWjm5Y4cDGVkY+nKkM20wC+SA92HJgcuY=; b=Dngkci3Y2pshlv/oVIOM5wWpj49W+zMNgfE7hdPGHixehZf5/wjCmDgG3940AfvBLM YGO40Co/SJDSsAQ18FGrXdKqa0M0EV2FKW2/+CzrfKtTeoYLvtG0AwfavJnLHJL9d6Y9 g9fweyEyx+1y2UvSwhwvo487l3vNqJrf9vHxfpaaR0rn+g6Ch7zq8j9Y63hqetIsIyoQ eoMgGArVMyWk8bggYG3/suphysLQFIL7603FPOCVv8lRFQC5VTz6CeAcVEdc7s4VfH69 WRYsfEBCj+sBi37c4IzRMPUiyx/rHd3aWrIBXCOQDOz+0PGbxOtIBKr0nu3xXCPPJ38G NYCg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=cWKCEnpE; 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 t37si492176eda.73.2018.11.27.12.11.15; Tue, 27 Nov 2018 12:11:16 -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=cWKCEnpE; 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 B1A31C2215A; Tue, 27 Nov 2018 20:10:56 +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 6FC6CC221B9; Tue, 27 Nov 2018 20:10:32 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 181E9C21EAE; Tue, 27 Nov 2018 19:57:27 +0000 (UTC) Received: from mail-lj1-f194.google.com (mail-lj1-f194.google.com [209.85.208.194]) by lists.denx.de (Postfix) with ESMTPS id A68A9C21DD7 for ; Tue, 27 Nov 2018 19:57:26 +0000 (UTC) Received: by mail-lj1-f194.google.com with SMTP id x85-v6so21221462ljb.2 for ; Tue, 27 Nov 2018 11:57:26 -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=s5tuNFuL3KUFvnEbMUeDwm3zdzbt8dPfpwD+7jSySnI=; b=cWKCEnpEj/MhLBa4NP4TWmRAjMNfc7gWfkpSK3bm3rUjwXB82BFCMcwfr/mH1cZZWH 7Op55sfRxL/15ye9829VNV+XIAm77qyL90rWrACq4dZf5UVwTuwFNXUZBDWI6JPLz5vq cg1e74fa4fN9E5o58FFQJ4iajmqyrt2VcMPlk= 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=s5tuNFuL3KUFvnEbMUeDwm3zdzbt8dPfpwD+7jSySnI=; b=ScJiYZUMc7CUga+N8YCOr6zCVheYxgk/ptcRVGwtTO+YkzSO/XATJRbuDSAchkNOid KXiJa7vBRrY34kQOz8ypOYI2DoeDwWQf/u5vLfWe5LjVW7FxL3EUvPsoJtJvy44MOoYq Vv0YZ6i2LdFvSag7cD1xaY5Tjz/us/RcANSAFx+yZgj1A1VdKJWID2hKDkMJrNbCk3JR ZGKSvM/hp2TFfZFvD6tMSKBcYg/luJ202lwHH9xzBWgRYomzhqCqVzOu8WDf4BWYimYl /ioBnbUe9C3e2XeRre88dt/JT46qZ++Rhi7CToUfu/SFcuFRHcCZKFGbJFCqxznzM+yq fErw== X-Gm-Message-State: AA+aEWb9BoVdJC5S+ru586Iq7iEyEj5JC+/JWo+c+2eN9Vh2xQVvoG/p 7ZeHeR5kYzazzcdasjJJ4fqIgaL/r1o= X-Received: by 2002:a2e:9783:: with SMTP id y3-v6mr20426505lji.167.1543348645773; Tue, 27 Nov 2018 11:57:25 -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.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 27 Nov 2018 11:57:25 -0800 (PST) From: Ruslan Trofymenko To: u-boot@lists.denx.de Date: Tue, 27 Nov 2018 21:57:16 +0200 Message-Id: <1543348642-31045-2-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 1/7] cmd: part: Add 'number' sub-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" This sub-command serves for getting the partition index from partition name. Also it can be used to test the existence of specified partition. Signed-off-by: Ruslan Trofymenko Reviewed-by: Simon Glass --- cmd/part.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/cmd/part.c b/cmd/part.c index bfb6488..653e13c 100644 --- a/cmd/part.c +++ b/cmd/part.c @@ -24,6 +24,7 @@ enum cmd_part_info { CMD_PART_INFO_START = 0, CMD_PART_INFO_SIZE, + CMD_PART_INFO_NUMBER }; static int do_part_uuid(int argc, char * const argv[]) @@ -149,6 +150,9 @@ static int do_part_info(int argc, char * const argv[], enum cmd_part_info param) case CMD_PART_INFO_SIZE: snprintf(buf, sizeof(buf), LBAF, info.size); break; + case CMD_PART_INFO_NUMBER: + snprintf(buf, sizeof(buf), "%d", part); + break; default: printf("** Unknown cmd_part_info value: %d\n", param); return 1; @@ -172,6 +176,11 @@ static int do_part_size(int argc, char * const argv[]) return do_part_info(argc, argv, CMD_PART_INFO_SIZE); } +static int do_part_number(int argc, char * const argv[]) +{ + return do_part_info(argc, argv, CMD_PART_INFO_NUMBER); +} + static int do_part(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { if (argc < 2) @@ -185,6 +194,8 @@ static int do_part(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) return do_part_start(argc - 2, argv + 2); else if (!strcmp(argv[1], "size")) return do_part_size(argc - 2, argv + 2); + else if (!strcmp(argv[1], "number")) + return do_part_number(argc - 2, argv + 2); return CMD_RET_USAGE; } @@ -206,5 +217,8 @@ U_BOOT_CMD( " part can be either partition number or partition name\n" "part size \n" " - set environment variable to the size of the partition (in blocks)\n" - " part can be either partition number or partition name" + " part can be either partition number or partition name\n" + "part number \n" + " - set environment variable to the partition number using the partition name\n" + " part must be specified as partition name" ); From patchwork Tue Nov 27 19:57:17 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ruslan Trofymenko X-Patchwork-Id: 152165 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp218234ljp; Tue, 27 Nov 2018 12:12:57 -0800 (PST) X-Google-Smtp-Source: AJdET5crpZvsxDniFOuDSumI8svdi/sMPf687GL7T9p2eAY3acCqwYriaON7y7WbosZ03Xvh5kLf X-Received: by 2002:a17:906:5652:: with SMTP id v18-v6mr24557453ejr.137.1543349577499; Tue, 27 Nov 2018 12:12:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543349577; cv=none; d=google.com; s=arc-20160816; b=v/Pg1ipIf0Psti37b1Zfm9umQH6yt98hxQ9AOCg4EXkJjI1sBSeYJF8XFUxyVXWPVa BeCoZyYyjA3461gfjzCX57ZXI7P3XljxeokuNoCMeu+DxZuUXaXWQTA1ubZW7+srgbXo MfVSaZ5oJ22j/C6OVRD26a8xtnKdS2DITFpFGfaG/ev5j4eFPaivw7L6bFIiBtBtUcmV m7GLMZ396c7wgGV+bOBz98KDdM1KfWrrXFRthi/6t4FoPWQqpCOCEneD2wk/rvb6gA2b r7MPTW2kldLiL4Qp0ZkXZn+gOJ2K8MV07DnkH4V+ofvXuOw1h3dAmAHJ85dQMUkNoF/w bJCw== 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=++7P0wzqhfkucuAGrwbXBijwcDauJO7HPXNeJi9cTJg=; b=byIr6b5vcmokXgZnQx6Jb21xwVqhaGnWBdSB1EPYatstCvrKC1N5ZCPAIDej9XpLLM TiYfdlq+RG/dboDsKiIw+6F91vxbTyEu61q4v6TZ4s7QCm9D3tpKLunbQeBNyUnc5aCu S0q0yUfZAqUnozUozHqvgH1pDn8j+IjCJEVeG0dCxP310mLDVJq43FlD3YXMlASrh8NZ znP6WLX/qiWDatvtphzfdAsZOBLW3nLnMqwsCQBC5xT9MVLEj0xQ6N9gw3L5jmzhCBFr vbCJa5H+bHYI68MRnyT1Tx2VYRcjTU2JUu8bQ+HpjBJokHarrj9x4+Uz4mS9xkpUlaol 2EAw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=je8RPPPk; 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 g22-v6si1483311ejt.296.2018.11.27.12.12.57; Tue, 27 Nov 2018 12:12:57 -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=je8RPPPk; 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 15F18C2212E; Tue, 27 Nov 2018 20:11:15 +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 229E7C2224A; Tue, 27 Nov 2018 20:10:33 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id B6166C21EAE; Tue, 27 Nov 2018 19:57:28 +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 AED22C21DD7 for ; Tue, 27 Nov 2018 19:57:27 +0000 (UTC) Received: by mail-lf1-f65.google.com with SMTP id p86so17552577lfg.5 for ; Tue, 27 Nov 2018 11:57:27 -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=td7UrvqWOv/LAmUd0izhkv7BNJplqeU6joJ1sAYEW9s=; b=je8RPPPk1REs3sbv+AtjAzrx0ze9vr5CnMQ1RUor/RnWulJZTWNKi9Gs+Qg8+8tHGM aDoT03sYHc3pWGHhfwyvAu711AZgKQBTXRX3Q+xK8T+QPCSDrX7OI3ASE9lJ+inPesDz K+cDh9w6BUtx3f+68S7CrXNK57nibym5jlKwQ= 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=td7UrvqWOv/LAmUd0izhkv7BNJplqeU6joJ1sAYEW9s=; b=Ui7CG61gWKe9dt/nb+POdbu4jZzAXElPtyrxxj9Menux2mej1DxXHimW2bqBFa813c yLUXyOqGZEKHllUpnDkKBCMbHSpHAHcRGY96dQzYuj4lHeT8bDkvjs1BrnyWwdbLoVuH EsH2byfq9koz3nH8XYX88wL2cpIsGr+0J3eiGk+Ffl1ITGOhFS6TK4szRdFuWlnLCc9f Fipuon48sd48PtUecpEp2K7JKaj64Q+KZHZ4487MV5qFqsGqw/aoVWfimZmiDvrDr9Gk HeaJPP8Wuu/t48xMNg9mRNyI9yBxwsEIf3fZ4ea401Q1+/nK1tKlgJ3IVhLvV1vKbvsH 8vZw== X-Gm-Message-State: AGRZ1gJOwh86qJRr75bSVO5RBvLLMxvkokimcTyr3yLmnfa7KsG/PAzD omJN2RZ84BwfK/A20jthXRYRb0pFOZ8= X-Received: by 2002:a19:f89:: with SMTP id 9mr19336452lfp.10.1543348646918; Tue, 27 Nov 2018 11:57:26 -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.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 27 Nov 2018 11:57:26 -0800 (PST) From: Ruslan Trofymenko To: u-boot@lists.denx.de Date: Tue, 27 Nov 2018 21:57:17 +0200 Message-Id: <1543348642-31045-3-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 2/7] disk: part: Extend API to get partition info 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" This patch adds part_get_info_by_dev_and_name_or_num() function which allows us to get partition info from its number or name. Partition of interest is specified by string like "device_num:partition_number" or "device_num#partition_name". The patch was extracted from [1]. [1] https://android-review.googlesource.com/c/platform/external/u-boot/+/729880/2 Signed-off-by: Ruslan Trofymenko --- disk/part.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ include/part.h | 21 ++++++++++++++++++ 2 files changed, 89 insertions(+) diff --git a/disk/part.c b/disk/part.c index f30f9e9..ad4239d 100644 --- a/disk/part.c +++ b/disk/part.c @@ -675,6 +675,74 @@ int part_get_info_by_name(struct blk_desc *dev_desc, const char *name, return part_get_info_by_name_type(dev_desc, name, info, PART_TYPE_ALL); } +/** + * Get partition info from device number and partition name. + * + * Parse a device number and partition name string in the form of + * "device_num#partition_name", for example "0#misc". If the partition + * is found, sets dev_desc and part_info accordingly with the information + * of the partition with the given partition_name. + * + * @param[in] dev_iface Device interface + * @param[in] dev_part_str Input string argument, like "0#misc" + * @param[out] dev_desc Place to store the device description pointer + * @param[out] part_info Place to store the partition information + * @return 0 on success, or -1 on error + */ +static int part_get_info_by_dev_and_name(const char *dev_iface, + const char *dev_part_str, + struct blk_desc **dev_desc, + disk_partition_t *part_info) +{ + char *ep; + const char *part_str; + int dev_num; + + part_str = strchr(dev_part_str, '#'); + if (!part_str || part_str == dev_part_str) + return -1; + + dev_num = simple_strtoul(dev_part_str, &ep, 16); + if (ep != part_str) { + /* Not all the first part before the # was parsed. */ + return -1; + } + part_str++; + + *dev_desc = blk_get_dev(dev_iface, dev_num); + if (!*dev_desc) { + printf("Could not find %s %d\n", dev_iface, dev_num); + return -1; + } + if (part_get_info_by_name(*dev_desc, part_str, part_info) < 0) { + printf("Could not find \"%s\" partition\n", part_str); + return -1; + } + return 0; +} + +int part_get_info_by_dev_and_name_or_num(const char *dev_iface, + const char *dev_part_str, + struct blk_desc **dev_desc, + disk_partition_t *part_info) +{ + /* Split the part_name if passed as "$dev_num#part_name". */ + if (!part_get_info_by_dev_and_name(dev_iface, dev_part_str, + dev_desc, part_info)) + return 0; + /* + * Couldn't lookup by name, try looking up the partition description + * directly. + */ + if (blk_get_device_part_str(dev_iface, dev_part_str, + dev_desc, part_info, 1) < 0) { + printf("Couldn't find partition %s %s\n", + dev_iface, dev_part_str); + return -1; + } + return 0; +} + void part_set_generic_name(const struct blk_desc *dev_desc, int part_num, char *name) { diff --git a/include/part.h b/include/part.h index 0750aee..331b3d5 100644 --- a/include/part.h +++ b/include/part.h @@ -202,6 +202,27 @@ int part_get_info_by_name(struct blk_desc *dev_desc, const char *name, disk_partition_t *info); /** + * Get partition info from dev number + part name, or dev number + part number. + * + * Parse a device number and partition description (either name or number) + * in the form of device number plus partition name separated by a "#" + * (like "device_num#partition_name") or a device number plus a partition number + * separated by a ":". For example both "0#misc" and "0:1" can be valid + * partition descriptions for a given interface. If the partition is found, sets + * dev_desc and part_info accordingly with the information of the partition. + * + * @param[in] dev_iface Device interface + * @param[in] dev_part_str Input partition description, like "0#misc" or "0:1" + * @param[out] dev_desc Place to store the device description pointer + * @param[out] part_info Place to store the partition information + * @return 0 on success, or -1 on error + */ +int part_get_info_by_dev_and_name_or_num(const char *dev_iface, + const char *dev_part_str, + struct blk_desc **dev_desc, + disk_partition_t *part_info); + +/** * part_set_generic_name() - create generic partition like hda1 or sdb2 * * Helper function for partition tables, which don't hold partition names From patchwork Tue Nov 27 19:57:18 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ruslan Trofymenko X-Patchwork-Id: 152164 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp217340ljp; Tue, 27 Nov 2018 12:12:10 -0800 (PST) X-Google-Smtp-Source: AFSGD/UNzmruwvVnJfodv1UWCPZC9OQcs9CxyT4mxPtmq2JqgH1/oZSsfILUiv8QiGLRsHfId3iq X-Received: by 2002:a50:9996:: with SMTP id m22mr28419780edb.7.1543349530090; Tue, 27 Nov 2018 12:12:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543349530; cv=none; d=google.com; s=arc-20160816; b=jAcag9w+EVLhOj9gyqIi5ETm5i5N0zkIBUT3vQT22Aj5ZPAfP7vExd6Wzbx28xe4EQ /Uli3EsvA5P9hY1T+3KEn2lSRCQcYe+W5S4+AHXD7EILuEcZHYMYbpMDFF1sICBTOYyG 93fJWvu8Vpgczs2caoJEiCEJNjhXCV5X0sqihOBT0/zFSSoUq2NwOC+oHLGOjKrWHo+z 0i6ssuX4Y9i1qIgyl5eGa/rRz5+XChnZhALlUseiJcW2wtq54v2vHbOkhPcBFl+7w6oI DufcdKF0eCcvX/p6jrAsADqAtTt6/WQLa8q8dOp/eMppb49E3rXxHjqfSNWz5zuW34GW ehhw== 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=LzL4tAFqks0wCVEXgvYMroLYpXaKmMxjokPXQGu2Ud4=; b=RtkPqWC+vdBHZI4tFh8/s8WDlspU8D8q9DEsXdTnttX/xldOJKcg3adrwWO4fnbE99 4AGUg2GFE9ffGbzwkZcBW5MZ9sJlRpBiaQsM3YW2yWayAaH7Qzomrz5yoVlrtaCMgD0e fi1rX6cm33AYIggbVrWFraQhOSmpTAtiqZ6/khM9CQ8s4WLQ7UXx8+TpYxEsWyh4m6qY W3sqzQyGIaBfG+3wXGhuZyUS1bNapEeTEgEEh2GZL/ZN4m3z6pgzcCRGJl93iabiKWqN 2CMFjcjuLkapR1K1xb7/+EFXRhtZ65/fLAzkUahGjlgjWbD8ipAI8hksHhC3dqEnEkI+ 7HyQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=ZeQndFia; 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 k30si2533779edc.86.2018.11.27.12.12.09; Tue, 27 Nov 2018 12:12:10 -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=ZeQndFia; 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 9C5A3C22222; Tue, 27 Nov 2018 20:11:37 +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 EC08AC2226A; Tue, 27 Nov 2018 20:10:33 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 18F3FC21DD7; Tue, 27 Nov 2018 19:57:30 +0000 (UTC) Received: from mail-lj1-f193.google.com (mail-lj1-f193.google.com [209.85.208.193]) by lists.denx.de (Postfix) with ESMTPS id 88F31C21EAE for ; Tue, 27 Nov 2018 19:57:29 +0000 (UTC) Received: by mail-lj1-f193.google.com with SMTP id u6-v6so21205439ljd.1 for ; Tue, 27 Nov 2018 11:57:29 -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=YdwjkWJMfVu8dcwkSSJSmprU/53Gnzq3Koj/jqPhr8Y=; b=ZeQndFia/cp6SoSXWRKAgktGeyKX/sUi7B7J4/dMH+PnKwEbOcM59NGXdy/fhQuNzr /+Vvw4fsTUdvO/el7YZ3GD5L0xBqEMSiK4Ef6VN29eSABSgoUStqOf+Cs3W+2tCRmMrx 8yA4O96fF3t3d2ix4lNl4ok50XCZkfGfTli1g= 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=YdwjkWJMfVu8dcwkSSJSmprU/53Gnzq3Koj/jqPhr8Y=; b=FtnN2BLMWwt2KfKHQ9z2bIID8L7wq/smWGm1R9Xf02x0NdmVjWR/CvhTEOAfUxDFEW CTMaFxMC13+bEFTTp5UnA7o0HQ1sfYyLHMtyYGeSCMtHrSBocmVzZb9G4yxWFyWNoyTq wFMo0NynhtCObEUyCMZ1e3FXEcWW2LGZKzdFQRD6vtxZdRp9vutn+A2Szib0w9ofOoQA oownloWYq1Pwktds4XDAxn3E/XCPiscrSgNSzenq7jwEg6taqoJGPiIse3GIbXpUzbbu CPTILV7X7grrJKrRazscrwcYTz25rmpodUAyPlwBMALzBE++YMZxP52PonTDn04o+2Zz 5sWw== X-Gm-Message-State: AA+aEWaibGyfnGbb4zO3iBFJekA1Z5JIKEO9FPwhB8ZyztyAdmNucLE7 lfOOcc0EOE4vbjnH4qlaBROLZnrmqGI= X-Received: by 2002:a2e:458b:: with SMTP id s133-v6mr20375153lja.170.1543348648289; Tue, 27 Nov 2018 11:57:28 -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.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 27 Nov 2018 11:57:27 -0800 (PST) From: Ruslan Trofymenko To: u-boot@lists.denx.de Date: Tue, 27 Nov 2018 21:57:18 +0200 Message-Id: <1543348642-31045-4-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 3/7] common: Implement A/B metadata 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" This patch determines the A/B-specific bootloader message structure that is the basis for implementation of recovery and A/B update functions. A/B metadata is stored in this structure and used to decide which slot should we use to boot the device. Also some basic functions for A/B metadata manipulation are implemented (like slot selection). The patch was extracted from commits [1], [2] with some coding style fixes. [1] https://android-review.googlesource.com/c/platform/external/u-boot/+/729878/2 [2] https://android-review.googlesource.com/c/platform/external/u-boot/+/729880/2 Signed-off-by: Ruslan Trofymenko --- common/Kconfig | 10 ++ common/Makefile | 1 + common/android_ab.c | 278 +++++++++++++++++++++++++++++++++++ include/android_ab.h | 34 +++++ include/android_bootloader_message.h | 164 +++++++++++++++++++++ 5 files changed, 487 insertions(+) create mode 100644 common/android_ab.c create mode 100644 include/android_ab.h create mode 100644 include/android_bootloader_message.h diff --git a/common/Kconfig b/common/Kconfig index 57bd16d..0ff4679 100644 --- a/common/Kconfig +++ b/common/Kconfig @@ -748,6 +748,16 @@ config UPDATE_TFTP_MSEC_MAX default 100 depends on UPDATE_TFTP +config ANDROID_AB + bool "Android A/B updates" + default n + help + If enabled, adds support for the new Android A/B update model. This + allows the bootloader to select which slot to boot from based on the + information provided by userspace via the Android boot_ctrl HAL. This + allows a bootloader to try a new version of the system but roll back + to previous version if the new one didn't boot all the way. + endmenu menu "Blob list" diff --git a/common/Makefile b/common/Makefile index 88079d1..a1a252c 100644 --- a/common/Makefile +++ b/common/Makefile @@ -104,6 +104,7 @@ endif endif obj-y += image.o +obj-$(CONFIG_ANDROID_AB) += android_ab.o obj-$(CONFIG_ANDROID_BOOT_IMAGE) += image-android.o obj-$(CONFIG_$(SPL_TPL_)OF_LIBFDT) += image-fdt.o obj-$(CONFIG_$(SPL_TPL_)FIT) += image-fit.o diff --git a/common/android_ab.c b/common/android_ab.c new file mode 100644 index 0000000..25daba7 --- /dev/null +++ b/common/android_ab.c @@ -0,0 +1,278 @@ +// SPDX-License-Identifier: BSD-2-Clause +/* + * Copyright (C) 2017 The Android Open Source Project + */ + +#include + +#include +#include +#include +#include + +/** + * Compute the CRC-32 of the bootloader control struct. + * + * Only the bytes up to the crc32_le field are considered for the CRC-32 + * calculation. + */ +static uint32_t ab_control_compute_crc(struct android_bootloader_control *abc) +{ + return crc32(0, (void *)abc, offsetof(typeof(*abc), crc32_le)); +} + +/** + * Initialize android_bootloader_control to the default value. + * + * It allows us to boot all slots in order from the first one. This value + * should be used when the bootloader message is corrupted, but not when + * a valid message indicates that all slots are unbootable. + */ +static void ab_control_default(struct android_bootloader_control *abc) +{ + int i; + const struct android_slot_metadata metadata = { + .priority = 15, + .tries_remaining = 7, + .successful_boot = 0, + .verity_corrupted = 0, + .reserved = 0 + }; + + memcpy(abc->slot_suffix, "a\0\0\0", 4); + abc->magic = ANDROID_BOOT_CTRL_MAGIC; + abc->version = ANDROID_BOOT_CTRL_VERSION; + abc->nb_slot = ANDROID_NUM_SLOTS; + memset(abc->reserved0, 0, sizeof(abc->reserved0)); + for (i = 0; i < abc->nb_slot; ++i) + abc->slot_info[i] = metadata; + + memset(abc->reserved1, 0, sizeof(abc->reserved1)); + abc->crc32_le = ab_control_compute_crc(abc); +} + +/** + * Load the boot_control struct from disk into newly allocated memory. + * + * This function allocates and returns an integer number of disk blocks, + * based on the block size of the passed device to help performing a + * read-modify-write operation on the boot_control struct. + * The boot_control struct offset (2 KiB) must be a multiple of the device + * block size, for simplicity. + * + * @param[in] dev_desc Device where to read the boot_control struct from + * @param[in] part_info Partition in 'dev_desc' where to read from, normally + * the "misc" partition should be used + * @return boot_control loaded from disk or NULL on error + */ +static struct android_bootloader_control *ab_control_create_from_disk( + struct blk_desc *dev_desc, const disk_partition_t *part_info) +{ + ulong abc_offset, abc_blocks; + struct android_bootloader_control *abc; + + abc_offset = offsetof(struct android_bootloader_message_ab, + slot_suffix); + if (abc_offset % part_info->blksz) { + printf("ANDROID: Boot control block not block aligned.\n"); + return NULL; + } + abc_offset /= part_info->blksz; + + abc_blocks = DIV_ROUND_UP(sizeof(struct android_bootloader_control), + part_info->blksz); + if (abc_offset + abc_blocks > part_info->size) { + printf("ANDROID: boot control partition too small. Need at"); + printf(" least %lu blocks but have %lu blocks.\n", + abc_offset + abc_blocks, part_info->size); + return NULL; + } + abc = malloc_cache_aligned(abc_blocks * part_info->blksz); + if (!abc) + return NULL; + + if (blk_dread(dev_desc, part_info->start + abc_offset, abc_blocks, + abc) != abc_blocks) { + printf("ANDROID: Could not read from boot control partition\n"); + free(abc); + return NULL; + } + debug("ANDROID: Loaded ABC, %lu blocks.\n", abc_blocks); + return abc; +} + +/** + * Store the loaded boot_control block. + * + * Store back to the same location it was read from with + * ab_control_create_from_misc(). + * + * @param[in] abc Pointer to the boot_control struct and the extra bytes after + * it up to the nearest block boundary + * @param[in] dev_desc Device where we should write the boot_control struct + * @param[in] part_info Partition on the 'dev_desc' where to write + * @return 0 on success and -1 on error + */ +static int ab_control_store(struct android_bootloader_control *abc, + struct blk_desc *dev_desc, + const disk_partition_t *part_info) +{ + ulong abc_offset, abc_blocks; + + abc_offset = offsetof(struct android_bootloader_message_ab, + slot_suffix) / part_info->blksz; + abc_blocks = DIV_ROUND_UP(sizeof(struct android_bootloader_control), + part_info->blksz); + if (blk_dwrite(dev_desc, part_info->start + abc_offset, abc_blocks, + abc) != abc_blocks) { + printf("ANDROID: Could not write back the misc partition\n"); + return -1; + } + return 0; +} + +/** + * Compare two slots. + * + * The function determines slot which is should we boot from among the two. + * + * @param[in] a The first bootable slot metadata + * @param[in] b The second bootable slot metadata + * @return Negative if the slot "a" is better, positive of the slot "b" is + * better or 0 if they are equally good. + */ +static int ab_compare_slots(const struct android_slot_metadata *a, + const struct android_slot_metadata *b) +{ + /* Higher priority is better */ + if (a->priority != b->priority) + return b->priority - a->priority; + + /* Higher successful_boot value is better, in case of same priority */ + if (a->successful_boot != b->successful_boot) + return b->successful_boot - a->successful_boot; + + /* Higher tries_remaining is better to ensure round-robin */ + if (a->tries_remaining != b->tries_remaining) + return b->tries_remaining - a->tries_remaining; + + return 0; +} + +int ab_select_slot(struct blk_desc *dev_desc, disk_partition_t *part_info) +{ + struct android_bootloader_control *abc; + u32 crc32_le; + int slot, i; + bool store_needed = false; + char slot_suffix[4]; + + abc = ab_control_create_from_disk(dev_desc, part_info); + if (!abc) { + /* + * This condition represents an actual problem with the code or + * the board setup, like an invalid partition information. + * Signal a repair mode and do not try to boot from either slot. + */ + return -1; + } + + crc32_le = ab_control_compute_crc(abc); + if (abc->crc32_le != crc32_le) { + printf("ANDROID: Invalid CRC-32 (expected %.8x, found %.8x), ", + crc32_le, abc->crc32_le); + printf("re-initializing A/B metadata.\n"); + ab_control_default(abc); + store_needed = true; + } + + if (abc->magic != ANDROID_BOOT_CTRL_MAGIC) { + printf("ANDROID: Unknown A/B metadata: %.8x\n", abc->magic); + free(abc); + return -1; + } + + if (abc->version > ANDROID_BOOT_CTRL_VERSION) { + printf("ANDROID: Unsupported A/B metadata version: %.8x\n", + abc->version); + free(abc); + return -1; + } + + /* + * At this point a valid boot control metadata is stored in abc, + * followed by other reserved data in the same block. We select a with + * the higher priority slot that + * - is not marked as corrupted and + * - either has tries_remaining > 0 or successful_boot is true. + * If the selected slot has a false successful_boot, we also decrement + * the tries_remaining until it eventually becomes unbootable because + * tries_remaining reaches 0. This mechanism produces a bootloader + * induced rollback, typically right after a failed update. + */ + + /* Safety check: limit the number of slots. */ + if (abc->nb_slot > ARRAY_SIZE(abc->slot_info)) { + abc->nb_slot = ARRAY_SIZE(abc->slot_info); + store_needed = true; + } + + slot = -1; + for (i = 0; i < abc->nb_slot; ++i) { + if (abc->slot_info[i].verity_corrupted || + !abc->slot_info[i].tries_remaining) { + debug("ANDROID: unbootable slot %d tries: %d, ", + i, abc->slot_info[i].tries_remaining); + debug("corrupt: %d\n", + abc->slot_info[i].verity_corrupted); + continue; + } + debug("ANDROID: bootable slot %d pri: %d, tries: %d, ", + i, abc->slot_info[i].priority, + abc->slot_info[i].tries_remaining); + debug("corrupt: %d, successful: %d\n", + abc->slot_info[i].verity_corrupted, + abc->slot_info[i].successful_boot); + + if (slot < 0 || + ab_compare_slots(&abc->slot_info[i], + &abc->slot_info[slot]) < 0) { + slot = i; + } + } + + if (slot >= 0 && !abc->slot_info[slot].successful_boot) { + printf("ANDROID: Attempting slot %c, tries remaining %d\n", + ANDROID_BOOT_SLOT_NAME(slot), + abc->slot_info[slot].tries_remaining); + abc->slot_info[slot].tries_remaining--; + store_needed = true; + } + + if (slot >= 0) { + /* + * Legacy user-space requires this field to be set in the BCB. + * Newer releases load this slot suffix from the command line + * or the device tree. + */ + memset(slot_suffix, 0, sizeof(slot_suffix)); + slot_suffix[0] = ANDROID_BOOT_SLOT_NAME(slot); + if (memcmp(abc->slot_suffix, slot_suffix, + sizeof(slot_suffix))) { + memcpy(abc->slot_suffix, slot_suffix, + sizeof(slot_suffix)); + store_needed = true; + } + } + + if (store_needed) { + abc->crc32_le = ab_control_compute_crc(abc); + ab_control_store(abc, dev_desc, part_info); + } + free(abc); + + if (slot < 0) + return -1; + + return slot; +} diff --git a/include/android_ab.h b/include/android_ab.h new file mode 100644 index 0000000..53f6dc6 --- /dev/null +++ b/include/android_ab.h @@ -0,0 +1,34 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ +/* + * Copyright (C) 2017 The Android Open Source Project + */ + +#ifndef __ANDROID_AB_H +#define __ANDROID_AB_H + +#include + +/* Android standard boot slot names are 'a', 'b', 'c', ... */ +#define ANDROID_BOOT_SLOT_NAME(slot_num) ('a' + (slot_num)) + +/* Number of slots */ +#define ANDROID_NUM_SLOTS 2 + +/** + * Select the slot where to boot from. + * + * On Android devices with more than one boot slot (multiple copies of the + * kernel and system images) selects which slot should be used to boot from and + * registers the boot attempt. This is used in by the new A/B update model where + * one slot is updated in the background while running from the other slot. If + * the selected slot did not successfully boot in the past, a boot attempt is + * registered before returning from this function so it isn't selected + * indefinitely. + * + * @param[in] dev_desc Place to store the device description pointer + * @param[in] part_info Place to store the partition information + * @return The slot number (>= 0) on success, or -1 on error + */ +int ab_select_slot(struct blk_desc *dev_desc, disk_partition_t *part_info); + +#endif /* __ANDROID_AB_H */ diff --git a/include/android_bootloader_message.h b/include/android_bootloader_message.h new file mode 100644 index 0000000..1f19273 --- /dev/null +++ b/include/android_bootloader_message.h @@ -0,0 +1,164 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ +/* + * This file was taken from the AOSP Project. + * Repository: https://android.googlesource.com/platform/bootable/recovery/ + * File: bootloader_message/include/bootloader_message/bootloader_message.h + * Commit: 8b309f6970ab3b7c53cc529c51a2cb44e1c7a7e1 + * + * Copyright (C) 2008 The Android Open Source Project + */ + +#ifndef __ANDROID_BOOTLOADER_MESSAGE_H +#define __ANDROID_BOOTLOADER_MESSAGE_H + +/* + * compiler.h defines the types that otherwise are included from stdint.h and + * stddef.h + */ +#include + +/* + * Spaces used by misc partition are as below: + * 0 - 2K Bootloader Message + * 2K - 16K Used by Vendor's bootloader (the 2K - 4K range may be optionally + * used as bootloader_message_ab struct) + * 16K - 64K Used by uncrypt and recovery to store wipe_package for A/B + * devices + * Note that these offsets are admitted by bootloader,recovery and uncrypt, so + * they are not configurable without changing all of them. + */ +static const size_t ANDROID_BOOTLOADER_MESSAGE_OFFSET_IN_MISC; +static const size_t ANDROID_WIPE_PACKAGE_OFFSET_IN_MISC = 16 * 1024; + +/* + * Bootloader Message (2-KiB) + * + * This structure describes the content of a block in flash + * that is used for recovery and the bootloader to talk to + * each other. + * + * The command field is updated by linux when it wants to + * reboot into recovery or to update radio or bootloader firmware. + * It is also updated by the bootloader when firmware update + * is complete (to boot into recovery for any final cleanup) + * + * The status field is written by the bootloader after the + * completion of an "update-radio" or "update-hboot" command. + * + * The recovery field is only written by linux and used + * for the system to send a message to recovery or the + * other way around. + * + * The stage field is written by packages which restart themselves + * multiple times, so that the UI can reflect which invocation of the + * package it is. If the value is of the format "#/#" (eg, "1/3"), + * the UI will add a simple indicator of that status. + * + * We used to have slot_suffix field for A/B boot control metadata in + * this struct, which gets unintentionally cleared by recovery or + * uncrypt. Move it into struct bootloader_message_ab to avoid the + * issue. + */ +struct android_bootloader_message { + char command[32]; + char status[32]; + char recovery[768]; + + /* + * The 'recovery' field used to be 1024 bytes. It has only ever + * been used to store the recovery command line, so 768 bytes + * should be plenty. We carve off the last 256 bytes to store the + * stage string (for multistage packages) and possible future + * expansion. + */ + char stage[32]; + + /* + * The 'reserved' field used to be 224 bytes when it was initially + * carved off from the 1024-byte recovery field. Bump it up to + * 1184-byte so that the entire bootloader_message struct rounds up + * to 2048-byte. + */ + char reserved[1184]; +}; + +/* + * The A/B-specific bootloader message structure (4-KiB). + * + * We separate A/B boot control metadata from the regular bootloader + * message struct and keep it here. Everything that's A/B-specific + * stays after struct bootloader_message, which should be managed by + * the A/B-bootloader or boot control HAL. + * + * The slot_suffix field is used for A/B implementations where the + * bootloader does not set the androidboot.ro.boot.slot_suffix kernel + * commandline parameter. This is used by fs_mgr to mount /system and + * other partitions with the slotselect flag set in fstab. A/B + * implementations are free to use all 32 bytes and may store private + * data past the first NUL-byte in this field. It is encouraged, but + * not mandatory, to use 'struct bootloader_control' described below. + */ +struct android_bootloader_message_ab { + struct android_bootloader_message message; + char slot_suffix[32]; + + /* Round up the entire struct to 4096-byte */ + char reserved[2016]; +}; + +#define ANDROID_BOOT_CTRL_MAGIC 0x42414342 /* Bootloader Control AB */ +#define ANDROID_BOOT_CTRL_VERSION 1 + +struct android_slot_metadata { + /* + * Slot priority with 15 meaning highest priority, 1 lowest + * priority and 0 the slot is unbootable + */ + u8 priority : 4; + /* Number of times left attempting to boot this slot */ + u8 tries_remaining : 3; + /* 1 if this slot has booted successfully, 0 otherwise */ + u8 successful_boot : 1; + /* + * 1 if this slot is corrupted from a dm-verity corruption, + * 0 otherwise + */ + u8 verity_corrupted : 1; + /* Reserved for further use */ + u8 reserved : 7; +} __packed; + +/* + * Bootloader Control AB. + * + * This struct can be used to manage A/B metadata. It is designed to + * be put in the 'slot_suffix' field of the 'bootloader_message' + * structure described above. It is encouraged to use the + * 'bootloader_control' structure to store the A/B metadata, but not + * mandatory. + */ +struct android_bootloader_control { + /* NULL terminated active slot suffix */ + char slot_suffix[4]; + /* Bootloader Control AB magic number (see BOOT_CTRL_MAGIC) */ + u32 magic; + /* Version of struct being used (see BOOT_CTRL_VERSION) */ + u8 version; + /* Number of slots being managed */ + u8 nb_slot : 3; + /* Number of times left attempting to boot recovery */ + u8 recovery_tries_remaining : 3; + /* Ensure 4-bytes alignment for slot_info field */ + u8 reserved0[2]; + /* Per-slot information. Up to 4 slots */ + struct android_slot_metadata slot_info[4]; + /* Reserved for further use */ + u8 reserved1[8]; + /* + * CRC32 of all 28 bytes preceding this field (little endian + * format) + */ + u32 crc32_le; +} __packed; + +#endif /* __ANDROID_BOOTLOADER_MESSAGE_H */ 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" +); + From patchwork Tue Nov 27 19:57:20 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ruslan Trofymenko X-Patchwork-Id: 152168 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp220996ljp; Tue, 27 Nov 2018 12:15:29 -0800 (PST) X-Google-Smtp-Source: AJdET5exko6NVUc+c0Md12huDmhCzz0GtcyjLmcqIifZZ9825Mr5y6hcb9WdUjN2JzQZQJVpn++i X-Received: by 2002:a17:906:6011:: with SMTP id o17-v6mr24732653ejj.237.1543349729689; Tue, 27 Nov 2018 12:15:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543349729; cv=none; d=google.com; s=arc-20160816; b=pOjfngk0NHcCJI62pJMHQTCirCZgw6ug9E4PGFVFwNVG1pOyOoAiBhZ0e58KHcT5yv /eqPeMVd5AnHhzAmR2OhNzY6OuDJb/iih2wpTlWQSYhdtUNQUmZ7MW9WeNGzjz7/lah6 mrFo0gauXLwklaq0wkQfTU0eYdy8tHGraIUzAGm4K49uV7AOigRo02BEAG1bBz/9wN0+ vs4fgU8H+SKLjaAxAdc512Zz+qusj186/1NsWOBe6UqJkKYychmTuRhN+akvNQTQi9a+ ZlubZSk0GxURY2hro2OxAxMFaU8vRSJ0Wj0pZHCw8NtcSafKTHvoLifOl9Rp3AQcbDzR 75jw== 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=gvJq0oUXy++aLFXsBx5fz1GnBfdDQa5hgpQZxvNaS9k=; b=D0PYKOPm0sE5e9I4eCYY16aMaXDMPoegprTUmbqiYKcFkdS1wSGx1kkinwYSl7viSa rkBISr6EC/8/VEAe2rUmCpGPMGHefGrpKRUcaUGZBSVBtvIQDJvuPlNUxd/V31ow9/oe 1MjFollGLhMYwbe5XRr5QOSEEvcDqQ0m/6Xo3FMjfiLUK2iHoPEKanlawSKRNFFNo/ba K+uWsPlIB8GUN/yoRyGbP9qRAVBdG+Ny3A+UAt8mQWVNmYcuw9KZVRtkJ1ysaIlwmUI7 rePw1LP/m4WnmQlign2MkC4a1giN6SRr+PxYCcoMHhtmpn1KbAwyej7/IyUIlsAb3r9d LnUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=eTfuwRq9; 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 m17si2325646edf.177.2018.11.27.12.15.29; Tue, 27 Nov 2018 12:15:29 -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=eTfuwRq9; 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 4D40CC22271; Tue, 27 Nov 2018 20:12:36 +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 04452C222F3; Tue, 27 Nov 2018 20:10:36 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 7731BC2213D; Tue, 27 Nov 2018 19:57:32 +0000 (UTC) Received: from mail-lf1-f68.google.com (mail-lf1-f68.google.com [209.85.167.68]) by lists.denx.de (Postfix) with ESMTPS id D5320C2212B for ; Tue, 27 Nov 2018 19:57:31 +0000 (UTC) Received: by mail-lf1-f68.google.com with SMTP id l10so17524968lfh.9 for ; Tue, 27 Nov 2018 11:57:31 -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=OpzblhBULa92Trq+cRJm/VnawupM9RxyuctNtApvjy4=; b=eTfuwRq9L6rtIv+xWxVWODnsTMxOroty+4dAPZJ4uMPLKDXUVc1toVFb5yvi0vyL7D hu9p2046VBAEeFJ2P93jk2abu4OHYdc50nnIfmudgc0WY5C+Mq3puDr+lhat3HxhDvlc j3Yn8yWCpmJSLEGecQ2Mqu1KsR6YIdMuClU8I= 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=OpzblhBULa92Trq+cRJm/VnawupM9RxyuctNtApvjy4=; b=bzvZC/Wh+tPRERrxNcHgwMVUzYXZIlp/D3j2XxphMpRZZAeRlgZ/yPDR0yDjJt28Og q+wiAtR/oqTzfXk6TUy5k8UT3f/IlrHchYE2DpRbA8ZyaXZOZrbCAak25BQN7S2+2fKe mqcQfgEGd21J/bZ3CB+9uOtngudjEtk4ocNcFEHWJAIT+v3GtcZzSRuOVN8/AqG3XwMW kSkGu4D5YlnAmnkesada6T+Bw/A89QNwvcoB99fN62WdIfI6gJYCrrtoT/k7xvhittHZ 7RQZH1Qds/CNoCY3wZqUaZXhl6tGaUGSfObSlCOI5PHSSW69/HDKmDxb5X6l8QDXvul2 2XRA== X-Gm-Message-State: AGRZ1gKOYMwywh6Hi3905Pw4u4owbeIgzdT5m/v6Opn6CA8X7GfiOqJu rp0Qopk9GzEekzhtnKFRA6OiiVK8ZcY= X-Received: by 2002:a19:5402:: with SMTP id i2mr19163488lfb.128.1543348651010; Tue, 27 Nov 2018 11:57:31 -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.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 27 Nov 2018 11:57:30 -0800 (PST) From: Ruslan Trofymenko To: u-boot@lists.denx.de Date: Tue, 27 Nov 2018 21:57:20 +0200 Message-Id: <1543348642-31045-6-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 5/7] test/py: Add base test case for A/B updates 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" Add sandbox test for 'android_ab_select' command. Test: ./test/py/test.py --bd sandbox --build -k test_ab Signed-off-by: Ruslan Trofymenko Reviewed-by: Simon Glass --- configs/sandbox_defconfig | 2 ++ test/py/tests/test_ab.py | 74 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+) create mode 100644 test/py/tests/test_ab.py diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig index 5a744f4..f246f89 100644 --- a/configs/sandbox_defconfig +++ b/configs/sandbox_defconfig @@ -20,6 +20,7 @@ CONFIG_PRE_CON_BUF_ADDR=0x100000 CONFIG_LOG_MAX_LEVEL=6 CONFIG_LOG_ERROR_RETURN=y CONFIG_DISPLAY_BOARDINFO_LATE=y +CONFIG_ANDROID_AB=y CONFIG_CMD_CPU=y CONFIG_CMD_LICENSE=y CONFIG_CMD_BOOTZ=y @@ -61,6 +62,7 @@ CONFIG_CMD_TIME=y CONFIG_CMD_TIMER=y CONFIG_CMD_SOUND=y CONFIG_CMD_QFW=y +CONFIG_CMD_ANDROID_AB_SELECT=y CONFIG_CMD_BOOTSTAGE=y CONFIG_CMD_PMIC=y CONFIG_CMD_REGULATOR=y diff --git a/test/py/tests/test_ab.py b/test/py/tests/test_ab.py new file mode 100644 index 0000000..f27538e --- /dev/null +++ b/test/py/tests/test_ab.py @@ -0,0 +1,74 @@ +# SPDX-License-Identifier: GPL-2.0 +# (C) Copyright 2018 Texas Instruments, + +# Test A/B update commands. + +import os +import pytest +import u_boot_utils + +class ABTestDiskImage(object): + """Disk Image used by the A/B tests.""" + + def __init__(self, u_boot_console): + """Initialize a new ABTestDiskImage object. + + Args: + u_boot_console: A U-Boot console. + + Returns: + Nothing. + """ + + filename = 'test_ab_disk_image.bin' + + persistent = u_boot_console.config.persistent_data_dir + '/' + filename + self.path = u_boot_console.config.result_dir + '/' + filename + + with u_boot_utils.persistent_file_helper(u_boot_console.log, persistent): + if os.path.exists(persistent): + u_boot_console.log.action('Disk image file ' + persistent + + ' already exists') + else: + u_boot_console.log.action('Generating ' + persistent) + fd = os.open(persistent, os.O_RDWR | os.O_CREAT) + os.ftruncate(fd, 524288) + os.close(fd) + cmd = ('sgdisk', persistent) + u_boot_utils.run_and_log(u_boot_console, cmd) + + cmd = ('sgdisk', '--new=1:64:512', '-c 1:misc', persistent) + u_boot_utils.run_and_log(u_boot_console, cmd) + cmd = ('sgdisk', '-l', persistent) + u_boot_utils.run_and_log(u_boot_console, cmd) + + cmd = ('cp', persistent, self.path) + u_boot_utils.run_and_log(u_boot_console, cmd) + +di = None +@pytest.fixture(scope='function') +def ab_disk_image(u_boot_console): + global di + if not di: + di = ABTestDiskImage(u_boot_console) + return di + +@pytest.mark.boardspec('sandbox') +@pytest.mark.buildconfigspec('android_ab') +@pytest.mark.buildconfigspec('cmd_android_ab_select') +@pytest.mark.requiredtool('sgdisk') +def test_ab(ab_disk_image, u_boot_console): + """Test the 'android_ab_select' command.""" + + u_boot_console.run_command('host bind 0 ' + ab_disk_image.path) + + output = u_boot_console.run_command('android_ab_select slot_name host 0#misc') + assert 're-initializing A/B metadata' in output + assert 'Attempting slot a, tries remaining 7' in output + output = u_boot_console.run_command('printenv slot_name') + assert 'a' in output + + output = u_boot_console.run_command('android_ab_select slot_name host 0:1') + assert 'Attempting slot b, tries remaining 7' in output + output = u_boot_console.run_command('printenv slot_name') + assert 'b' in output From patchwork Tue Nov 27 19:57:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ruslan Trofymenko X-Patchwork-Id: 152167 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp220721ljp; Tue, 27 Nov 2018 12:15:15 -0800 (PST) X-Google-Smtp-Source: AFSGD/W24EyicAe/FdRN57Sj4PXPZPd04TL5nhct+qjeKvY/U9v+6EmUiD642T8iBoB5s76W9kOg X-Received: by 2002:a50:b2e1:: with SMTP id p88mr17226153edd.254.1543349715706; Tue, 27 Nov 2018 12:15:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543349715; cv=none; d=google.com; s=arc-20160816; b=0sIM0xgKJRF4ZHbiyl8of6d/t42ON675FNMrekTqhp8VVKZulzAE4bAzMI9lHRUFzz Li8zA/LGhWPqWEeOSyx/O95IxpDH6sOBF/09RHugFMkVqCA+BcilOHwe94WpRa6iTIJ7 MCDGId4Yesq20lCwSfmvWOXKFOhI3/DhOuXdMuwiuXspwW4ZbkQu9FQMPdPj1C8KjKbn zpvZpoU6JX3ndL4xmtUcE8k2WJ7HAXbjl5iyMdmdtWj798Ez+NjIw708SpszjUKqKZpo Jhf6LgLJNIBoY+M+s1FWUEqHhMVlI0LxN4/dKC9iHOpY1tD5mJynasdmEa7Q22TxebPK obNA== 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=aTQlXZII2j8kWJ+MqmbdZmzR1AMbNry5rSv1MyWm8Gc=; b=ACM53BSGxagbt/s1+Q4vn3ncMJ/37HasI7GmeDP56jDmmRXQ1W73nwVtavJdg5Edh8 XvNmycLHBSDgGgJSls+qDR5F3oyXJzAe6OCYgGHBG8/5uvDYji4ROIt6fBq9EVnSrffw RIRkKMpd144Celh5WCJP/m88IDsQvzX7NlB9meeGEPAUYcNiPp01XZ/cfnP7zGu7N92X zZssfLAKvYFyqV15/yOev3JRKJLXxATIBOprBPP+qSFU3+P43P3T0WTKVYuCtbrqbmdI f9VIH6kQDE/KK9L1zRcLPtppz1yyYf9f/HIpM+flP0MokW/W8xXr07K+U1ODWs+amPXj DonQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=RO9syJp4; 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 12-v6si202910ejh.281.2018.11.27.12.15.15; Tue, 27 Nov 2018 12:15:15 -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=RO9syJp4; 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 3FD3AC22275; Tue, 27 Nov 2018 20:12:59 +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 51816C222C8; Tue, 27 Nov 2018 20:10:37 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 59597C21DD7; Tue, 27 Nov 2018 19:57:33 +0000 (UTC) Received: from mail-lj1-f193.google.com (mail-lj1-f193.google.com [209.85.208.193]) by lists.denx.de (Postfix) with ESMTPS id EC7F3C2213D for ; Tue, 27 Nov 2018 19:57:32 +0000 (UTC) Received: by mail-lj1-f193.google.com with SMTP id e5-v6so21215116lja.4 for ; Tue, 27 Nov 2018 11:57:32 -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=XYw6i1Y6fVC5N1eyTU8b/QtuL77IyS6jVFxXRtbtlw8=; b=RO9syJp4qBGGEGYvvKRE3+2foZ2/hzk/n5rPTIkHFXtI95WUBtXjvdLU7ZYi7U9ytP iRhMsEC3owulBbIdpakUiRJXQ0vVnKpKqFWioyrqE6Rb+TuLCNL5wxnArDBU1HHkoEmv sdRBijIe5vsZw+7BKP3ta6h4BUw5iyQ2hfxh0= 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=XYw6i1Y6fVC5N1eyTU8b/QtuL77IyS6jVFxXRtbtlw8=; b=CSqoBRAQCuIkBmRhV/4rv1ADt8u0fUcTndUI7iJIaXygtOCWjz6i5QwpBp3Jl211p/ xlnZWN4cUPx0alJhXs+nWUcXqdsrWKIOGsRNFV/NpSRfz3jJWcbgQe5cI60Lt5XobdAV Kufx9cp7R9a0f6ESkkOeYX5W7gCIl2NLsemYl788+TJL+pwXFl3t8Qm9t7RMKNv2vfV+ rj49p7J+WtIZ5eAJZDkKR1ubcWGXe21cfs8IuKWE7wiHNer71YSnkBL8IPu66eeAvro3 6+Iz8931LU3UWy0Zq2k0zLAJzQR7XNnqE8TqusE/PSmvYxef8e9dZYvR+pV75IJOUekW WWJQ== X-Gm-Message-State: AA+aEWb+pNgOsM7bUHu7UMd16x7JodRezmf3QeBnojLLLfwpKQwiKHfm wwBZTPHWossfec7fnjnuliCNMBbZeNI= X-Received: by 2002:a2e:5152:: with SMTP id b18-v6mr18251462lje.88.1543348652197; Tue, 27 Nov 2018 11:57:32 -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.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 27 Nov 2018 11:57:31 -0800 (PST) From: Ruslan Trofymenko To: u-boot@lists.denx.de Date: Tue, 27 Nov 2018 21:57:21 +0200 Message-Id: <1543348642-31045-7-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 6/7] doc: android: Add simple guide for A/B updates 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" Add a short documentation for A/B enablement and 'android_ab_select' command usage. Signed-off-by: Ruslan Trofymenko --- doc/README.android-ab | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 doc/README.android-ab diff --git a/doc/README.android-ab b/doc/README.android-ab new file mode 100644 index 0000000..230088c --- /dev/null +++ b/doc/README.android-ab @@ -0,0 +1,67 @@ +Android A/B updates +=================== + +Overview +-------- + +A/B system updates ensures modern approach for system update. This feature +allows one to use two sets (or more) of partitions referred to as slots +(normally slot A and slot B). The system runs from the current slot while the +partitions in the unused slot can be updated [1]. + +A/B enablement +-------------- + +The A/B updates support can be activated by specifying next options in +your board configuration file: + + CONFIG_ANDROID_AB=y + CONFIG_CMD_ANDROID_AB_SELECT=y + +The disk space on target device must be partitioned in a way so that each +partition which needs to be updated has two or more instances. The name of +each instance must be formed by adding suffixes: _a, _b, _c, etc. +For example: boot_a, boot_b, system_a, system_b, vendor_a, vendor_b. + +As a result you can use 'android_ab_select' command to ensure A/B boot process +in your boot script. This command analyzes and processes A/B metadata stored +on a special partition (e.g. "misc") and determines which slot should be used +for booting up. + +Command usage +------------- + + android_ab_select + +for example: + + => android_ab_select slot_name mmc 1:4 + +or + + => android_ab_select slot_name mmc 1#misc + +Result: + + => printenv slot_name + slot_name=a + +Based on this slot information, the current boot partition should be defined, +and next kernel command line parameters should be generated: + + - androidboot.slot_suffix= + - root= + +For example: + + androidboot.slot_suffix=_a root=/dev/mmcblk1p12 + +A/B metadata is organized according to AOSP reference [2]. On the first system +start with A/B enabled, when 'misc' partition doesn't contain required data, +the default A/B metadata will be created and written to 'misc' partition. + +References +---------- + +[1] https://source.android.com/devices/tech/ota/ab +[2] bootable/recovery/bootloader_message/include/bootloader_message/bootloader_message.h From patchwork Tue Nov 27 19:57:22 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ruslan Trofymenko X-Patchwork-Id: 152169 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp221550ljp; Tue, 27 Nov 2018 12:16:02 -0800 (PST) X-Google-Smtp-Source: AFSGD/UIROeTJjfLuHmFonTQ1gYC1DzF0UnOvu6UluM1qvTo7SlMODL6tPUHkLSv03epOBPbE/wG X-Received: by 2002:a50:b3c9:: with SMTP id t9mr28406501edd.270.1543349762031; Tue, 27 Nov 2018 12:16:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543349762; cv=none; d=google.com; s=arc-20160816; b=1FkFMox7TlGa1CH1RJ9KMBTStnwO9LXxy5MEkJ+UVE51nsunSvsZkLeu403pLytE2G TaJ1gfYzyCoqP1l8ZGqrJNAmhdPq72Ky0rfs42LAH3dUa8CfUh+r6tn8bnCU3uo5ypgc DzIiDXMWCXBoX8HTf/NL7lB9VX5F4I4kbBCkcJphq7q75KZbXGEc7d2S1grzaHCXJE/O TvEXhf2Zjw7kDeFDFFcV0Y8etD1gRO4iiHixTWZl8bMplAVn2Of4a5EcVIxmFruWmzh7 6J6PHNsV3mo0x9ujqkla9jKyqg+8cVswVoae9i1oMgO5nvuKnS6tm4LhKWon3Ijz1/0s Izrg== 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=VZ6H9i2aPseda/2dlA2ehdTbtfTY/U53r3Y4/bqkHeE=; b=i5QipvNvlg6pYPmYRE4rifl2fs05gB0deJqIFcoGmeyjwX1TsL/7GR1WiPuRED3mc+ 4hDfiu+gMBEpyQjNNiJ7OCbNvV6NpRINw/OHtG//R39KuFxsJfYr2ZgiZeRsuIz8+zhn J3CQs3gN17yXSn4aNLgDlByeZwTtn/S7yxRFti9whhdVThWAJ6rtNJe6pFlR6XZZEZ94 XLnGcfFYVNJRweaShBGWBVk2XMjm5nlD1Qk2yv0gBlvnnFZSHqf3EhAzhZFyGuPz2z3t p+CMdaMqoHiwZRAH2dd5FHTr1d+MfEl/+pgUZruqH2KzhdJVVSgCA6jG624qNFNQ28Pc bcZw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b="CwlI/qH/"; 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 v57si621211edc.38.2018.11.27.12.16.01; Tue, 27 Nov 2018 12:16:02 -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="CwlI/qH/"; 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 914E5C222BD; Tue, 27 Nov 2018 20:13:20 +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 4E9F3C22258; Tue, 27 Nov 2018 20:10:38 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 74A68C21EAE; Tue, 27 Nov 2018 19:57:34 +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 136A1C21DD7 for ; Tue, 27 Nov 2018 19:57:34 +0000 (UTC) Received: by mail-lf1-f65.google.com with SMTP id f23so17499411lfc.13 for ; Tue, 27 Nov 2018 11:57:34 -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=GhuCnt9nw1BTunbAHLO2hw5OzI4cDQJNyjLf5DIPBvY=; b=CwlI/qH/13pQc3z6+Qs6LSUAyhiV35NBewwj+su7ZAc9JPFqHPJtIb6871xBL4M7l1 6RTPum54tOzXD8lHDV4D6a3JvxRDzKmNa6ieYgnfBtW2UjKH1t7Yw6JiTefHpjXoUPt3 YZDMaUblV0ZDBzagHq8krse0sG7unIHSJS7Go= 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=GhuCnt9nw1BTunbAHLO2hw5OzI4cDQJNyjLf5DIPBvY=; b=O+dYL7jInkvjkEJZOkdzG+ffI7hGKVdbQ+Z3faVcJqCyeNbXwIZRwIhrdMlTQfCTSl QphuPbFB5RClsdmf6OeeJj/Zsa26ehHCvhQsPofStpcyLtR8T/i+nv7b4RG8Cbgbb+st Phy3rHBHK8f1NnvQtdl+ueOrJLB3lg6LHCzJqdu+yuZYuLHYMF/1MqFuIIhkTeWH3C1g qzOCTMy/coIEXQ3Vk7SaFnWMybHDmi3ApgAniW4KRvqM9bEaTtMmahLp1Uz8TY0Y++mE jxJVQOwqqMjx/v19qalvAEbqQtOxFrszlM06FBwYBNQ+2pwyS/zrMoY4szYPSMffwULp Nz7g== X-Gm-Message-State: AGRZ1gIo04l96arcevV0wFh1d6+UUCRRxZ97GzehcgYTkDkg/6BAH9kv do71rJjzl4HEv6k5ZeNO7lGDm+mYO98= X-Received: by 2002:a19:5394:: with SMTP id h20mr20349276lfl.75.1543348653305; Tue, 27 Nov 2018 11:57:33 -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.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 27 Nov 2018 11:57:32 -0800 (PST) From: Ruslan Trofymenko To: u-boot@lists.denx.de Date: Tue, 27 Nov 2018 21:57:22 +0200 Message-Id: <1543348642-31045-8-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 7/7] env: am57xx: Implement A/B boot process 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" Add support for A/B boot process on AM57xx based boards: 1. Define 'slot_suffix' variable (using 'android_ab_select' command) 2. Extend 'emmc_android_boot' boot command (add commands for A/B boot process) 'android_ab_select' command is used to decide which slot should be used for booting up. A/B metadata resides in 'misc' partition. To activate the A/B boot process, the following config options must be set: CONFIG_ANDROID_AB=y CONFIG_CMD_ANDROID_AB_SELECT=y For successful A/B boot, the corresponding A/B infrastructure must be involved on Android side [1] (including mounting system as root), and disk must be partitioned accordingly. When A/B boot is enabled, there are some known limitations currently exist (not related to A/B patches, need to be implemented later): 1. The 'Verified Boot' sequence is not supported 2. dev path to system partition (system_a or system_b) is passed via 'bootargs' as 'root=' argument like 'root=/dev/mmcblk1p12', but further we'll need to rework it with respect to dm-verity requirements [2] In case when A/B partitions are not present in system (and A/B boot is enabled), boot up process will be terminated and next message will be shown: "boot_a(b) partition not found" [1] https://source.android.com/devices/tech/ota/ab [2] https://source.android.com/devices/tech/ota/ab/ab_implement#kernel Signed-off-by: Ruslan Trofymenko --- include/environment/ti/boot.h | 44 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 40 insertions(+), 4 deletions(-) diff --git a/include/environment/ti/boot.h b/include/environment/ti/boot.h index 3c9c87f..3ace316 100644 --- a/include/environment/ti/boot.h +++ b/include/environment/ti/boot.h @@ -63,6 +63,36 @@ #define AVB_VERIFY_CMD "" #endif +#define CONTROL_PARTITION "misc" + +#if defined(CONFIG_CMD_ANDROID_AB_SELECT) +#define AB_SELECT \ + "if part number mmc 1 " CONTROL_PARTITION " control_part_number; " \ + "then " \ + "echo " CONTROL_PARTITION \ + " partition number:${control_part_number};" \ + "android_ab_select slot_name " \ + "mmc ${mmcdev}:${control_part_number};" \ + "else " \ + "echo " CONTROL_PARTITION " partition not found;" \ + "exit;" \ + "fi;" \ + "setenv slot_suffix _${slot_name};" \ + "if part number mmc ${mmcdev} system${slot_suffix} " \ + "system_part_number; then " \ + "setenv bootargs_ab " \ + "ro root=/dev/mmcblk${mmcdev}p${system_part_number} " \ + "rootwait init=/init skip_initramfs " \ + "androidboot.slot_suffix=${slot_suffix};" \ + "echo A/B cmdline addition: ${bootargs_ab};" \ + "setenv bootargs ${bootargs} ${bootargs_ab};" \ + "else " \ + "echo system${slot_suffix} partition not found;" \ + "fi;" +#else +#define AB_SELECT "" +#endif + #define DEFAULT_COMMON_BOOT_TI_ARGS \ "console=" CONSOLEDEV ",115200n8\0" \ "fdtfile=undefined\0" \ @@ -91,10 +121,16 @@ "mmc dev $mmcdev; " \ "mmc rescan; " \ AVB_VERIFY_CHECK \ - "part start mmc ${mmcdev} boot boot_start; " \ - "part size mmc ${mmcdev} boot boot_size; " \ - "mmc read ${loadaddr} ${boot_start} ${boot_size}; " \ - "bootm ${loadaddr}#${fdtfile};\0 " + AB_SELECT \ + "if part start mmc ${mmcdev} boot${slot_suffix} boot_start; " \ + "then " \ + "part size mmc ${mmcdev} boot${slot_suffix} " \ + "boot_size; " \ + "mmc read ${loadaddr} ${boot_start} ${boot_size}; " \ + "bootm ${loadaddr}#${fdtfile}; " \ + "else " \ + "echo boot${slot_suffix} partition not found; " \ + "fi;\0" #ifdef CONFIG_OMAP54XX