Add validation to u-boot cmd setenv

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

Add validation to u-boot cmd setenv

ソリューションへジャンプ
827件の閲覧回数
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, 

タグ(2)
0 件の賞賛
返信
1 解決策
794件の閲覧回数
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.

元の投稿で解決策を見る

4 返答(返信)
802件の閲覧回数
Bio_TICFSL
NXP TechSupport
NXP TechSupport
0 件の賞賛
返信
799件の閲覧回数
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 件の賞賛
返信
795件の閲覧回数
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.

791件の閲覧回数
pilotnite
Contributor III

Correct function was _do_env_set

0 件の賞賛
返信