根据韦东山视频,自己制作一个简单的helloworld功能,个人学习笔记,如有错误欢迎交流
1. cmd_helloworld.c文件
根据cmd_bootm.c修改
1.1 .c文件预备工作
建立文件后的相应预备工作
1.1.1. 编写好程序功能作者的注释。
1.1.2. 包含头文件(从cmd_bootm.c中复制,不知道是否够用)。
#include <common.h>
#include <watchdog.h>
#include <command.h>
#include <image.h>
#include <malloc.h>
#include <zlib.h>
#include <bzlib.h>
#include <environment.h>
#include <asm/byteorder.h>
1.2 int do_helloworld()函数
初步试验的功能比较简单,仅保留print函数,待日后加入复杂功能进行练习。
int do_helloworld (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
{
printf ("helloworld....by KoRant\n");
return 1;
}
1.3 U_BOOT_CMD()
修改U_BOOT_CMD函数。具体修改的内容为“name”替换,“cmd ”替换,“usage”及“help”修改。
U_BOOT_CMD(
helloworld, CFG_MAXARGS, 1, do_helloworld,
"helloworld - First try\n",
"[addr [arg ...]]\n - First try First try First try First try\n" //对[addr [arg ...]]理解不够深入???
"\tpassing arguments 'arg ...'; when booting a Linux kernel,\n"
"\t'arg' can be the address of an initrd image\n"
);
1.4 Makefile修改
修改common目录下的Makefile文件,不然gcc无法产生相应功能的链接文件。