
Hi,
I'm new to u-boot. I'm trying to store the return value of gpio command to a variable.
I have the following, (switch released): Tegra186 (P2771-0000-500) # gpio input FF1 gpio: pin FF1 (gpio 241) value is 1 Tegra186 (P2771-0000-500) # setexpr X 'gpio input FF1' Tegra186 (P2771-0000-500) # echo $X 0
But I'm expecting X to be 1, the return value of gpio.
If I press the switch I see the value change to 0, so I know the gpio state changes Tegra186 (P2771-0000-500) # gpio input FF1 gpio: pin FF1 (gpio 241) value is 0
Thanks, -Damien

Hello Damien,
On Wed, 2020-04-08 at 11:27 +0300, Damien LEFEVRE wrote:
Hi,
I'm new to u-boot. I'm trying to store the return value of gpio command to a variable.
I have the following, (switch released): Tegra186 (P2771-0000-500) # gpio input FF1 gpio: pin FF1 (gpio 241) value is 1 Tegra186 (P2771-0000-500) # setexpr X 'gpio input FF1' Tegra186 (P2771-0000-500) # echo $X 0
But I'm expecting X to be 1, the return value of gpio.
What you want to do is look at the return value of the gpio command. The return value in U-Boot is stored in a variable $?, similar to POSIX shells. As this variable is always the return value of the last command, you have to save its value immediately after running `gpio input`:
=> gpio input FF1 => setenv X $?
Afterwards, you can continue however you like, e.g.
=> echo $X
If I press the switch I see the value change to 0, so I know the gpio state changes Tegra186 (P2771-0000-500) # gpio input FF1 gpio: pin FF1 (gpio 241) value is 0
Thanks, -Damien
Hope this helps!
participants (2)
-
Damien LEFEVRE
-
Harald Seiler