U-boot分析与移植(4)----U-boot 添加命令
来源:互联网 发布:网络监控管理平台 编辑:程序博客网 时间:2024/06/11 21:00
我们初步了解U-Boot执行流程后,知道
U-Boot的每一个命令都是通过U_BOOT_CMD宏定义的。这个宏在include/command.h头文件中定义,每一个命令定义一个cmd_tbl_t结构体。# /*命令宏U_BOOT_CMD*/ # #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}
每一个命令宏U_BOOT_CMD用cmd_tbl_t结构体描述一个命令
1. struct cmd_tbl_s { 2. char *name; /* Command Name */ 3. int maxargs; /* maximum number of arguments */ 4. int repeatable; /* autorepeat allowed? */ 5. /* Implementation function */ 6. int (*cmd)(struct cmd_tbl_s *, int, int, char *[]); 7. char *usage; /* Usage message (short) */ 8. #ifdef CFG_LONGHELP 9. char *help; /* Help message (long) */ 10. #endif 11. #ifdef CONFIG_AUTO_COMPLETE 12. /* do auto completion on the arguments */ 13. int (*complete)(int argc, char *argv[], char last_char, int maxv, char *cmdv[]); 14. #endif 15. };
参数意义是:
name这是命令名字,不需要用双引号括起来maxargs最大参数的个数rep命令是否可重复,就是下一次按回车时再执行cmd对应的函数指针usage字符串表示的简短说明help字符串表示的详细说明在源代码里可发现命令都是在cmd_xxx.c里实现的
现在我们添加一个简单的测试命令
1、在common目录下添加一个hello.c文件
1. #include <common.h> 2. #include <command.h> 3. 4. #ifdef CONFIG_CMD_HELLO 5. int do_hello(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) 6. { 7. int i; 8. printf("argc = %d\n",argc); 9. for(i = 0; i < argc; i++) 10. printf("i = %d, %s\n",i,argv[i]); 11. return 0; 12. } 13. U_BOOT_CMD(hello,CONFIG_SYS_MAXARGS,0,do_h
do_xxx函数必须定义成这样形式:
- cmd_tbl_s 结构体里的成员 int (*cmd)(struct cmd_tbl_s *, int, int, char *[]);
int do_hello(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
在填参数个数时要注意,CONFIG_SYS_MAXARGS是在include/configs/smdk2140.h里定义的,默认16
2、在common/Makefile中的#command添加如下内容:4、编译后下到板上
1. U-Boot 2009.11 (12鏈?14 2011 - 00:44:00) 2. 3. 4. DRAM: 64 MB 5. 6. Flash: 512 kB 7. 8. NAND: NAND_ECC_NONE selected by board driver. This is not recommended !! 9. 10. 64 MiB 11. 12. In: serial 13. 14. Out: serial 15. 16. Err: serial 17. 18. Net: dm9000 19. 20. Hit any key to stop autoboot: 0 21. 22. BAI2011/12/13 # hello 23. 24. argc = 1 25. 26. i = 0, hello 27. 28. BAI2011/12/13 # hello this is my test! 29. 30. argc = 5 31. 32. i = 0, hello 33. 34. i = 1, this 35. 36. i = 2, is 37. 38. i = 3, my 39. 40. i = 4, test! 41. 42. BAI2011/12/13 #
- U-boot分析与移植(4)----U-boot 添加命令
- U-boot分析与移植(4)----U-boot 添加命令
- U-boot分析与移植(4)----U-boot 添加命令
- U-boot分析与移植(4)-U-boot 添加命令
- U-boot分析与移植(5)----U-boot移植
- U-boot分析与移植(5)----U-boot移植
- U-boot分析与移植(5)----U-boot移植
- U-boot分析与移植(5)----U-boot移植
- U-boot分析与移植(6)----U-boot--Makefile
- U-boot分析与移植(6)----U-boot--Makefile
- u-boot移植分析
- 添加u-boot命令
- 添加U-Boot命令
- u-boot添加命令
- U-BOOT添加命令
- u-boot添加命令
- u-boot添加命令
- 添加u-boot命令
- 第六周任务(5)
- C语言运算符优先级列表
- Android开发之SurfaceView
- JAVA技术入门
- xss相关的少见内容
- U-boot分析与移植(4)----U-boot 添加命令
- jquery 鼠标移上去显示大图片
- Gitolite架设git服务器
- U-boot分析与移植(5)----U-boot移植
- RIASEC & World-of-Work Map 职业测评
- CSS控制文本溢出显示省略号
- JQuery------技巧(1)
- 在Eclipse里重新安装ADT插件提示
- 创建物化视图并定时refresh