Implement Custom U-Boot Command

Implement custom u-boot command

doc/README.commands describes how commands should be implemented.

Your new C file should be in directory cmd/. In cmd/Makefile you will have to add your object file, e.g.

obj-$(CONFIG_CMD_TIMER) += timer.o

In cmd/Kconfig add a new configuration option for your command. The Kconfig syntax is described in https://www.kernel.org/doc/Documentation/kbuild/kconfig-language.txt.

Run

make menuconfig

to enable your configuration option.

Yocto u-boot Custom Commands

IMHO you have two options for adding the additional sourcecode to your YP build:

  1. If you have only a small number of changes: Add the patches to your layer and "activate" them via SRC_URI.
  2. If you have more changes: create a separate git branch/repo for "your" U-Boot version.

The fastest way of testing your changes may be to checkout a separate U-Boot repo somewhere and use a generated SDK. Another way may be to use the devshell [1]

I'm not an expert on U-Boot's source layout, but I would say it depends which type of command it is. If it's a "generic" one like date the cmd/ subdirectory would be best.

If you're looking for an example on which you can base your work maybe the timer command in cmd/misc.c would be a good start.

[1] http://www.openembedded.org/wiki/Devshell

How to enter U-Boot command?

The U-boot timeout (according to its configuration flags at compile time) may be as short as 2 seconds.

I use this way to enter the prompt:

1- Prepare serial port along with your terminal (like ckermit).

2- Reset the board and then send some arbitrary commands via serial.

The U-boot should stop autoboot process unless it is configured otherwise at compile time.

How to use uboot test command 'or' -o option

A string is considered true if it's non-empty, and false if it's empty:

$ if test ""; then echo true; else echo false; fi
false
$ if test "x"; then echo true; else echo false; fi
true

It follows that test "" -o x is true. You can also use -o between more complex comparisons:

# Make sure 0 < $x < 10
if test "$x" -le 0 -o "$x" -ge 10; then echo "out of range"; fi

However, POSIX recommends using the portable shell construct || instead of relying on the legacy operator test -o.

Extra commands in raspberry pi u-boot using yocto

After going through different rpi3 defconfig files found the correct file and created a patch for that file. The looks like this
rpi-timer.patch

diff --git a/configs/rpi_3_defconfig b/configs/rpi_3_defconfig
index 9b281a4f15..053d36e244 100644
--- a/configs/rpi_3_defconfig
+++ b/configs/rpi_3_defconfig
@@ -45,3 +45,4 @@ CONFIG_SYS_WHITE_ON_BLACK=y
CONFIG_CONSOLE_SCROLL_LINES=10
CONFIG_PHYS_TO_BUS=y
CONFIG_OF_LIBFDT_OVERLAY=y
+CONFIG_CMD_TIMER=y

Now needed to apply the patch to the fetched source in yocto.
Here is the .bbappend file recipes-bsp/u-boot/u-boot_%.bbappend for applying the patch

FILESEXTRAPATHS_prepend := "${THISDIR}/files:"
SRC_URI += " file://rpi-timer.patch "

Loading custom u-boot script

As said in the comments, i was able to make a patch for u-boot-tegra/include/config_distro_bootcmd.h that has the variable distro_bootcmd set to my script content. When i then build my yocto image and boot up my Jetson Nano, i can see that the variable is in fact set.

This way should work for any u-boot and not just for Jetson Nano. Just find the bootcmd variable in the u-boot that runs at default boot and patch it.



Related Topics



Leave a reply



Submit