您现在的位置: 主页 > MCU > 单片机技术应用 > TQ2440之uboot---2.U_BOOT_CMD 分析 -
本文所属标签:
为本文创立个标签吧:

TQ2440之uboot---2.U_BOOT_CMD 分析 -

来源: 网络用户发布,如有版权联系网管删除 2018-09-06 

[导读]
start_armboot{}main_loop{1. 环境变量mtdparts, 调用mtdparts_init2. 如果在启动过程中 无空格键按下则boot_zImage有空格键按下则 run_command("menu",0)3. shell过程,读取用户端输入并执行相应的命令

start_armboot

本文引用地址: http://www.21ic.com/app/mcu/201806/764760.htm

{

}

main_loop

{

1. 环境变量mtdparts, 调用mtdparts_init

2. 如果在启动过程中 无空格键按下则boot_zImage

有空格键按下则 run_command("menu",0)

3. shell过程,读取用户端输入并执行相应的命令

{

从输入端获得命令,保存在全局变量comsole_buffer中

执行 run_command();

}

}

run_command

{

1. 对;进行解析,划分出一个个完整的命令

2. 然后对每一个完整的命令执行:

{

parse_line

{

line 是指整个的命令行字符串;

假设line = nboot 0x32000000 kernel; bootm 0x32000000

先去掉开头的空格,

然后对命令进行解析,找到空格之后将空格替换为\0,这样解析出命令和参数

}

find_cmd(argv[0])

{

从 __u_boot_cmd_start 到 __u_boot_cmd_end 的array进行遍历,

从找到的cmd_tbl_t中,字符串寻找cmdtp->name与argv[0]相同的命令

}

找到命令后,调用cmd_tbl_t->cmd调用函数

}

}

1.

U_BOOT_CMD(

mtdparts, 6, 0, do_jffs2_mtdparts,

"mtdparts- define flash/nand partitionsn",

"n"

);

cmd_tbl_t __u_boot_cmd_mtdparts Struct_Section = {mtdparts, 6, 0, do_jffs2_mtdparts, usage, help};

以下从doc/README.command 翻译

要想在u-boot中添加命令,必须新建一个command structure。要想创建一个command structure,则首先包含 "command.h" 头文件,然后用U_BOOT_CMD宏填充 cmd_tbl_t struct。

经过宏展开后新创建的这个结构体的名字会__u_boot_cmd开头,然后连接器会把这个结构体连接到指定的section上。

这样link才能从代码中提取所有的命令,生成一个静态的array。这样就可以通过遍历一个以__u_boot_cmd_starty开头的数组找到所要的命令。

1.

struct cmd_tbl_s {

char *name; /* Command Name */

int maxargs; /* maximum number of arguments */

int repeatable; /* autorepeat allowed? */

/* Implementation function */

int (*cmd)(struct cmd_tbl_s *, int, int, char *[]);

char *usage; /* Usage message (short) */

char *help; /* Help message (long) */

#ifdef CONFIG_AUTO_COMPLETE

/* do auto completion on the arguments */

int (*complete)(int argc, char *argv[], char last_char, int maxv, char *cmdv[]);

#endif

};

#define Struct_Section __attribute__ ((unused,section (".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}

typedef struct cmd_tbl_s cmd_tbl_t;

extern cmd_tbl_t __u_boot_cmd_start;

extern cmd_tbl_t __u_boot_cmd_end;

这里要看的是##name和#name这两个操作.##name将字符直接跟在后面, #name会将name这个字符中以"..."的形式放置。

1.

U_BOOT_CMD(

tftpboot, 3, 1, do_tftpb,

"tftpboot- boot image via network using TFTP protocoln",

"[loadAddress] [bootfilename]n"

);

usage= "tftpboot- boot image via network using TFTP protocoln";

help= "[loadAddress] [bootfilename]n";

cmd_tbl_t __u_boot_cmd_tftpboot __attribute__ ((unused,section (".u_boot_cmd"))) = {"tftpboot", 3, 1, do_tftpb, "tftpboot- boot image via network using TFTP protocoln",

"[loadAddress] [bootfilename]n"};

int do_tftpb (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])

{

return netboot_common (TFTP, cmdtp, argc, argv);

}




              查看评论 回复



嵌入式交流网主页 > MCU > 单片机技术应用 > TQ2440之uboot---2.U_BOOT_CMD 分析 -
 

"TQ2440之uboot---2.U_BOOT_CMD 分析 -"的相关文章

网站地图

围观()