diff mbox series

[v1,1/1] env: fat: Allow overriding interface, device and partition

Message ID 20211230145026.5592-1-hyyoxhk@163.com
State Superseded
Delegated to: Tom Rini
Headers show
Series [v1,1/1] env: fat: Allow overriding interface, device and partition | expand

Commit Message

He Yong Dec. 30, 2021, 2:50 p.m. UTC
For platform which can boot on different device, this allows
to override interface, device and partition from board code.

Signed-off-by: hyyxohk <hyyoxhk@163.com>
---
 env/fat.c              | 30 +++++++++++++++++-------------
 include/env_internal.h | 20 ++++++++++++++++++++
 2 files changed, 37 insertions(+), 13 deletions(-)

Comments

Simon Glass Jan. 27, 2022, 3:05 p.m. UTC | #1
Hi,

On Thu, 30 Dec 2021 at 07:50, hyyxohk <hyyoxhk@163.com> wrote:
>
> For platform which can boot on different device, this allows
> to override interface, device and partition from board code.
>
> Signed-off-by: hyyxohk <hyyoxhk@163.com>
> ---
>  env/fat.c              | 30 +++++++++++++++++-------------
>  include/env_internal.h | 20 ++++++++++++++++++++
>  2 files changed, 37 insertions(+), 13 deletions(-)
>

What is this feature used for?

Regards,
Simon
[..]
He Yong Jan. 29, 2022, 8:26 a.m. UTC | #2
Hi:
Override the env_fat_get_dev_part function in the board file, you can 
load env from sdcard or emmc without modifying any configuration 
of u-boot, it is very useful for  building wic firmware by yocto. 


it has been done under env/ext4.c

















At 2022-01-27 23:05:57, "Simon Glass" <sjg@chromium.org> wrote:
>Hi,
>
>On Thu, 30 Dec 2021 at 07:50, hyyxohk <hyyoxhk@163.com> wrote:
>>
>> For platform which can boot on different device, this allows
>> to override interface, device and partition from board code.
>>
>> Signed-off-by: hyyxohk <hyyoxhk@163.com>
>> ---
>>  env/fat.c              | 30 +++++++++++++++++-------------
>>  include/env_internal.h | 20 ++++++++++++++++++++
>>  2 files changed, 37 insertions(+), 13 deletions(-)
>>
>
>What is this feature used for?
>
>Regards,
>Simon
>[..]
Simon Glass Feb. 11, 2022, 3:05 p.m. UTC | #3
Hi,

On Sat, 29 Jan 2022 at 01:26, 何勇 <hyyoxhk@163.com> wrote:
>
> Hi:
> Override the env_fat_get_dev_part function in the board file, you can
> load env from sdcard or emmc without modifying any configuration
> of u-boot, it is very useful for  building wic firmware by yocto.
>
> it has been done under env/ext4.c

I cannot see it. Can you please point me to the line number in that file?

Do you have an English-text name you could use for the patch?

Regards,
Simon


>
>
>
>
>
>
>
> At 2022-01-27 23:05:57, "Simon Glass" <sjg@chromium.org> wrote:
> >Hi,
> >
> >On Thu, 30 Dec 2021 at 07:50, hyyxohk <hyyoxhk@163.com> wrote:
> >>
> >> For platform which can boot on different device, this allows
> >> to override interface, device and partition from board code.
> >>
> >> Signed-off-by: hyyxohk <hyyoxhk@163.com>
> >> ---
> >>  env/fat.c              | 30 +++++++++++++++++-------------
> >>  include/env_internal.h | 20 ++++++++++++++++++++
> >>  2 files changed, 37 insertions(+), 13 deletions(-)
> >>
> >
> >What is this feature used for?
> >
> >Regards,
> >Simon
> >[..]
He Yong Feb. 17, 2022, 3:16 p.m. UTC | #4
sorry i just saw the email

I have reworked the patch for v3 based on u-boot mainline

















At 2022-02-11 23:05:47, "Simon Glass" <sjg@chromium.org> wrote:
>Hi,
>
>On Sat, 29 Jan 2022 at 01:26, 何勇 <hyyoxhk@163.com> wrote:
>>
>> Hi:
>> Override the env_fat_get_dev_part function in the board file, you can
>> load env from sdcard or emmc without modifying any configuration
>> of u-boot, it is very useful for  building wic firmware by yocto.
>>
>> it has been done under env/ext4.c
>
>I cannot see it. Can you please point me to the line number in that file?
>
>Do you have an English-text name you could use for the patch?
>
>Regards,
>Simon
>
>
>>
>>
>>
>>
>>
>>
>>
>> At 2022-01-27 23:05:57, "Simon Glass" <sjg@chromium.org> wrote:
>> >Hi,
>> >
>> >On Thu, 30 Dec 2021 at 07:50, hyyxohk <hyyoxhk@163.com> wrote:
>> >>
>> >> For platform which can boot on different device, this allows
>> >> to override interface, device and partition from board code.
>> >>
>> >> Signed-off-by: hyyxohk <hyyoxhk@163.com>
>> >> ---
>> >>  env/fat.c              | 30 +++++++++++++++++-------------
>> >>  include/env_internal.h | 20 ++++++++++++++++++++
>> >>  2 files changed, 37 insertions(+), 13 deletions(-)
>> >>
>> >
>> >What is this feature used for?
>> >
>> >Regards,
>> >Simon
>> >[..]
diff mbox series

Patch

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_ */