From patchwork Mon Jan 17 15:03:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: He Yong X-Patchwork-Id: 1580821 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=163.com header.i=@163.com header.a=rsa-sha256 header.s=s110527 header.b=FQiyhlTR; dkim-atps=neutral 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=) 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 bilbo.ozlabs.org (Postfix) with ESMTPS id 4JcwCM0xq3z9ssD for ; Tue, 18 Jan 2022 02:03:41 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id A789C82C6D; Mon, 17 Jan 2022 16:03:32 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=163.com 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=163.com header.i=@163.com header.b="FQiyhlTR"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 0ED9E83037; Mon, 17 Jan 2022 16:03:30 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.2 Received: from m12-16.163.com (m12-16.163.com [220.181.12.16]) by phobos.denx.de (Postfix) with ESMTP id 1E27480F9E for ; Mon, 17 Jan 2022 16:03:19 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=163.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=hyyoxhk@163.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id; bh=FIOxcveXMYE2jvQebK EKCzR7SSRym2UkQizorImD9SI=; b=FQiyhlTRGRDkcMteuYU7tknnDuuY8xMyFq fgKCdXzTYtEUFV/6OUXDe2N4N3K1XoQigcOABX61H7DYDCg+7OPorLQIS4Glk5mA GzlOZx0dFmt1rD4M74rDRUJ2u4y19HUKOGx1ow1In7qoN3ZMazhhnl6BWLvRo/6t EPUOjzFVA= Received: from localhost.localdomain (unknown [183.220.91.230]) by smtp12 (Coremail) with SMTP id EMCowADH_eYxheVhN4_DAg--.48694S2; Mon, 17 Jan 2022 23:03:13 +0800 (CST) From: hyyxohk To: u-boot@lists.denx.de, joe.hershberger@ni.com, wd@denx.de Subject: [PATCH v2 1/1] env: fat: Allow overriding interface, device and partition Date: Mon, 17 Jan 2022 23:03:13 +0800 Message-Id: <20220117150313.5320-1-hyyoxhk@163.com> X-Mailer: git-send-email 2.17.1 X-CM-TRANSID: EMCowADH_eYxheVhN4_DAg--.48694S2 X-Coremail-Antispam: 1Uf129KBjvJXoWxGF4xXryfXrW5Cw1rKr1ftFb_yoWrAFWUpF sxGr98K393Xw13A39Iv3WUGrn8Kwn5C34rGr12kw18CF1rGF4UXr1kt39Fv3Wj9a40grWr ZFWvqa1Fkr1DXaUanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07UCJmUUUUUU= X-Originating-IP: [183.220.91.230] X-CM-SenderInfo: pk1105lkn6il2tof0z/1tbiVhKL0lqzn8j4xQAAse 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.2 at phobos.denx.de X-Virus-Status: Clean For platform which can boot on different device, this allows to override interface, device and partition from board code. Signed-off-by: hyyxohk --- env/fat.c | 34 +++++++++++++++++++--------------- include/env_internal.h | 20 ++++++++++++++++++++ 2 files changed, 39 insertions(+), 15 deletions(-) diff --git a/env/fat.c b/env/fat.c index fdccd6cd2a..6251d9649b 100644 --- a/env/fat.c +++ b/env/fat.c @@ -32,7 +32,12 @@ DECLARE_GLOBAL_DATA_PTR; -static char *env_fat_device_and_part(void) +__weak const char *env_fat_get_intf(void) +{ + return (const char *)CONFIG_ENV_FAT_INTERFACE; +} + +__weak char *env_fat_get_dev_part(void) { #ifdef CONFIG_MMC static char *part_str; @@ -60,14 +65,15 @@ static int env_fat_save(void) int dev, part; int err; loff_t size; + const char *ifname = env_fat_get_intf(); + const char *dev_and_part = env_fat_get_dev_part(); err = env_export(&env_new); if (err) return err; - part = blk_get_device_part_str(CONFIG_ENV_FAT_INTERFACE, - env_fat_device_and_part(), - &dev_desc, &info, 1); + part = blk_get_device_part_str(ifname, dev_and_part, + &dev_desc, &info, 1); if (part < 0) return 1; @@ -77,8 +83,7 @@ static int env_fat_save(void) * This printf is embedded in the messages from env_save that * will calling it. The missing \n is intentional. */ - printf("Unable to use %s %d:%d... \n", - CONFIG_ENV_FAT_INTERFACE, dev, part); + printf("Unable to use %s %d:%d...\n", ifname, dev, part); return 1; } @@ -93,8 +98,7 @@ static int env_fat_save(void) * This printf is embedded in the messages from env_save that * will calling it. The missing \n is intentional. */ - printf("Unable to write \"%s\" from %s%d:%d... \n", - file, CONFIG_ENV_FAT_INTERFACE, dev, part); + printf("Unable to write \"%s\" from %s%d:%d...\n", file, ifname, dev, part); return 1; } @@ -117,15 +121,16 @@ static int env_fat_load(void) struct disk_partition info; int dev, part; int err1; + const char *ifname = env_fat_get_intf(); + const char *dev_and_part = env_fat_get_dev_part(); #ifdef CONFIG_MMC - if (!strcmp(CONFIG_ENV_FAT_INTERFACE, "mmc")) + if (!strcmp(ifname, "mmc")) mmc_initialize(NULL); #endif - part = blk_get_device_part_str(CONFIG_ENV_FAT_INTERFACE, - env_fat_device_and_part(), - &dev_desc, &info, 1); + part = blk_get_device_part_str(ifname, dev_and_part, + &dev_desc, &info, 1); if (part < 0) goto err_env_relocate; @@ -135,8 +140,7 @@ static int env_fat_load(void) * This printf is embedded in the messages from env_save that * will calling it. The missing \n is intentional. */ - printf("Unable to use %s %d:%d... \n", - CONFIG_ENV_FAT_INTERFACE, dev, part); + printf("Unable to use %s %d:%d...\n", ifname, dev, part); goto err_env_relocate; } @@ -154,7 +158,7 @@ static int env_fat_load(void) * will calling it. The missing \n is intentional. */ printf("Unable to read \"%s\" from %s%d:%d... \n", - CONFIG_ENV_FAT_FILE, CONFIG_ENV_FAT_INTERFACE, dev, part); + CONFIG_ENV_FAT_FILE, ifname, dev, part); goto err_env_relocate; } diff --git a/include/env_internal.h b/include/env_internal.h index 174c3b1a79..e42ae826ef 100644 --- a/include/env_internal.h +++ b/include/env_internal.h @@ -245,6 +245,26 @@ const char *env_ext4_get_dev_part(void); * @return an enum env_location value on success, or -ve error code. */ enum env_location env_get_location(enum env_operation op, int prio); + +/** + * env_fat_get_intf() - Provide the interface for env in FAT + * + * It is a weak function allowing board to overidde the default interface for + * U-Boot env in FAT: CONFIG_ENV_FAT_INTERFACE + * + * @return string of interface, empty if not supported + */ +const char *env_fat_get_intf(void); + +/** + * env_fat_get_dev_part() - Provide the device and partition for env in FAT + * + * It is a weak function allowing board to overidde the default device and + * partition used for U-Boot env in FAT: CONFIG_ENV_FAT_DEVICE_AND_PART + * + * @return string of device and partition + */ +char *env_fat_get_dev_part(void) #endif /* DO_DEPS_ONLY */ #endif /* _ENV_INTERNAL_H_ */