实现自定义 u-boot 命令

Implement custom u-boot command

我想将自定义命令添加到 u-boot 是一个简单的 hello world 命令。

搜索后我发现了这个 link ,它说要查看 cmd/misc.c 中的 timer 命令作为起点。

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

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

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

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:

主持人OS:

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

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

启用您的配置选项。

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

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

在命令列表中看到该命令

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

obj-$(CONFIG_CMD_SOURCE) += cmd_source.o

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

obj-y += cmd_source.o

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