问题
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