Patchwork [U-Boot,2/2] am335x_evm: Add CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG support

login
register
mail settings
Submitter Tom Rini
Date Oct. 24, 2012, 5:28 p.m.
Message ID <1351099697-8786-3-git-send-email-trini@ti.com>
Download mbox | patch
Permalink /patch/193874/
State Accepted
Delegated to: Tom Rini
Headers show

Comments

Tom Rini - Oct. 24, 2012, 5:28 p.m.
We add CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG, CONFIG_BOARD_LATE_INIT to
set the variables and then fdtfile and findfdt to make us of this.  It
is now possible to do 'run findfdt' to have fdtfile be set to the value
of the dtb file to load for the board we are running on.

Signed-off-by: Tom Rini <trini@ti.com>
---
 arch/arm/cpu/armv7/am33xx/board.c |   20 ++++++++++++++++++++
 include/configs/am335x_evm.h      |   10 ++++++++++
 2 files changed, 30 insertions(+)
Stephen Warren - Oct. 24, 2012, 7:21 p.m.
On 10/24/2012 11:28 AM, Tom Rini wrote:
> We add CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG, CONFIG_BOARD_LATE_INIT to
> set the variables and then fdtfile and findfdt to make us of this.  It
> is now possible to do 'run findfdt' to have fdtfile be set to the value
> of the dtb file to load for the board we are running on.

> diff --git a/arch/arm/cpu/armv7/am33xx/board.c b/arch/arm/cpu/armv7/am33xx/board.c

> +#ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
> +	char safe_string[HDR_NAME_LEN + 1];
> +
> +	/* Now set variables based on the header. */
> +	strncpy(safe_string, (char *)header.name, sizeof(header.name));
> +	safe_string[sizeof(header.name)] = 0;
> +	setenv("board_name", safe_string);
> +
> +	strncpy(safe_string, (char *)header.version, sizeof(header.version));
> +	safe_string[sizeof(header.version)] = 0;
> +	setenv("board_rev", safe_string);
> +#endif

By the way, is there any way to flag these variables as not being saved
in the environment by saveenv? With the code above, the values will get
over-written every time, so it's not such a big deal; the only issue is
that the value needlessly gets saved into flash or uEnv.txt.

But what about a runtime-calculated variable that is only sometimes set?
I suppose the answer there is to explicitly clear it if you aren't
setting it.

Or what about if the environment gets saved to uEnv.txt on an SD card
which gets moved to a compatible but different board or board revision,
running an older U-Boot that doesn't have this patch; then, the values
stick around even though they're stale.
Tom Rini - Oct. 24, 2012, 8:56 p.m.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 10/24/12 12:21, Stephen Warren wrote:
> On 10/24/2012 11:28 AM, Tom Rini wrote:
>> We add CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG, 
>> CONFIG_BOARD_LATE_INIT to set the variables and then fdtfile and
>>  findfdt to make us of this.  It is now possible to do 'run 
>> findfdt' to have fdtfile be set to the value of the dtb file to 
>> load for the board we are running on.
> 
>> diff --git a/arch/arm/cpu/armv7/am33xx/board.c 
>> b/arch/arm/cpu/armv7/am33xx/board.c
> 
>> +#ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG +	char 
>> safe_string[HDR_NAME_LEN + 1]; + +	/* Now set variables based on
>>  the header. */ +	strncpy(safe_string, (char *)header.name, 
>> sizeof(header.name)); +	safe_string[sizeof(header.name)] = 0; + 
>> setenv("board_name", safe_string); + +	strncpy(safe_string, (char
>> *)header.version, sizeof(header.version)); + 
>> safe_string[sizeof(header.version)] = 0; +	setenv("board_rev", 
>> safe_string); +#endif
> 
> By the way, is there any way to flag these variables as not being 
> saved in the environment by saveenv? With the code above, the 
> values will get over-written every time, so it's not such a big 
> deal; the only issue is that the value needlessly gets saved into 
> flash or uEnv.txt.
> 
> But what about a runtime-calculated variable that is only sometimes
> set? I suppose the answer there is to explicitly clear it if you
> aren't setting it.

Joe?  Am I thinking right that your env work leads us down the path of
being able to do this?

> Or what about if the environment gets saved to uEnv.txt on an SD 
> card which gets moved to a compatible but different board or board
>  revision, running an older U-Boot that doesn't have this patch; 
> then, the values stick around even though they're stale.

Yes, there's potential problems, but I think we can work around it or
live with it.  And FYI, uEnv.txt is (more or less) an un-mkimage'd
boot.scr file :)

- -- 
Tom
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://www.enigmail.net/

iQIcBAEBAgAGBQJQiFYXAAoJENk4IS6UOR1WyIMP/iGYC6j001RpBgV3zn3AgAvG
5h+2f9C/LgSrEiuH2FarginkbOqyRR1fn/GYbwK/hK3+UMyPU7bY2m++VJ1RobQ8
j8A4HGHxBh/afrpkly/TtgXjJeK5NPxB7AH0mu0UBsBAFg7b64dVjVc1ZUuwkqBO
zddoFhLOvpUAuBOPiVZLBUREdgGs23pG7HO7yfyEbdUsZv6U09zlY/FQR06JgANu
2AjUZ932oH54448qmXdX2ePdX8zpWeXmsHwEDWX8kgJbGiUSe2oQbBc/u27/g1KS
LiJKfh9YaJV8EYkeF+i/CDwWNI81ykuHsSOem/AsXNhk3/r2Ua54WB3oUXHEZji1
h6J+3wxF1pS/9r5/FzHsKaeR5GCGXDDEDONlDuJb4PB0ZCuDfzGmsAOBxtA/0GiU
U6S3Cxwk7ajmXdtbVpZ+kzIemsqHbJd2wXKR2UDPa7fNqiTDa0XLfvWuwx6PdAmJ
aZoz344padFBdv/qVmF8657pUMaPW8A4YuTFmf1sj2QD3BtA5ATbMKD2Wu5RXbjY
feb/BxbZihfnCSA3RoyDCZC7Bh/OHz9v2lK6aSBQR1Jh+4ozmn6njla5iNVKcLuX
SbRyjJk1kmaAOUcdhDV6py9I+Fs8CmGFynBSCSkY+8nIiCzVl8587z8bcAOp6lHn
Fq0Kcoybbkp2lhyqAUG0
=sttt
-----END PGP SIGNATURE-----

Patch

diff --git a/arch/arm/cpu/armv7/am33xx/board.c b/arch/arm/cpu/armv7/am33xx/board.c
index 978b184..a138848 100644
--- a/arch/arm/cpu/armv7/am33xx/board.c
+++ b/arch/arm/cpu/armv7/am33xx/board.c
@@ -223,6 +223,26 @@  int board_init(void)
 	return 0;
 }
 
+#ifdef CONFIG_BOARD_LATE_INIT
+int board_late_init(void)
+{
+#ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
+	char safe_string[HDR_NAME_LEN + 1];
+
+	/* Now set variables based on the header. */
+	strncpy(safe_string, (char *)header.name, sizeof(header.name));
+	safe_string[sizeof(header.name)] = 0;
+	setenv("board_name", safe_string);
+
+	strncpy(safe_string, (char *)header.version, sizeof(header.version));
+	safe_string[sizeof(header.version)] = 0;
+	setenv("board_rev", safe_string);
+#endif
+
+	return 0;
+}
+#endif
+
 #ifdef CONFIG_DRIVER_TI_CPSW
 static void cpsw_control(int enabled)
 {
diff --git a/include/configs/am335x_evm.h b/include/configs/am335x_evm.h
index 339d4bd..3adf548 100644
--- a/include/configs/am335x_evm.h
+++ b/include/configs/am335x_evm.h
@@ -29,6 +29,7 @@ 
 #define CONFIG_SYS_LONGHELP		/* undef to save memory */
 #define CONFIG_SYS_HUSH_PARSER		/* use "hush" command parser */
 #define CONFIG_SYS_PROMPT		"U-Boot# "
+#define CONFIG_BOARD_LATE_INIT
 #define CONFIG_SYS_NO_FLASH
 #define MACH_TYPE_TIAM335EVM		3589	/* Until the next sync */
 #define CONFIG_MACH_TYPE		MACH_TYPE_TIAM335EVM
@@ -46,11 +47,13 @@ 
 
 /* set to negative value for no autoboot */
 #define CONFIG_BOOTDELAY		1
+#define CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
 #define CONFIG_EXTRA_ENV_SETTINGS \
 	"loadaddr=0x80200000\0" \
 	"fdtaddr=0x80F80000\0" \
 	"rdaddr=0x81000000\0" \
 	"bootfile=/boot/uImage\0" \
+	"fdtfile=\0" \
 	"console=ttyO0,115200n8\0" \
 	"optargs=\0" \
 	"mmcdev=0\0" \
@@ -79,6 +82,13 @@ 
 	"ramboot=echo Booting from ramdisk ...; " \
 		"run ramargs; " \
 		"bootm ${loadaddr}\0" \
+	"findfdt="\
+		"if test $board_name = A335BONE; then " \
+			"setenv fdtfile am335x-bone.dtb; fi; " \
+		"if test $board_name = A33515BB; then " \
+			"setenv fdtfile am335x-evm.dtb; fi; " \
+		"if test $board_name = A335X_SK; then " \
+			"setenv fdtfile am335x-evmsk.dtb; fi\0" \
 
 #define CONFIG_BOOTCOMMAND \
 	"if mmc rescan ${mmcdev}; then " \