From patchwork Wed Dec 12 17:12:28 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ruslan Trofymenko X-Patchwork-Id: 153578 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp2051172ljp; Wed, 12 Dec 2018 09:12:44 -0800 (PST) X-Google-Smtp-Source: AFSGD/Vm0hPiINqd9ADFgYjO+t7G8PsNGENuPCaY53/VsrtpHktHQRURwT/yWQcvYTDaYsvHq8Db X-Received: by 2002:a50:a347:: with SMTP id 65mr20120752edn.40.1544634763974; Wed, 12 Dec 2018 09:12:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544634763; cv=none; d=google.com; s=arc-20160816; b=q094dXCzR6FlUrb7ZPmLIth2ryTEM12yNeqWgftmQn5nTp5+6S0g+BrmjgosqllMzh U5i0N7vrlJXz/hIQT4WyTxYi4ftbkqfGbvSxSZ6YbLC5JR3Xdsrs3x5MBTslP5bF/haO o2jxqhke3o8HSegR2mETbxD6+9luq1F1HIO55OX8BUD3XcvITXDPogGa/MUspTesBKaY jVZqlHP+++ttDbY4tCP+D86qjhATBSmfcMatNBSa/yGZIVmzxmhzub6KYW2b19VN2jYH Nn5L8TdjbhFdBbfq+bWlre83/VWdQ5he/8kr7xSh+OjS87SNjP7EELMgy86O8HSzQ9x/ 08tA== 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=FGDL7CGXhjmA6Xu7hdiLAWcY52FksH1klNNpAItm9tk=; b=rSexsTRJG/8018uWxKEehLGP+Wxdyn9qV/whyaYKF9XX3iyluCHYW+mEj+1MB54u6n frSGQl9NcPfudsjqtLBG9pOK+x2CtWwfcwotqtKIU29LbqVv0FUi/VTT3Z7904SlbAZR dcUFApx3aMBSMWDclHIbskKcOGuk/NUbOH2GRd9fAtEAkm19SXOyV9xljXzrkR6gV7us SoLkMYYtQBqpDe0U06UNHBgSw+o7uNSGOERMOetcZeeMkX1ptLFwBFiXv1De9J6Tgr+O GidOg1NRagEqTG6nKsMmUC3ZokExohfUFq2ZZy5QlI5Twjn4OyW9oLgM8SDgaRdd9Rs4 DT1Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=ZpwhZDns; 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 e19-v6si5657783ejj.140.2018.12.12.09.12.43; Wed, 12 Dec 2018 09:12:43 -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=ZpwhZDns; 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 0750FC2276C; Wed, 12 Dec 2018 17:12:42 +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 0A848C21F51; Wed, 12 Dec 2018 17:12:41 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 36F2BC21FE1; Wed, 12 Dec 2018 17:12:39 +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 B68CEC21FD2 for ; Wed, 12 Dec 2018 17:12:38 +0000 (UTC) Received: by mail-lf1-f66.google.com with SMTP id z13so14094194lfe.11 for ; Wed, 12 Dec 2018 09:12:38 -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=veTJ1CqzhnJWnT/G+NcjVe+w+V622zMQKl82TBQKqis=; b=ZpwhZDns1PfkBonwuimr4HeS/BA6wcr+w+Qo2+J9OOj7YY+EECtM8Bk9dSt+pLfpIT y5Popi5diMNjkARPCh3dwX8isNgXkdfvEr206vqM6G9d9Pci4GL2kqJ55my2g/H1qAzM cp8RD9SczzrpjHuJ5dAo750qFXjUihxAtNFMY= 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=veTJ1CqzhnJWnT/G+NcjVe+w+V622zMQKl82TBQKqis=; b=bVHI5zqWSwMQNwtbNJpqbrEm9ZLADntEazFheSVjXD1oIhtiLzvtCa9i5pT7+0rw1v hYn1tY+JSOWA84P3ycLjBNEUdLuHkjjIdr0aZuklAesue+vML8/gJ/nScQZjslVyLMpN 1FpMvQAgi8GCslB4pwYeB5tvb82hYlURT0q/DG+p8e7QBsWee+ltKMjB+PJDLHUcNgp9 jfvYvHsaB2Xzumg5dXqKoiFRlO/P0pPusAA/BxeCkG2aXTxn0cEGSeWLOG2KcqW8ym5X Tvg4rvyhbyjc43iI79fZQbHG9+P/2uEzP0YhSVSCxgn5odT0jeGr7Wl4an7Kry5WBMbo I3Jg== X-Gm-Message-State: AA+aEWa4QJXSiw7G9Nvq55bFlP9iPXpptXX3TVRWIFQ+lTO4ihhiiRcI PyM+XSdVISn+SNOfUIyZVOwPUiKDpeY= X-Received: by 2002:a19:910d:: with SMTP id t13mr2371527lfd.98.1544634757870; Wed, 12 Dec 2018 09:12:37 -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.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 12 Dec 2018 09:12:37 -0800 (PST) From: Ruslan Trofymenko To: u-boot@lists.denx.de Date: Wed, 12 Dec 2018 19:12:28 +0200 Message-Id: <1544634754-3435-2-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 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: Alistair Strachan Reviewed-by: Sam Protsenko Reviewed-by: Simon Glass Reviewed-by: Igor Opaniuk --- Changes in v2: None 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 Wed Dec 12 17:12:29 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ruslan Trofymenko X-Patchwork-Id: 153580 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp2052449ljp; Wed, 12 Dec 2018 09:13:49 -0800 (PST) X-Google-Smtp-Source: AFSGD/WTt+fZPgF7wFm4Q2rXenNIFKUuFOW6iY//KZBWWdcCX+fuKLieu3C50NGD2Bj7Ik3tgbrC X-Received: by 2002:a05:6402:1643:: with SMTP id s3mr19364843edx.66.1544634829709; Wed, 12 Dec 2018 09:13:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544634829; cv=none; d=google.com; s=arc-20160816; b=Kq23mMBtKTEICPXje/AonArzHk8zCXdEqewL5yjq4aOv+8/s2R1Ocef8ucVTA8XCwO S2ZEmO6p/0d4rCX1vE7VXC0NoiEoyI8lclb9Wt8H54f7yFm076MrCSEK04tttIdUSCQq k1Ng+faSbDnNwevGm+06/NZGht0KPYmhrKHHN1KShttzQSvRRbVhH+dn1Rwh9QIbQ+ZF KWck5ISe3jVdtdBXGe7Pd0MyucP6t0MgCZkyx89i0kbvI72F8Esid2Tm4H685r4AKU5Q QqI71SeBoaAz4HXjhHbPwyK0xoZPmAL5X9WZnYFNRZ8KRdyQ1iqHLMyZhbHNYLO3aPrH t6cA== 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=5j8ri2vZlRnLANWIXhs/Wq2AYoWjeqB0ygLVH+oaVk0=; b=da1GVq6HmB+V4NaL4dDWzNV3hCgo+h83rGmOWDKOqCrUSPX01CEHFV+kJYWPAMjPAm eqzIhZhzmjkKpg5xcv3AdkAwj31g5oDvBAuQzq9fJdLH3MBJ5sBZ4xrUY5E39W7dAC6I zclRkRPiBaltPKTdnlsVySyF5EBchKL8bEJW4AZ4XA77+KPGhAXVEh2Zxl8yBr6VX783 +BG62olRDdZw6ANZZ4ywh7pCCKOfXCeoTemz3z8cXRHuU8NAea5i3oTiB2Npysh0bNCR l9Kai7eTXH6tYJr2Dbz3FATavwpTuUJBK2ds2ttbnem1q9yx9LIFSXofBlH56yxBCAZ5 qp5w== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=RchUe9zh; 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 gx11-v6si4467510ejb.297.2018.12.12.09.13.49; Wed, 12 Dec 2018 09:13:49 -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=RchUe9zh; 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 4E920C22773; Wed, 12 Dec 2018 17:13:21 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=RCVD_IN_MSPIKE_H2, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id AAF8DC22780; Wed, 12 Dec 2018 17:12:43 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 8A877C21F51; Wed, 12 Dec 2018 17:12:40 +0000 (UTC) Received: from mail-lf1-f49.google.com (mail-lf1-f49.google.com [209.85.167.49]) by lists.denx.de (Postfix) with ESMTPS id 2BD93C21F18 for ; Wed, 12 Dec 2018 17:12:40 +0000 (UTC) Received: by mail-lf1-f49.google.com with SMTP id p6so14135097lfc.1 for ; Wed, 12 Dec 2018 09:12:40 -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=QqIbVjRsV6hkpdb57n+XKYo8jqMZRxMlVSSjl+oFxPM=; b=RchUe9zhUCtZvRkVdK3cvV8K0Izbj5aOfe2ge2l9fJiZ8PAvHaeFlv96wNU5eQVCpX peMdELsEAhOCfa06jdcCgIDml+4dzJUL03WnvV33XMsns82XJwLTuEx+V24QEL2jGchO v/pgyNNCeGZIlJ1RRTWL1gDUQA7plTASYny7g= 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=QqIbVjRsV6hkpdb57n+XKYo8jqMZRxMlVSSjl+oFxPM=; b=E9Owde/PSu5HMPp+hi8182o2DuIrzpCtnonSE6CQp0eTJGwSPru9HjxJri/PzPfEuw M+P24H+g6523av5aenziBQu1g5U/syqjFs7WiPAVQHh567jQZddu0mcNFey0ZdeiSTBR BuMLRl7GwR65WRoKcp26wPr5IpQpCI21JMEZHJ9vVr5yPS2boOcG3vuPPnFbSpdoWYhL QtWBbPf4+NNp9H/spsfOEfAIp45Fy7PGPiz5lwr9W+BnadrixLJPBfBy9OJmXj0kj0kF eX2BHaoZ2WbRl3OMEGjRR7p4veS9R/KOGdWB/R62X5oPYWlrSObadiXWhjd6oJry1IQU +u/g== X-Gm-Message-State: AA+aEWYH46Zb+LYphI8jFNJuVwDh0HHitud20nbAjS+lLwvz3xYCtzSR BgRtMYWpxGqQCkuv0CcYR+STl98GnD0= X-Received: by 2002:ac2:4343:: with SMTP id o3mr7089734lfl.129.1544634759062; Wed, 12 Dec 2018 09:12:39 -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.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 12 Dec 2018 09:12:38 -0800 (PST) From: Ruslan Trofymenko To: u-boot@lists.denx.de Date: Wed, 12 Dec 2018 19:12:29 +0200 Message-Id: <1544634754-3435-3-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 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 Reviewed-by: Alistair Strachan Reviewed-by: Sam Protsenko Reviewed-by: Simon Glass --- Changes in v2: * Error codes are changed to -EINVAL instead of -1 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..7b739ad 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 a negative 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 -EINVAL; + + dev_num = simple_strtoul(dev_part_str, &ep, 16); + if (ep != part_str) { + /* Not all the first part before the # was parsed. */ + return -EINVAL; + } + 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 -EINVAL; + } + if (part_get_info_by_name(*dev_desc, part_str, part_info) < 0) { + printf("Could not find \"%s\" partition\n", part_str); + return -EINVAL; + } + 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 -EINVAL; + } + 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..9d57b65 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 a negative 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 Wed Dec 12 17:12:30 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ruslan Trofymenko X-Patchwork-Id: 153583 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp2054906ljp; Wed, 12 Dec 2018 09:16:07 -0800 (PST) X-Google-Smtp-Source: AFSGD/VQ0oOTGqqIqPxiMDa25EsVYp/1owwQ3LoRIengHUxAUTsVkCndxKIMThovXWOkLuXMo5UK X-Received: by 2002:a50:bc12:: with SMTP id j18mr19959732edh.50.1544634967385; Wed, 12 Dec 2018 09:16:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544634967; cv=none; d=google.com; s=arc-20160816; b=oJejiAceH6Rr8J4421pGoFcaxkvd0zE2tdzJ2EXE7qUHXIKQds8EAkdcQPsoqE1Mua TCVKgm/KsEvB/+6Mm40FK3mZdm2ijR6FeqpZrIif49fjme3CttJekMM8R6YxdEDqUjsJ ImOX/ie4eybOMMs4ZND8EE/EwiboNQXLXO/BSk4XSijVPgiBu2btbIE4epzQfdVhe4zu AbjvXoZVgRLZnBDQ3G0W65Zf2XmXS0650/dt84LSC50hxbdtSXLo9K/WnIRs35Q5YLn+ ip4hu9lLWQsN/A/QImh8rViFJlfopHDT8B1zj2SZgv8doZRGOsb6pYW72y7j7Z2RgVp3 AM8A== 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=AzpZW2YzKI+u+RMdStfIxIZHwTVMnEZg3eU0SJsttjk=; b=t7PlGsdOjFs3wicNGkCMPiQOsdLAl7FtIxoWN9Bn/Yms0Py3rUUnKJnnDBGp3KoX/S pB853MzuCvGvYb1+szJLXoH56eH5NZrE6geQ0JAlPDFh0c++a4of7Iq8mhieTv8AkGOQ BwUt0WQQqbxVCQ2DWFnqpwh4V3x7Soe3AJvNd5qFWWYthhkTDeNpezQl1zOkCP48nsLQ 1gZy4l6xmo2dkJ6IbcAi1ATTT28kKzDadRwP1ZHrViNUdiQIiQlaWuSqKa7SLPWKpzqt k+0eqCZEgDs7Yh4PcNZamf5agA7OtgUchk9TY8gAX+j9d33c1oIvrH6kG5y8NMgi7fsq 2LSQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=OrbXIVvb; 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 i25si2689281edj.422.2018.12.12.09.16.06; Wed, 12 Dec 2018 09:16:07 -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=OrbXIVvb; 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 A964EC22760; Wed, 12 Dec 2018 17:14:04 +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 9F9C0C229B9; Wed, 12 Dec 2018 17:12:55 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id EB547C229A5; Wed, 12 Dec 2018 17:12:46 +0000 (UTC) Received: from mail-lj1-f195.google.com (mail-lj1-f195.google.com [209.85.208.195]) by lists.denx.de (Postfix) with ESMTPS id 23DA5C22769 for ; Wed, 12 Dec 2018 17:12:42 +0000 (UTC) Received: by mail-lj1-f195.google.com with SMTP id e5-v6so16966699lja.4 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=cEBdtUWsKkR3rJe4eze4AquublkCUISct9IxrA4jeJA=; b=OrbXIVvb7tKb1IQhkkVWd1iuXNIjTEhIhoYtw/cBVGEiBxnT17AAeh+CNLDgQK8Sq/ vIYEfDmAtQ3F/2uVX8HDYtOlxz7if5yywHBUdaF5n3pN4jGIB/YFO1Z0k0hjUUHiWQYy tPHQvZuRoAAzNrrftIkP4TkjQkYg8cHRNctaI= 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=cEBdtUWsKkR3rJe4eze4AquublkCUISct9IxrA4jeJA=; b=ULtO/dDWBjw0JJ187pzJS3fHoRF4fIFdejPmZGQWQhIhHRmctAMm86PjZhy13qTEkc Vbbtk3tJ6hTVBxQFECuu58b/eKqrQso84zuDzkt6diO1Lyqy4Y6fUEPtIhn1McLHpm8K ORovj0oXY3YaBmEKivQdkSB9X810jf2CSSFmUUNg4AVWC/guvUz8kz2oy59hRR1tq238 46sXg9M5GcyNlgX3IQudqDit2FvUbHLO9dma50guEtTglIz4M6ncVuHpSOGW46H0nuR3 rsJVnyuIr4O18luQJPc5sFQd86ufxQTylepAVRkdt1VygAO5e5YC7Uw6EJSe0ASFTeg9 1BlQ== X-Gm-Message-State: AA+aEWZ2Pxdc6RaCneM29Wi6+X79BbzBABLs0ITWy8H8PIcb2Yv8dAQT cUh/PVmt29+iBrPRz4hWqNlx3wqCauo= X-Received: by 2002:a2e:9d86:: with SMTP id c6-v6mr12570344ljj.146.1544634760626; Wed, 12 Dec 2018 09:12:40 -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.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 12 Dec 2018 09:12:40 -0800 (PST) From: Ruslan Trofymenko To: u-boot@lists.denx.de Date: Wed, 12 Dec 2018 19:12:30 +0200 Message-Id: <1544634754-3435-4-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 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 Reviewed-by: Sam Protsenko --- Changes in v2: * Function return codes are clarified * Some types and constants are renamed (for compactness) * android_bootloader_message.h is renamed to android_bl_msg.h * 'debug' calls are changed to 'log_debug' * Order of headers is changed * android_bl_msg.h was synced with AOSP master counterpart common/Kconfig | 10 ++ common/Makefile | 1 + common/android_ab.c | 277 +++++++++++++++++++++++++++++++++++++++++++++++ include/android_ab.h | 34 ++++++ include/android_bl_msg.h | 169 +++++++++++++++++++++++++++++ 5 files changed, 491 insertions(+) create mode 100644 common/android_ab.c create mode 100644 include/android_ab.h create mode 100644 include/android_bl_msg.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 65d89dc..acc3851 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..dda2263 --- /dev/null +++ b/common/android_ab.c @@ -0,0 +1,277 @@ +// 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 andr_bl_control *abc) +{ + return crc32(0, (void *)abc, offsetof(typeof(*abc), crc32_le)); +} + +/** + * Initialize andr_bl_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 andr_bl_control *abc) +{ + int i; + const struct andr_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 + * @param[out] pointer to pointer to andr_bl_control data + * @return 0 on success and a negative on error + */ +static int ab_control_create_from_disk(struct blk_desc *dev_desc, + const disk_partition_t *part_info, + struct andr_bl_control **abc) +{ + ulong abc_offset, abc_blocks; + + abc_offset = offsetof(struct andr_bl_msg_ab, slot_suffix); + if (abc_offset % part_info->blksz) { + printf("ANDROID: Boot control block not block aligned.\n"); + return -EINVAL; + } + abc_offset /= part_info->blksz; + + abc_blocks = DIV_ROUND_UP(sizeof(struct andr_bl_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 -EINVAL; + } + *abc = malloc_cache_aligned(abc_blocks * part_info->blksz); + if (!*abc) + return -ENOMEM; + + 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 -EIO; + } + log_debug("ANDROID: Loaded ABC, %lu blocks\n", abc_blocks); + return 0; +} + +/** + * Store the loaded boot_control block. + * + * Store back to the same location it was read from with + * ab_control_create_from_misc(). + * + * @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 + * @param[in] abc Pointer to the boot control struct and the extra bytes after + * it up to the nearest block boundary + * @return 0 on success and a negative on error + */ +static int ab_control_store(struct blk_desc *dev_desc, + const disk_partition_t *part_info, + struct andr_bl_control *abc) +{ + ulong abc_offset, abc_blocks; + + abc_offset = offsetof(struct andr_bl_msg_ab, slot_suffix) / + part_info->blksz; + abc_blocks = DIV_ROUND_UP(sizeof(struct andr_bl_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 -EIO; + } + 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 andr_slot_metadata *a, + const struct andr_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 andr_bl_control *abc = NULL; + u32 crc32_le; + int slot, i, ret; + bool store_needed = false; + char slot_suffix[4]; + + ret = ab_control_create_from_disk(dev_desc, part_info, &abc); + if (!abc || ret < 0) { + /* + * 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 ret; + } + + 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 -ENODATA; + } + + if (abc->version > ANDROID_BOOT_CTRL_VERSION) { + printf("ANDROID: Unsupported A/B metadata version: %.8x\n", + abc->version); + free(abc); + return -ENODATA; + } + + /* + * 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) { + log_debug("ANDROID: unbootable slot %d tries: %d, ", + i, abc->slot_info[i].tries_remaining); + log_debug("corrupt: %d\n", + abc->slot_info[i].verity_corrupted); + continue; + } + log_debug("ANDROID: bootable slot %d pri: %d, tries: %d, ", + i, abc->slot_info[i].priority, + abc->slot_info[i].tries_remaining); + log_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(dev_desc, part_info, abc); + } + free(abc); + + if (slot < 0) + return -EINVAL; + + return slot; +} diff --git a/include/android_ab.h b/include/android_ab.h new file mode 100644 index 0000000..c1b901d --- /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 a negative 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_bl_msg.h b/include/android_bl_msg.h new file mode 100644 index 0000000..f37e01a --- /dev/null +++ b/include/android_bl_msg.h @@ -0,0 +1,169 @@ +/* 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_BL_MSG_H +#define __ANDROID_BL_MSG_H + +/* + * compiler.h defines the types that otherwise are included from stdint.h and + * stddef.h + */ +#include +#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. + */ +#define ANDROID_MISC_BM_OFFSET 0 +#define ANDROID_MISC_WIPE_OFFSET SZ_16K + +/** + * 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 andr_bl_msg { + 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. + * + * The update_channel field is used to store the Omaha update channel + * if update_engine is compiled with Omaha support. + */ +struct andr_bl_msg_ab { + struct andr_bl_msg message; + char slot_suffix[32]; + char update_channel[128]; + + /* Round up the entire struct to 4096-byte */ + char reserved[1888]; +}; + +#define ANDROID_BOOT_CTRL_MAGIC 0x42414342 /* Bootloader Control AB */ +#define ANDROID_BOOT_CTRL_VERSION 1 + +struct andr_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 andr_bl_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 andr_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_BL_MSG_H */ 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" +); From patchwork Wed Dec 12 17:12:32 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Ruslan Trofymenko X-Patchwork-Id: 153582 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp2054792ljp; Wed, 12 Dec 2018 09:16:01 -0800 (PST) X-Google-Smtp-Source: AFSGD/UE69ykPhS+t7ni5oo/vXuSiV/2+bqdqxLgYZi5TgplVYOTx3BKAyd0CAukFmgoP7PjqADE X-Received: by 2002:a17:906:790b:: with SMTP id b11-v6mr15961334ejo.228.1544634961230; Wed, 12 Dec 2018 09:16:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544634961; cv=none; d=google.com; s=arc-20160816; b=Q5bH/0Qg5qQS3e+MgUX2d3l13InaUIH1uE00s2REejQr6ar/4DMNuavhi1RTTBzPRj uWnGdIOEbaIXGXfXsesJ1PdjmKwUE1d4a8zhadtRiT8A1x3uK01y17jgsZdRbeBEyB1l 7P+atbbGfG/c0/qSfVkYh0iSPivYDlE9/i7guaBYUeHTKEJoE5uVO/ugPp3L8F1v8cs3 S2iTsDeXvb0X6/W6PG1nahb3Pj8Ur/IvPijD2LNtFhvAHMiRzwZeMtzPUFFp2QgmgBZ5 91oE53YHI7007mD7wkZkQ4tSxPdJ5P4jSncCopwNZdumSIflndydKAdnnEmii6LY6ONC pfUA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence:subject :cc:mime-version:references:in-reply-to:message-id:date:to:from :dkim-signature; bh=+UIra8PaPwtnj8rmquQ4V02SZhiKxFsJKlR5IhHlRYc=; b=kIto3WqZsdp5UASBp4q/sQef81gXqDxfhN/ivjzc63WRqXq45SePs2b7lLeyC9+v6z jmfc+A7rvJm5mxpeKJ/l4xqRJJ6sJA6CKZFSBsOVfHBU69Q13yF2mssaqHyzbvHZfWRZ sJIor/ElmX6DtIQcaiZA5R/MDbya7jt9fZ0rthn0OWn1N1TSIk0a7xWc6jGOwhZttDHb FWqvClgNONy6gub0tY2Zk/rTBeSX/3pDby3n01FW0Uq81CB8uc1zA+wgCGDyNIYFKYxE TWU7Zg3WNvG8WNmjwW/IXBsRSDg3DedINvP4XOiIVgPN8lN28OMwQlltv69KsOwdST75 UMaw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=X8M+ggWU; 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 y49si827349edd.80.2018.12.12.09.16.00; Wed, 12 Dec 2018 09:16:01 -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=X8M+ggWU; 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 C6FE1C2293E; Wed, 12 Dec 2018 17:13:42 +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 CC223C21FF8; Wed, 12 Dec 2018 17:12:52 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id C3F9EC22782; Wed, 12 Dec 2018 17:12:49 +0000 (UTC) Received: from mail-lj1-f169.google.com (mail-lj1-f169.google.com [209.85.208.169]) by lists.denx.de (Postfix) with ESMTPS id 055DEC22775 for ; Wed, 12 Dec 2018 17:12:44 +0000 (UTC) Received: by mail-lj1-f169.google.com with SMTP id x85-v6so16982008ljb.2 for ; Wed, 12 Dec 2018 09:12:43 -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 :mime-version:content-transfer-encoding; bh=UKBCx6drYikbJNWrDKSg3ERr1i62RZmFh/Iz7ecHmOE=; b=X8M+ggWUua1OWv8n89kcSSR4sUTFxstvcdT/1HZL019jKT9O2YioOFXiR8aXBfr3b4 jVWpFj22r87HZi4ae9jchI7SpP1xGUVLzzRXiHDau/FCrxvk1dXSA46bCPjy7UnTuLjJ 1ZYuvO56s/HMLxiTuuuEpV4hvnzalyPwiYHf8= 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:mime-version:content-transfer-encoding; bh=UKBCx6drYikbJNWrDKSg3ERr1i62RZmFh/Iz7ecHmOE=; b=mswdvJXn2l9FMwdEz0D+ZuER7ezxoBJuSnqmP/0yj/p4Tr1OLa9Tn3aG1ESlr7QzeA ogn2BGxfLKnIfNJ8v/P368MLK6xNUq9u4te6NZ9FdQwXm0hzl0LfeNq2BgkEpEEAEhlQ Q8IdRQu6wzzLVK90r2yO32JPr8d/wOQvH8VneLjOs0XZrzqOXsFshZMmQl3qfRT1rT0R fXvqG8lrOTHGYcCEJuU/xlN/vrE1Imko0w3mQKjtWUqJ1hOjy6C9KPx1Wobsfne9khzJ GltRB4M/VbxBNvMcunFwdR1jKAsdVMu6H+W7L+Wpm6dOc5aaHElyj1pcwlUrzhNeO1kz 3i9Q== X-Gm-Message-State: AA+aEWYuHpPD0PRFg8F73H2n1m0Rih/wqN588gGQDCevoEr0SknlkmWn 4PkvkErLqD/Y34FJrO4dRhB2lRDYJfQ= X-Received: by 2002:a2e:8546:: with SMTP id u6-v6mr3330393ljj.95.1544634763202; Wed, 12 Dec 2018 09:12:43 -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.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 12 Dec 2018 09:12:42 -0800 (PST) From: Ruslan Trofymenko To: u-boot@lists.denx.de Date: Wed, 12 Dec 2018 19:12:32 +0200 Message-Id: <1544634754-3435-6-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> MIME-Version: 1.0 Cc: Tom Rini , Praneeth Bajjuri , Alistair Strachan Subject: [U-Boot] [PATCH v2 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: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Add sandbox test for 'ab_select' command. Test: ./test/py/test.py --bd sandbox --build -k test_ab Signed-off-by: Ruslan Trofymenko Reviewed-by: Alistair Strachan Reviewed-by: Sam Protsenko Reviewed-by: Simon Glass --- Changes in v2: * Сhanges related to command renaming * Assertion condition was clarified. Full command output is controlled. 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 5b65c61..b6a642e 100644 --- a/configs/sandbox_defconfig +++ b/configs/sandbox_defconfig @@ -21,6 +21,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 @@ -49,6 +50,7 @@ CONFIG_CMD_SF=y CONFIG_CMD_SPI=y CONFIG_CMD_USB=y CONFIG_CMD_AXI=y +CONFIG_CMD_AB_SELECT=y CONFIG_CMD_TFTPPUT=y CONFIG_CMD_TFTPSRV=y CONFIG_CMD_RARP=y diff --git a/test/py/tests/test_ab.py b/test/py/tests/test_ab.py new file mode 100644 index 0000000..b90ca87 --- /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_ab_select') +@pytest.mark.requiredtool('sgdisk') +def test_ab(ab_disk_image, u_boot_console): + """Test the 'ab_select' command.""" + + u_boot_console.run_command('host bind 0 ' + ab_disk_image.path) + + output = u_boot_console.run_command('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 'slot_name=a' in output + + output = u_boot_console.run_command('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 'slot_name=b' in output From patchwork Wed Dec 12 17:12:33 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Ruslan Trofymenko X-Patchwork-Id: 153585 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp2056334ljp; Wed, 12 Dec 2018 09:17:24 -0800 (PST) X-Google-Smtp-Source: AFSGD/UxtPY7AdJNUpU8pI/gSPJpYOrLYNKPIQ3uPfghEcdpu5rYqHtbiErDGGW/96g6TMjXOuvr X-Received: by 2002:a50:95ce:: with SMTP id x14mr19504434eda.204.1544635044852; Wed, 12 Dec 2018 09:17:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544635044; cv=none; d=google.com; s=arc-20160816; b=Dey/jCqQ+ps90CTb4hr81DE6abSPlQcjZD2sav73jf0NSteeoxllREqN2NLKYZ7BOf wdBsDkVv4OP/epv+FPjHyh6WTEDiF/N0beMQm3CkK0DKTAb/t7feSBfNNdjM0yB4nAia UUT1Rr7iZy0D45UBJtyU3itzyrNVrvrTP0U93WVyxKuU0rR62VeY2qdGwRm5WFPFHsT2 5FeEHNsdXC55Zq/pbxWssOuK0RaNCMPEt5QS9kB2i6fH1DczWVfIh14Wh064yLt+Wdc3 kN13li9htF19VGswxf5xbJInNbVa7JVl/9jKqOOCQyKyZK8p0uj8W5ImciVTlX4m3lnK T6Ug== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence:subject :cc:mime-version:references:in-reply-to:message-id:date:to:from :dkim-signature; bh=jvur939V/vm5BC6N+D/gwmhQv58K40fIeKERM87N3Fw=; b=is2KeLDZDQRZxQswGyLZwY627G+Z7eGRu/1UMxghv5oPO1yjNJZ/qTG4yqfdaqGQ5f Ab3/Tq3Wd8vVwpe9hnZWJTkaRjgn87o56B4ztQtNElWacsBetffS/5amlgPt+mSIQLmP QfbrtjEaMsMIZLWCyBxhCoZQUm9swS3t3Vkb8icZt+GYL+TfqqBpL8887rvWTo9h3i87 arMz6zSVMga8nTznyJR8hArpuETyuhimuOxetzZ6jZc1kmJnoBeuta+k6PJvUtKRN3lQ wUFGEqHtsX29ridS8BTmG+KCax4a+eScZMecntJTliee/mWkg3YBLYszbbvowro3c1Ju maBg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=PRhJ2aM1; 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 c2si2548160edl.50.2018.12.12.09.17.24; Wed, 12 Dec 2018 09:17:24 -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=PRhJ2aM1; 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 6B310C2298D; Wed, 12 Dec 2018 17:15:22 +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 A8799C2276C; Wed, 12 Dec 2018 17:13:03 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id E61A1C22757; Wed, 12 Dec 2018 17:12:49 +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 05BACC2299A for ; Wed, 12 Dec 2018 17:12:45 +0000 (UTC) Received: by mail-lf1-f66.google.com with SMTP id v5so14123213lfe.7 for ; Wed, 12 Dec 2018 09:12:45 -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 :mime-version:content-transfer-encoding; bh=e/enG2uvEGD/wycTPqUap5iR8CRALykv2bHfgUNiEBY=; b=PRhJ2aM1Im+7CSq48gl4LX7rQ0Bw49upCEBEZPv41iDuZnFB6mPDwsOE/0DcG6At3h ISlAxVWCu44hbqNU0/hFQUzJ30iqpfeVd0OiMbPl8CJPNaszf9xpfMhzAujZVVrecrRA NlhqfLg++naw7/Q2zvEa8ykzCV3QzCR8u1ANI= 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:mime-version:content-transfer-encoding; bh=e/enG2uvEGD/wycTPqUap5iR8CRALykv2bHfgUNiEBY=; b=aP5BAfbzs3tcbVu4aiIasfsmEWWnnwU5pMkjPvu6ZtQ2gVFT15sM9698bXAQ8SifRB ljb4m+oJ/G9lFb8YvrSpG7li0O90TuLAESpsOD9C2Varr7H9oiilkv5I7Sesqqq44W9q 1mdnhsv8CgIMHx7sdJ7tdFIZFXP8R/VtYpBKcl5gjWcSNV3ACoooqs7t29ugGKspR88T vmExHoCct4IMQJI7Vz52fkkf/D7qtNn94znCKzvB9+EWmVUQ+E4eGBr9co6o1tp2Ei2U 0wOyVjiR1XTFXUwnEn0FIk7daI6QI5nSG0vX9uxnm0cuSZglTCrLLIZ/0yWSmi1j6ZTd yJvA== X-Gm-Message-State: AA+aEWbDCT2cIcmo39Xx62oS7S2aQ8NbR/03Nb7HssCT8ENXkSfZycur Jq37/9JCV1s+TbRMDKTOZDr+TN/VZC4= X-Received: by 2002:a19:a7c1:: with SMTP id q184mr11537578lfe.4.1544634764312; Wed, 12 Dec 2018 09:12:44 -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.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 12 Dec 2018 09:12:43 -0800 (PST) From: Ruslan Trofymenko To: u-boot@lists.denx.de Date: Wed, 12 Dec 2018 19:12:33 +0200 Message-Id: <1544634754-3435-7-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> MIME-Version: 1.0 Cc: Tom Rini , Praneeth Bajjuri , Alistair Strachan Subject: [U-Boot] [PATCH v2 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: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Add a short documentation for A/B enablement and 'ab_select' command usage. Signed-off-by: Ruslan Trofymenko Reviewed-by: Alistair Strachan Reviewed-by: Sam Protsenko Reviewed-by: Simon Glass Reviewed-by: Igor Opaniuk --- Changes in v2: * Сhanges related to command renaming (android_ab_select -> ab_select) 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..9f37ed5 --- /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_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 '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 +------------- + + ab_select + +for example: + + => ab_select slot_name mmc 1:4 + +or + + => 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 Wed Dec 12 17:12:34 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Ruslan Trofymenko X-Patchwork-Id: 153584 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp2056083ljp; Wed, 12 Dec 2018 09:17:12 -0800 (PST) X-Google-Smtp-Source: AFSGD/VJOs6EjgXB42+j67b6xYA8nIn4Ks6J4yMSRyCeYYtRUd1Fc1Mv1E39hm+xVjXIsX1Ljp/u X-Received: by 2002:a17:906:b893:: with SMTP id hb19-v6mr15579353ejb.76.1544635032339; Wed, 12 Dec 2018 09:17:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544635032; cv=none; d=google.com; s=arc-20160816; b=Ql7B1YiMBwwxtGua2rphBJQ8V1Rk4I+6Ch8ef8oLXI0SrgcgaLX4TZNU7TdVXIgCJ4 Gu0XrU5Mc08b/mb+vpdxB77pK1SorsSmB/VqHgkuFe3dr96J69aI5TV30+upXr6q4w0R +3wQHfrQEzuZ3gyk4Lqd9n208s7/o250lB9K+AHcPVNZJbH/maIMCKjgg6pxGJ+usWIe xWLPUWW7wi7qKipeED9xmikZCwkUkNMD/8L1K1MotjE7f2Pa0s0yni4zk7rlUThhSDye d9e0uiy3KjXUydkneumAMABXdO6vEbVw5bK1TbR9Q3AG5mSWZugK/vdWEurexEnFbUvM Lj0w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence:subject :cc:mime-version:references:in-reply-to:message-id:date:to:from :dkim-signature; bh=jKiKpOOGdcOisUJhDM6ccR6e9hFUT2fq2GVDFqy9eW4=; b=SEpvEWrTjK5QGXHTmIRAetrR2kQ8IeMYpK2BwCxNPqNuXSUCP3h+ZUEEasLDdVazMx vIPg5RT91PTx66aVexjVdug2iyMQb0N62K1BHv3yxVxxhlay7HWrka25acSxT5GQxTIm 62w0787RdP9QjjASxeUoPWf7iTgnxJ26gOoIP5j71nfa9qhR8h61C30KNGnzLoh3lkMS PJDdzwappaiANFYRRwC3DQbfC4eVPTRhA4lVD31MBfxAbqsaDZeq8+aaXfmzW472xxuL i59bSXf+3HXTKDiuQAK9zNcAjWbMtUtY2OrkvjWMjOOYUgYBIKviEA6AOywvCI7G2c1o E+Rw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=TggbaAZ+; 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 o1-v6si2915087eji.22.2018.12.12.09.17.12; Wed, 12 Dec 2018 09:17:12 -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=TggbaAZ+; 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 D65DCC2278B; Wed, 12 Dec 2018 17:14:42 +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 6CDCBC22788; Wed, 12 Dec 2018 17:12:59 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 7F0C9C22784; Wed, 12 Dec 2018 17:12:50 +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 5CDE2C22779 for ; Wed, 12 Dec 2018 17:12:46 +0000 (UTC) Received: by mail-lf1-f65.google.com with SMTP id y11so2822972lfj.4 for ; Wed, 12 Dec 2018 09:12:46 -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 :mime-version:content-transfer-encoding; bh=ZHaDFBTgtxPyauUYIbe2xZhoBPmdz9uZMKjIbwpkzlE=; b=TggbaAZ+swcqlDZGwvX6TJp9NUYe1KKFDc9gArETCSKZf7wBo0CuiisMe2ooQ933aa PLPwNkncd7pJ2jwphdw27rJ5s58xbcvQL4V4MWnxhCth0hLkb97zV3rxJ6ojk/c4glqq aVoDtxRiEQyVEwJ7sbQHkGsxL1EeJT48+A9/E= 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:mime-version:content-transfer-encoding; bh=ZHaDFBTgtxPyauUYIbe2xZhoBPmdz9uZMKjIbwpkzlE=; b=NcYRDhSWEaqwKYP5gpsevbH0s0pEHhnYOs8eUrWH4GagnV3r1q/BVRuCE3FnLh7e6Q qoN3td1TuqtSnFdald8B7gbBsAE4fIpy5eViVeuRQIXNQRDcWGVAUNH1bpkGQY5eEv+a aKvCSTUtzEA0rucVoYtJp6di+xJ05hYdOwEOFEKpHc2BOsegzQsJ9Rn8W6Y4DjhInUS7 T+VZN9ipwsvlsrfV0kAg9L9FYGtwF40ICh7EilbYCzcwdNT61VvCyi9jyfT2TYmU8W8y UxrX9EosnD9+F9jEarHMYeHRCX6+UfU2iRVqvoPKHLOkwLrsoQ/R3rqwJYpeoBoP0pai Dppg== X-Gm-Message-State: AA+aEWaN6nxAR2/aU0RsExYRTGQVWpUExWR7fvFy+oTnqDK/k/l5d6xP uU4HHeTkJ38Lc8b6U2j8Q3uvJP/Z0VY= X-Received: by 2002:a19:d90c:: with SMTP id q12mr11733088lfg.24.1544634765524; Wed, 12 Dec 2018 09:12:45 -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.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 12 Dec 2018 09:12:44 -0800 (PST) From: Ruslan Trofymenko To: u-boot@lists.denx.de Date: Wed, 12 Dec 2018 19:12:34 +0200 Message-Id: <1544634754-3435-8-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> MIME-Version: 1.0 Cc: Tom Rini , Praneeth Bajjuri , Alistair Strachan Subject: [U-Boot] [PATCH v2 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: , 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 'ab_select' command) 2. Extend 'emmc_android_boot' boot command (add commands for A/B boot process) '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_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 Reviewed-by: Alistair Strachan Reviewed-by: Sam Protsenko Reviewed-by: Simon Glass Reviewed-by: Igor Opaniuk --- Changes in v2: * Сhanges related to command renaming (android_ab_select -> ab_select) * Slotted sections (e.g. system_a and system_b) are added to the default sections if CONFIG_CMD_AB_SELECT flag is defined * Rebased on top of master * system partitions sizes increased to 1024 MiB (to be consistent with recent changes to boot.h file) include/environment/ti/boot.h | 58 ++++++++++++++++++++++++++++++++++++++----- 1 file changed, 52 insertions(+), 6 deletions(-) diff --git a/include/environment/ti/boot.h b/include/environment/ti/boot.h index 5891009..e3ba689 100644 --- a/include/environment/ti/boot.h +++ b/include/environment/ti/boot.h @@ -23,6 +23,18 @@ #define VBMETA_PART "" #endif +#if defined(CONFIG_CMD_AB_SELECT) +#define COMMON_PARTS \ + "name=boot_a,size=10M,uuid=${uuid_gpt_boot_a};" \ + "name=boot_b,size=10M,uuid=${uuid_gpt_boot_b};" \ + "name=system_a,size=1024M,uuid=${uuid_gpt_system_a};" \ + "name=system_b,size=1024M,uuid=${uuid_gpt_system_b};" +#else +#define COMMON_PARTS \ + "name=boot,size=10M,uuid=${uuid_gpt_boot};" \ + "name=system,size=1024M,uuid=${uuid_gpt_system};" +#endif + #ifndef PARTS_DEFAULT /* Define the default GPT table for eMMC */ #define PARTS_DEFAULT \ @@ -40,8 +52,7 @@ "name=efs,size=16M,uuid=${uuid_gpt_efs};" \ "name=crypto,size=16K,uuid=${uuid_gpt_crypto};" \ "name=recovery,size=40M,uuid=${uuid_gpt_recovery};" \ - "name=boot,size=10M,uuid=${uuid_gpt_boot};" \ - "name=system,size=768M,uuid=${uuid_gpt_system};" \ + COMMON_PARTS \ "name=vendor,size=256M,uuid=${uuid_gpt_vendor};" \ "name=cache,size=256M,uuid=${uuid_gpt_cache};" \ "name=ipu1,size=1M,uuid=${uuid_gpt_ipu1};" \ @@ -63,6 +74,35 @@ #define AVB_VERIFY_CMD "" #endif +#define CONTROL_PARTITION "misc" + +#if defined(CONFIG_CMD_AB_SELECT) +#define AB_SELECT \ + "if part number mmc 1 " CONTROL_PARTITION " control_part_number; " \ + "then " \ + "echo " CONTROL_PARTITION \ + " partition number:${control_part_number};" \ + "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 +131,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