1

I want to add custom command command to u-boot be it a simple hello world command.

After searching I found this link Yocto u-boot Custom Commands where it says to look at timer command in cmd/misc.c as starting point.

How do I bring this timer command to my u-boot image? I assume I have make changes to the makefiles but not sure which makefile I should edit.

I am using qemu to test the u-boot image in Ubuntu 18.04 using the following method

  1. Cloned the u-boot source from github.
  2. Installed all the build dependencies in the system.
  3. Prepared u-boot config files using make qemu_arm_config ARCH=arm CROSS_COMPILE=arm-none-eabi-
  4. Build u-boot make all ARCH=arm CROSS_COMPILE=arm-none-eabi-
  5. Launch qemu with u-boot image qemu-system-arm -M virt -nographic -kernel u-boot

U-boot log

$ qemu-system-arm -M virt -nographic -kernel u-boot 


U-Boot 2020.01-dirty (Mar 29 2020 - 15:46:14 +0530)

DRAM:  128 MiB
WARNING: Caches not enabled
Flash: 128 MiB
*** Warning - bad CRC, using default environment

In:    pl011@9000000
Out:   pl011@9000000
Err:   pl011@9000000
Net:   No ethernet found.
Hit any key to stop autoboot:  0 
=> timer
Unknown command 'timer' - try 'help'
=> 

Few more details

U-boot:

Host OS:

Distributor ID: Ubuntu
Description:    Ubuntu 18.04.4 LTS
Release:    18.04
Codename:   bionic
Eklavya
  • 17,618
  • 4
  • 28
  • 57
Bhargav Das
  • 81
  • 2
  • 14
  • As far as I can see in https://gitlab.denx.de/u-boot/u-boot/-/blob/master/cmd/misc.c#L60 this command is under `#ifdef CONFIG_CMD_TIMER`. It means you have to enable it in the configuration file. Edit your *.config* or, if you wish to keep your changes survive longer, *qemu_arm_config* by adding `CONFIG_CMD_TIMER=y` to it and try again. – 0andriy Mar 29 '20 at 21:17

2 Answers2

1

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.

Xypron
  • 2,215
  • 1
  • 12
  • 24
0

U-boot comes with a lot of stock commands which one can run on the u-boot console similar to the Linux console commands like 'ls'. The source for every command can be found under 'common/' directory with file names starting with 'cmd_'. However, not all commands are enabled by default.

From the code, you can open 'common/Makefile' and under the '# command' section you can find the list of all the commands masked with config flags 'CONFIG_*'. To enable a command, you have to simply #define the corresponding flag under the 'include/configs/.h' file and build the source. Now, you can see the command in the list of commands by running 'help'.

To enable a command 'source', in the 'common/Makefile', you can find

obj-$(CONFIG_CMD_SOURCE) += cmd_source.o

Simply include the corresponding flag in 'include/configs/.h' file as follows

obj-y += cmd_source.o

refer :http://studyzone.dgpride.com/2016/11/u-boot-how-to-add-new-command-to-u-boot.html

fad
  • 43
  • 1
  • 9