
Hi all,
trying to follow Wolfgang Denk's suggestion in http://lists.denx.de/pipermail/u-boot/2011-September/102118.html:
I agree that it makes sense to generalize and clean up this interface. It makes sense to select individual variables, and it makes sense to unify the "-f" handling to enforce actions on protected variables (while without "-f" only actions on the "normal" variables should be done).
I can even imagine introducing a new variable that contains the name of the write-protected variables (and probably other properties, like being excluded from saveenv, etc.) - this has been discussed a number of times before, now we have the code base in place to actually implement it.
All we need to do is extend the struct entry (in "include/search.h") by an "int flags"), and we can there register properties like read-only, don't-save etc. In a first step this could be added transparently - so we could remove all the special handling of "ethaddr", "serial#" etc. in common/cmd_nvedit.c; then we could unify this to include "eth1addr" etc as well; then we could extend it to read the names of such variables and their properties from a variable, etc.
here I am proposing a set of changes in the behaviour of the environment import/set_to_default functions.
Since a PATCH-er is worth a thousand words, I decided to take the risk and implement it first so to get your feedback on code rather than words...
======= PATCH 1 ======= The most shocking change lies in the "new" himport_ex() function, which has 3 new arguments:
1-2) "nvars", "vars", number and list of variables to take into account (0 means ALL)
3) "apply" callback function which is in charge of checking whether a variable can be overwritten, and possibly immediately apply the changes. This parameter would be either set to NULL (in which case nothing should change wrt to the past -- i.e. environment is blindly imported) or to "env_check_apply()" function, whose code was taken away from _do_env_set(). This would be useful, for instance, for "baudrate" or "stdin,stderr,stdout", whose changes would not otherwise be effective until the next reboot.
The idea is that there should be a single place where all the checks are to be performed. So the same function env_check_apply() is called from _do_env_set() as well (thus keeping the previous behavior).
I know we're talking about heavy changes here... this is a just a draft -- I would just like some feedback about the whole idea, before putting more time into it.
======= PATCH 2 ======= Here I added the same behaviour when deleting variables. Not quite sure whether this makes sense or not.
======= PATCH 3 ======= Here I added the code for setting to default individual variables
======= PATCH 4 ======= Here I implemented the code for importing individual variables (and also taking into account "-f" for forcing).
Thank you for your patience, Gerlando Falauto
Gerlando Falauto (4): Groundwork for generalization of env interface env: check and apply changes on delete/destroy env: implement selective "env default" env: implement "env import -n var[,var...]"
README | 2 + common/cmd_nvedit.c | 221 +++++++++++++++++++++++++++++++-------------- common/env_common.c | 28 ++++++- include/config_cmd_all.h | 1 + include/environment.h | 7 ++ include/search.h | 19 ++++- lib/hashtable.c | 67 +++++++++++++-- 7 files changed, 266 insertions(+), 79 deletions(-)