Chinaunix首页 | 论坛 | 博客
  • 博客访问: 59169
  • 博文数量: 12
  • 博客积分: 15
  • 博客等级: 民兵
  • 技术积分: 70
  • 用 户 组: 普通用户
  • 注册时间: 2011-11-05 09:18
文章分类
文章存档

2012年(12)

我的朋友

分类:

2012-07-01 17:22:02

默认uboot是按下任意键停止autoboot,有人觉得不爽,害怕终端操作用户误操作,要指定特殊按键
这个功能很简单,例如要按下ESC键,停止自动boot
只需要添加
  1. #define CONFIG_AUTOBOOT_KEYED 1
  2. #define CONFIG_AUTOBOOT_PROMPT "Press ESC to abort autoboot in %d seconds"
  3. #define CONFIG_AUTOBOOT_DELAY_STR "linux"
  4. #define CONFIG_AUTOBOOT_STOP_STR "\x1b"
即可,0x1B就是ESC的ascii码

在2008.10等高版本uboot上这样做就可以了,低版本的倒计时有些问题,以下是我在uboot1.3.4上的修改
  1. #if defined(CONFIG_BOOTDELAY) && (CONFIG_BOOTDELAY >= 0)
  2. # if defined(CONFIG_AUTOBOOT_KEYED)
  3. static __inline__ int abortboot(int bootdelay)
  4. {
  5.     int abort = 0;
  6.     unsigned int start_tick = get_ticks();
  7.     uint64_t t1=endtick(1);

  8.     uint64_t etime = endtick(bootdelay);
  9.     struct {
  10.         char* str;
  11.         u_int len;
  12.         int retry;
  13.     }
  14.     delaykey [] = {
  15.         { str: getenv ("bootdelaykey"), retry: 1 },
  16.         { str: getenv ("bootdelaykey2"), retry: 1 },
  17.         { str: getenv ("bootstopkey"), retry: 0 },
  18.         { str: getenv ("bootstopkey2"), retry: 0 },
  19.     };

  20.     char presskey [MAX_DELAY_STOP_STR];
  21.     u_int presskey_len = 0;
  22.     u_int presskey_max = 0;
  23.     u_int i;

  24. # ifdef CONFIG_AUTOBOOT_PROMPT
  25.     printf(CONFIG_AUTOBOOT_PROMPT,bootdelay);
  26.     printf("\b\b\b\b\b\b\b\b\b");
  27. # endif

  28. # ifdef CONFIG_AUTOBOOT_DELAY_STR
  29.     if (delaykey[0].str == NULL)
  30.         delaykey[0].str = CONFIG_AUTOBOOT_DELAY_STR;
  31. # endif
  32. # ifdef CONFIG_AUTOBOOT_DELAY_STR2
  33.     if (delaykey[1].str == NULL)
  34.         delaykey[1].str = CONFIG_AUTOBOOT_DELAY_STR2;
  35. # endif
  36. # ifdef CONFIG_AUTOBOOT_STOP_STR
  37.     if (delaykey[2].str == NULL)
  38.         delaykey[2].str = CONFIG_AUTOBOOT_STOP_STR;
  39. # endif
  40. # ifdef CONFIG_AUTOBOOT_STOP_STR2
  41.     if (delaykey[3].str == NULL)
  42.         delaykey[3].str = CONFIG_AUTOBOOT_STOP_STR2;
  43. # endif

  44.     for (i = 0; i < sizeof(delaykey) / sizeof(delaykey[0]); i ++) {
  45.         delaykey[i].len = delaykey[i].str == NULL ?
  46.                  0 : strlen (delaykey[i].str);
  47.         delaykey[i].len = delaykey[i].len > MAX_DELAY_STOP_STR ?
  48.                  MAX_DELAY_STOP_STR : delaykey[i].len;

  49.         presskey_max = presskey_max > delaykey[i].len ?
  50.                  presskey_max : delaykey[i].len;

  51. # if DEBUG_BOOTKEYS
  52.         printf("%s key:<%s>\n",
  53.          delaykey[i].retry ? "delay" : "stop",
  54.          delaykey[i].str ? delaykey[i].str : "NULL");
  55. # endif
  56.     }

  57.     /* In order to keep up with incoming data, check timeout only
  58.      * when catch up.
  59.      */

  60.     while (!abort && get_ticks() <= etime) {
  61.         for (i = 0; i < sizeof(delaykey) / sizeof(delaykey[0]); i ++) {
  62.             if (delaykey[i].len > 0 &&
  63.              presskey_len >= delaykey[i].len &&
  64.              memcmp (presskey + presskey_len - delaykey[i].len,
  65.                  delaykey[i].str,
  66.                  delaykey[i].len) == 0) {
  67. # if DEBUG_BOOTKEYS
  68.                 printf("got %skey\n",
  69.                  delaykey[i].retry ? "delay" : "stop");
  70. # endif

  71. # ifdef CONFIG_BOOT_RETRY_TIME
  72.                 /* don't retry auto boot */
  73.                 if (! delaykey[i].retry)
  74.                     retry_time = -1;
  75. # endif
  76.                 abort = 1;
  77.                 printf("\n");
  78.             }
  79.         }
  80.         
  81.         if(get_ticks() > t1)
  82.         {
  83.             bootdelay--;
  84.             printf("%d\b",bootdelay);
  85.               
  86.              t1=endtick(1);
  87.         }
  88.         
  89.         if (tstc()) {            
  90.             if (presskey_len < presskey_max) {
  91.                 
  92.                 presskey [presskey_len ++] = getc();
  93.             }
  94.             else {
  95.                 for (i = 0; i < presskey_max - 1; i ++)
  96.                     presskey [i] = presskey [i + 1];
  97.                 
  98.                 presskey [i] = getc();
  99.             }
  100.         }
  101.     }
  102. # if DEBUG_BOOTKEYS
  103.     if (!abort)
  104.         puts("key timeout\n");
  105. # endif

  106. #ifdef CONFIG_SILENT_CONSOLE
  107.     if (abort)
  108.         gd->flags &= ~GD_FLG_SILENT;
  109. #endif

  110.     return abort;
  111. }

  112. # else    /* !defined(CONFIG_AUTOBOOT_KEYED) */

阅读(5992) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~