问题描述
我想在U-Boot的if语句中使用命令'gpio input'的返回,但是它似乎不起作用。
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 :
但是无论GPIO是高电平还是低电平,它总是返回1。
But it always return 1 whether the GPIO is high or low.
我也试图通过使用setenv命令将gpio status命令的结果存储到变量中,但是它也不起作用。
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:我已经在U-boot源代码中修改了gpio.c文件,因此该命令仅返回 0或 1而不是 gpio:引脚50(gpio 50)的值为1',但我认为这无关紧要。只是规定,否则 -eq 1是没有意义的。
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 ?
预先感谢!
推荐答案
命令的返回值可以在环境变量$?中找到,例如
The return value of a command can be found in environment variable $?, e.g.
gpio input 50; echo $?
如果存在if语句,则在编译U-Boot时取决于配置。使用CONFIG_HUSH_PARSER = y启用它。启用后,如果gpio输入102,您可以编写
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
这篇关于如何在U-Boot CLI中测试命令的返回的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!