SEP6200的U-BOOT中的指令注册添加
来源:互联网 发布:日语n1网络课程 编辑:程序博客网 时间:2024/06/04 18:55
在u-boot中如果我们要实现自己命令的具体功能,在comman文件夹中建立对应的.c文件。首先为了能让系统找到该指令,所以要在命令表中注册一下。
#define U_BOOT_CMD(name,maxargs,rep,cmd,usage,help) \
cmd_tbl_t __u_boot_cmd_##name Struct_Section = {#name, maxargs, rep, cmd, usage, help}
“##”与“#”都是预编译操作符,“##”有字符串连接的功能,“#”表示后面紧接着的是一个字符串。
#define Struct_Section __attribute__ ((unused,section (".u_boot_cmd")))
其中,unused表示该函数或变量可能不使用,这个属性可以避免编译器产生警告信息。
凡通过U_BOOT_CMD定义的cmd_tbl_t变量会全部被放在.u_boot_cmd段当中。这也是在你写的.c文件的末尾必须要写的,为了完成注册这个动作。
比如说:U_BOOT_CMD(nandboot,0,0,do_nandboot,"boot from nand","--help") 通过宏展开就是:
_u_boot_cmd_nandboot __attribute__((unused, section(".u_boot_cmd"))) = {"nandboot", 0, 0, do_nandboot, "boot from nand","--help"}
具体的用法例子:
#define U_BOOT_CMD(name,maxargs,rep,cmd,usage,help) \
cmd_tbl_t __u_boot_cmd_##name Struct_Section = {#name, maxargs, rep, cmd, usage, help}
“##”与“#”都是预编译操作符,“##”有字符串连接的功能,“#”表示后面紧接着的是一个字符串。
#define Struct_Section __attribute__ ((unused,section (".u_boot_cmd")))
其中,unused表示该函数或变量可能不使用,这个属性可以避免编译器产生警告信息。
凡通过U_BOOT_CMD定义的cmd_tbl_t变量会全部被放在.u_boot_cmd段当中。这也是在你写的.c文件的末尾必须要写的,为了完成注册这个动作。
比如说:U_BOOT_CMD(nandboot,0,0,do_nandboot,"boot from nand","--help") 通过宏展开就是:
_u_boot_cmd_nandboot __attribute__((unused, section(".u_boot_cmd"))) = {"nandboot", 0, 0, do_nandboot, "boot from nand","--help"}
关于cmd_tbl_s结构体定义如下:
struct cmd_tbl_s { char *name; /* 命令名*/ int maxargs; /* 最大参数个数*/ int repeatable; /* 是否自动重复*/ int (*cmd)(struct cmd_tbl_s *, int, int, char *[]); /* 响应函数*/ char *usage; /* 简短的帮助信息*/#ifdef CONFIG_SYS_LONGHELP char *help; /* 较详细的帮助信息*/#endif#ifdef CONFIG_AUTO_COMPLETE /* 自动补全参数*/ int (*complete)(int argc, char *argv[], char last_char, int maxv, char *cmdv[]);#endif};
具体的用法例子:
比如我们要加入一条mytest命令:比如点亮我们板子上的LED灯
int do_mytest(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]){//init the registor of GPIOswitch(argc){case 2:switch(on_off(argv[1])){case 0 : {*(volatile unsigned long *)0x30006110 = 0x0;*(volatile unsigned long *)0x30006114 = 0x0e00;*(volatile unsigned long *)0x30066118 = 0xffffffff; printf("is off?");}break;case 1 : {*(volatile unsigned long *)0x30006110 = 0x0;*(volatile unsigned long *)0x30006114 = 0x0e00;*(volatile unsigned long *)0x30066118 = 0x0; printf("is on?");}break;default : break;}break;default: printf("%s - %s\n", cmdtp -> name, cmdtp -> usage);}//enable the LEDreturn 0;}U_BOOT_CMD(mytest,2,1,do_mytest,"light up 3 of the led ~~","you can light on/off the led on the board by : mytest on/off");
要使得该命令可以在我们的u-boot里面去使用还需要改一些配置文件
1)在uboot/common/Makefile文件中加入需要编译的命令文件,使得该cmd_xxxxx文件可以得到编译,例如加入COBJS-$(CONFIG_CMD_MYTEST) += cmd_mytest.o ,可以让cmd_mytest.c文件可以编译生成.o文件
2)在u-boot\include\config_cmd_all.h
u-boot\include\config_cmd_default.h两个文件中加入预定义宏,使得uboot在编译命令时能加入该命令。例如#define CONFIG_CMD_MYTEST
3)在u-boot\include\configs\SEP0611.h文件中同样加入宏定义
4)最后执行编译即可
- SEP6200的U-BOOT中的指令注册添加
- u-boot 内核引导与添加指令
- u-boot 内核引导与添加指令
- U-Boot提供的指令
- u-boot中的常用指令汇总
- 分析u-boot中的“.word”伪指令
- u-boot命令的添加
- U-boot命令的添加
- U-boot命令的添加
- u-boot 中的汇编指令asr adrl ldr
- U-boot添加命令的两个版本
- U-Boot添加命令的方法
- U-boot中添加DNW的支持
- U-Boot添加命令的方法
- U-Boot添加命令的方法
- U-Boot添加命令的方法
- 添加u-boot命令
- 添加U-Boot命令
- c# 默认 访问修饰符 小结
- 纯虚函数与虚函数的区别
- 【读书笔记-重构与模式】 抽象工厂与单例模式的组合使用
- QoS、SLA、HA
- [同域] 嵌入式iframe子页面与父页面js通信方式
- SEP6200的U-BOOT中的指令注册添加
- 短信发送--短信的发送流程(framework)
- Maven的多模块(Multi-Module)工程的pom编写
- JAVA程序员必看的15本书的电子版
- read funciton
- MFC----windows控件----滑动条控件
- Junit的遇到的问题
- 面向对象设计原则
- MUCH:专跑Android游戏的国产PSP