#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"
);

 

最新文章

  1. 全球HTTPS时代已来,你跟上了吗?
  2. zerojs! 造出最好的 CMS 轮子
  3. .Net JIT
  4. tyvj[1089]smrtfun
  5. 基于HTML5的电信网管3D机房监控应用
  6. VS2012发布网站IIS配置
  7. JavaScript下全选反选的Demo程序里实现checkmeonly函数 DOM
  8. jQuery控制元素隐藏和显示
  9. 《Java从入门到放弃》JavaSE篇:综合练习——单身狗租赁系统(数组版)
  10. iOS多线程编程
  11. 利用linq的Take Skip方法解决 集合拆分的问题
  12. java.util.zip
  13. hdu 3247 AC自动+状压dp+bfs处理
  14. JQuery未来元素事件监听写法
  15. 05_解决mac百度网盘下载速度慢问题
  16. Python-str-操作-6
  17. 关于Jar包 和 war
  18. 机器学习中的损失函数 (着重比较:hinge loss vs softmax loss)
  19. CentOs - 使用ssh key远程登录
  20. vue-devtools必备工具

热门文章

  1. Filter学习总结,顺便提及点servlet3.0异步filter和异步监听
  2. Siebel计划和实施
  3. Java反射创建带构造参数的类 并执行方法
  4. CentOS 7.3 下 Mysql(mariadb)的安装
  5. Scrum _GoodJob
  6. IOS VLC (第三方音频)的使用
  7. OpenCV人脸识别
  8. 贪心算法,今年暑假不AC
  9. python-文件基本操作(一)
  10. 【luogu P4462 [CQOI2018]异或序列】 题解