u-boot-2010.03在LT2440上的移植详解 (八)

来源:互联网 发布:绿色傲剑数据 编辑:程序博客网 时间:2024/04/28 02:59

u-boot-2010.03在LT2440上的移植详解 (八)

郑重声明,这系列文章改写自博客园 黄刚先生的《嵌入式Linux之我行——u-boot-2009.08在2440上的移植详解》

转载时请注明出处

文章出处:http://www.lt-net.cn

编译系统Ubuntu10.04交叉编译器arm-linux-gcc 4.3.3硬件设备LT2440开发板  测试软件u-boot-2010.03依赖库无

uboot下载地址:http://ftp.denx.de/pub/u-boot/u-boot-2010.03.tar.bz2

本次移植在u-boot-2010.03原有功能的基础上增加如下特性:

  1.支持2KB  page Nand Flash读写
  2.支持Nand/Nor Flash启动自动识别
  3.支持DM9000AEP 10M/100M自适应网卡
  4.支持yaffs文件系统烧写
  5.支持USB下载功能
  6.支持一键式菜单
  7.支持启动Logo
  8.支持ubifs(待续)

上接:u-boot-2010.03在LT2440上的移植详解 (七)


支持一键式下载菜单,菜单的条目您可以自由添加,效果如下:

#####      LT2440 U-Boot -2010.03                 #####
#####     Welcome to Embeded World                #####
#####                        designed by: LuTong  #####
#####                        www.lt-net.cn        #####
Download u-boot or STEPLDR.nb1 to Nand Flash
[e] Download e-boot to Nand Flash
[n] Download u-boot to Nor Flash
[k] Download Linux Kernel uImage to Nand Flash
[y] Download YAFFS2 Image to Nand Flash
[g] Download to SDRAM and Run
[d] Download Linux Kernel to SDRAM and RUN
[f] Format the Nand Flash
[l] Low-level Format the entire Nand Flash
Set the boot parameters
Boot the system
[r] Reboot U-Boot
[q] Quit from menu
Enter your selection:


首先我们增加一个menu菜单命令,需要增加一个cmd_menu.c的文件,文件内容如下:

  1. #include <common.h>
  2. #include <command.h>
  3. #include <def.h>
  4. #include <nand.h>
  5. extern char console_buffer[];
  6. extern int readline (const char *const prompt);
  7. extern char awaitkey(unsigned long delay, int* error_p);
  8. extern void download_nkbin_to_flash(void);
  9. /**
  10. * Parses a string into a number.  The number stored at ptr is
  11. * potentially suffixed with K (for kilobytes, or 1024 bytes),
  12. * M (for megabytes, or 1048576 bytes), or G (for gigabytes, or
  13. * 1073741824).  If the number is suffixed with K, M, or G, then
  14. * the return value is the number multiplied by one kilobyte, one
  15. * megabyte, or one gigabyte, respectively.
  16. *
  17. * @param ptr where parse begins
  18. * @param retptr output pointer to next char after parse completes (output)
  19. * @return resulting unsigned int
  20. */
  21. static unsigned long memsize_parse2 (const char *const ptr, const char **retptr)
  22. {
  23. unsigned long ret = simple_strtoul(ptr, (char **)retptr, 0);
  24.     int sixteen = 1;
  25. switch (**retptr) {
  26.   case 'G':
  27.   case 'g':
  28.    ret <<= 10;
  29.   case 'M':
  30.   case 'm':
  31.    ret <<= 10;
  32.   case 'K':
  33.   case 'k':
  34.    ret <<= 10;
  35.    (*retptr)++;
  36.             sixteen = 0;
  37.   default:
  38.    break;
  39. }
  40.     if (sixteen)
  41.         return simple_strtoul(ptr, NULL, 16);
  42.    
  43. return ret;
  44. }
  45. void param_menu_usage()
  46. {
  47.     printf("/r/n##### Parameter Set Menu #####/r/n");
  48.     printf("[v] View the parameters/r/n");
  49.     printf("[s] Set parameter /r/n");
  50.     printf("[d] Delete parameter /r/n");
  51.     printf("[w] Save your  parameters to flash memeory /r/n");
  52.     printf("[q] Quit /r/n");
  53.     printf("Enter your selection: ");
  54. }
  55. void param_menu_shell(void)
  56. {
  57.     char c;
  58.     char cmd_buf[256];
  59.     char name_buf[20];
  60.     char val_buf[256];
  61.    
  62.     while (1)
  63.     {
  64.         param_menu_usage();
  65.         c = awaitkey(-1, NULL);
  66.         printf("%c/n", c);
  67.         switch (c)
  68.         {
  69.             case 'v':
  70.             {
  71.                 strcpy(cmd_buf, "printenv ");
  72.                 printf("Name(Hint:Press 'Enter' to view all paramters): ");
  73.                 readline(NULL);
  74.                 strcat(cmd_buf, console_buffer);
  75.                 run_command(cmd_buf, 0);
  76.                 break;
  77.             }
  78.             
  79.             case 's':
  80.             {
  81.                 sprintf(cmd_buf, "setenv ");
  82.                 printf("Name: ");
  83.                 readline(NULL);
  84.                 strcat(cmd_buf, console_buffer);
  85.                 printf("Value: ");
  86.                 readline(NULL);
  87.                 strcat(cmd_buf, " ");
  88.                 strcat(cmd_buf, console_buffer);
  89.                 run_command(cmd_buf, 0);
  90.                 break;
  91.             }
  92.             
  93.             case 'd':
  94.             {
  95.                 sprintf(cmd_buf, "setenv ");
  96.                 printf("Name: ");
  97.                 readline(NULL);
  98.                 strcat(cmd_buf, console_buffer);
  99.                 run_command(cmd_buf, 0);
  100.                 break;
  101.             }
  102.             
  103.             case 'w':
  104.             {
  105.                 sprintf(cmd_buf, "saveenv");
  106.                 run_command(cmd_buf, 0);
  107.                 break;
  108.             }
  109.             
  110.             case 'q':
  111.             {
  112.                 return;
  113.                 break;
  114.             }
  115.         }
  116.     }
  117. }
  118. void main_menu_usage(void)
  119. {
  120.     printf("/r/n#####      LT2440 U-Boot -2010.03         #####/r/n");
  121.     printf("/r#####     Welcome to Embeded World       #####/r/n");
  122.     printf("/r#####                    designed by: LuTong  #####/r/n");
  123.     printf("/r#####            www.lt-net.cn        #####/r/n");
  124.    
  125.     printf("[u] Download u-boot or STEPLDR.nb1 to Nand Flash/r/n");
  126.     printf("[e] Download e-boot to Nand Flash/r/n");
  127. if (isNORFlash())
  128.     printf("[n] Download u-boot to Nor Flash/r/n");
  129.     printf("[k] Download Linux Kernel uImage to Nand Flash/r/n");
  130. #ifdef CONFIG_CMD_JFFS2
  131.     printf("[j] Download JFFS2  Image to Nand Flash/r/n");
  132. #endif
  133.     printf("[y] Download YAFFS2 Image to Nand Flash/r/n");
  134.     printf("[g] Download to SDRAM and Run /r/n");
  135.     printf("[d] Download Linux Kernel to SDRAM and RUN/r/n");
  136.     printf("[f] Format the Nand Flash/r/n");
  137.     printf("[l] Low-level Format the entire Nand Flash/r/n");
  138.     printf("[s] Set the boot parameters/r/n");
  139.     printf("[b] Boot the system/r/n");
  140.     printf("[r] Reboot U-Boot/r/n");
  141.     printf("[q] Quit from menu/r/n");
  142.     printf("Enter your selection: ");
  143. }
  144. void menu_shell(void)
  145. {
  146.     char c;
  147.     char cmd_buf[200];
  148.     char *p = NULL;
  149.     unsigned long size;
  150.     unsigned long offset;
  151.     struct mtd_info *mtd = &nand_info[nand_curr_device];
  152.     while (1)
  153.     {
  154.         main_menu_usage();
  155.         c = awaitkey(-1, NULL);
  156.         printf("%c/n", c);
  157.         switch (c)
  158.         {
  159.      case 'u':
  160.   {
  161.                  strcpy(cmd_buf, "usbslave 1 0x3000a000; nand erase 0x0; nand write 0x3000a000 0x0  0x60000");
  162.                  run_command(cmd_buf, 0);
  163.                  break;
  164.   }
  165.             case 'n':
  166.             {
  167.                 if (isNORFlash())
  168.                 {
  169.                     strcpy(cmd_buf, "usbslave 1 0x3000a000; protect off all; erase 0 5FFFF; cp.b 0x3000a000  0 $(filesize)");
  170.                     run_command(cmd_buf, 0);
  171.                 }
  172.    break;
  173.             }
  174.      case 'e':
  175.   {
  176.                  strcpy(cmd_buf, "usbslave 1 0x3000a000; nand erase 80000 80000; nand write 0x3000a000 80000 80000 ");
  177.                  run_command(cmd_buf, 0);
  178.                  break;
  179.   }
  180.             
  181.             case 'k':
  182.             {
  183.                 strcpy(cmd_buf, "usbslave 1 0x3000a000; nand erase 0x100000 0x300000 ; nand write 0x3000a0000  x100000  0x300000");
  184.                 run_command(cmd_buf, 0);
  185.                 break;
  186.             }
  187. #if 0
  188.             case 'j':
  189.             {
  190.                 strcpy(cmd_buf, "usbslave 1 0x30008000; nand erase jffs2; nand write.jffs2 0x30008000 jffs2 $(filesize)");
  191.                 run_command(cmd_buf, 0);
  192.                 break;
  193.             }
  194. #endif
  195.             case 'y':
  196.             {
  197.                 strcpy(cmd_buf, "usbslave 1 0x3000a000; nand erase 0x400000 0xFC00000; nand write.yaffs2 0x3000a000 0x400000  $(filesize)");
  198.                 run_command(cmd_buf, 0);
  199.                 break;
  200.             }
  201.             case 'g':
  202.             {
  203.                 extern volatile U32 downloadAddress;
  204.                 extern int download_run;
  205.                
  206.                 download_run = 1;
  207.                 strcpy(cmd_buf, "usbslave 1");
  208.                 run_command(cmd_buf, 0);
  209.                 download_run = 0;
  210.                 sprintf(cmd_buf, "go %x", downloadAddress);
  211.                 run_command(cmd_buf, 0);
  212.                 break;
  213.             }
  214.    case 'd':
  215.    {
  216.     strcpy(cmd_buf, "usbslave 1 0x3000a000;bootm 0x3000a000");
  217.     run_command(cmd_buf, 0);
  218.    }
  219.             case 'b':
  220.             {
  221.                 printf("Booting Linux Nand Flash/n");
  222.                 strcpy(cmd_buf, "nand read.jffs2 0x3000a000 0x100000 0x300000; bootm 0x3000a000");
  223.                 run_command(cmd_buf, 0);
  224.                 break;
  225.             }
  226.             case 'f':
  227.             {
  228.                 strcpy(cmd_buf, "nand erase ");
  229.                 printf("Start address: ");
  230.                 readline(NULL);
  231.                 strcat(cmd_buf, console_buffer);
  232.                 printf("Size(eg. 4000000, 0x4000000, 64m and so on): ");
  233.                 readline(NULL);
  234.                 p = console_buffer;
  235.                 size = memsize_parse2(p, &p);
  236.                 sprintf(console_buffer, " %x", size);
  237.                 strcat(cmd_buf, console_buffer);
  238.                 run_command(cmd_buf, 0);
  239.                 break;
  240.             }
  241.             case 's':
  242.             {
  243.                 param_menu_shell();
  244.                 break;
  245.             }
  246.             case 'l':
  247.             {
  248.   printf("Warning : the whole nand flash will be erased ,press y to erase ,any other key to return!");
  249.   c = awaitkey(-1, NULL);
  250.   if(c=='y')
  251.   {
  252.                 strcpy(cmd_buf, "nand scrub");
  253.   run_command(cmd_buf, 0);
  254.   }
  255.                 break;
  256.             }
  257.             case 'r':
  258.             {
  259.     strcpy(cmd_buf, "reset");
  260.     run_command(cmd_buf, 0);
  261.                 break;
  262.             }
  263.             
  264.             case 'q':
  265.             {
  266.                 return;   
  267.                 break;
  268.             }
  269.         }
  270.                
  271.     }
  272. }
  273. int do_menu (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  274. {
  275.     menu_shell();
  276.     return 0;
  277. }
  278. U_BOOT_CMD(
  279. menu, 3, 0, do_menu,
  280. "menu - display a menu, to select the items to do something/n",
  281. " - display a menu, to select the items to do something"
  282. );
复制代码

修改当前目录Makefile
gedit common/Makefile

// 在155行添加如下语句
COBJS-y += cmd_menu.o


为了一启动LT2440就执行菜单命令,需要在开机的过程中执行menu命令,做如下修改

#  gedit common/main.c

 

// 在439行添加如下语句
run_command("menu", 0);


重新编译u-boot,u-boot就支持menu菜单了,运行情况如下:

U-Boot 2010.03 (12鏈?09 2010 - 11:53:28)
DRAM:  64 MB
## Unknown FLASH on Bank 1 - Size = 0x00000000 = 0 MB
Flash:  0 kB
NAND:  256 MiB
In:    serial
Out:   serial
Err:   serial
Net:   dm9000
dm9000 i/o: 0x18000300, id: 0x90000a46
DM9000: running in 16 bit mode
MAC: 08:00:3e:26:0a:5b
#####      LT2440 U-Boot -2010.03                 #####
#####     Welcome to Embeded World                #####
#####                        designed by: LuTong  #####
#####                        www.lt-net.cn        #####
Download u-boot or STEPLDR.nb1 to Nand Flash
[e] Download e-boot to Nand Flash
[k] Download Linux Kernel uImage to Nand Flash
[y] Download YAFFS2 Image to Nand Flash
[g] Download to SDRAM and Run
[d] Download Linux Kernel to SDRAM and RUN
[f] Format the Nand Flash
[l] Low-level Format the entire Nand Flash
Set the boot parameters
Boot the system
[r] Reboot U-Boot
[q] Quit from menu
Enter your selection:


证明添加一键式菜单成功

下接:u-boot-2010.03在LT2440上的移植详解 (九)

原创粉丝点击