U-Boot2017.01的启动过程比较复杂,本文分为6部分讲述,笔者将主要过程和函数调用关系整理成一个文档方便查看,文档链接为 U-Boot2017.01启动过程分析pdf U-Boot2017.01源码分析及启动命令解析
启动过程6部分内容如下 01-U-Boot2017.01 启动过程概述 02-U-Boot2017.01 SPL阶段分析 03-U-Boot2017.01 U-Boot阶段分析 04-U-Boot2017.01 加载内核过程 05-U-Boot2017.01 bootz加载过程 06-U-Boot2017.01 读取uEnv.txt过程
bootz命令加载过程如下: U_BOOT_CMD 命令解析过程如下
/*********************************************** U_BOOT_CMD 命令解析 ***********************************************/ /* cmd/bootz.c */ U_BOOT_CMD( bootz, CONFIG_SYS_MAXARGS, 1, do_bootz, "boot Linux zImage image from memory", bootz_help_text) /* cmd/test.c */ U_BOOT_CMD( test, CONFIG_SYS_MAXARGS, 1, do_test, "minimal test like /bin/sh", "[args..]" ); /* include/command.h */ #define U_BOOT_CMD(_name, _maxargs, _rep, _cmd, _usage, _help) \ U_BOOT_CMD_COMPLETE(_name, _maxargs, _rep, _cmd, _usage, _help, NULL) /* include/command.h */ #define U_BOOT_CMD_COMPLETE(_name, _maxargs, _rep, _cmd, _usage, _help, _comp) \ ll_entry_declare(cmd_tbl_t, _name, cmd) = \ U_BOOT_CMD_MKENT_COMPLETE(_name, _maxargs, _rep, _cmd, _usage, _help, _comp); /* include/command.h */ #define U_BOOT_CMD_MKENT_COMPLETE(_name, _maxargs, _rep, _cmd, _usage, _help, _comp) \ { #_name, _maxargs, _rep, _cmd, _usage, _CMD_HELP(_help) _CMD_COMPLETE(_comp)} /* include/command.h */ #ifdef CONFIG_AUTO_COMPLETE # define _CMD_COMPLETE(x) x, #else # define _CMD_COMPLETE(x) #endif #ifdef CONFIG_SYS_LONGHELP # define _CMD_HELP(x) x, #else # define _CMD_HELP(x) #endif typedef struct cmd_tbl_s cmd_tbl_t; 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 * const[]); char *usage; /* Usage message (short) */ #ifdef CONFIG_SYS_LONGHELP char *help; /* Help message (long) */ #endif #ifdef CONFIG_AUTO_COMPLETE /* do auto completion on the arguments */ int (*complete)(int argc, char * const argv[], char last_char, int maxv, char *cmdv[]); #endif }; /* include/linker_lists.h */ #define ll_entry_declare(_type, _name, _list) \ _type _u_boot_list_2_##_list##_2_##_name __aligned(4) \ __attribute__((unused, \ section(".u_boot_list_2_"#_list"_2_"#_name)))以test命令为例,讲述命令解析的过程
/*********************************************** u_BOOT_CMD 以test为例 ***********************************************/ /* cmd/test.c */ U_BOOT_CMD( test, CONFIG_SYS_MAXARGS, 1, do_test, "minimal test like /bin/sh", "[args..]" ); /* include/command.h */ ll_entry_declare(struct cmd_tbl_s, test, do_test) = {test, CONFIG_SYS_MAXARGS, 1, do_test, "boot Linux zImage image from memory", bootz_help_text}; typedef struct cmd_tbl_s cmd_tbl_t; 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 * con char *usage; /* Usage message (short) */ #ifdef CONFIG_SYS_LONGHELP char *help; /* Help message (long) */ #endif #ifdef CONFIG_AUTO_COMPLETE /* do auto completion on the arguments */ int (*complete)(int argc, char * const argv[], char #endif }; /* include/linker_lists.h */ struct cmd_tbl_s _u_boot_list_2_do_test_2_test __aligned(4) __attribute__((unused, \ section(".u_boot_list_2_"#_list"_2_"#_name))) struct cmd_tbl_s _u_boot_list_2_do_test_2_test \ __attribute__((unused, \ section(".u_boot_list_2_"#_list"_2_"#_name))) struct cmd_tbl_s _u_boot_list_2_do_test_2_test{ char *name; /* test */ int maxargs; /* 16*/ int repeatable; /* 1 */ /* do_test */ int (*cmd)(struct cmd_tbl_s *, int, int, char * const[]); char *usage; /* "minimal test like /bin/sh" */ #ifdef CONFIG_SYS_LONGHELP char *help; /* [args..]" */ #endif #ifdef CONFIG_AUTO_COMPLETE /* NULL */ int (*complete)(int argc, char * const argv[], char #endif };