⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 btldr_ui.c~

📁 针对德州仪器DM270开发板的bootloader,其实现了内核的下载以及文件系统的下载
💻 C~
📖 第 1 页 / 共 4 页
字号:
            case 'p':            case 'P':              *dest = sd_PARPORT;              return 1;              break;            default:              return 0; // Failed.              break;          }        }      }    }  }  return 0; // Failed.}/****************************** Routine: Description: ******************************/static int find_format(port_format_t *format, char *line){  int i,j;  for (i=0; i<util_strlen(line); i++) {    if ('-' == line[i]) {      if ('f' == line[i+1]) {        // we found the "-f", now find the token that follows.        for (j=i+2; j<util_strlen(line); j++) {          if (' ' == line[j]) continue;          // Found the start of next token. Luckily          // the first character is all we really need.          switch (line[j]) {            case 'n':            case 'N':              *format = f_NA;              return 1;              break;            case 's':            case 'S':              *format = f_SREC;              return 1;              break;            case 'r':            case 'R':              *format = f_RR_BINARY;              return 1;              break;            default:              return 0; // Failed.              break;          }        }      }    }  }  return 0; // Failed.}/****************************** Routine: Description:   Usage: copy -c <comp> -s <src> -d <dest> -f <format>   Examples: copy -c kernel -s ser -d ram -f srec             copy -c kernel -s par -d ram -f rrbin             copy -c filesys -s ether -d ram -f srec             copy -c filesys -s ram -d flash -f na             copy -c kernel -s flash -d ram -f na             ..etc.. ******************************/static void do_copy_command(char *line){  comp_t comp;  src_dest_t src;  src_dest_t dest;  port_format_t format;  int ret = 0;  if (!find_comp(&comp,line)) {    invalid_command();    return;  }  if (!find_src(&src,line)) {    invalid_command();    return;  }  if (!find_dest(&dest,line)) {    invalid_command();    return;  }  if (!find_format(&format,line)) {    invalid_command();    return;  }  meter_line_len = 0;  ret = cmd_copy_comp(comp,src,dest,format,progress_meter,METER_INTERV);  if (ret != 0) {    util_printf("\nWarning: flash write error - flash not erased; Aborting\n");    util_printf("Press <Enter>....\n");    util_gets(cmd,CMDMAX);      }}#ifndef BSPCONF_BTLDR_NO_MENUS/****************************** Routine: Description: ******************************/static void do_help_command(void){  util_printf(" help - Displays this report.\n");  util_printf(" menu - Switch to menu base UI.\n");  util_printf(" boot      - Boots the kernel. The kernel\n");  util_printf("             choosen is the one loaded in ram\n");  util_printf("             otherwise the XIP one in Flash.\n");  util_printf(" boot_auto - Boots the kernel. The kernel\n");  util_printf("             choosen is the one loaded in ram\n");  util_printf("             unless there isn't one, in which\n");  util_printf("             case the one in flash is used. The\n");  util_printf("             boot operation will automatically xfer\n");  util_printf("             the kernel and/or filesystem from\n");  util_printf("             flash to ram only *if* needed prior to\n");  util_printf("             jumping to the kernel. No xfer takes\n");  util_printf("             place for XIP components in flash.\n");  util_printf(" def  - Runs the \"default boot cmd\"\n");  util_printf(" set  - By itself, shows current settings.\n");  util_printf("        To change a setting use following form:\n");  util_printf(" set [param] [value]\n");  util_printf("        param       | Typical Value  \n");  util_printf("        ------------+--------------  \n");  util_printf("        mode        | menu or cmd    \n");  util_printf("        bootcmd     | copy -c k -s e -d r -f rrbin; boot\n");  util_printf("        loadfmt     | srec or rrbin  \n");  util_printf("        loadport    | ser par or eth \n");  util_printf("        consoleport | ser par or usb \n");  util_printf("        serverip    | nn.nn.nn.nn    \n");  util_printf("        servermac   | nn:nn:nn:nn:nn:nn\n");  util_printf("        devip       | nn.nn.nn.nn    \n");  util_printf("        devmac      | nn:nn:nn:nn:nn:nn\n");  util_printf("        kpath       |                \n");  util_printf("        fpath       |                \n");#if defined(DSC24_OSD)  util_printf("        opath       |                \n");  util_printf("        osdenable   | yes or no      \n");#endif  util_printf("        kcmdline    |                \n");  util_printf(" copy -c [comp] -s [src] -d [dest] -f [format]\n");  util_printf("        Tells bootloader to copy comp image from src to dest.\n");  util_printf("        where comp = [b]ootldr | [p]arams | [k]ernel | [f]ilesys\n");  util_printf("        where src&dest = [r]am | [f]lash | [e]ther | [s]erial | [p]ar\n");  util_printf("        where format = [n]otapplicable | [s]rec | [r]rbin\n");  util_printf(" eraseflash [comp]\n");  util_printf("        where comp = [b]ootldr | [p]arams | [k]ernel | [f]ilesys | [a]ll\n");}#endif/****************************** Routine: Description: ******************************/#ifdef BSPCONF_BTLDR_FLASH_DEBUGstatic void sector_erase_flash(void){  int err;  int addr=0;  while (1) {    clear();    util_printf(  "Erase Flash Sector\n");    util_printf(  "-----------------------\n");    util_printf(  "          0. --to Erase Menu--\n"       );    util_printf(  "  <address>. Hex address in the sector to be erased\n");    util_printf(  "\n"                       );    util_printf(  "  Which? "                );        util_gets(cmd,CMDMAX);    err=util_hexstrtoint(cmd, &addr);    if (! err) {      if ( addr == 0 ) return;      util_printf("Are you sure? ");      util_gets(cmd,CMDMAX);      if (('y' == cmd[0]) || ('Y' == cmd[0])) {	flash_erase_range(addr, addr);	util_printf("Press enter to continue");	util_gets(cmd,CMDMAX);      }    }    else {      util_printf( "\n\nInvalid hexidemical number (use 0-9, A-F, a-f): %s\n",		   cmd);      util_printf(  "Press enter to continue");      util_gets(cmd,CMDMAX);    }  }}#endif#ifndef BSPCONF_BTLDR_NO_MENUS/****************************** Routine: Description: ******************************/static void do_erase_flash(void){  while (1) {    clear();    util_printf(  "Erase [comp] from Flash\n");    util_printf(  "-----------------------\n");    util_printf(  "  0. --to MAIN--\n"       );    util_printf(  "  1. Erase [BootLoader]\n");    util_printf(  "  2. Erase [Params]\n"    );    util_printf(  "  3. Erase [Kernel]\n"    );    util_printf(  "  4. Erase [FileSys]\n"   );#ifdef REPLACE_VECTOR_TABLE    util_printf(  "  5. Erase [Vector table]\n");    util_printf(  "  6. Erase ALL\n"         );#else    util_printf(  "  5. Erase ALL\n"         );#endif#ifdef BSPCONF_BTLDR_FLASH_DEBUG    util_printf(  "  s. Erase sector\n"      );#endif    util_printf(  "\n"                       );    util_printf(  "  Which? "                );        util_gets(cmd,CMDMAX);    switch (cmd[0]) {      case '0': return; break;      case '1':        util_printf("Are you sure? ");        util_gets(cmd,CMDMAX);        if (('y' == cmd[0]) || ('Y' == cmd[0])) { erase_comp(c_BOOTLDR); }        break;      case '2':        util_printf("Are you sure? ");        util_gets(cmd,CMDMAX);        if (('y' == cmd[0]) || ('Y' == cmd[0])) { erase_comp(c_PARAMS); }        break;      case '3':        util_printf("Are you sure? ");        util_gets(cmd,CMDMAX);        if (('y' == cmd[0]) || ('Y' == cmd[0])) { erase_comp(c_KERNEL); }        break;      case '4':        util_printf("Are you sure? ");        util_gets(cmd,CMDMAX);        if (('y' == cmd[0]) || ('Y' == cmd[0])) { erase_comp(c_FILESYS); }        break;#ifdef REPLACE_VECTOR_TABLE      case '5':              util_printf("Are you sure? ");              util_gets(cmd,CMDMAX);              if (('y' == cmd[0]) || ('Y' == cmd[0])) { erase_comp(c_VECTORS); }              break;                  case 6:#else      case '5':#endif        util_printf("Are you sure? ");        util_gets(cmd,CMDMAX);        if (('y' == cmd[0]) || ('Y' == cmd[0])) { flash_erase(); }        break;#ifdef BSPCONF_BTLDR_FLASH_DEBUG      case 's':      case 'S':	sector_erase_flash();	break;#endif      default : break;    }  }}#endif/****************************** Routine: Description: ******************************/static void top_level_parse(unsigned char *cmd){  // Remember, the cmd we receive may actually be several  // seperated by ';'. (e.g cmd1; cmd2; cmd3; cmd4). We'll  // accept a max number of these and treat each one as a  // separate command executed in the order encountered.  #define MAXCMDS 10  /* best guess at a realistic limit. */  #define MAXLEN  100 /* best guess at a realistic limit. */  unsigned char cmd_copy[MAXLEN];  unsigned char *cmds_list[MAXCMDS];  unsigned char *a_cmd;  int i, cmd_i;  // First, get a writable copy of supplied cmd.  util_strncpy(cmd_copy,cmd,MAXLEN);  for (i=0; i<MAXCMDS; i++) cmds_list[i]=NULL;  cmd_i = 0;  cmds_list[cmd_i] = cmd_copy; // record the first, and maybe only, command.  // Next, identify the others, if any.  for (i=1; i<util_strlen(cmd); i++) {    if (';' == cmd_copy[i]) {      if ('\\' == cmd_copy[i-1]) {        // since the user has supplied a '\' prior to the ';' we'll take this        // to mean than this ';' is part of the command and not a command separator        // so we'll replace it with a space and continue looking for the next real        // ';' which is a command separator. Take for example the following user        // command: "set bootcmd copy -c k -s f -d r -f n\; boot",        // which is all one command and if the user hadn't escaped the ';' then        // it would look like two commands separated by a ';'.        cmd_copy[i-1] = ' ';      }      else {        // We've located the end of a command.        cmd_copy[i] = 0; // terminate that cmd string...        cmd_i++;        i++;        while (' ' == cmd_copy[i]) { i++; } // eat up any spaces to next cmd.        cmds_list[cmd_i] = &(cmd_copy[i]); // ...and record the start of next cmd.      }    }  }  // okay, execute each one.  for (i=0; i<MAXCMDS; i++) {    if (NULL == cmds_list[i]) break;    a_cmd = cmds_list[i];    util_printf("\n%s\n",a_cmd);    if (0 == util_strncmp("5",a_cmd,util_strlen("5"))) {      // Special case to support `chat`, for those that want      // to use it to drive the UI automatically. Whether      // the bootloader comes up in menu mode or command      // line mode, in either case, if `chat` sends a "5      // <cr>" sequence to the UI it will put the bootloader      // in command line mode (if not already there) and      // cause the bootloader to respond with a burst of      // chars the last seven of which will be the command      // line prompt string ("rrload> "). From that point on      // `chat` is synchronize and all furthur `chat` dialog      // will be to the bootloader's command line interface.      // note: the key point here is that this was      // accomplished without `chat` needing to be aware of      // which mode (command/menu) the bootloader came up      // in. Also, "5" was picked here intentionally to      // match the entry on the top level of the menu mode      // screen; recall that "5" at the top level menu takes      // you to command line mode. If that number ever changes,      // we'll have to adapt here as well.      return;    }    else if (0 == util_strncmp("menu",a_cmd,util_strlen("menu"))) {      UI_mode = 0; // setup to exit cmdline mode.    }    else if (0 == util_strncmp("boot_auto",a_cmd,util_strlen("boot_auto"))) {      cmd_boot_kernel(TRUE,progress_meter,METER_INTERV);    }    else if (0 == util_strncmp("boot",a_cmd,util_strlen("boot"))) {      cmd_boot_kernel(FALSE,progress_meter,METER_INTERV);    }    else if (0 == util_strncmp("def",a_cmd,util_strlen("def"))) {      process_default_boot_cmd(par->CMD_FIELD); // ... if there is one.    }    else if (0 == util_strncmp("set",a_cmd,util_strlen("set"))) {      do_set_command(a_cmd+(util_strlen("set")));    }    else if (0 == util_strncmp("copy",a_cmd,util_strlen("copy"))) {      do_copy_command(a_cmd+(util_strlen("copy")));    }    else if (0 == util_strncmp("eraseflash",a_cmd,util_strlen("eraseflash"))) {      do_erase_flash_cmd(a_cmd+(util_strlen("eraseflash")));    }#ifndef BSPCONF_BTLDR_NO_MENUS    else if (0 == util_strncmp("help",a_cmd,util_strlen("help"))) {      do_help_command();    }#endif    else if (0 == util_strncmp("version",a_cmd,util_strlen("version"))) {      util_printf(" ** version %s **", RRLOAD_VERSION);    }    else {      if (util_strlen(a_cmd) > 0) {        invalid_command();      }    }  }}/****************************** Routine: Description: ******************************/static void cmd_line_mode(void){  #define LEN 100  unsigned char cmd[LEN];  clear();  util_printf(  "Command Line Mode\n"            );  util_printf(  "-----------------\n"            );  util_printf(  "\n"                             );#ifndef BSPCONF_BTLDR_NO_MENUS  util_printf(  "  \"help\" -- for help.\n"      );  util_printf(  "  \"menu\" -- for Menu Mode\n"  );#endif  util_printf(  "\n"                             );  while ('C' == UI_mode) {    util_printf("\nrrload> ");    util_gets(cmd,LEN);    util_strip_CRLF(cmd);    top_level_parse(cmd);  }}#ifndef BSPCONF_BTLDR_NO_MENUS/****************************** Routine: Description: ******************************/static void params_edit_menu(void){  while (1) {    clear();    util_printf(  "View/Edit Params\n"                                 );    util_printf(  "----------------\n"                                 );    util_printf(  "  0. --to MAIN--\n"                                 );    util_printf(  "  1. ui mode [cmd|menu]  : %s\n",par->MODE_FIELD    );    util_printf(  "  2. default boot cmd    : %s\n",par->CMD_FIELD     );    util_printf(  "  3. I/O load format     : %s\n",par->FORMAT_FIELD  );    util_printf(  "  4. I/O load port       : %s\n",par->PORT_FIELD    );    util_printf(  "  5. console port        : %s\n",par->CON_FIELD     );    util_printf(  "                             \n");    util_printf(  " Linux Settings              \n");    util_printf(  "  6. Kernel cmdline      : %s\n",par->kernel_cmdline);    util_printf(  "  7. Device MAC          : %s\n",par->device_MAC    );    util_printf(  "                             \n");    util_printf(  " rrload TFTP Settings        \n");    util_printf(  "  8. Server IP    (tftp) : %s\n",par->server_IP     );    util_printf(  "  9. Server MAC   (tftp) : %s\n",par->server_MAC    );    util_printf(  "  a. Device IP    (tftp) : %s\n",par->device_IP     );    util_printf(  "  b. Kernal Path  (tftp) : %s\n",par->kernel_path   );    util_printf(  "  c. FileSys Path (tftp) : %s\n",par->filesys_path  );#if defined(DSC24_OSD)    util_printf(  "  d. OSD Img Path (tftp) : %s\n",par->OSD_path  );    util_printf(  "                             \n");    util_printf(  " OnScreenDisplay (OSD) Logo Settings           \n");    util_printf(  "  e. Enable OSD          : %s\n",par->OSD_enable    );#endif    util_printf(  "\n"                                                 );    util_printf(  "  Edit Which? "                                     );    util_gets(cmd,CMDMAX);    switch (cmd[0]) {      case '0':        return;        break;      case '1':        util_printf("new val = ");        util_gets(par->MODE_FIELD, par->MAX_STR_LEN);        util_strip_CRLF(par->MODE_FIELD);        break;      case '2':        util_printf("new val = ");        util_gets(par->CMD_FIELD, par->MAX_STR_LEN);        util_strip_CRLF(par->CMD_FIELD);        break;      case '3':        util_printf("new val = ");        util_gets(par->FORMAT_FIELD, par->MAX_STR_LEN);        util_strip_CRLF(par->FORMAT_FIELD);        break;      case '4':        util_printf("new val = ");        util_gets(par->PORT_FIELD, par->MAX_STR_LEN);        util_strip_CRLF(par->PORT_FIELD);        break;      case '5':        util_printf("new val = ");        util_gets(par->CON_FIELD, par->MAX_STR_LEN);        util_strip_CRLF(par->CON_FIELD);        switch (par->CON_FIELD[0]) {          case 'S':          case 's':            io_change_con(SER);            break;          case 'P':          case 'p':            io_change_con(PAR);            break;#ifdef USE_USB          case 'U':

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -