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 \n");
           return 0;
 } 
}
 
  
void showmainmenu(void)
{   
 printf("\r\n##### u-boot cmd menu ##### \r\n");
 if(isbootfromnor())
   printf("[o] download u-boot to nor \r\n"); 
 printf("[n] download u-boot to nand \r\n");
 printf("[k] download kernel to nand \r\n");
 printf("[f] download yaffs-rootfs to nand \r\n");
 printf("[r] reset the u-boot \r\n");
 printf("[b] boot the system \r\n");
 printf("[q] quit from menu \r\n");    
}
 
  
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! \n"); 
}
 
  
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 \n"
 "press corresponding key, the u-boot will help you download file to the suited memory location \n"
 "note: this menu only support yaffs rootfs, if you want to download jffs rootfs, you must input cmd by hand! \n"
 "if you want to download rootfs, you must input 3 paramters like <menu> <rootfs_name> <rootfs_size> \n"
);
 
  
 
 
 

 

转载于:https://www.cnblogs.com/zhu-g5may/p/10084942.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值