[U-Boot] where *precisely* is u-boot's environment stored?
Robert P. J. Day
rpjday at crashcourse.ca
Wed Jul 6 11:38:58 CEST 2016
kind of embarrassed that i don't know the answer to this but, short
form of question, when i build a u-boot.bin and copy it to NOR flash
on my target board, where is the environment stored such that user
space fw_printenv and fw_setenv utilities can get at them?
longer form of question: i just used yocto project to build for my
MPC8315E-RDB target board, and one of the artifacts generated was
"u-boot.bin", apparently ready for copying to NOR flash on this board,
NOR flash being at 0xfe000000. i poked around trying to figure out
where the environment was stored in that image, and i found the
following in include/env_default.h:
... snip ...
const uchar default_environment[] = {
#endif
#ifdef CONFIG_ENV_CALLBACK_LIST_DEFAULT
ENV_CALLBACK_VAR "=" CONFIG_ENV_CALLBACK_LIST_DEFAULT "\0"
#endif
#ifdef CONFIG_ENV_FLAGS_LIST_DEFAULT
ENV_FLAGS_VAR "=" CONFIG_ENV_FLAGS_LIST_DEFAULT "\0"
#endif
#ifdef CONFIG_BOOTARGS
"bootargs=" CONFIG_BOOTARGS "\0"
#endif
#ifdef CONFIG_BOOTCOMMAND
"bootcmd=" CONFIG_BOOTCOMMAND "\0"
#endif
... etc etc ...
i then checked u-boot.sym and found:
fe04c920 g O .text 00000389 default_environment
and if i "hexdump -C" the "u-boot.bin" file, sure enough, there it is,
the apparent beginning of the default environment at 0x0004c920:
0004c900 8d ef 02 2d 25 2e 2a 73 00 00 00 00 25 73 25 64 |...-%.*s....%s%d|
0004c910 2c 25 64 00 70 61 72 74 69 74 69 6f 6e 00 00 00 |,%d.partition...|
0004c920 62 6f 6f 74 63 6d 64 3d 73 65 74 65 6e 76 20 62 |bootcmd=setenv b|
0004c930 6f 6f 74 61 72 67 73 20 72 6f 6f 74 3d 2f 64 65 |ootargs root=/de|
0004c940 76 2f 6e 66 73 20 72 77 20 6e 66 73 72 6f 6f 74 |v/nfs rw nfsroot|
0004c950 3d 24 73 65 72 76 65 72 69 70 3a 24 72 6f 6f 74 |=$serverip:$root|
... and on and on ...
so AFAICT, the default_environment[] ends up in the executable (and,
consequently, in flash) i'm assuming based on wherever the linker
places it based on the "u-boot.lds" file, correct?
however, if i look at the defn file for this target board,
include/configs/MPC8315ERDB.h, i can see the various config settings
defining where the environment resides, things like
CONFIG_ENV_IS_IN_FLASH, CONFIG_ENV_ADDR and so on:
#if !defined(CONFIG_SYS_RAMBOOT)
#define CONFIG_ENV_IS_IN_FLASH 1
#define CONFIG_ENV_ADDR \
(CONFIG_SYS_MONITOR_BASE + CONFIG_SYS_MONITOR_LEN)
#define CONFIG_ENV_SECT_SIZE 0x10000 /* 64K(one sector) for env */
#define CONFIG_ENV_SIZE 0x2000
and if i build the package u-boot-fw-utils to get the user space
utilities "fw_printenv" and "fw_setenv", that package needs to be told
where the environment is stored, and that's based on what it gets from
the board's header file, which in this case defines:
#define CONFIG_SYS_MONITOR_LEN (384 * 1024) /* Reserve 384 kB for Mon */
which represents an env offset of 0x00060000 into flash.
so what is the correlation between those two addresses? there's the
actual address of default_environment[] based on where the linker puts
it (0xfe04c920), as opposed to where fw-utils will (apparently) look
for the environment (0xfe060000). what's the connection here?
rday
--
========================================================================
Robert P. J. Day Ottawa, Ontario, CANADA
http://crashcourse.ca
Twitter: http://twitter.com/rpjday
LinkedIn: http://ca.linkedin.com/in/rpjday
========================================================================
More information about the U-Boot
mailing list