GPIO handling in uboot


I am working with a vf61 and wanted to set the GPIO at boot time by uboot.

What I can do is setting, clearing, toogling of the gpios in uboot. However, saving Information to Flash does not work as expected. I used the example shown here:

How can I save the gpio startup setting to the Environment?

Thanks and best regards - Tom


Colibri VFxx # version

U-Boot 2015.04+fslc+gb66337d (Dec 30 2015 - 16:11:51)
arm-angstrom-linux-gnueabi-gcc (Linaro GCC 4.9-2015.03) 4.9.3 20150311
GNU ld (GNU Binutils) Linaro 2015.01-2 2.25.0

The article you are refering is for E-Boot bootloader and is not applicable for U-Boot bootloader.
To handle GPIOs in U-Boot one need to use ‘gpio’ command, for more information refer this article.
To set the GPIO during startup in U-Boot one could add a script to set the IO.

# setenv set-io 'gpio set <gpio-number>'
# setenv bootcmd 'run set-io; run ubiboot; run sdboot'
# saveenv


Configure the GPIO directly from board file’s board init method.


diff --git i/board/toradex/colibri_vf/colibri_vf.c w/board/toradex/colibri_vf/colibri_vf.c
index 3272733..ca30af8 100644
--- i/board/toradex/colibri_vf/colibri_vf.c
+++ w/board/toradex/colibri_vf/colibri_vf.c
@@ -478,6 +483,11 @@ int board_init(void)
        setbits_le32(&scsc->sosc_ctr, SCSC_SOSC_CTR_SOSC_EN);
+       gpio_request(53, "test-gpio");
+       gpio_direction_output(53, 1);


thanks for you explanation. I setup the bootloader and try to changed some gpio pins in board_init(), but it does not change anything:

gpio_request(10, "stop");
gpio_direction_output(10, 0); /* 1 would not work either */

I may have missed something? Is GPIO 10 not eqivalent to the 10 here? or is it configured somewhere else later?

I checked with GPIO 10 at my end, it worked as expected.
At which SODIMM pin are you checking? GPIO 10 is available at SODIMM_23.

On uboot start I can do something like

gpio clear 10
gpio set 10

and my relay (that is connected to this pin) is release/set. So I think, the connection is correct in general!?

To show my way i go:

  • load toradex bootloader git respoitory

  • setting oe crosscompile environment by

    source /usr/local/oecore-x86_64/environment-setup-armv7at2hf-vfp-neon-angstrom-linux-gnueabi

  • configure bootloader code by

make colibri_vf_defconfig

  • edit the file

gedit ./board/toradex/colibri_vf/colibri_vf.c

  • compile uboot

  • copy uboot to SDcard

  • do on the boards uboot boot promt a

    run setupdate

    run update_uboot


    env default -a


Is this correct so far?

Looks good to me. May be also you could add a debug printf along with the gpio code you added. To eable the debug messages define ‘DEBUG’ on top of the board file.

Yes, if it is connected to SODIMM_23 it will work as expected.

How would I do enabling DEBUG. Is it a simple #define DEBUG? I trieds some places without success.

I am still not sure, if the bootloader really changed (even with the steps below). Is there a way to see this?

When I startup uboot, I see a message U-Boot 2015.04… with a date from december. Is it the Build time or the git branch time?

Yes it’s a #define, instead you can use printf directly. Check/compare the ver output from U-Boot
prompt. The binary one need to update is u-boot-nand.imx