📄 cfg_utility.c
字号:
/* cfg_utility.c
---------------------------------------------------------------------------
Copyright (c) 2002, 2003 Intel Corporation
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of Intel Corporation nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
---------------------------------------------------------------------------
system: IXDP2400
subsystem: BootMonitor
author: lagarwal
revisions:
--------------------------------------------------------------------------
*/
#include <cyg/infra/cyg_type.h>
#include <cyg/hal/cfg_utility.h>
#include <cyg/io/i2c.h>
#include <redboot.h>
#include <cyg/hal/hal_ixdp2400.h>
extern int passwd_input;
static cmd_fun do_cfg;
RedBoot_cmd("cfg",
"Manage config PROM",
"{cmds}",
do_cfg
);
// read PROM function
local_cmd_entry("read",
"Read config PROM",
"-n <device id>",
cmd_cfg_rd,
CFG_cmds
);
// write PROM function
local_cmd_entry("write",
"Write config PROM",
"-n <device id>",
cmd_cfg_wr,
CFG_cmds
);
// update test status and date fields
local_cmd_entry("teststatus",
"Update Test Status and Date",
"-n <device id>",
cmd_cfg_ts,
CFG_cmds
);
// Define table boundaries
CYG_HAL_TABLE_BEGIN( __CFG_cmds_TAB__, CFG_cmds);
CYG_HAL_TABLE_END( __CFG_cmds_TAB_END__, CFG_cmds);
extern struct cmd __CFG_cmds_TAB__[], __CFG_cmds_TAB_END__;
/*These Global variables are used for checksum computation by the routine and
*need to be initialized to r=55665, c1=52845 and c2= 22719 */
unsigned short r;
unsigned short c1 = 52845;
unsigned short c2 = 22719;
static void
cfg_usage(char *why)
{
printf("*** invalid 'cfg' command: %s\n", why);
cmd_usage(__CFG_cmds_TAB__, &__CFG_cmds_TAB_END__, "cfg ");
}
static void
do_cfg(int argc, char *argv[])
{
struct cmd *cmd;
if (argc < 2) {
cfg_usage("Too few arguments");
return;
}
if ((cmd = cmd_search(__CFG_cmds_TAB__, &__CFG_cmds_TAB_END__,
argv[1])) != (struct cmd *)0) {
(cmd->fun)(argc, argv);
return;
}
cfg_usage("Unrecognized command");
}
/**************************************************************************
Function:get_man_id()
This function gives the Manufacturer's ID to be stored on the config prom
Arguments: manid -Ptr to store the manufacturer's ID,
user -1 take input from user
0 default value
Returns: none
***************************************************************************/
void get_man_id(unsigned char *manid, unsigned char *curr_manid,int user)
{
unsigned char temp[CFG_MAN_ID_LEN + 1];
if(user)
{
memset(temp, '\0', CFG_MAN_ID_LEN + 1);
memcpy(temp, curr_manid, CFG_MAN_ID_LEN);
printf("Current Manufcaturer's ID is %s\nEnter new Value: ",temp);
gets((char *)temp, (CFG_MAN_ID_LEN + 1), 0);
if(*temp == '\0')
memcpy((char *)manid, (const char*)curr_manid, CFG_MAN_ID_LEN);
else
memcpy((char *)manid, (const char*)temp, CFG_MAN_ID_LEN);
}
else
memcpy((char*)manid, DEFAULT_MANID, CFG_MAN_ID_LEN);
return ;
}
/**************************************************************************
Function:get_dev_id()
This function gives the Device ID to be stored on the config prom
Arguments: devid -Ptr to store the Device ID,
user -1 take input from user
0 default value
Returns: none
***************************************************************************/
void get_dev_id(unsigned char *devid, unsigned char *curr_devid,int user, int id)
{
char c[2];
unsigned long num;
if(user)
{
printf("Current Device ID is %d\nEnter Device ID: ", *curr_devid);
gets(c,2, 0);
parse_num(c,&num,0,0);
if(*c=='\0')
*devid = *curr_devid;
else
*devid = (unsigned char)num;
}
else
{
*devid = (unsigned char)id;
}
return;
}
void get_op_freq(unsigned int *freq, unsigned int *curr_freq, int user)
{
char c[5];
unsigned long num;
if(user)
{
printf("Current operating freq. is %d MHZ\nEnter new operating freq. (in MHZ): ", *curr_freq);
gets(c, 5, 0);
parse_num(c, &num, 0, 0);
if(*c == '\0')
*freq = *curr_freq;
else
*freq = num;
}
else
{
*freq = DEFAULT_OP_FREQ;
}
return;
}
/**************************************************************************
Function:get_model_id()
This function returns the Model ID
Arguments: model_id - Ptr to store the model ID,
curr_model_id - ptr to current model id. in case the
user enters null, this will be retained. This is used
only when user=1
user - 1 take input from user
0 default value
Returns: none
***************************************************************************/
void get_model_id(unsigned char *model_id, unsigned char *curr_model_id,
int user, int id)
{
unsigned char temp[CFG_MODEL_ID_LEN + 1];
if(user)
{
memset(temp, '\0', CFG_MODEL_ID_LEN + 1);
memcpy(temp, curr_model_id, CFG_MODEL_ID_LEN);
printf("Current Model ID is %s\nEnter new Model ID: ",temp);
gets(temp, (CFG_MODEL_ID_LEN + 1), 0);
if(*temp == '\0')
memcpy((char*)model_id, (const char*)curr_model_id, CFG_MODEL_ID_LEN);
else
memcpy((char*)model_id, (const char*)temp, CFG_MODEL_ID_LEN);
}
else
{
switch(id)
{
case PL_DEV_ID:
memcpy((char*)model_id, "PL", CFG_MODEL_ID_LEN);
break;
case BW_DEV_ID:
memcpy((char*)model_id, "BW", CFG_MODEL_ID_LEN);
break;
case BD_DEV_ID:
memcpy((char*)model_id, "BD", CFG_MODEL_ID_LEN);
break;
case MI_DEV_ID:
memcpy((char*)model_id, "MI", CFG_MODEL_ID_LEN);
break;
case BI_DEV_ID:
memcpy((char*)model_id, "BI", CFG_MODEL_ID_LEN);
break;
case KI_DEV_ID:
memcpy((char*)model_id, "KI", CFG_MODEL_ID_LEN);
default:
return;
}
}
}
/**************************************************************************
Function:void get_part_rev(char* partrev, int user)
This function returns the Part rev in string format
Arguments: partrev - Ptr to store the part rev,
curr_partrev - Ptr to current partrev. This is used in case
the user enters null. This is used only when user=1
user - 1 take input from user
0 default value
Returns: none
***************************************************************************/
void get_part_rev(unsigned char *partrev, unsigned char *curr_partrev,int user)
{
unsigned char temp[CFG_PARTREV_LEN + 1];
if(user)
{
printf("Part Revision is %c%c\n", *(curr_partrev), *(curr_partrev + 1));
}
printf("Enter Part Rev.(should start with 0): ");
gets(temp, (CFG_PARTREV_LEN + 1), 0);
if(*temp=='\0')
memcpy((char *)partrev, (const char*)curr_partrev, CFG_PARTREV_LEN);
else
memcpy((char *)partrev, (const char*)temp, CFG_PARTREV_LEN);
return;
}
/**************************************************************************
Function:char * get_part_num(char * partnum, int user)
This function returns the Part number in string format
Arguments: partnum - Ptr to store the part number,
curr_partnum - Ptr to current partnum. This is used in case
the user enters null. This is used only when user=1
user - 1 take input from user
0 default value
Returns: none
***************************************************************************/
void get_part_num(unsigned char *partnum, unsigned char *curr_partnum,int user)
{
unsigned char temp[CFG_PARTNUM_LEN + 1];
if(user)
{
memset(temp, '\0', CFG_PARTNUM_LEN + 1);
memcpy(temp, curr_partnum, CFG_PARTNUM_LEN);
printf("Current Part Number is %s\n", temp);
}
printf("Enter Part Number(should start with A): ");
gets(temp, (CFG_PARTNUM_LEN + 1),0);
if(*temp == '\0')
memcpy((char *)partnum, (const char*)curr_partnum, CFG_PARTNUM_LEN);
else
memcpy((char *)partnum, (const char*)temp, CFG_PARTNUM_LEN);
}
/**************************************************************************
Function:void get_serial_num(char * sernum)
This function returns the Serial number in string format
Arguments: sernum - Ptr to store the serial number,
curr_sernum - Ptr to current sernum. This is used in case
the user enters null.
Returns: none
***************************************************************************/
void get_serial_num(unsigned char *sernum,unsigned char *curr_sernum, int user)
{
unsigned char temp[CFG_SERIAL_NUM_LEN + 1];
if(user)
{
memset(temp, '\0', CFG_SERIAL_NUM_LEN + 1);
memcpy(temp, curr_sernum, CFG_SERIAL_NUM_LEN);
printf("Current Serial Number is %s\n", temp);
}
printf("Enter Serial Number: ");
gets(temp, (CFG_SERIAL_NUM_LEN + 1),0);
if(*temp=='\0')
memcpy((char *)sernum, (const char*)curr_sernum, CFG_SERIAL_NUM_LEN);
else
memcpy((char *)sernum, (const char*)temp, CFG_SERIAL_NUM_LEN);
return ;
}
/**************************************************************************
Function:void get_mac_addr(unsigned long *macaddr, user, npu)
This function returns the NPU's Ethernet MAC address
Arguments: macaddr - Ptr to store the mac addr,
curr_mac - Ptr to current MAC addr in case the user enters null
user - 1 take input from user
0 default value
npu - 1 for master
0 for slave
Returns: none
***************************************************************************/
int get_mac_addr(unsigned char *mac, unsigned char *curr_mac, int user, char *msg)
{
/*The MAC (Media Access Control) address is a 6-byte hex number
*(e.g., 00-20-AF-ED-97-A5) coded and installed by the manufacturer of
*the Ethernet hardware. The first 3 bytes are a unique Vendor ID for
*the manufacturer. The last 3 bytes may be the card's incremental
*serial number
*/
unsigned int mac_vid; /*The vendor ID portion of the MAC addr*/
unsigned int mac_sno; /*The serial no. portion of the mac addr*/
int i;
unsigned char str_mac[13];
if(user)
{
printf("Current MAC address is %02x %02x %02x %02x %02x %02x\n", curr_mac[0],
curr_mac[1], curr_mac[2], curr_mac[3], curr_mac[4], curr_mac[5]);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -