1、在common目录下新增cmd_menu.c文件,内容为:
#include<common.h> #include<command.h> #ifdef CONFIG_MENUKEY static char awaitkey(unsigned longdelay, int* error_p) { int i; charc; if (delay ==-1) { while (1) { if (tstc()) return getc(); } } else { for (i = 0; i < delay; i++) { if (tstc()) returngetc(); udelay (10*1000); } } if(error_p) *error_p = -1; return 0; } voidmain_menu_usage(void) { printf(" *****************luozhiyong***************** "); printf(" ======== User Menu ======== "); printf(" "); printf("[1] 下载 u-boot.bin 写入 Nand Flash "); printf("[2] 下载 Linux(uImage) 内核镜像写入 Nand Flash "); printf("[3] 下载 yaffs2(fs.yaffs) 文件系统镜像写入 Nand Flash "); printf("[4] 下载 Linux(uImage) 内核镜像到内存并运行 "); printf("[5]重启设备 "); printf("[q] 退出菜单 "); printf(" "); printf("输入选择: "); } void menu_shell(void) { charc; charcmd_buf[200]; while (1) { main_menu_usage(); c = awaitkey(-1, NULL); printf("%c ", c); switch (c) { case '1': { strcpy(cmd_buf, "tftp 0x32000000 u-boot.bin; nand erase 0x00x60000; nand write 0x32000000 0x0 0x60000"); run_command(cmd_buf, 0); break; } case '2': { strcpy(cmd_buf, "tftp 0x32000000 uImage; nand erase 0x800000x200000; nand write 0x32000000 0x80000 0x200000"); run_command(cmd_buf, 0); break; } case '3': { strcpy(cmd_buf, "tftp 0x32000000 fs.yaffs; nand erase 0x280000;nand write.yaffs2 0x32000000 0x280000 $(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, intflag, int argc, char *argv[]) { menu_shell(); return0; } U_BOOT_CMD( menu, 1, 0, do_menu, "User Menu", "U-boot Download Menu " ); #endif
2、修改common目录下的Makefile文件,将cmd_menu.o加入编译:
COBJS-y +=main.o COBJS-y +=cmd_menu.o COBJS-y += ACEX1K.o
至此,在终端下输入 menu 就可以看到自己创建的菜单
注:如果要开机自启动,则在main.c的#ifdef CONFIG_AUTO_COMPLETE...#endif句断后加上:
# ifdef CONFIG_MENUKEY
if (menukey == CONFIG_MENUKEY) {
run_command ("menu", 0);
disable_ctrlc(prev);
}else{
run_command (s, 0);
}
#endif /* CONFIG_MENUKEY */
其他相似链接:http://lanyin1225.blog.163.com/blog/static/126261290201281322430504/