[U-Boot] Protected variable 'ethaddr' can be reset to default value (or deleted)

Hector Palacios hector.palacios at digi.com
Wed May 28 12:28:57 CEST 2014


Hello,

I have enabled environment flags and have protected "ethaddr" variable in write-once 
mode: "ethaddr:mo".

As expected, once set, I cannot overwrite this variable with standard setenv command.
Also as expected, I can overwrite it at any time by passing the -f (forced) option to 
setenv:
	setenv -f ethaddr XX:XX:XX:XX:XX:XX

The 'env default' command is supposed to reset the environment to the default values. 
Its help is:

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

So I expect that 'env default ethaddr' does not change the value of 'ethaddr' (which 
actually occurs) because the variable is protected, but that adding the -f option does 
change the value to the default (which doesn't occur). In other words:

   env default ethaddr		Does not change 'ethaddr' (OK)
   env default -f ethaddr	Does not change 'ethaddr' (Problem #1)

Similarly, I was also expecting that 'env default -a', which resets the whole 
environment to its default values, does not modify protected 'ethaddr' (like it 
happens when you specify the variable) and that 'env default -f -a' resets it. 
However, both commands do reset the protected variables. In other words:

   env default -a		Changes/deletes 'ethaddr' (Problem #2)
   env default -f -a		Changes/deletes 'ethaddr' (OK)

Actually the '-f' option, despite being in the help text is not taken into 
consideration at the 'default' subcommand. This can easily be checked in function 
do_env_default() in common/cmd_nvedit.c, where the local variable 'flag' is not 
propagated anywhere in the function.

I can easily fix Problem #1 by propagating local variable 'flag' in do_env_default() 
to set_default_vars().

Problem #2 is more difficult because U-Boot is creating a new env table from scratch, 
disregarding previous existing entries, and calling env_flags_validate() in 
'env_op_create' mode, which only checks for ENV_FLAGS_VARACCESS_PREVENT_CREATE permission.
Any ideas on how to properly fix this?

Best regards,
--
Hector Palacios


More information about the U-Boot mailing list