u-boot에서 업그레이드 메뉴 만들기

10461 단어
tftp를 이용하여 u-boot에서 시스템 코드 업그레이드 메뉴를 제작하고 프레임워크에서SD카드에 있는 파일을 불러와서 tftp를 대체하여 시스템 프로그램을 빠르게 태우거나 업그레이드할 수 있다(kernel/rootfs/others).
#include <common.h>
#include <command.h>
#include <s_record.h>
#include <net.h>
#include <exports.h>
#include <xyzModem.h>

#include <stdio_dev.h>

#define MACR_OPERATE_CODE	0
#define MACR_UPGRADE_XLOADER	(MACR_OPERATE_CODE+1)
#define MACR_UPGRADE_UBOOT	(MACR_OPERATE_CODE+2)
#define MACR_UPGRADE_KERNAL	(MACR_OPERATE_CODE+3)
#define MACR_UPGRADE_ROOTFS	(MACR_OPERATE_CODE+4)
#define MACR_UPGRADE_EXTFS	(MACR_OPERATE_CODE+5)

#define IS_TRUE	1
#define IS_FALSE	0
#define MACR_MAC_ADDR	0
#define MACR_SERVER_ADDR	1
#define MACR_LOCAL_ADDR	2

static char uboot_version[]={CONFIG_UBOOT_VERSION};
static char ip_set_default_flag[3] = {IS_FALSE,IS_FALSE,IS_FALSE};
static void menu_usage(void)
{
    printf("\r
"); printf("---------XXX System Operate Menu--------\r
"); printf("[r] Reboot system\r
"); printf("[b] Boot system\r
"); printf("[x] Upgrade [x-loader]\r
"); printf("[u] Upgrade [u-boot]\r
"); printf("[k] Upgrade [linux kernel]\r
"); printf("[f] Upgrade [root filesystem]\r
"); #if 0 printf("[e] Upgrade [extended filesystem]\r
"); #endif printf("[v] View the u-boot version\r
"); printf("[q] Quit from menu\r
"); printf("--------------------------------------------\r
"); printf("Select operation by inputting r/b/x,etc..\r
"); printf("\r
"); } static void ip_display(void) { char *s=NULL; s=getenv ("serverip"); if(s) printf("server ip:%s
",s); else printf("server ip is not set !!!
"); s=NULL; s=getenv ("ipaddr"); if(s) printf("client ip:%s
",s); else printf("client ip is not set !!!
"); } static void confirm_display(void) { printf("input 'y' to continue or 'n' to cancel,default is 'n'\r
"); } /*set a group addr info (MAC addr,server ip,local ip) if the ethaddr/server ip/ipaddr env are not set */ static void ip_set_default(void) { #if defined(CONFIG_PRE_SET_IP) if (!getenv ("ethaddr")) { uchar enetaddr[]={CONFIG_DEFAULT_MAC}; setenv("ethaddr",enetaddr); ip_set_default_flag[MACR_MAC_ADDR] = IS_TRUE; } if (!getenv ("serverip")) { uchar serverip[]={CONFIG_DEFAULT_SERVER}; setenv("serverip",serverip); ip_set_default_flag[MACR_SERVER_ADDR] = IS_TRUE; } if (!getenv ("ipaddr")) { uchar clientip[]={CONFIG_DEFAULT_LOCAL}; setenv("ipaddr",clientip); ip_set_default_flag[MACR_LOCAL_ADDR] = IS_TRUE; } #endif } /* restore ethaddr/server ip/ipaddr info which are set by ip_set_default func */ static void ip_restore_org(void) { #if defined(CONFIG_PRE_SET_IP) if(ip_set_default_flag[MACR_MAC_ADDR] == IS_TRUE) { uchar enetaddr[]={""}; setenv("ethaddr",enetaddr); ip_set_default_flag[MACR_MAC_ADDR] = IS_FALSE; } if(ip_set_default_flag[MACR_SERVER_ADDR] == IS_TRUE) { uchar serverip[]={""}; setenv("serverip",serverip); ip_set_default_flag[MACR_SERVER_ADDR] = IS_FALSE; } if(ip_set_default_flag[MACR_LOCAL_ADDR] == IS_TRUE) { uchar clientip[]={""}; setenv("ipaddr",clientip); ip_set_default_flag[MACR_LOCAL_ADDR] = IS_FALSE; } #endif } extern ulong NetBootFileXferSize; static void excute_operation(unsigned char op_code) { signed char result=0; signed char fs_cmd[64]={"nand write.i 0x82000000 "}; signed char temp_buffer[16]; switch(op_code) { case MACR_UPGRADE_XLOADER: run_command("mw.b 0x82000000 0xFF 0x20000",0); result=run_command("tftp MLO",0); if(result==1) { run_command("nand erase 0x00000 0x20000",0); run_command("nandecc hw 2",0); run_command("nand write.i 0x82000000 0x00000 0x20000",0); run_command("nandecc hw 1",0); printf("
** Upgrade x-loader Successfully **
"); } else { printf("
** Upgrade x-loader Error **
"); } break; case MACR_UPGRADE_UBOOT: run_command("mw.b 0x82000000 0xFF 0x80000",0); result=run_command("tftp u-boot.bin",0); if(result==1) { run_command("nand erase 0x80000 0x80000",0); run_command("nandecc hw 2",0); run_command("nand write.i 0x82000000 0x80000 0x80000",0); run_command("nandecc hw 1",0); printf("
** Upgrade U-boot Successfully **
"); } else { printf("
** Upgrade u-boot Error **
"); } break; case MACR_UPGRADE_KERNAL: //run_command("mw.b 0x82000000 0xFF 0x400000",0); result=run_command("tftp uImage",0); if(result==1) { run_command("nand erase 0x280000 0x400000",0); run_command("nandecc hw 1",0); run_command("nand write.i 0x82000000 0x280000 0x400000",0); printf("
** Upgrade Linux kernel Successfully **
"); } else { printf("
** Upgrade Linux kernel Error **
"); } break; #if 0 case MACR_UPGRADE_EXTFS: printf("
Upgrade Extended filesystem may take some time, waiting ......

"); //run_command("mw.b 0x82000000 0xFF 0x10000000",0); result=run_command("tftp RFODNCC_ext_ubi.img",0); sprintf(temp_buffer, "0x%X ",(unsigned int)NetBootFileXferSize); strcat(fs_cmd,"0x8880000 "); strcat(fs_cmd,temp_buffer); if(result==1) { run_command("nand erase 0x8880000 0x8000000",0); run_command("nandecc hw 1",0); printf("
Flash flash now, it may take some time,waiting ......
"); run_command(fs_cmd,0); printf("
** Upgrade Extended filesystem Successfully **
"); } else { printf("
** Upgrade Extended filesystem Error **
"); } break; #endif case MACR_UPGRADE_ROOTFS: printf("
Upgrade Root filesystem may take some time, waiting ......

"); //run_command("mw.b 0x82000000 0xFF 0x10000000",0); result=run_command("tftp RFODNCC_root_ubi.img",0); sprintf(temp_buffer, "0x%X ",(unsigned int)NetBootFileXferSize); strcat(fs_cmd,"0x880000 "); strcat(fs_cmd,temp_buffer); if(result==1) { run_command("nand erase 0x880000 0x8000000",0); run_command("nandecc hw 1",0); printf("
Flash flash now, it may take some time,waiting ......
"); run_command(fs_cmd,0); printf("
** Upgrade Root filesystem Successfully **
"); } else { printf("
** Upgrade Root filesystem Error **
"); } break; } } int main_menu(void) { unsigned char c; ip_set_default(); while(1) { menu_usage(); //if (tstc()) { c = getc(); switch(c) { case 'x': case 'X': printf("[%c]
",c); printf("Selected Upgrade x-loader
"); ip_display(); confirm_display(); c = getc(); printf("%c
",c); if(c=='y' || c=='Y') { excute_operation(MACR_UPGRADE_XLOADER); } else { printf("Cancel Operation\r
"); } break; case 'u': case 'U': printf("[%c]
",c); printf("Selected Upgrade u-boot
"); ip_display(); confirm_display(); c = getc(); printf("%c
",c); if(c=='y' || c=='Y') { excute_operation(MACR_UPGRADE_UBOOT); } else { printf("Cancel Operation\r
"); } break; case 'k': case 'K': printf("[%c]
",c); printf("Selected Upgrade linux kernel
"); ip_display(); confirm_display(); c = getc(); printf("%c
",c); if(c=='y' || c=='Y') { excute_operation(MACR_UPGRADE_KERNAL); } else { printf("Cancel Operation\r
"); } break; #if 0 case 'e': case 'E': printf("[%c]
",c); printf("Selected Upgrade extended filesystem
"); ip_display(); confirm_display(); c = getc(); printf("%c
",c); if(c=='y' || c=='Y') { excute_operation(MACR_UPGRADE_EXTFS); } else { printf("Cancel Operation\r
"); } break; #endif case 'f': case 'F': printf("[%c]
",c); printf("Selected Upgrade root filesystem
"); ip_display(); confirm_display(); c = getc(); printf("%c
",c); if(c=='y' || c=='Y') { excute_operation(MACR_UPGRADE_ROOTFS); } else { printf("Cancel Operation\r
"); } break; case 'v': case 'V': printf("[%c]
",c); printf("Selected View the u-boot version
"); printf("
u-boot version is:%s
",uboot_version); break; case 'q': case 'Q': printf("[%c]
",c); printf("Selected Quit from menu
"); /* restore the ip env info */ ip_restore_org(); return 0; case 'b': case 'B': run_command("boot",0); /* restore the ip env info */ ip_restore_org(); case 'r': case 'R': run_command("reset",0); return 0; break; } } } return 0; } U_BOOT_CMD( menu,3, 0, main_menu, "menu list the operation code and operation content", "input operation code,eg.a,b.etc" );

좋은 웹페이지 즐겨찾기