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 4486DC433F5 for ; Thu, 30 Dec 2021 14:50:45 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 5D56782F73; Thu, 30 Dec 2021 15:50:43 +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="EU7+D7VR"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 0350583063; Thu, 30 Dec 2021 15:50:41 +0100 (CET) Received: from m12-11.163.com (m12-11.163.com [220.181.12.11]) by phobos.denx.de (Postfix) with ESMTP id 6584182F73 for ; Thu, 30 Dec 2021 15:50:36 +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=XYynH35yevJyp9/wln 0i5AO/oqazw0WqV3pFViIH7oo=; b=EU7+D7VRYv/XBdr5w634JYo0Axc9WmCURK r/KQnP4ZYeWemO07ZuaK/K9lpgLTSW/a1H/IK70GPObxezq3dq22chSXbOFOLJvw wHkdyj42ZtNVi15PCMSPsOUBv/lKyeg4wAYVryJnCLnCKscmG0cNmAx5Z70IsDRh 9RNl7zqXc= Received: from localhost.localdomain (unknown [183.220.92.149]) by smtp7 (Coremail) with SMTP id C8CowABXPB0yx81hfSTzNQ--.30337S2; Thu, 30 Dec 2021 22:50:28 +0800 (CST) From: hyyxohk To: u-boot@lists.denx.de, joe.hershberger@ni.com Cc: wd@denx.de Subject: [PATCH v1 1/1] env: fat: Allow overriding interface, device and partition Date: Thu, 30 Dec 2021 22:50:26 +0800 Message-Id: <20211230145026.5592-1-hyyoxhk@163.com> X-Mailer: git-send-email 2.17.1 X-CM-TRANSID: C8CowABXPB0yx81hfSTzNQ--.30337S2 X-Coremail-Antispam: 1Uf129KBjvJXoWxGF4xXrWUAryDJr15tF13urg_yoWrAr4UpF 43Gr98G393Xr13A39Iv3WDCrn8Kwn5C34rGr12kw18C3WfGF4UXr1kt39Fv3Wj9a40qrWr AFWvqF4Fkr1DXaUanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07UZNV9UUUUU= X-Originating-IP: [183.220.92.149] X-CM-SenderInfo: pk1105lkn6il2tof0z/1tbiHhR50lSIy24w6AAAsA X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.38 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 | 30 +++++++++++++++++------------- include/env_internal.h | 20 ++++++++++++++++++++ 2 files changed, 37 insertions(+), 13 deletions(-) diff --git a/env/fat.c b/env/fat.c index 9d37d26f9e..fdd875034b 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,13 +65,14 @@ 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(), + 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... ", - CONFIG_ENV_FAT_INTERFACE, dev, part); + printf("Unable to use %s %d:%d... ", 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... ", - file, CONFIG_ENV_FAT_INTERFACE, dev, part); + printf("Unable to write \"%s\" from %s%d:%d... ", file, ifname, dev, part); return 1; } @@ -117,14 +121,15 @@ 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(), + 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... ", - CONFIG_ENV_FAT_INTERFACE, dev, part); + printf("Unable to use %s %d:%d... ", 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... ", - 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_ */ -- 2.17.1