Reputation: 101
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
u-boot
source from github.make qemu_arm_config ARCH=arm CROSS_COMPILE=arm-none-eabi-
make all ARCH=arm CROSS_COMPILE=arm-none-eabi-
qemu-system-arm -M virt -nographic -kernel u-boot
$ 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'
=>
U-boot:
Host OS:
Distributor ID: Ubuntu
Description: Ubuntu 18.04.4 LTS
Release: 18.04
Codename: bionic
Upvotes: 1
Views: 5815
Reputation: 53
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
Upvotes: 0
Reputation: 2483
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.
Upvotes: 1