All of lore.kernel.org
 help / color / mirror / Atom feed
* Basic syntax question
@ 2020-04-08  8:27 Damien LEFEVRE
  2020-04-08 12:51 ` Harald Seiler
  0 siblings, 1 reply; 2+ messages in thread
From: Damien LEFEVRE @ 2020-04-08  8:27 UTC (permalink / raw)
  To: u-boot

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Basic syntax question
  2020-04-08  8:27 Basic syntax question Damien LEFEVRE
@ 2020-04-08 12:51 ` Harald Seiler
  0 siblings, 0 replies; 2+ messages in thread
From: Harald Seiler @ 2020-04-08 12:51 UTC (permalink / raw)
  To: u-boot

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!
-- 
Harald

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-04-08 12:51 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-08  8:27 Basic syntax question Damien LEFEVRE
2020-04-08 12:51 ` Harald Seiler

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.