1. /uboot_src/common目录添加cmd_xxx.c文件,参考其他cmd.c文件,大致实现以下两部分

    /*命令具体实现*/
    static int do_check_sd(cmd_tbl_t *cmdtp, int flag, int argc,
    			char * const argv[])
    {
    	xxxx
    }
    /**/
    U_BOOT_CMD(check_sd, 2, 1, do_check_sd,
    	"check tf/SD card.",
    	"[do_check_sd] "
    );

    注:U_BOOT_CMD(name,maxargs,repeatable,command,”usage”,”help”)

    name:命令名,非字符串,但在U_BOOT_CMD中用“#”符号转化为字符串
    maxargs:命令的最大参数个数
    repeatable:是否自动重复(按Enter键是否会重复执行)
    command:该命令对应的响应函数指针
    usage:简短的使用说明(字符串)
    help:较详细的使用说明(字符串)

  1. 添加cmd_xxx.c到/uboot_src/common/Makefile中,obj-$(CONFIG_CMD_XXX) += cmd_xxx.o
  2. /uboot_src/include/configs/xxx.h中添加 #define CONFIG_CMD_XXX,编译
  3. 重新编译Uboot

例子:uboot增加自定义命令(LED):

  1. /include/configs/xxx.h
    #define CONFIG_BOARD_SPECIFIC_LED             //板载特别LED
    #define CONFIG_GPIO_LED                      //LED的IO操作,即编译../driver/misc/gpio_led.c
    #define CONFIG_STATUS_LED                    //LED的状态控制操作,即编译../driver/misc/status_led.c
    #define CONFIG_CMD_LED                       //使用LED命令,即编译cmd_led.c
  2. /drivers/misc/status_led.c & ./include/status_led.c\h:
    #elif defined(CONFIG_BOARD_SPECIFIC_LED)
    /**/
    #define STATUS_LED_BIT         (32*2 + 3)    /*gpio2-3*/
    #define STATUS_LED_PERIOD      (CONFIG_SYS_HZ / 2)
    #define STATUS_LED_STATE        STATUS_LED_BLINKING
    #define STATUS_LED_BOOT		0	/* LED 0 used for boot status */
  3. /common/cmd_led.c:
    do_led函数:
    static int led_init_flag = 0;/**/
    void *base = (void *)EVM_SYSC_BASE;/*VIENNA_SYSC_MMR_BASE  0xB3F00000 */
    /**/
      if( led_init_flag == 0)
      {
        for(i=0; led_commands[i].string; i++){
          writel(SYSC_CLK_EN_GPIO_2_MASK/*BIT(26)*/, base + SYSC_CLOCK_EN_SET_REG_0/*0x114*/);/* setup GPIO clock (bank 2) Clock*/
          writel(BIT(3), base + SYSC_PAD_EN_SET_REG_2/*0x144*/); //Pin Mux
          __led_init(led_commands[i].mask, 0);
        }
        //printf("%s: __led_init!\n", __func__);
        led_init_flag = 1;
      }