📄 env_platform.c
字号:
/************************************************************************
*
* env_platform.c
*
* Platform specific part of ENV module (shell environment variables)
*
*
* ######################################################################
*
* Copyright (c) 1999-2000 MIPS Technologies, Inc. All rights reserved.
*
* Unpublished rights reserved under the Copyright Laws of the United States of
* America.
*
* This document contains information that is proprietary to MIPS Technologies,
* Inc. ("MIPS Technologies"). Any copying, modifying or use of this information
* (in whole or in part) which is not expressly permitted in writing by MIPS
* Technologies or a contractually-authorized third party is strictly
* prohibited. At a minimum, this information is protected under unfair
* competition laws and the expression of the information contained herein is
* protected under federal copyright laws. Violations thereof may result in
* criminal penalties and fines.
* MIPS Technologies or any contractually-authorized third party reserves the
* right to change the information contained in this document to improve
* function, design or otherwise. MIPS Technologies does not assume any
* liability arising out of the application or use of this information. Any
* license under patent rights or any other intellectual property rights owned
* by MIPS Technologies or third parties shall be conveyed by MIPS Technologies
* or any contractually-authorized third party in a separate license agreement
* between the parties.
* The information contained in this document constitutes one or more of the
* following: commercial computer software, commercial computer software
* documentation or other commercial items. If the user of this information, or
* any related documentation of any kind, including related technical data or
* manuals, is an agency, department, or other entity of the United States
* government ("Government"), the use, duplication, reproduction, release,
* modification, disclosure, or transfer of this information, or any related
* documentation of any kind, is restricted in accordance with Federal
* Acquisition Regulation 12.212 for civilian agencies and Defense Federal
* Acquisition Regulation Supplement 227.7202 for military agencies. The use of
* this information by the Government is further restricted in accordance with
* the terms of the license agreement(s) and/or applicable contract terms and
* conditions covering this information from MIPS Technologies or any
* contractually-authorized third party.
*
************************************************************************/
/************************************************************************
* Include files
************************************************************************/
#include <sysdefs.h>
#include <sys_api.h>
#include <syscon_api.h>
#include <env_api.h>
#include <env.h>
#include <product.h>
#include <eeprom_api.h>
#include <syserror.h>
#include <stdio.h>
#include <errno.h>
#include <string.h>
/************************************************************************
* Definitions
************************************************************************/
/************************************************************************
* Public variables
************************************************************************/
/************************************************************************
* Static variables
************************************************************************/
/* Default settings of env. variables */
static char *default_ip = "0.0.0.0";
static char *default_ethaddr = "00.00.00.00.00.00";
static char *default_subnetmask;
static char *default_gateway;
static char *default_bootserver;
static char *default_bootprot = "tftp";
static char *default_bootfile = "";
static char *env_sn = "baseboardserial";
static char *default_MAC = "0";
/************************************************************************
* Static function prototypes
************************************************************************/
static bool
hex_s2num(
char *raw, /* The string */
void *decoded, /* Decoded data */
UINT32 size ); /* Size of decoded data */
static bool
decode_number(
char *raw, /* The string */
void *decoded, /* Decoded data */
UINT32 size, /* Size of decoded data */
UINT32 base ); /* Base (8/10/16) */
/************************************************************************
* Implementation : Static functions
************************************************************************/
/************************************************************************
*
* decode_number
* Description :
* -------------
*
* Decode number
*
* Return values :
* ---------------
*
* TRUE -> OK, FALSE -> Failed
*
************************************************************************/
static bool
decode_number(
char *raw, /* The string */
void *decoded, /* Decoded data */
UINT32 size, /* Size of decoded data */
UINT32 base ) /* Base (8/10/16) */
{
char *endp;
UINT32 number;
if( !raw )
return FALSE;
/* Do the decoding */
errno = 0;
number = strtoul( raw, &endp, base );
if( decoded )
{
switch( size )
{
case sizeof(UINT8) :
*(UINT8 *)decoded = (UINT8)number;
break;
case sizeof(UINT16) :
*(UINT16 *)decoded = (UINT16)number;
break;
case sizeof(UINT32) :
*(UINT32 *)decoded = (UINT32)number;
break;
default :
return FALSE;
}
}
return
( errno || (*endp != '\0') ) ?
FALSE : TRUE;
}
/************************************************************************
*
* hex_s2num
*
* Description :
* -------------
*
* Decode decimal number
*
* Return values :
* ---------------
*
* TRUE -> OK, FALSE -> Failed
*
************************************************************************/
static bool
hex_s2num(
char *raw, /* The string */
void *decoded, /* Decoded data */
UINT32 size ) /* Size of decoded data */
{
return decode_number( raw, decoded, size, 16 );
}
/************************************************************************
* Implementation : Public functions
************************************************************************/
/************************************************************************
*
* env_setup_env_board
* Description :
* -------------
*
* Create board specific system environment variables
*
* Return values :
* ---------------
*
* TRUE -> OK, else FALSE
*
************************************************************************/
bool
env_setup_env_board(
bool default_switch )
{
char msg[40];
char *raw;
t_sn_ascii sn;
t_mac_addr mac_addr;
UINT32 rc = TRUE;
default_subnetmask = default_ip;
default_gateway = default_ip;
default_bootserver = default_ip;
switch( sys_platform )
{
case PRODUCT_PB1000_ID:
case PRODUCT_MALTA_ID :
case PRODUCT_ATLASA_ID :
if( default_switch || !env_get( "ethaddr", &raw, NULL, 0 ) )
raw = default_ethaddr; /* Create new */
if( env_set( "ethaddr", raw, ENV_ATTR_RW,
default_ethaddr, env_mac_s2num ) != OK )
{
rc = FALSE;
}
#if 0
/* MAC address */
if( SYSCON_read( SYSCON_COM_EN0_MAC_ADDR_ID,
(void *)&mac_addr,
sizeof(t_mac_addr) ) == OK )
{
sprintf( msg, "%02x.%02x.%02x.%02x.%02x.%02x",
mac_addr[0],
mac_addr[1],
mac_addr[2],
mac_addr[3],
mac_addr[4],
mac_addr[5] );
if( env_set( env_mac, msg, ENV_ATTR_RW, NULL,
env_mac_s2num ) != OK )
{
rc = FALSE;
}
}
else
{
if( env_unset( env_mac ) != OK )
rc = FALSE;
}
#endif
/* Serial number */
if( SYSCON_read( SYSCON_BOARD_SN_ID,
(void *)&sn,
sizeof(t_sn_ascii) ) == OK )
{
if( env_set( env_sn, (char *)sn, ENV_ATTR_RO, NULL, NULL ) != OK )
rc = FALSE;
}
else
{
if( env_unset( env_sn ) != OK )
rc = FALSE;
}
/* IP address */
if( default_switch || !env_get( "ipaddr", &raw, NULL, 0 ) )
raw = default_ip; /* Create new */
if( env_set( "ipaddr", raw, ENV_ATTR_RW,
default_ip, env_ip_s2num ) != OK )
{
rc = FALSE;
}
/* Subnet mask */
if( default_switch || !env_get( "subnetmask", &raw, NULL, 0 ) )
raw = default_subnetmask; /* Create new */
if( env_set( "subnetmask", raw, ENV_ATTR_RW,
default_subnetmask, env_ip_s2num ) != OK )
{
rc = FALSE;
}
/* Default gateway */
if( default_switch || !env_get( "gateway", &raw, NULL, 0 ) )
raw = default_gateway; /* Create new */
if( env_set( "gateway", raw, ENV_ATTR_RW,
default_gateway, env_ip_s2num ) != OK )
{
rc = FALSE;
}
/* Default boot protocol */
if( default_switch || !env_get( "bootprot", &raw, NULL, 0 ) )
raw = default_bootprot; /* Create new */
if( env_set( "bootprot", raw, ENV_ATTR_RW,
default_bootprot, env_decode_bootprot ) != OK )
{
rc = FALSE;
}
/* Default boot server (TFTP) */
if( default_switch || !env_get( "bootserver", &raw, NULL, 0 ) )
raw = default_bootserver; /* Create new */
if( env_set( "bootserver", raw, ENV_ATTR_RW,
default_bootserver, env_ip_s2num ) != OK )
{
rc = FALSE;
}
/* Default boot file */
if( default_switch || !env_get( "bootfile", &raw, NULL, 0 ) )
raw = default_bootfile; /* Create new */
if( env_set( "bootfile", raw, ENV_ATTR_RW,
default_bootfile, NULL ) != OK )
{
rc = FALSE;
}
/* Default MAC */
if( default_switch || !env_get( "MAC", &raw, NULL, 0 ) )
raw = default_MAC; /* Create new */
if( env_set( "MAC", raw, ENV_ATTR_RW,
default_MAC, hex_s2num ) != OK )
{
rc = FALSE;
}
break;
case PRODUCT_SEAD_ID :
case PRODUCT_SEAD2_ID :
break;
default :
break;
}
return rc;
}
/************************************************************************
*
* env_decode_bootprot
* Description :
* -------------
*
* Decode boot protocol (currently tftp or asc)
* (not all protocols legal on all platforms)
*
* Return values :
* ---------------
*
* TRUE -> OK, FALSE -> Failed
*
************************************************************************/
bool
env_decode_bootprot(
char *raw, /* The string */
void *decoded, /* Decoded data */
UINT32 size ) /* Size of decoded data */
{
if( decoded && (size != sizeof(UINT32)) )
return FALSE;
if( strcmp( raw, "tftp" ) == 0 )
{
if( (sys_platform == PRODUCT_SEAD_ID) ||
(sys_platform == PRODUCT_SEAD2_ID) )
{
return FALSE;
}
else
{
if( decoded )
*(UINT32 *)decoded = PROTOCOL_TFTP;
return TRUE;
}
}
else if( strcmp( raw, "asc" ) == 0 )
{
if( decoded )
*(UINT32 *)decoded = PROTOCOL_ASC;
return TRUE;
}
else
return FALSE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -