分类: 嵌入式
2011-04-17 20:08:51
参考资料:
u-boot-2011.03在TQ2440上的移植(9)--TFTP下载菜单制作1、在common文件夹下添加tftp_menu.c, 内容如下:
#include
#include
static char awaitkey(unsigned long delay, int* error_p)
{
int i;
char c;
if (delay == -1)
{
while (1)
{
if (tstc()) /* we got a key press */
return getc();
}
}
else
{
for (i = 0; i < delay; i++)
{
if (tstc()) /* we got a key press */
return getc();
udelay (10*1000);
}
}
if (error_p)
*error_p = -1;
return 0;
}
void main_menu_usage(void)
{
printf("\r\n---u-boot-tftp-menu---\r\n");
printf("[1] u-boot.bin --> Nand Flash\r\n");
printf("[2] Linux(uImage) --> Nand Flash\r\n");
printf("[3] yaffs2 --> Nand Flash\r\n");
printf("[4] Linux(uImage) --> Ram & Run\r\n");
printf("[5] System Restart\r\n");
printf("[q] quite menu\r\n");
}
void menu_shell(void)
{
char c;
char cmd_buf[200];
while (1)
{
main_menu_usage();
c = awaitkey(-1, NULL);
printf("%c\n", c);
switch (c)
{
case '1':
{
strcpy(cmd_buf, "tftp 0x32000000 u-boot.bin; nand erase 0x0 0x40000; nand write 0x32000000 0x0 0x40000");
run_command(cmd_buf, 0);
break;
}
case '2':
{
strcpy(cmd_buf, "tftp 0x32000000 uImage; nand erase 0x200000 0x500000; nand write 0x32000000 0x200000 0x400000");
run_command(cmd_buf, 0);
break;
}
case '3':
{
strcpy(cmd_buf, "tftp 0x32000000 fs.yaffs2; nand erase 0x400000; nand write.yaffs2 0x32000000 0x400000 $(filesize)");
run_command(cmd_buf, 0);
break;
}
case '4':
{
strcpy(cmd_buf, "tftp 0x32000000 uImage; bootm 0x32000000");
run_command(cmd_buf, 0);
break;
}
case '5':
{
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(
tftp_menu, 1, 0, do_menu,
"Download Menu",
"U-boot Download Menu by Hotips\n"
);
2、修改common下同目录cmd_menu.c的Makefile文件
vi common/Makefile 添加如下一行
COBJS-y += tftp_menu.o
3、make后下载到板子Nandflash 地址0处
启动uboot进入控制台后,输入命令tftp_menu进入菜单如下
4、TFTP工具的使用
Tftpd32可以从网址:下载,解压后运行如下图:
Current Directory 为存放要下载的image的目录
Server interface 为电脑即服务器的ip地址
点击Show Dir如果看见存放在Current Directory路径,证明Tftp已经可用。