本章来分析u-boot的快捷菜单
FriendlyARMMenu在main.c函数的main_loop ()中被调用:
{
void FriendlyARMMenu(void);
FriendlyARMMenu();
}
FriendlyARMMenu() 源码如下:
void FriendlyARMMenu(void)
{
char cmd_buf[300];
while(1) {
int c;
printf("##### FriendlyARM U-Boot(" RELEASE_MARK ") for 2440 #####\n");
printf("[f] Format the nand flash\n");
printf("[v] Download u-boot.bin\n");
printf("[k] Download Linux kernel\n");
printf("[y] Download root yaffs2 image\n");
printf("[a] Download Absolute User Application\n");
printf("[s] Set the boot parameter of Linux\n");
printf("[b] Boot Linux\n");
printf("[r] Reboot\n");
//printf("[d] Download and Run\n");
printf("[q] Quit to shell\n");
printf("Enter your Selection:");
c = getc();
printf("%c\n", c >= ' ' && c <= 127 ? c : ' ');
switch(c) {
case 'F': case 'f':
strcpy(cmd_buf, "nand erase");
run_command(cmd_buf, 0);
break;
case 'V': case 'v':
strcpy(cmd_buf, "usbslave 1 30000000; nand erase 0 40000; nand write.i 30000000 0 $(filesize_aligned);saveenv");
run_command(cmd_buf, 0);
break;
case 'K': case 'k':
strcpy(cmd_buf, "usbslave 1 30000000; nand erase 60000 500000; nand write.i 30000000 60000 $(filesize_aligned);saveenv");
run_command(cmd_buf, 0);
break;
case 'Y': case 'y':
strcpy(cmd_buf, "usbslave 1 30000000; nand erase 560000; nand write.yaffs 30000000 560000 $(filesize)");
run_command(cmd_buf, 0);
break;
case 'A': case 'a':
strcpy(cmd_buf, "usbslave 1 30000000; nand erase; nand write.i 30000000 0 $(filesize_aligned)");
run_command(cmd_buf, 0);
break;
case 'S': case 's':
strcpy(cmd_buf, "askenv bootargs \"linux cmd line:\" 200;saveenv");
run_command(cmd_buf, 0);
break;
case 'D': case 'd':
strcpy(cmd_buf, "usbslave 1 30000000; go 30000000");
run_command(cmd_buf, 0);
break;
case 'B': case 'b': case 'R': case 'r':
strcpy(cmd_buf, "reset");
run_command(cmd_buf, 0);
while(1);
case 'Q': case 'q':
return;
default:
;
}
}
}
1、分析 “[v] Download u-boot.bin\n"这条命令的执行过程:
strcpy(cmd_buf, "usbslave 1 30000000; nand erase 0 40000; nand write.i 30000000 0 $(filesize_aligned);saveenv");
usbslave 1 30000000;这条指令是把usb接收发送的数据下载到0x30000000。
nand erase 0 40000;这条指令是擦除内核分区0~0x00040000地址的数据。
nand write.i 30000000 0 $ (filesize_aligned); 这条指令是将0x30000000地址开始( $ (filesize_aligned) 大小的文件)烧写到nand flash内核分区中 0~$(filesize_aligned)地址空间中去。
saveenv这条指令是保存当前环境变量到nandflash。
2、分析 “[k] Download Linux kernel\n"这条命令的执行过程:
strcpy(cmd_buf, "usbslave 1 30000000; nand erase 60000 500000; nand write.i 30000000 60000 $(filesize_aligned);saveenv");
usbslave 1 30000000;这条指令是把usb接收发送的数据下载到0x30000000。
nand erase 60000 500000;这条指令是擦除内核分区60000~0x560000地址的数据(擦除60000 地址后面500000个地址数据)。
nand write.i 30000000 60000 $ (filesize_aligned); 这条指令是将0x30000000地址开始( $ (filesize_aligned) 大小的文件)烧写到nand flash内核分区中 60000 ~$(filesize_aligned)地址空间中去。
saveenv这条指令是保存当前环境变量到nandflash。
3、run_command(cmd_buf, 0);
通过run_command()函数运行strcpy拷贝到cmd_buf中的指令。
例如:"usbslave 1 30000000; nand erase 60000 500000; nand write.i 30000000 60000 $(filesize_aligned);saveenv"
这条指令,由run_command解析并且执行。