U-Boot Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v4 1/1] env: fat: Allow overriding interface, device and partition
@ 2022-02-17 16:07 He Yong
  2022-04-08 12:31 ` Tom Rini
  0 siblings, 1 reply; 2+ messages in thread
From: He Yong @ 2022-02-17 16:07 UTC (permalink / raw)
  To: u-boot, sjg; +Cc: joe.hershberger, wd

For platform which can boot on different device, this allows
to override interface, device and partition from board code

Signed-off-by: He Yong <hyyoxhk@163.com>
---
 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 07c227ecc0..b704c03363 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


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v4 1/1] env: fat: Allow overriding interface, device and partition
  2022-02-17 16:07 [PATCH v4 1/1] env: fat: Allow overriding interface, device and partition He Yong
@ 2022-04-08 12:31 ` Tom Rini
  0 siblings, 0 replies; 2+ messages in thread
From: Tom Rini @ 2022-04-08 12:31 UTC (permalink / raw)
  To: He Yong; +Cc: u-boot, sjg, joe.hershberger, wd

[-- Attachment #1: Type: text/plain, Size: 284 bytes --]

On Fri, Feb 18, 2022 at 12:07:25AM +0800, He Yong wrote:

> For platform which can boot on different device, this allows
> to override interface, device and partition from board code
> 
> Signed-off-by: He Yong <hyyoxhk@163.com>

Applied to u-boot/master, thanks!

-- 
Tom

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 659 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-04-08 12:31 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-02-17 16:07 [PATCH v4 1/1] env: fat: Allow overriding interface, device and partition He Yong
2022-04-08 12:31 ` Tom Rini

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox