15

I am working with an embedded linux kit that is running u-boot. In order to get everything booting properly, I had to modify some environment variables and store them with the 'saveenv' command.

Now I would like to go back and see what the defaults were, verify that I know exactly what was changed, and figure out a way to change those defaults so that each unit in production won't need to be individually booted and modified.

Is there a way to tell u-boot to clear any saved data so I can see what the defaults are again? The flash type is QSPI if that makes a difference.

KyleL
  • 1,379
  • 2
  • 13
  • 35
  • 2
    The U-Boot environment area is validated with a 32-bit CRC, so if you clobber it, just a byte will do, in the nonvolatile storage, then U-Boot will revert to its default settings on startup. – sawdust Dec 18 '13 at 20:45

4 Answers4

29

On your kit, try

help env

and look for "env default".

env default [-f] var [...] - [forcibly] reset variable(s) to their default values

That sounds like what you are looking for.

env default -a

does a nonpersistent change, then "printenv" shows the defaults.

To change defaults, you would rebuild your u-boot.bin with changes e.g. to CONFIG_EXTRA_ENV_SETTINGS.

Joe Kul
  • 2,454
  • 16
  • 16
  • I found the configuration in ./u-boot/include/configs/board-vendor.h.template. However, in that section for CONFIG_EXTRA_ENV_SETTINGS, I see things like: "loadaddr=@nstart@\0" Do you know where that 'nstart' and other similar variables are set? I'd rather not just replace them with a number if there's a better way. – KyleL Dec 17 '13 at 13:36
  • Current u-boot does not seem to have board-vendor.h, and I don't recognize variable syntax @nstart, sorry. – Joe Kul Dec 17 '13 at 18:14
  • It must be something specific to my kit (Avnet Zedboard using Xilinx Petalinux). Thanks for the help! – KyleL Dec 17 '13 at 18:55
6

To use default vars without removing them from flash execute

env default -a

within u-boot and then execute $bootcmd. Joe Kul's solution.

To erase the vars from the SPI flash execute

run eraseenv

within u-boot and then reboot.

Joshua
  • 1,185
  • 14
  • 23
  • Note that `run eraseenv`, more specifically `eraseenv`, has to be defined first. It is not an out of the box command. https://www.denx.de/wiki/publish/DULG/to-delete/UBootCmdGroupEnvironment.html – Catalin Apr 05 '21 at 14:59
  • 1
    @Catalin Ok, the Zynq development environment from Xilinx has it be defined and I don't know how far back up the food chain it goes. – Joshua Apr 06 '21 at 17:10
2

The eraseenv is not defined in my case. According to @Joshua's answer, I find the following command does what eraseenv does.

env default -a
saveenv
Iceberg
  • 2,744
  • 19
  • 19
  • Hello @Iceberg, when I do `env default -a` from linux userspace I get the error as `env: 'default': No such file or directory`. please let me know how to use this command. – Preeti Jan 25 '22 at 15:29
  • @Preeti I believe I executed these commands in the console of u-boot instead of the command line of linux. – Iceberg Jan 25 '22 at 15:31
  • may be I am confused here. My board is completely booted up and linux user space is loaded(for example I can execute `fw_printenv`) but `env default -a` is showing error. Do I need to enable this in my config file like `include/configs/stm32mp1.h`? – Preeti Jan 25 '22 at 15:35
  • No, the `env default -a` command cannot be run from within linux. The linux `env` command is entirely unrelated to u-boot. As far as I can tell there is no easy way to reset the u-boot environment from within linux. I think you could probably do it by using `dd` to clear out the appropriate storage, which would cause u-boot to revert to the compiled-in default environment (but I have not tried this) – David Robertson Jan 25 '22 at 20:42
1
# add uboot env variable
setenv my_var 1

# printenv my_var
my_var=1

# remove/unset uboot env variable
setenv my_var

# printenv my_var
## Error: "my_var" not defined
bguiz
  • 27,371
  • 47
  • 154
  • 243
mattes
  • 11
  • 1