How to test the return of a command in U-Boot CLI

只谈情不闲聊 提交于 2020-03-05 05:09:25

问题


I would like to use the return of the command 'gpio input' in an if statement in U-Boot but it doesn't seem to work.

So I've tried something like :

if test {gpio status 50} -eq 1; then echo 1; else echo 0; fi;

But it always return 1 whether the GPIO is high or low.

I also tried to store the result of the gpio status command into a variable by using the setenv command but it doesn't work either.

PS: I've modified the gpio.c file in the U-boot source code so the command returns just '0' or '1' instead of 'gpio: pin 50 (gpio 50) value is 1' but I think it doesn't matter. Just precising since otherwise the '-eq 1' makes no sense.

Do you have any idea of how I could proceed to do this ?

Thanks in advance !


回答1:


The return value of a command can be found in environment variable $?, e.g.

gpio input 50; echo $?

If an if statement exists depends on the configuration when compiling U-Boot. Use CONFIG_HUSH_PARSER=y to enable it. When enabled you can write

if gpio input 102; then setenv board_name revA ; else setenv board_name revB;fi


来源:https://stackoverflow.com/questions/55381641/how-to-test-the-return-of-a-command-in-u-boot-cli

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!