Hello All,
I want to add a validation rule to a custom variable I'm defining in the u-boot environment. Let's call it foo, and the only values foo should accept are null or ttyLP0,115200.
My u-boot environment is protected, so only specific variables are whitelisted. foo will be whitelisted.
I was able to achieve this for fw_setenv by creating patch for libubootenv under src/fw_printenv.c for the Linux user-space:
root@localhost:~# fw_setenv foo woof Error: invalid value for "foo": woof root@localhost:~#
root@localhost:~# fw_setenv foo null root@localhost:~# fw_printenv | grep foo foo=null
Now, I'm trying to figure out how to do this for u-boot-imx setenv. I looked into the cmd/nvedit.c function env_set and applied the same logic, but that did not work. Am I in the right place for setenv, or is there different code for setenv?
Any help will be highly appreciated.
Cheers,
Solved! Go to Solution.
I was able to find the right function and patch it through with my validation rule. Correct function was _do_end_set in cmd/nvedit.c.
Autoboot in 3 seconds
=> setenv current_console woof
## Error: invalid value for "current_console": woof
=> setenv current_console null
=> printenv current_console
current_console=null
Thank you for your support.
Hello,
You must saveenv the variables, but please check this page>
https://docs.u-boot.org/en/latest/usage/environment.html
https://community.nxp.com/t5/i-MX-Processors/U-boot-Environment-Variables-Source-Code/m-p/974719
Regards
Thank you for the feedback and the links.
Maybe I was not clear enough, but what I'm looking for is the C-code implementation of setenv so I can add my validation rule.
So when a user executes from the u-boot prompt:
=> setenv foo 'woof'
It should reject it with an error. It should only accept null or ttyLP0,115200 as input values, or it should reset the value back to its original state. Similar to environment variables serial# and ethaddr, which you cannot reset. You can setenv and saveenv, but on the next reset, it will set back to its original value.
As I explained in my first post, I did add the code in cmd/nvedit.c function env_set, but I'm not sure if this is the right function for setenv or if there is another function call.
I hope I have made my request clearer now. What I'm trying to achieve is a way to enforce validation rules directly within the setenv function in the u-boot code.
Thank you for your assistance.
I was able to find the right function and patch it through with my validation rule. Correct function was _do_end_set in cmd/nvedit.c.
Autoboot in 3 seconds
=> setenv current_console woof
## Error: invalid value for "current_console": woof
=> setenv current_console null
=> printenv current_console
current_console=null
Thank you for your support.
Correct function was _do_env_set