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的文件,文件内容如下:
- #include
- #include
- #include
- #include
- extern char console_buffer[];
- extern int readline (const char *const prompt);
- extern char awaitkey(unsigned long delay, int* error_p);
- extern void download_nkbin_to_flash(void);
- /**
- * Parses a string into a number. The number stored at ptr is
- * potentially suffixed with K (for kilobytes, or 1024 bytes),
- * M (for megabytes, or 1048576 bytes), or G (for gigabytes, or
- * 1073741824). If the number is suffixed with K, M, or G, then
- * the return value is the number multiplied by one kilobyte, one
- * megabyte, or one gigabyte, respectively.
- *
- * @param ptr where parse begins
- * @param retptr output pointer to next char after parse completes (output)
- * @return resulting unsigned int
- */
- static unsigned long memsize_parse2 (const char *const ptr, const char **retptr)
- {
- unsigned long ret = simple_strtoul(ptr, (char **)retptr, 0);
- int sixteen = 1;
- switch (**retptr) {
- case 'G':
- case 'g':
- ret <<= 10;
- case 'M':
- case 'm':
- ret <<= 10;
- case 'K':
- case 'k':
- ret <<= 10;
- (*retptr)++;
- sixteen = 0;
- default:
- break;
- }
- if (sixteen)
- return simple_strtoul(ptr, NULL, 16);
-
- return ret;
- }
- void param_menu_usage()
- {
- printf("/r/n##### Parameter Set Menu #####/r/n");
- printf("[v] View the parameters/r/n");
- printf("[s] Set parameter /r/n");
- printf("[d] Delete parameter /r/n");
- printf("[w] Save your parameters to flash memeory /r/n");
- printf("[q] Quit /r/n");
- printf("Enter your selection: ");
- }
- void param_menu_shell(void)
- {
- char c;
- char cmd_buf[256];
- char name_buf[20];
- char val_buf[256];
-
- while (1)
- {
- param_menu_usage();
- c = awaitkey(-1, NULL);
- printf("%c/n", c);
- switch (c)
- {
- case 'v':
- {
- strcpy(cmd_buf, "printenv ");
- printf("Name(Hint:Press 'Enter' to view all paramters): ");
- readline(NULL);
- strcat(cmd_buf, console_buffer);
- run_command(cmd_buf, 0);
- break;
- }
-
- case 's':
- {
- sprintf(cmd_buf, "setenv ");
- printf("Name: ");
- readline(NULL);
- strcat(cmd_buf, console_buffer);
- printf("Value: ");
- readline(NULL);
- strcat(cmd_buf, " ");
- strcat(cmd_buf, console_buffer);
- run_command(cmd_buf, 0);
- break;
- }
-
- case 'd':
- {
- sprintf(cmd_buf, "setenv ");
- printf("Name: ");
- readline(NULL);
- strcat(cmd_buf, console_buffer);
- run_command(cmd_buf, 0);
- break;
- }
-
- case 'w':
- {
- sprintf(cmd_buf, "saveenv");
- run_command(cmd_buf, 0);
- break;
- }
-
- case 'q':
- {
- return;
- break;
- }
- }
- }
- }
- void main_menu_usage(void)
- {
- printf("/r/n##### LT2440 U-Boot -2010.03 #####/r/n");
- printf("/r##### Welcome to Embeded World #####/r/n");
- printf("/r##### designed by: LuTong #####/r/n");
- printf("/r##### www.lt-net.cn #####/r/n");
-
- printf("[u] Download u-boot or STEPLDR.nb1 to Nand Flash/r/n");
- printf("[e] Download e-boot to Nand Flash/r/n");
- if (isNORFlash())
- printf("[n] Download u-boot to Nor Flash/r/n");
- printf("[k] Download Linux Kernel uImage to Nand Flash/r/n");
- #ifdef CONFIG_CMD_JFFS2
- printf("[j] Download JFFS2 Image to Nand Flash/r/n");
- #endif
- printf("[y] Download YAFFS2 Image to Nand Flash/r/n");
- printf("[g] Download to SDRAM and Run /r/n");
- printf("[d] Download Linux Kernel to SDRAM and RUN/r/n");
- printf("[f] Format the Nand Flash/r/n");
- printf("[l] Low-level Format the entire Nand Flash/r/n");
- printf("[s] Set the boot parameters/r/n");
- printf("[b] Boot the system/r/n");
- printf("[r] Reboot U-Boot/r/n");
- printf("[q] Quit from menu/r/n");
- printf("Enter your selection: ");
- }
- void menu_shell(void)
- {
- char c;
- char cmd_buf[200];
- char *p = NULL;
- unsigned long size;
- unsigned long offset;
- struct mtd_info *mtd = &nand_info[nand_curr_device];
- while (1)
- {
- main_menu_usage();
- c = awaitkey(-1, NULL);
- printf("%c/n", c);
- switch (c)
- {
- case 'u':
- {
- strcpy(cmd_buf, "usbslave 1 0x3000a000; nand erase 0x0; nand write 0x3000a000 0x0 0x60000");
- run_command(cmd_buf, 0);
- break;
- }
- case 'n':
- {
- if (isNORFlash())
- {
- strcpy(cmd_buf, "usbslave 1 0x3000a000; protect off all; erase 0 5FFFF; cp.b 0x3000a000 0 $(filesize)");
- run_command(cmd_buf, 0);
- }
- break;
- }
- case 'e':
- {
- strcpy(cmd_buf, "usbslave 1 0x3000a000; nand erase 80000 80000; nand write 0x3000a000 80000 80000 ");
- run_command(cmd_buf, 0);
- break;
- }
-
- case 'k':
- {
- strcpy(cmd_buf, "usbslave 1 0x3000a000; nand erase 0x100000 0x300000 ; nand write 0x3000a0000 x100000 0x300000");
- run_command(cmd_buf, 0);
- break;
- }
- #if 0
- case 'j':
- {
- strcpy(cmd_buf, "usbslave 1 0x30008000; nand erase jffs2; nand write.jffs2 0x30008000 jffs2 $(filesize)");
- run_command(cmd_buf, 0);
- break;
- }
- #endif
- case 'y':
- {
- strcpy(cmd_buf, "usbslave 1 0x3000a000; nand erase 0x400000 0xFC00000; nand write.yaffs2 0x3000a000 0x400000 $(filesize)");
- run_command(cmd_buf, 0);
- break;
- }
- case 'g':
- {
- extern volatile U32 downloadAddress;
- extern int download_run;
-
- download_run = 1;
- strcpy(cmd_buf, "usbslave 1");
- run_command(cmd_buf, 0);
- download_run = 0;
- sprintf(cmd_buf, "go %x", downloadAddress);
- run_command(cmd_buf, 0);
- break;
- }
- case 'd':
- {
- strcpy(cmd_buf, "usbslave 1 0x3000a000;bootm 0x3000a000");
- run_command(cmd_buf, 0);
- }
- case 'b':
- {
- printf("Booting Linux Nand Flash/n");
- strcpy(cmd_buf, "nand read.jffs2 0x3000a000 0x100000 0x300000; bootm 0x3000a000");
- run_command(cmd_buf, 0);
- break;
- }
- case 'f':
- {
- strcpy(cmd_buf, "nand erase ");
- printf("Start address: ");
- readline(NULL);
- strcat(cmd_buf, console_buffer);
- printf("Size(eg. 4000000, 0x4000000, 64m and so on): ");
- readline(NULL);
- p = console_buffer;
- size = memsize_parse2(p, &p);
- sprintf(console_buffer, " %x", size);
- strcat(cmd_buf, console_buffer);
- run_command(cmd_buf, 0);
- break;
- }
- case 's':
- {
- param_menu_shell();
- break;
- }
- case 'l':
- {
- printf("Warning : the whole nand flash will be erased ,press y to erase ,any other key to return!");
- c = awaitkey(-1, NULL);
- if(c=='y')
- {
- strcpy(cmd_buf, "nand scrub");
- run_command(cmd_buf, 0);
- }
- break;
- }
- case 'r':
- {
- strcpy(cmd_buf, "reset");
- run_command(cmd_buf, 0);
- break;
- }
-
- case 'q':
- {
- return;
- break;
- }
- }
-
- }
- }
- int do_menu (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
- {
- menu_shell();
- return 0;
- }
- U_BOOT_CMD(
- menu, 3, 0, do_menu,
- "menu - display a menu, to select the items to do something/n",
- " - display a menu, to select the items to do something"
- );
复制代码
修改当前目录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上的移植详解 (九)