TX2440 ARM开发板Uboot移植 (六、实现启动快捷菜单)

1、在common目录下新增cmd_menu.c文件,内容为:

#include <common.h>
#include <command.h>

static char awaitkey(unsigned long delay, int* error_p)
{
    int i;
    char c;
    if (delay == -1) {
        while (1) {
            if (tstc()) /* we got a key press */
                return getc();
        }
    }
    else {        
        for (i = 0; i < delay; i++) {
      if (tstc()) /* we got a key press */
       return getc();
            udelay (10*1000);
        }
    }
    if (error_p)
        *error_p = -1;
    return 0;
}

void main_menu_usage(void)
{
 printf("\r\n######## Hotips TFTP DownLoad for SMDK2440 ########\r\n");
 printf("\r\n");
 printf("[1] 下载 u-boot.bin       写入 Nand Flash\r\n");
 printf("[2] 下载 Linux(uImage)    内核镜像写入 Nand Flash\r\n");
 printf("[3] 下载 yaffs2(fs.yaffs) 文件系统镜像写入 Nand Flash\r\n");
 printf("[4] 下载 Linux(uImage)    内核镜像到内存并运行\r\n");
 printf("[5] 重启设备\r\n");
 printf("[q] 退出菜单\r\n");
 printf("\r\n");
 printf("输入选择: ");
}

void menu_shell(void)
{
    char c;
    char cmd_buf[200];

    while (1)
    {
      main_menu_usage();
      c = awaitkey(-1, NULL);
      printf("%c\n", c);
      switch (c)
      {
  case '1':
  {
          strcpy(cmd_buf, "tftp 0x32000000 u-boot.bin; nand erase 0x0 0x60000; nand write 0x32000000 0x0 0x60000");
          run_command(cmd_buf, 0);
          break;
  }
        case '2':
        {
          strcpy(cmd_buf, "tftp 0x32000000 uImage; nand erase 0x80000 0x200000; nand write 0x32000000 0x80000 0x200000");
          run_command(cmd_buf, 0);
     break;
        }
        case '3':
        {
          strcpy(cmd_buf, "tftp 0x32000000 fs.yaffs; nand erase 0x280000; nand write.yaffs2 0x32000000 0x280000 $(filesize)");
          run_command(cmd_buf, 0);
          break;
        }
  case '4':
        {
          strcpy(cmd_buf, "tftp 0x32000000 uImage; bootm 0x32000000");
          run_command(cmd_buf, 0);
          break;
        }
  case '5':
        {
          strcpy(cmd_buf, "reset");
          run_command(cmd_buf, 0);
          break;
        }
        case 'q':
        {
          return;    
          break;
        }
      }
    }
}

int do_menu (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
{
    menu_shell();
    return 0;
}

U_BOOT_CMD(
 menu, 1, 0, do_menu,
 "Download Menu",
 "U-boot Download Menu by Hotips\n"
);

2、修改common目录下的Makefile文件,将cmd_menu.o加入编译:

COBJS-y += main.o
COBJS-y += cmd_menu.o
COBJS-y += ACEX1K.o

你可能感兴趣的:(堆栈,文件系统,u-boot,ARM9,fl2440)