u-boot에서 업그레이드 메뉴 만들기
#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"
);
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
다양한 언어의 JSONJSON은 Javascript 표기법을 사용하여 데이터 구조를 레이아웃하는 데이터 형식입니다. 그러나 Javascript가 코드에서 이러한 구조를 나타낼 수 있는 유일한 언어는 아닙니다. 저는 일반적으로 '객체'{}...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.