实现自定义u-boot命令

时间:2020-03-29 10:42:31

标签: linux embedded-linux qemu bootloader u-boot

我想向u-boot添加自定义命令命令,因为它是一个简单的hello world命令。

搜索后,我发现此链接Yocto u-boot Custom Commands表示以timer中的cmd/misc.c命令作为起点。

如何将这个timer命令带到u-boot映像中? 我假设我已经对makefile进行了更改,但是不确定我应该编辑哪个makefile。

我正在使用qemu通过以下方法在Ubuntu 18.04中测试u-boot映像

  1. 克隆了github上的u-boot来源。
  2. 在系统中安装了所有构建依赖项。
  3. 使用make qemu_arm_config ARCH=arm CROSS_COMPILE=arm-none-eabi-准备的u-boot配置文件
  4. 构建u-boot make all ARCH=arm CROSS_COMPILE=arm-none-eabi-
  5. 使用u-boot映像qemu-system-arm -M virt -nographic -kernel u-boot启动qemu

U引导日志

$ 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:

主机操作系统:

Distributor ID: Ubuntu
Description:    Ubuntu 18.04.4 LTS
Release:    18.04
Codename:   bionic

2 个答案:

答案 0 :(得分:1)

doc / README.commands描述了应如何实现命令。

您的新C文件应该在目录cmd /中。在cmd / Makefile中,您将必须添加目标文件,例如

obj-$(CONFIG_CMD_TIMER) += timer.o

在cmd / Kconfig中为您的命令添加一个新的配置选项。 https://www.kernel.org/doc/Documentation/kbuild/kconfig-language.txt中描述了Kconfig语法。

运行

make menuconfig

启用您的配置选项。

答案 1 :(得分:0)

U-boot 附带了许多可以在 u-boot 控制台上运行的常用命令,类似于 Linux 控制台命令,如“ls”。每个命令的源代码都可以在“common/”目录下找到,文件名以“cmd_”开头。但是,并非所有命令都默认启用。

从代码中,您可以打开“common/Makefile”,在“#command”部分下,您可以找到用配置标志“CONFIG_*”屏蔽的所有命令的列表。要启用命令,您必须简单地#define 'include/configs/.h' 文件下的相应标志并构建源代码。现在,您可以通过运行“help”在命令列表中看到该命令。

要启用命令'source',在'common/Makefile'中,您可以找到

obj-$(CONFIG_CMD_SOURCE) += cmd_source.o

只需在'include/configs/.h'文件中包含相应的标志,如下

obj-y += cmd_source.o

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