• cmd_menu.c


    
    
    #include <common.h>
    #include <config.h>
    #include <command.h>
    
    
    static char cmd_buf[200];
    static int quit_flag = 0;
        
    char awaitkey(unsigned long delay, int* error_p)
    {
        int i;
    
    
        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;
    }
    
    
    static int isbootfromnor(void)
    {
        volatile unsigned long *pa = (volatile unsigned long * )0;
     unsigned long pb;
    
    
     pb = *pa;
     *pa = 0x12345678;
     if(*pa != 0x12345678) { //不可写
           
               return 1;
      }
     else{  
            *pa = pb;
         printf("nand ");
               return 0;
     } 
    }
    
    
    void showmainmenu(void)
    {   
     printf(" ##### u-boot cmd menu ##### ");
     if(isbootfromnor())
       printf("[o] download u-boot to nor "); 
     printf("[n] download u-boot to nand ");
     printf("[k] download kernel to nand ");
     printf("[f] download yaffs-rootfs to nand ");
     printf("[r] reset the u-boot ");
     printf("[b] boot the system ");
     printf("[q] quit from menu ");    
    }
    
    
    void do_uboot_load_o(void)
    {
        strcpy(cmd_buf, "protect off all;erase 0 7ffff;tftp 30000000 u-boot.bin;cp.b 30000000 0 80000");
        run_command(cmd_buf, 0);
    }
    
    
    void do_uboot_load_n(void)
    {
        strcpy(cmd_buf, "nand erase.part u-boot;tftp 30000000 u-boot.bin;nand write 30000000 u-boot");
        run_command(cmd_buf, 0);
    }
    
    
    void do_kernel_load(void)
    {
        strcpy(cmd_buf, "nand erase.part kernel;tftp 30000000 uImage;nand write 30000000 kernel");
        run_command(cmd_buf, 0);
    }
    
    
    void do_rootfs_load(char * const argv[])
    {
        char *p = cmd_buf + 14;
        strcpy(cmd_buf, "nand erase.part rootfs");
        run_command(cmd_buf, 0);
        strcpy(cmd_buf, "tftp 30000000 ");
        strcpy(p, argv[1]);
        run_command(cmd_buf, 0);
        strcpy(cmd_buf, "nand write.yaffs 30000000 460000 ");
        p = cmd_buf + 33;
        strcpy(p, argv[2]);
        run_command(cmd_buf, 0);
    }
    
    
    void do_reset_cmd(void)
    {
        run_command("reset", 0);
    }
    
    
    void do_bootm_cmd(void)
    {
        run_command("boot", 0);
    }
    
    
    void do_quit(void)
    {
        quit_flag = 1;
    }
    
    
    void pre_handle(void)
    {
        printf("sure you have prepared file by tftp! "); 
    }
    
    
    void menu_shell(char * const argv[])
    {
         char cmd;
         showmainmenu();
      while(1){
              cmd = awaitkey(-1, NULL);
        switch(cmd){
            case 'o':
                   pre_handle();
                      do_uboot_load_o();
                   break;
                   case 'n':
                   pre_handle();
                   do_uboot_load_n();
                   break;
             case 'k':
                   pre_handle();
             do_kernel_load();
                   break;
          case 'f':
                   pre_handle();
                   do_rootfs_load(argv);
                   break;
          case 'r':do_reset_cmd();
                   break;
          case 'b':
             do_bootm_cmd();
                   break;
          case 'q':
                do_quit();
                   break;
        }
        if(quit_flag == 1)
           break;
        cmd = 0;
      }
     quit_flag = 0;
    }
    
    
    int do_menu(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
    {
        menu_shell(argv);
        return 0;
    }
    
    

    U_BOOT_CMD(
     menu, 3, 1, do_menu,
     "sure you have prepared file by tftp, and press corresponding key",
     "sure you have prepared file by tftp "
     "press corresponding key, the u-boot will help you download file to the suited memory location "
     "note: this menu only support yaffs rootfs, if you want to download jffs rootfs, you must input cmd by hand! "
     "if you want to download rootfs, you must input 3 paramters like <menu> <rootfs_name> <rootfs_size> "
    );
    
    
     
    
    
  • 相关阅读:
    TestNG测试用例编写和执行
    Myeclipse+TestNG白盒测试环境搭建
    Jmeter创建一个简单的http接口用例
    python 格式化日期
    测试需求分析总结
    mac终端配色
    浅谈游戏中BUFF的设计要点
    图片头代码
    My.Ioc 代码示例——避免循环依赖
    My.Ioc 代码示例——谈一谈如何实现装饰器模式,兼谈如何扩展 My.Ioc
  • 原文地址:https://www.cnblogs.com/zhu-g5may/p/10084942.html
Copyright © 2020-2023  润新知