public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Hector Palacios <hector.palacios@digi.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] Protected variable 'ethaddr' can be reset to default value (or deleted)
Date: Wed, 28 May 2014 12:28:57 +0200	[thread overview]
Message-ID: <5385BA69.2050000@digi.com> (raw)

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

                 reply	other threads:[~2014-05-28 10:28 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5385BA69.2050000@digi.com \
    --to=hector.palacios@digi.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox