How to set General Purpose Input/Output (GPIO) during the execution of U-Boot on BeagleBone Black
By: George Calin
Tags: Gpio, Yoctoproject, Embedded Training, Embedded Linux, Embedded

Why is important to set the General Purpose Input/Output as early as possible?

Depending on your embedded board (embedded boards have by definition limited resources), accessing the U-Boot gets your things done several seconds in advance. Just before loading the Linux Kernel, and long before loading the Root File System.

For an example, during the start up of my BeagleBone Black, I am getting the desired result 5 seconds earlier, by enabling the GPIOs at U-Boot time, than doing the same thing with methods within Root File System. My little benchmark “app” concerns lighting up a LED connected to the BeaglebBone Black through its expansion slots.

That was all about the introductory concepts, I shall guide you through understanding the practical solution.

Set GPIO at U-Boot Time with BeagleBone Black

Connect USB-To-serial TTL cable to the BeagleBone Black

Mount USB-to-serial TTL controller

Next, I am going to walk you through connecting and setting up the serial connection to the BeagleBone Black to be able to communicate your commands and “read its feedback”.

Boot BeagleBone Black and get into the U-boot command prompt

By default the RBL(ROM bootloader) of BeagleBone Black boots from the internal eMMC. Only when holding down the boot button (“USER 2” button), it will search for a bootloader on the SD card.

Thus, press USER 2 button of BeagleBone Black after powering it up to choose the U-Boot version stored on the micro SD Card.

The following is an example of a U-Boot sequence log and warning messages in case you do not press the boot button. It applies to my BeagleBone Black configuration (which U-Boot version exists there, etc).

Although it is likely yours is not going to look 100% similarly, I am placing it here because what you are going to get will be structured the same:

U-Boot 2018.09-00002-g0b54a51eee (Sep 10 2018 - 19:41:39 -0500), Build: jenkins-github_Bootloader-Builder-65



CPU : AM335X-GP rev 2.1

I2C: ready

DRAM: 512 MiB

No match for driver 'omap_hsmmc'

No match for driver 'omap_hsmmc'

Some drivers were not found

Reset Source: Power-on reset has occurred.

RTC 32KCLK Source: External.

MMC: OMAP SD/MMC: 0, OMAP SD/MMC: 1



Loading Environment from EXT4...

** Unable to use mmc 0:1 for loading the env **



Board: BeagleBone Black

<ethaddr> not set. Validating first E-fuse MAC

BeagleBone Black:

BeagleBone: cape eeprom: i2c_probe: 0x54:

BeagleBone: cape eeprom: i2c_probe: 0x55:

BeagleBone: cape eeprom: i2c_probe: 0x56:

BeagleBone: cape eeprom: i2c_probe: 0x57:

Net: eth0: MII MODE

cpsw, usb_ether

Press SPACE to abort autoboot in 2 seconds

This is the U-Boot sequence log and warning messages in case you press the boot button:

U-Boot SPL 2020.01 (Jan 06 2020 - 20:56:31 +0000)

Trying to boot from MMC1





U-Boot 2020.01 (Jan 06 2020 - 20:56:31 +0000)



CPU : AM335X-GP rev 2.1

Model: TI AM335x BeagleBone Black

DRAM: 512 MiB

WDT: Started with servicing (60s timeout)

NAND: 0 MiB

MMC: OMAP SD/MMC: 0, OMAP SD/MMC: 1

Loading Environment from FAT... *** Warning - bad CRC, using default environment



<ethaddr> not set. Validating first E-fuse MAC

Net: eth0: ethernet@4a100000

Warning: usb_ether MAC addresses don't match:

Address in ROM is de:ad:be:ef:00:01

Address in environment is 04:79:b7:ec:35:75

, eth1: usb_ether

Hit any key to stop autoboot: 0

As you can easily spot, there are two different versions of U-Boot in place.

Without pressing the “boot” button, so to say, pre-installed with my BeagleBone Black there is

U-Boot 2018.09-00002-g0b54a51eee (Sep 10 2018 - 19:41:39 -0500), Build: jenkins-github_Bootloader-Builder-65

With the MicroSD Card I have a newer one:

U-Boot SPL 2020.01 (Jan 06 2020 - 20:56:31 +0000)

Trying to boot from MMC1

!!! Hit twice the SPACE Key immediately after starting the boot sequence so that BeagleBone Black to enter the U-Boot command prompt.

List all the commands supported by the U-boot shell

U-Boot# help

? - alias for 'help'

askenv - get environment variables from stdin

base - print or set address offset

bdinfo - print Board Info structure

boot - boot default, i.e., run 'bootcmd'

bootd - boot default, i.e., run 'bootcmd'

bootm - boot application image from memory

bootp - boot image via network using BOOTP/TFTP protocol

bootz - boot Linux zImage image from memory

chpart - change active partition

cmp - memory compare

coninfo - print console devices and information

cp - memory copy

crc32 - checksum calculation

dfu - Device Firmware Upgrade

dhcp - boot image via network using DHCP/TFTP protocol

echo - echo args to console

editenv - edit environment variable

eeprom - EEPROM sub-system

env - environment handling commands

exit - exit script

ext2load- load binary file from a Ext2 filesystem

ext2ls - list files in a directory (default /)

ext4load- load binary file from a Ext4 filesystem

ext4ls - list files in a directory (default /)

false - do nothing, unsuccessfully

fatinfo - print information about filesystem

fatload - load binary file from a dos filesystem

fatls - list files in a directory (default /)

fatwrite- write file into a dos filesystem

fdt - flattened device tree utility commands

go - start application at address 'addr'

gpio - input/set/clear/toggle gpio pins

help - print command description/usage

i2c - I2C sub-system

iminfo - print header information for application image

imxtract- extract a part of a multi-image

itest - return true/false on integer compare

load - load binary file from a filesystem

loadb - load binary file over serial line (kermit mode)

loads - load S-Record file over serial line

loady - load binary file over serial line (ymodem mode)

loop - infinite loop on address range

ls - list files in a directory (default /)

md - memory display

mm - memory modify (auto-incrementing address)

mmc - MMC sub system

mmcinfo - display MMC info

mtdparts- define flash/nand partitions

mtest - simple RAM read/write test

mw - memory write (fill)

nand - NAND sub-system

nboot - boot from NAND device

nfs - boot image via network using NFS protocol

nm - memory modify (constant address)

ping - send ICMP ECHO_REQUEST to network host

printenv- print environment variables

reset - Perform RESET of the CPU

run - run commands in an environment variable

saveenv - save environment variables to persistent storage

setenv - set environment variables

sf - SPI flash sub-system

showvar - print local hushshell variables

sleep - delay execution for some time

source - run script from memory

test - minimal test like /bin/sh

tftpboot- boot image via network using TFTP protocol

true - do nothing, successfully

usb - USB sub-system

usbboot - boot from USB device

version - print monitor, compiler and linker version

How to get supplementary information about U-boot shell commands

Note: => or ‘U-Boot#’ stand for the command prompt in the U-Boot shell.