bootloader---2.U_BOOT_CMD分析

本文介绍了U-Boot系统的命令解析流程,包括如何定义和注册命令、命令的解析与执行过程,以及具体实例分析。此外还详细解释了如何在U-Boot中添加新的命令。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

start_armboot
{
}
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 partitions\n",
    "\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 protocol\n",
    "[loadAddress] [bootfilename]\n"
);

usage=    "tftpboot- boot image via network using TFTP protocol\n";
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 protocol\n",
    "[loadAddress] [bootfilename]\n"};
    
int do_tftpb (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
{
    return netboot_common (TFTP, cmdtp, argc, argv);
}

set -e export RLM_LICENSE="10.247.222.136@5053" cd ${WORKSPACE}/code chmod 755 ${WORKSPACE}/code/build.sh if [ $? -eq 0 ];then echo "build.sh file exists" else echo "no file build.sh or permission deny" exit fi if [ "${product_name}" = "ICSD_YB" ];then bash ${WORKSPACE}/code/build.sh -v ${product_name} ${boot_url} ${osd_url} elif [ "${product_name}" = "ICSD_ZK" ];then bash ${WORKSPACE}/code/build.sh -v ${product_name} ${boot_url} ${tp_url} elif [ "${product_branch}" = "br_ichs_2.0.0_release" ];then if [ "${mr_release}" = "F2" ];then bash ${WORKSPACE}/code/build.sh -v ICHS_F2 https://cmc-szver-artifactory.cmc.tools.huawei.com/artifactory/cmc-sz-inner/ICHS/ICHS%20200/ICHS%20200.0.007-1500300.B010/ICHS_F2_MPC584BX_BOOTLOADER_V11.tar.gz?_t=1715572255931 elif [ "${mr_release}" = "X2" ];then bash ${WORKSPACE}/code/build.sh -v ICHS_X2 https://cmc-szver-artifactory.cmc.tools.huawei.com/artifactory/cmc-sz-inner/ICHS/ICHS%20200/ICHS%20200.0.004-1710300.B010/ICHS_X2_MPC584BX_BOOTLOADER_V13.tar.gz?_t=1712573054471 elif [ "${mr_release}" = "X4" ];then bash ${WORKSPACE}/code/build.sh -v ICHS_X4 https://cmc-szver-artifactory.cmc.tools.huawei.com/artifactory/cmc-sz-inner/ICHS/ICHS%20200/ICHS%20200.0.006-0100400.B010/ICHS_X4_MPC584BX_BOOTLOADER_V6.tar.gz?_t=1712461946857 elif [ "${mr_release}" = "F3" ];then bash ${WORKSPACE}/code/build.sh -v ICHS_F3 https://cmc-szver-artifactory.cmc.tools.huawei.com/artifactory/cmc-sz-inner/ICHS/ICHS%20200/ICHS%20200.0.001-1501300.B004/ICHS_F3_MPC584BX_BOOTLOADER_V2.tar.gz?_t=1717654488502 elif [ "${mr_release}" = "F1A" ];then bash ${WORKSPACE}/code/build.sh -v ICHS_F1A https://cmc-szver-artifactory.cmc.tools.huawei.com/artifactory/cmc-sz-inner/ICHS/ICHS%20200/ICHS%20200.0.001-1502200.B001/ICHS_F1A_MPC584BX_BOOTLOADER_V1.tar.gz?_t=1723453286790 elif [ "${mr_release}" = "F2H" ];then bash ${WORKSPACE}/code/build.sh -v ICHS_F2H https://cmc-szver-artifactory.cmc.tools.huawei.com/artifactory/cmc-sz-inner/ICHS/ICHS%20200/ICHS%20200.0.001-1500290.B010/ICHS_F2H_MPC584BX_BOOTLOADER_V1.tar.gz?_t=1737463266641 elif [ "${mr_release}" = "F1CH" ];then bash ${WORKSPACE}/code/build.sh -v ICHS_F1CH https://cmc-szver-artifactory.cmc.tools.huawei.com/artifactory/cmc-sz-inner/ICHS/ICHS%20200/ICHS%20200.0.001-1502700.B010/ICHS_F1CH_MPC584BX_BOOTLOADER_V1.tar.gz?_t=1739350995574 else echo "porduct error" fi else bash ${WORKSPACE}/code/build.sh -v ${product_name} ${boot_url} fi 帮我转换成python脚本
最新发布
03-21
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值