From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id BA3BDEB64DA for ; Sat, 24 Jun 2023 21:42:05 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id BDD1185CB1; Sat, 24 Jun 2023 23:42:01 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="mNdiGslL"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id A486485D4E; Sat, 24 Jun 2023 23:41:59 +0200 (CEST) Received: from mail-vs1-xe29.google.com (mail-vs1-xe29.google.com [IPv6:2607:f8b0:4864:20::e29]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id D8E0085C5A for ; Sat, 24 Jun 2023 23:41:56 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=jpewhacker@gmail.com Received: by mail-vs1-xe29.google.com with SMTP id ada2fe7eead31-440cff7870aso2231789137.1 for ; Sat, 24 Jun 2023 14:41:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1687642915; x=1690234915; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=yWk7fl3piYt4Ikrm1yVbQAvQ2KmPoTnm0DQr4vZW58w=; b=mNdiGslL7vhqr37hQ1r6Q+UtIfXPwiWXxKvrTmOEtytN6UvVmJYutZsVSrLsHCtohl VOT0qIksupu24efswr7coa/ml5PzUmeZtRTHvWcLlNatZzOKZLQKplHzaZ1qRB0jHvWE 8XeKiTWb6NdVN7ZtQwlVznh0imhQ3p3FtWyxVfTPHNLzLggKzCu/o++Us7+Ku0dBnqMA gx5HQtaG2P0WPwSEbJqc8W65KqruJED9F0TbAJib/Buo/kuo+2VhXmYyJD6Sy5NTGMo8 9JSw67DrBEmE99/xOUFmtJRjZPeSa3lZNAVFgWQsNrS4Gt67D6PE4Zh6B5aPg9K6P/Rp chBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687642915; x=1690234915; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=yWk7fl3piYt4Ikrm1yVbQAvQ2KmPoTnm0DQr4vZW58w=; b=V9/Z8QDqYQwSSZJDLLH1zet2Y7c3rCsflOE9YL4cEfTql6W6NrKKOsxUVhD/FTJUrf x2MoWCauTYU45qxdJGyz+jdkaZGMgFyPcOsXwa08PYLGNcwTtHKkE803PuWJTQZMW6GG B0a2iFJ+LxEsGPO9H8gcpfTT0kW50Mui/2lVOrO/CJdw7ceoCkCiXcpi2SvMJk5dBzG1 KLLpXOGEr7igmznTYZh6bjT5zfzPTR0ZORiA4QIUZLuEkklNPY7gzh39ukEQb3D8YTQb gsyeWubPizhUDBn6Nd+SMx7EP4SOalifCM08DHA2mz1lmVUJVlmMrQMqK1bCyPQljDRe M7oA== X-Gm-Message-State: AC+VfDzQhFm1XAy3XOM9tkRIBu9D7evq9OgpWMn9xczape6Qq2Y9xc+Q jlj6OvSkZUfy+iqvFhN0bJLT8M6iu4M= X-Google-Smtp-Source: ACHHUZ5KUcz4ybJm9GFtRZbNXTiIQZkZKr5pzlrQlZq2dRky8ROKgwpXMGZu0GLrSb+mjjAqpTrN5Q== X-Received: by 2002:a9d:77c9:0:b0:6b0:e442:f127 with SMTP id w9-20020a9d77c9000000b006b0e442f127mr11637799otl.12.1687557962816; Fri, 23 Jun 2023 15:06:02 -0700 (PDT) Received: from localhost.localdomain ([204.77.163.107]) by smtp.gmail.com with ESMTPSA id w8-20020a9d6748000000b006b72af9278bsm245739otm.17.2023.06.23.15.06.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Jun 2023 15:06:02 -0700 (PDT) From: Joshua Watt X-Google-Original-From: Joshua Watt To: u-boot@lists.denx.de Cc: Joshua Watt , Igor Opaniuk , Sam Protsenko Subject: [PATCH] android_ab: Add option to skip decrementing tries Date: Fri, 23 Jun 2023 17:05:48 -0500 Message-Id: <20230623220556.2864681-1-JPEWhacker@gmail.com> X-Mailer: git-send-email 2.33.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 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" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean It is is sometimes desired to be able to skip decrementing the number of tries remaining in an Android A/B boot, and instead just check which slot will be tried later. This can commonly be be the case for platforms that want to A/B u-boot itself, but are required to boot from a FAT MBR partition. In these cases, u-boot must do an early check that the MBR points to the correct A/B boot partition, and if not rewrite the MBR to point to the correct one and reboot. Decrementing the try count in this case is not desired because it means that each u-boot might constantly ping-pong overwriting the MBR and rebooting until all the retries are used up. Signed-off-by: Joshua Watt --- boot/android_ab.c | 9 ++++++--- cmd/ab_select.c | 20 ++++++++++++++++---- include/android_ab.h | 3 ++- 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/boot/android_ab.c b/boot/android_ab.c index 2d7b392666..60ae002978 100644 --- a/boot/android_ab.c +++ b/boot/android_ab.c @@ -181,7 +181,8 @@ static int ab_compare_slots(const struct slot_metadata *a, return 0; } -int ab_select_slot(struct blk_desc *dev_desc, struct disk_partition *part_info) +int ab_select_slot(struct blk_desc *dev_desc, struct disk_partition *part_info, + bool dec_tries) { struct bootloader_control *abc = NULL; u32 crc32_le; @@ -272,8 +273,10 @@ int ab_select_slot(struct blk_desc *dev_desc, struct disk_partition *part_info) log_err("ANDROID: Attempting slot %c, tries remaining %d\n", BOOT_SLOT_NAME(slot), abc->slot_info[slot].tries_remaining); - abc->slot_info[slot].tries_remaining--; - store_needed = true; + if (dec_tries) { + abc->slot_info[slot].tries_remaining--; + store_needed = true; + } } if (slot >= 0) { diff --git a/cmd/ab_select.c b/cmd/ab_select.c index 3e46663d6e..bfb67b8236 100644 --- a/cmd/ab_select.c +++ b/cmd/ab_select.c @@ -16,10 +16,19 @@ static int do_ab_select(struct cmd_tbl *cmdtp, int flag, int argc, struct blk_desc *dev_desc; struct disk_partition part_info; char slot[2]; + bool dec_tries = true; - if (argc != 4) + if (argc < 4) return CMD_RET_USAGE; + for (int i = 4; i < argc; i++) { + if (strcmp(argv[i], "--no-dec") == 0) { + dec_tries = false; + } else { + 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, @@ -27,7 +36,8 @@ static int do_ab_select(struct cmd_tbl *cmdtp, int flag, int argc, return CMD_RET_FAILURE; } - ret = ab_select_slot(dev_desc, &part_info); + + ret = ab_select_slot(dev_desc, &part_info, dec_tries); if (ret < 0) { printf("Android boot failed, error %d.\n", ret); return CMD_RET_FAILURE; @@ -41,9 +51,9 @@ static int do_ab_select(struct cmd_tbl *cmdtp, int flag, int argc, return CMD_RET_SUCCESS; } -U_BOOT_CMD(ab_select, 4, 0, do_ab_select, +U_BOOT_CMD(ab_select, 5, 0, do_ab_select, "Select the slot used to boot from and register the boot attempt.", - " \n" + " [--no-dec]\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" @@ -53,4 +63,6 @@ U_BOOT_CMD(ab_select, 4, 0, do_ab_select, " - 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" + " - If '--no-dec' is set, the number of tries remaining will not\n" + " decremented for the selected boot slot\n" ); diff --git a/include/android_ab.h b/include/android_ab.h index 3eb61125c6..1fee7582b9 100644 --- a/include/android_ab.h +++ b/include/android_ab.h @@ -30,6 +30,7 @@ struct disk_partition; * @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, struct disk_partition *part_info); +int ab_select_slot(struct blk_desc *dev_desc, struct disk_partition *part_info, + bool dec_tries); #endif /* __ANDROID_AB_H */ -- 2.33.0