📄 bootline.c.bak
字号:
#include "vxworks.h"
#include "bootLib.h"
#include "flashMem.h"
#include "arpa\inet.h"
const UINT8 DEFAULT_10M_MAC_ADRS[6] = {0x08,0x00,0x3e,0x03,0x02,0x09};
#ifdef INCLUDE_MOT_FEC
const DEFAULT_100M_MAC_ADRS[6] = {0x08,0x00,0x3e,0x03,0x02,0x0a};
#endif /* INCLUDE_MOT_FEC */
/******************************************************************************
*
* sysNvRamGet - get the contents of non-volatile RAM
*
* This routine copies the contents of non-volatile memory into a specified
* string. The string is terminated with an EOS.
*
* RETURNS: OK, or ERROR if access is outside the non-volatile RAM range.
*
* SEE ALSO: sysNvRamSet()
*/
STATUS sysNvRamGet
(
char *string, /* where to copy non-volatile RAM */
int strLen, /* maximum number of bytes to copy */
int offset /* byte offset into non-volatile RAM */
)
{
offset += NV_BOOT_OFFSET; /* boot line begins at <offset> = 0 */
if ((offset < 0)
|| (strLen < 0)
|| ((offset + strLen) > NV_RAM_SIZE))
return (ERROR);
sysFlashGet(string,(int)strLen,offset);
/*
printf("\n\nstring: %s\n", string);
printf("end of sysNvRamGet()\n");
*/
return (OK);
}
/*******************************************************************************
*
* sysNvRamSet - write to non-volatile RAM
*
* This routine copies a specified string into non-volatile RAM.
*
* RETURNS: OK, or ERROR if access is outside the non-volatile RAM range.
*
* SEE ALSO: sysNvRamGet()
*/
STATUS sysNvRamSet
(
char *string, /* string to be copied into non-volatile RAM */
int strLen, /* maximum number of bytes to copy */
int offset /* byte offset into non-volatile RAM */
)
{
STATUS result = OK;
/*
printf("start of sysNvRamSet()\n");
*/
offset += NV_BOOT_OFFSET; /* boot line begins at <offset> = 0 */
if ((offset < 0)
|| (strLen < 0)
|| ((offset + strLen) > 65536)) /*NV_RAM_SIZE))*/
return ERROR;
sysFlashErase(SECTOR_ERASE,(UINT8 *)FLASH_ADRS,NV_RAM_SIZE);
sysFlashWrite(NVRAM_INITIALIZED,NV_INIT_SIZE+1,0);
sysFlashWrite(string,(int)strLen,offset);
return result;
}
/******************************************************************************
*
* checkInetAddr - check for valid inet address in boot field
*/
LOCAL STATUS checkInetAddr
(
char *pInetAddr,
BOOL subnetMaskOK
)
{
char inetAddr [30];
int netmask;
/*
* The bzero() call corrects SPR 6326. The calls to bootNetmaskExtract()
* and inet_addr() did not delimit the input string with a '\0'. When
* inet_addr attempted to print the invalid address, the system would
* crash or hang.
*/
bzero (inetAddr, sizeof(inetAddr));
if (*pInetAddr == EOS)
return (OK);
strncpy (inetAddr, pInetAddr, sizeof (inetAddr) - 1);
if (subnetMaskOK)
{
if (bootNetmaskExtract (inetAddr, &netmask) < 0)
{
printf ("Error: invalid netmask in boot field \"%s\".\n", inetAddr);
return (ERROR);
}
}
if (inet_addr (inetAddr) == (ULONG) ERROR)
{
printf ("Error: invalid inet address in boot field \"%s\".\n",inetAddr);
return (ERROR);
}
return (OK);
}
/******************************************************************************
*
* bootLineSet - change the boot line contents in NVRAM
* RETURNS: OK or ERROR
*/
STATUS bootLineSet
(
char* bootLine
)
{
BOOT_PARAMS Params;
char* pS;
pS = (char *)malloc(255);
if (pS == NULL)
return(ERROR);
/* printf("\nBoot line is:%s",bootLine); */
pS = bootStringToStruct (bootLine, &Params);
if (*pS != EOS)
{
printf("\nBoot string failed to struct");
bootParamsErrorPrint (bootLine, pS);
return (ERROR);
}
/* check inet addresses */
if ((checkInetAddr(Params.ead, TRUE) != OK) ||
(checkInetAddr(Params.bad, TRUE) != OK) ||
(checkInetAddr(Params.had, FALSE) != OK) ||
(checkInetAddr(Params.gad, FALSE) != OK))
{
printf("\nThe Inet Address is invalid!");
return (ERROR);
}
sysNvRamSet(bootLine,strlen(bootLine)+1,0);
strcpy (BOOT_LINE_ADRS, bootLine);
return (OK);
}
/*******************************************************************************
*
* bootLineGet - get the boot line contents in NVRAM
* RETURNS: OK or ERROR
*/
STATUS bootLineGet
(
char* bootLine
)
{
if(sysNvRamGet(bootLine,BOOT_LINE_SIZE,0) == ERROR)
return (ERROR);
/* printf("\n The boot line exist is: %s",bootLine);*/
return (OK);
}
/*******************************************************************************
*
* macAdrsGet - get 10M_MAC/100M_MAC/10M_IP address from NVRAM
* adrs - adrs[0]~adrs[5] 10M_MAC address,ads[6]~adrs[11] 100M_MAC address
* adrs[12]~adrs[15] 10M_IP
* RETURNS: OK or ERROR
*/
STATUS macAdrsGet
(
UINT8* adrs
)
{
return (sysFlashGet(adrs,28,MAC_ADRS+5-FLASH_ADRS));
}
/*******************************************************************************
*
* macAdrsSet - set 10M_MAC/100M_MAC/10M_IP address from NVRAM
* adrs - adrs[0]~adrs[5] 10M_MAC address,ads[6]~adrs[11] 100M_MAC address
* adrs[12]~adrs[15] 10M_IP
* RETURNS: OK or ERROR
*/
STATUS macAdrsSet
(
UINT8* adrs
)
{
printErr("\nThe mac_adrs is:0x%8x",MAC_ADRS);
if (sysFlashErase(SECTOR_ERASE,(UINT8*)MAC_ADRS,65536) == ERROR)
return ERROR;
printErr("\nErase ok!");
if (sysFlashWrite(NVRAM_INITIALIZED,NV_INIT_SIZE+1,MAC_ADRS-FLASH_ADRS) == ERROR)
return ERROR;
printErr("\nWrite INIT ok!");
if (sysFlashWrite(adrs,6,MAC_ADRS-FLASH_ADRS+5) == ERROR)
return ERROR;
printErr("\nWrite ADRS ok!");
return (OK);
}
/************************************************************************************
*
* testNVRam - this routine test NVRam related routines
*/
void testNVRam(void){
char initValue[NV_INIT_SIZE+1];
if ((sysNvRamGet(&initValue[0],NV_INIT_SIZE+1,-NV_BOOT_OFFSET)) != ERROR)
{
if ( strcmp( initValue, NVRAM_INITIALIZED) != 0 )
{
printf("\nNVRam not initiated!");
(void)sysNvRamSet(DEFAULT_BOOT_LINE, strlen(DEFAULT_BOOT_LINE)+1,0);
}
printf("\nNVRam initiated!");
}
if ((sysNvRamGet (BOOT_LINE_ADRS, BOOT_LINE_SIZE, 0) == ERROR) ||
(*BOOT_LINE_ADRS == EOS))
{
/* either no non-volatile RAM or empty boot line */
printf("\nGet bootline Error!");
strcpy (BOOT_LINE_ADRS, DEFAULT_BOOT_LINE);
}
printf("\nThe bootline is:%s",(char*)BOOT_LINE_ADRS);
}
/*************************************************************************************
*
*testMac - this routine test Mac address and 10M IP set/get related routines
*/
void testMac(void){
char initValue[NV_INIT_SIZE+1];
UINT8 macAdrs[6];
if ((sysFlashGet(&initValue[0],NV_INIT_SIZE+1,MAC_ADRS-FLASH_ADRS)) != ERROR)
{
printf("\nMac address read ok!");
if ( strcmp( initValue, NVRAM_INITIALIZED) != 0 )
{
printf("\nMac address not set");
/* printf("\nThe 10M_MAC address is 0x%8x",DEFAULT_10M_MAC_ADRS); */
bcopy((UINT8*)DEFAULT_10M_MAC_ADRS,(UINT8*)macAdrs,6);
#ifdef INCLUDE_MOT_FEC
bcopy((UINT8*)DEFAULT_100M_MAC_ADRS,(UINT8*)(macAdrs+6),6);
bcopy((UINT8*)DEFAULT_10M_IP,(UINT8*)(macAdrs+12),16);
printf("The 10M_IP is %s",macAdrs+12);
#endif /* INCLUDE_MOT_FEC */
macAdrsSet(macAdrs);
}
else
macAdrsGet(macAdrs);
}
printf("\nMac address set ok");
bcopy((UINT8*)macAdrs,sysCpmEnetAddr,6);
#ifdef INCLUDE_MOT_FEC
bcopy((UINT8*)(macAdrs+6),sysFecEnetAddr,6);
bcopy((UINT8*)(macAdrs+12),sysCpmEnetIp,16);
#endif
printf("\nThe mac address is:%s",macAdrs);
}
STATUS flashParamSet (UINT8 *parameter, int length){
if (sysFlashErase (SECTOR_ERASE, (UINT8 *)FLASH_PARAM, 0x10000) == ERROR)
return (ERROR);
if (sysFlashWrite (parameter, length, FLASH_PARAM-FLASH_ADRS) == ERROR)
return (ERROR);
return (OK);
}
STATUS flashParamGet (UINT8 *parameter, int length){
bcopyBytes ((char *)FLASH_PARAM, parameter, length);
parameter[length] = EOS;
return (OK);
}
STATUS destiNetworkGet(UINT8 *adrs){
return (sysFlashGet(adrs,16,DESTINATION_NETWORK_ADRS-FLASH_ADRS));
}
STATUS destiNetworkSet(UINT8 *adrs){
printErr("\nThe destination network is:0x%8x",DESTINATION_NETWORK_ADRS);
if (sysFlashErase(SECTOR_ERASE,(UINT8*)DESTINATION_NETWORK_ADRS,65536) == ERROR)
return ERROR;
printErr("\nErase ok!");
if (sysFlashWrite(adrs,16,DESTINATION_NETWORK_ADRS-FLASH_ADRS) == ERROR)
return ERROR;
printErr("\nWrite ok!");
return (OK);
}
void printBootLogo(){
printErr("\n\n\n\rShanghai Optical Networking Technology Co.,Ltd.");
printErr("\n");
printErr("\n\rEmail:marketing@alloptic.com.cn");
printErr("\n\rWeb:www.alloptic.com.cn");
printErr("\n\rTel:86-21-64838770");
printErr("\n");
printErr("\n\rCopyright (C) 2005");
printErr("\n\n\n");
}
void printShellLogo(){
printErr("\n\rEntering Ca6004 Config Shell...done");
printErr("\n\r->");
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -