From patchwork Wed Apr 14 18:51:43 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rasmus Villemoes X-Patchwork-Id: 1466388 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=prevas.dk header.i=@prevas.dk header.a=rsa-sha256 header.s=selector1 header.b=j3Ma4Cdd; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FLBRr3Fvxz9sW1 for ; Thu, 15 Apr 2021 04:52:40 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id C91D081EB0; Wed, 14 Apr 2021 20:52:17 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=reject dis=none) header.from=prevas.dk Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=prevas.dk header.i=@prevas.dk header.b="j3Ma4Cdd"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 7E4F281E5A; Wed, 14 Apr 2021 20:52:08 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FORGED_SPF_HELO,MSGID_FROM_MTA_HEADER, SPF_HELO_PASS autolearn=no autolearn_force=no version=3.4.2 Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05on20722.outbound.protection.outlook.com [IPv6:2a01:111:f400:7d00::722]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 471E681E09 for ; Wed, 14 Apr 2021 20:51:55 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=reject dis=none) header.from=prevas.dk Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=rasmus.villemoes@prevas.dk ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=muNPbPlwwHaTPvdqs8HAcymQxwOZ3zrhxhJikpWspoZ2NtJ4ExTze9vTMJNtRMpyI266mBC/q81U34ANLJvDupkEqXrrUZMdUXO0yWkl2yNmQTK55ZCm2sfW9XryWr0j71wtYoKe9ueuV1UJ7IpY7vcnFtBsjttAeo+XWTtIouq3dwoljTWS98xs54KvoVoENG0GlQSuR26E8h8sYaEIn0teHso8ylb+oG692TrdAOzqgPMXsS7fUV+u8U8cyL3UhYhfvRdQMxQ9W7VEGVH+YgA5pRHCAG6a9QcTdwKlTJ/ZaLA1QAqmzBOBiTHZUgWCo7NrsZR1PB0lJuzFa7a/1g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=xxIMpAUzaT+DNcufNoAj1QYA0ZGUVBK6UNGRk0DTF6A=; b=ic2Jb5pYK/ZVeBjFsB8Epx8mU7AW87c71sELRgAlJVAK0PRRshGZSSNGahmymeT3vqtUejY9b6MNBbt8l/fSSN3F9rqEbJMKn8OeljuhdxRoGu4ai+eoqMiDWz6c+5SnHhHJlLxbxNdERfAncQa78iSAlFJmkKHLkkjqv46AkcKxuH6W56G7OpNqp+/s59hd/WLcaqR3uSChqc3oJeGRVU1hfRhBvCiONLFE6cwauRS4bLk+wdNKT/qgPfh+qrJ+dP4fSWx8CsQBlDbFLaqScl274/svHqXws7hRcw74f5Gc0QEjy/B8RxLGORi+JagvJkEODWMLhAwVoDoYRSd7yA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=prevas.dk; dmarc=pass action=none header.from=prevas.dk; dkim=pass header.d=prevas.dk; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=prevas.dk; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=xxIMpAUzaT+DNcufNoAj1QYA0ZGUVBK6UNGRk0DTF6A=; b=j3Ma4CddYnCsDTvzjt5IEAHvIny+liH3BQ6uLxQXKHzsIfJ5/tnVp8hx2YYsn06D/dMMS4GLCti5Tuqj+tW+nJNIc39COJpN5KalBsVc0HSqFnEbbZQUG/tJb32fAD6jQxXl4t+sUjrqUlq9gY97AuaYfz8301Pn4CDgs1BVpFc= Authentication-Results: lists.denx.de; dkim=none (message not signed) header.d=none;lists.denx.de; dmarc=none action=none header.from=prevas.dk; Received: from AM0PR10MB1874.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:208:3f::10) by AM0PR10MB2626.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:208:131::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.22; Wed, 14 Apr 2021 18:51:53 +0000 Received: from AM0PR10MB1874.EURPRD10.PROD.OUTLOOK.COM ([fe80::edba:45:89f8:b31f]) by AM0PR10MB1874.EURPRD10.PROD.OUTLOOK.COM ([fe80::edba:45:89f8:b31f%7]) with mapi id 15.20.4020.023; Wed, 14 Apr 2021 18:51:53 +0000 From: Rasmus Villemoes To: u-boot@lists.denx.de Cc: Joe Hershberger , Wolfgang Denk , Tom Rini , Heiko Schocher , Rasmus Villemoes Subject: [PATCH resend 2/2] env: add CONFIG_ENV_SECT_SIZE_AUTO Date: Wed, 14 Apr 2021 20:51:43 +0200 Message-Id: <20210414185143.4148401-3-rasmus.villemoes@prevas.dk> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210414185143.4148401-1-rasmus.villemoes@prevas.dk> References: <20210414185143.4148401-1-rasmus.villemoes@prevas.dk> X-Originating-IP: [80.208.71.248] X-ClientProxiedBy: AM6P193CA0127.EURP193.PROD.OUTLOOK.COM (2603:10a6:209:85::32) To AM0PR10MB1874.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:208:3f::10) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from prevas-ravi.prevas.se (80.208.71.248) by AM6P193CA0127.EURP193.PROD.OUTLOOK.COM (2603:10a6:209:85::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4042.16 via Frontend Transport; Wed, 14 Apr 2021 18:51:53 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 13c8a699-d655-47c2-e01e-08d8ff765ee5 X-MS-TrafficTypeDiagnostic: AM0PR10MB2626: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:2399; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: HGoDOqq4iYvQr+wcJvzx2E74Vlcrt9hWC+78ieCTr0y/r3JJ4OkOPp7oh+clAKt2V58yPCxe+7m9ZtW8kKAnjjCyPZQEnfzVQm1swmLYSSAiLioMMemew28bwZZpyAxCeZ+7Fe0OMrPU+XHljkCBf4dPnn+6aZOTNiw6ovxyqtlTx4ZTqTqPKkr+IktadCwfXiUayliw1JepajaM1gFi6HgqLgn/fxaRuWgwWa6VCRRnAE7nQqHeFNR5Y4ti7Dkmqy6AsQ8kkMbRaNaXIAxiTR59oBLwe4Top4Xhw6EdsJ9LA6cmRn+n1yuHxH6213U7cu9RDpNx/5B0s58nvBpT63LorJVjiWMAQU/UFhITShlnlGywV3Es3E4t/hmOqYY00eCJ4ttKzkkvpJv93eemYJqGNeduM58Pm3kijS2kl0n7Nz/2VVjDpl8Iu54oEQU+GABVA0+dLfd0WXpoqWJ7nC7Qrot7huZ2R8Nx/XpZ5IUHxkV/sFbEE13gwvPDSSvM8/YtWfDTuiD/zNquz8jZsDk74914XcPGjTGkqvFA9jnSEtqN+sru0UNzBdOJqcMAtkIXUBBoEqL/Wa45QOq1e8UnTavgQms7N6HX92KB/3lC2jaO1HmGgXuOJSMSVu9UgddmUanwHG10jbT7nw7LkBJ8IRfmKy7hPLSiN8AiIf8= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM0PR10MB1874.EURPRD10.PROD.OUTLOOK.COM; PTR:; CAT:NONE; SFS:(366004)(346002)(376002)(396003)(136003)(39830400003)(36756003)(52116002)(478600001)(38100700002)(2906002)(4326008)(8676002)(6506007)(5660300002)(16526019)(38350700002)(6486002)(186003)(8976002)(83380400001)(44832011)(26005)(66476007)(1076003)(86362001)(66946007)(2616005)(956004)(6512007)(6916009)(107886003)(316002)(8936002)(6666004)(66556008)(54906003); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData: Kni7JIbixLiiRy454QekbQIKbe4twP0H19s//XL5nri4Q26x4a7criKdl78/QE+OenqgZpx57chHAqmJKMeVWjNDHRQ6q2NnnlwZaP3GM0AKdfwAksqURd4n4nwK3sttAxrxWwu26bVkyLND52BaYwEe7sRIWwc3fYfDnGslmuK3D26eDzsL6SdAK5pm2ZUx2PdgB0EiyN1j5FfR2lEfyyJnBjEN+OiDIYwEtVCAW2EEzJ/8w1eQCnE6EUX9TTfS1nuGbXGJp1AcMjz9xFQxZPS9t2BYOzeyjQoy+Dqk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evas.dk X-MS-Exchange-CrossTenant-Network-Message-Id: 13c8a699-d655-47c2-e01e-08d8ff765ee5 X-MS-Exchange-CrossTenant-AuthSource: AM0PR10MB1874.EURPRD10.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Apr 2021 18:51:53.7481 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: d350cf71-778d-4780-88f5-071a4cb1ed61 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 7sRtuNwiwO2KnmWmS7MwZTNa/5uM4C1i2SxabtKDM7zETUUAxRj3NlBCcqt6EkNNo3epjay3w8SSrCm9NoioQBLYymhFZoLlk032YnHe6Pc= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR10MB2626 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 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.102.4 at phobos.denx.de X-Virus-Status: Clean This is roughly the U-Boot side equivalent to commit e282c422e0 (tools: fw_env: use erasesize from MEMGETINFO ioctl). The motivation is the case where one has a board with several revisions, where the SPI flashes have different erase sizes. In our case, we have an 8K environment, and the flashes have erase sizes of 4K (newer boards) and 64K (older boards). Currently, we must set CONFIG_ENV_SECT_SIZE to 64K to make the code work on the older boards, but for the newer ones, that ends up wasting quite a bit of time reading/erasing/restoring the last 56K. At first, I wanted to allow setting CONFIG_ENV_SECT_SIZE to 0 to mean "use the erase size the chip reports", but that config option is used in a number of preprocessor conditionals, and shared between ENV_IS_IN_FLASH and ENV_IS_IN_SPI_FLASH. So instead, introduce a new boolean config option, which for now can only be used with ENV_IS_IN_SPI_FLASH. If left off, there's no change in behaviour. The only slightly annoying detail is that, when selected, the compiler is apparently not smart enough to see that the the saved_size and saved_offset variables are only used under the same "if (sect_size > CONFIG_ENV_SIZE)" condition as where they are computed, so we need to initialize them to 0 to avoid "may be used uninitialized" warnings. On our newer boards with the 4K erase size, saving the environment now takes 0.080 seconds instead of 0.53 seconds, which directly translates to that much faster boot time since our logic always causes the environment to be written during boot. Signed-off-by: Rasmus Villemoes --- env/Kconfig | 14 ++++++++++++++ env/sf.c | 10 ++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/env/Kconfig b/env/Kconfig index b473d7cfe1..844c312870 100644 --- a/env/Kconfig +++ b/env/Kconfig @@ -324,6 +324,20 @@ config ENV_IS_IN_SPI_FLASH during a "saveenv" operation. CONFIG_ENV_OFFSET_REDUND must be aligned to an erase sector boundary. +config ENV_SECT_SIZE_AUTO + bool "Use automatically detected sector size" + depends on ENV_IS_IN_SPI_FLASH + help + Some boards exist in multiple variants, with different + flashes having different sector sizes. In such cases, you + can select this option to make U-Boot use the actual sector + size when figuring out how much to erase, which can thus be + more efficient on the flashes with smaller erase size. Since + the environment must always be aligned on a sector boundary, + CONFIG_ENV_OFFSET must be aligned to the largest of the + different sector sizes, and CONFIG_ENV_SECT_SIZE should be + set to that value. + config USE_ENV_SPI_BUS bool "SPI flash bus for environment" depends on ENV_IS_IN_SPI_FLASH diff --git a/env/sf.c b/env/sf.c index d9ed08a78e..06cc62e005 100644 --- a/env/sf.c +++ b/env/sf.c @@ -72,7 +72,7 @@ static int env_sf_save(void) { env_t env_new; char *saved_buffer = NULL, flag = ENV_REDUND_OBSOLETE; - u32 saved_size, saved_offset, sector; + u32 saved_size = 0, saved_offset = 0, sector; u32 sect_size = CONFIG_ENV_SECT_SIZE; int ret; @@ -80,6 +80,9 @@ static int env_sf_save(void) if (ret) return ret; + if (IS_ENABLED(CONFIG_ENV_SECT_SIZE_AUTO)) + sect_size = env_flash->mtd.erasesize; + ret = env_export(&env_new); if (ret) return -EIO; @@ -187,7 +190,7 @@ out: #else static int env_sf_save(void) { - u32 saved_size, saved_offset, sector; + u32 saved_size = 0, saved_offset = 0, sector; u32 sect_size = CONFIG_ENV_SECT_SIZE; char *saved_buffer = NULL; int ret = 1; @@ -197,6 +200,9 @@ static int env_sf_save(void) if (ret) return ret; + if (IS_ENABLED(CONFIG_ENV_SECT_SIZE_AUTO)) + sect_size = env_flash->mtd.erasesize; + /* Is the sector larger than the env (i.e. embedded) */ if (sect_size > CONFIG_ENV_SIZE) { saved_size = sect_size - CONFIG_ENV_SIZE;