Add validation to u-boot cmd setenv

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Add validation to u-boot cmd setenv

Jump to solution
668 Views
pilotnite
Contributor III

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, 

Tags (2)
0 Kudos
Reply
1 Solution
635 Views
pilotnite
Contributor III

@Bio_TICFSL 

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.

View solution in original post

4 Replies
643 Views
Bio_TICFSL
NXP TechSupport
NXP TechSupport
0 Kudos
Reply
640 Views
pilotnite
Contributor III

@Bio_TICFSL 

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.

 

0 Kudos
Reply
636 Views
pilotnite
Contributor III

@Bio_TICFSL 

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.

632 Views
pilotnite
Contributor III

Correct function was _do_env_set

0 Kudos
Reply