mirror of
https://github.com/ipmitool/ipmitool.git
synced 2026-01-21 16:42:19 +08:00
fix formatting and compile warnings
This commit is contained in:
parent
78f8f0793f
commit
12a6554416
@ -55,30 +55,21 @@
|
||||
*/
|
||||
#define LIMIT_ALL_REQUEST_SIZE 1
|
||||
|
||||
extern int verbose;
|
||||
extern int ipmi_spd_print(struct ipmi_intf * intf, uint8_t id);
|
||||
static void ipmi_fru_read_to_bin(struct ipmi_intf * intf,unsigned char * pFileName, unsigned char fruId);
|
||||
static void ipmi_fru_write_from_bin(struct ipmi_intf * intf, unsigned char * pFileName, unsigned char fruId);
|
||||
static int ipmi_fru_upg_ekeying(struct ipmi_intf * intf,unsigned char * pFileName, unsigned char fruId);
|
||||
static int ipmi_fru_get_multirec_location_from_fru(struct ipmi_intf * intf,
|
||||
unsigned char fruId,
|
||||
struct fru_info *pFruInfo,
|
||||
unsigned long * pRetLocation,
|
||||
unsigned long * pRetSize);
|
||||
|
||||
static int ipmi_fru_get_multirec_from_file(unsigned char * pFileName,
|
||||
unsigned char * pBufArea,
|
||||
unsigned long size,
|
||||
unsigned long offset);
|
||||
static int ipmi_fru_get_multirec_size_from_file(unsigned char * pFileName,
|
||||
unsigned long * pSize,
|
||||
unsigned long * pOffset);
|
||||
static void ipmi_fru_get_adjust_size_from_buffer(unsigned char * pBufArea,
|
||||
unsigned long *pSize);
|
||||
|
||||
static unsigned char fileName[512];
|
||||
|
||||
extern int verbose;
|
||||
extern int ipmi_spd_print(struct ipmi_intf * intf, uint8_t id);
|
||||
|
||||
static void ipmi_fru_read_to_bin(struct ipmi_intf * intf,unsigned char * pFileName, unsigned char fruId);
|
||||
static void ipmi_fru_write_from_bin(struct ipmi_intf * intf, unsigned char * pFileName, unsigned char fruId);
|
||||
static void ipmi_fru_upg_ekeying(struct ipmi_intf * intf,unsigned char * pFileName, unsigned char fruId);
|
||||
static int ipmi_fru_get_multirec_location_from_fru(struct ipmi_intf * intf, unsigned char fruId,
|
||||
struct fru_info *pFruInfo, unsigned long * pRetLocation,
|
||||
unsigned long * pRetSize);
|
||||
static int ipmi_fru_get_multirec_from_file(unsigned char * pFileName, unsigned char * pBufArea,
|
||||
unsigned long size, unsigned long offset);
|
||||
static int ipmi_fru_get_multirec_size_from_file(unsigned char * pFileName, unsigned long * pSize, unsigned long * pOffset);
|
||||
static void ipmi_fru_get_adjust_size_from_buffer(unsigned char * pBufArea, unsigned long *pSize);
|
||||
static void ipmi_fru_picmg_ext_print(unsigned char * fru_data, int off, int length);
|
||||
|
||||
/* get_fru_area_str - Parse FRU area string from raw data
|
||||
@ -125,8 +116,7 @@ get_fru_area_str(uint8_t * data, uint32_t * offset)
|
||||
break;
|
||||
}
|
||||
|
||||
if (size < 1)
|
||||
{
|
||||
if (size < 1) {
|
||||
*offset = off;
|
||||
return NULL;
|
||||
}
|
||||
@ -230,41 +220,41 @@ write_fru_area(struct ipmi_intf * intf, struct fru_info *fru, unsigned char id,
|
||||
if (fru->access && fru_data_rqst_size > 16)
|
||||
#endif
|
||||
fru_data_rqst_size = 16;
|
||||
do
|
||||
{
|
||||
|
||||
do {
|
||||
/* real destination offset */
|
||||
tmp = fru->access ? (doffset+off) >> 1 : (doffset+off);
|
||||
msg_data[0] = id;
|
||||
msg_data[1] = (unsigned char)tmp;
|
||||
msg_data[2] = (unsigned char)(tmp >> 8);
|
||||
tmp = finish - (doffset+off); /* bytes remaining */
|
||||
if (tmp > 16)
|
||||
{
|
||||
if (tmp > 16) {
|
||||
lprintf(LOG_INFO,"Writting 16 bytes");
|
||||
memcpy(&msg_data[3],(pFrubuf+soffset+off), 16);
|
||||
memcpy(&msg_data[3], pFrubuf + soffset + off, 16);
|
||||
req.msg.data_len = 16 + 3;
|
||||
}
|
||||
else
|
||||
{
|
||||
else {
|
||||
lprintf(LOG_INFO,"Writting %d bytes", tmp);
|
||||
memcpy(&msg_data[3],(pFrubuf+soffset+off), (unsigned char) tmp);
|
||||
memcpy(&msg_data[3], pFrubuf + soffset + off, (unsigned char)tmp);
|
||||
req.msg.data_len = tmp + 3;
|
||||
}
|
||||
|
||||
writeLength = req.msg.data_len-3;
|
||||
writeLength = req.msg.data_len - 3;
|
||||
|
||||
rsp = intf->sendrecv(intf, &req);
|
||||
if (!rsp)
|
||||
if (!rsp) {
|
||||
break;
|
||||
if ((rsp->ccode==0xc7 || rsp->ccode==0xc8 || rsp->ccode==0xca ) && --fru_data_rqst_size > 8)
|
||||
{
|
||||
}
|
||||
if ((rsp->ccode==0xc7 || rsp->ccode==0xc8 || rsp->ccode==0xca ) &&
|
||||
--fru_data_rqst_size > 8) {
|
||||
lprintf(LOG_NOTICE,"Bad CC -> %x\n", rsp->ccode);
|
||||
break; /*continue;*/
|
||||
}
|
||||
if (rsp->ccode)
|
||||
if (rsp->ccode > 0)
|
||||
break;
|
||||
|
||||
off += writeLength;
|
||||
|
||||
} while ((doffset+off) < finish);
|
||||
|
||||
return ((doffset+off) >= finish);
|
||||
@ -318,6 +308,7 @@ read_fru_area(struct ipmi_intf * intf, struct fru_info *fru, uint8_t id,
|
||||
if (fru->access && fru_data_rqst_size > 16)
|
||||
#endif
|
||||
fru_data_rqst_size = 16;
|
||||
|
||||
do {
|
||||
tmp = fru->access ? off >> 1 : off;
|
||||
msg_data[0] = id;
|
||||
@ -805,7 +796,6 @@ fru_area_print_multirec(struct ipmi_intf * intf, struct fru_info * fru,
|
||||
ipmi_fru_picmg_ext_print(fru_data,
|
||||
i + sizeof(struct fru_multirec_header),
|
||||
h->len);
|
||||
|
||||
break;
|
||||
}
|
||||
i += h->len + sizeof (struct fru_multirec_header);
|
||||
@ -831,15 +821,14 @@ static void ipmi_fru_picmg_ext_print(unsigned char * fru_data, int off, int leng
|
||||
|
||||
case FRU_PICMG_BACKPLANE_P2P:
|
||||
{
|
||||
unsigned char index, index2;
|
||||
unsigned char index;
|
||||
struct fru_picmgext_slot_desc * slot_d
|
||||
= (struct fru_picmgext_slot_desc*) &fru_data[offset];
|
||||
|
||||
offset += sizeof(struct fru_picmgext_slot_desc);
|
||||
printf(" FRU_PICMG_BACKPLANE_P2P\n");
|
||||
|
||||
for ( ; offset <= (start_offset+length) ; )
|
||||
{
|
||||
while (offset <= (start_offset+length)) {
|
||||
printf("\n");
|
||||
printf(" Channel Type: ");
|
||||
switch ( slot_d -> chan_type )
|
||||
@ -870,8 +859,7 @@ static void ipmi_fru_picmg_ext_print(unsigned char * fru_data, int off, int leng
|
||||
printf(" Slot Addr. : %02x\n", slot_d -> slot_addr );
|
||||
printf(" Channel Count: %i\n", slot_d -> chn_count);
|
||||
|
||||
for ( index = 0 ; index < (slot_d -> chn_count) ; index++ )
|
||||
{
|
||||
for (index = 0; index < (slot_d -> chn_count); index++) {
|
||||
struct fru_picmgext_chn_desc * d
|
||||
= (struct fru_picmgext_chn_desc *) &fru_data[offset];
|
||||
|
||||
@ -909,41 +897,33 @@ static void ipmi_fru_picmg_ext_print(unsigned char * fru_data, int off, int leng
|
||||
|
||||
case FRU_PICMG_BOARD_P2P:
|
||||
printf(" FRU_PICMG_BOARD_P2P\n");
|
||||
|
||||
guid_count = fru_data[offset];
|
||||
printf(" GUID count: %2d\n", guid_count);
|
||||
for (i = 0 ; i < guid_count; i++ )
|
||||
{
|
||||
|
||||
for (i = 0; i < guid_count; i++) {
|
||||
printf(" GUID %2d:\n", i);
|
||||
offset += sizeof(struct fru_picmgext_guid);
|
||||
}
|
||||
|
||||
for (
|
||||
++offset;
|
||||
offset < off + length;
|
||||
offset += sizeof(struct fru_picmgext_link_desc)
|
||||
)
|
||||
{
|
||||
for (++offset;
|
||||
offset < (off + length);
|
||||
offset += sizeof(struct fru_picmgext_link_desc)) {
|
||||
struct fru_picmgext_link_desc * d =
|
||||
(struct fru_picmgext_link_desc *) &fru_data[offset];
|
||||
|
||||
printf(" Link Grouping ID: 0x%02x\n", d->grouping);
|
||||
printf(" Link Type Extension: 0x%02x\n", d->ext);
|
||||
printf(" Link Type: ");
|
||||
if (d->type == 0 || d->type == 0xff)
|
||||
{
|
||||
if (d->type == 0 || d->type == 0xff) {
|
||||
printf("Reserved\n");
|
||||
}
|
||||
else if (d->type >= 0x06 && d->type <= 0xef)
|
||||
{
|
||||
else if (d->type >= 0x06 && d->type <= 0xef) {
|
||||
printf("Reserved\n");
|
||||
}
|
||||
else if (d->type >= 0xf0 && d->type <= 0xfe)
|
||||
{
|
||||
else if (d->type >= 0xf0 && d->type <= 0xfe) {
|
||||
printf("OEM GUID Definition\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
else {
|
||||
switch (d->type)
|
||||
{
|
||||
case FRU_PICMGEXT_LINK_TYPE_BASE:
|
||||
@ -986,7 +966,6 @@ static void ipmi_fru_picmg_ext_print(unsigned char * fru_data, int off, int leng
|
||||
printf(" Channel Number: 0x%02x\n", d->designator & 0x1f);
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case FRU_AMC_CURRENT:
|
||||
@ -1000,14 +979,15 @@ static void ipmi_fru_picmg_ext_print(unsigned char * fru_data, int off, int leng
|
||||
|
||||
max_current = fru_data[offset];
|
||||
max_current |= fru_data[++offset]<<8;
|
||||
|
||||
printf(" Maximum Internal Current(@12V): %i A\n", max_current / 10);
|
||||
printf(" Module Activation Rediness: %i sec.\n", fru_data[++offset]);
|
||||
|
||||
printf(" Descriptor Count: %i\n", fru_data[++offset]);
|
||||
printf("\n");
|
||||
|
||||
for(++offset; offset < off + length; offset += sizeof(struct fru_picmgext_activation_record))
|
||||
{
|
||||
for (++offset;
|
||||
offset < (off + length);
|
||||
offset += sizeof(struct fru_picmgext_activation_record)) {
|
||||
struct fru_picmgext_activation_record * a =
|
||||
(struct fru_picmgext_activation_record *) &fru_data[offset];
|
||||
|
||||
@ -1023,7 +1003,7 @@ static void ipmi_fru_picmg_ext_print(unsigned char * fru_data, int off, int leng
|
||||
{
|
||||
unsigned int index;
|
||||
|
||||
for(offset; offset < off + length; )
|
||||
while (offset < (off + length))
|
||||
{
|
||||
struct fru_picmgext_carrier_p2p_record * h =
|
||||
(struct fru_picmgext_carrier_p2p_record *) &fru_data[offset];
|
||||
@ -1053,7 +1033,6 @@ static void ipmi_fru_picmg_ext_print(unsigned char * fru_data, int off, int leng
|
||||
printf("[ local ID: %02d ]\n", d->remote_resource_id & 0x07);
|
||||
|
||||
offset += sizeof(struct fru_picmgext_carrier_p2p_descriptor);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1325,112 +1304,17 @@ ipmi_fru_print_all(struct ipmi_intf * intf)
|
||||
return rc;
|
||||
}
|
||||
|
||||
int
|
||||
ipmi_fru_main(struct ipmi_intf * intf, int argc, char ** argv)
|
||||
{
|
||||
int rc = 0;
|
||||
|
||||
if (argc == 0)
|
||||
rc = ipmi_fru_print_all(intf);
|
||||
else if (strncmp(argv[0], "help", 4) == 0)
|
||||
lprintf(LOG_ERR, "FRU Commands: print read write upgEkey");
|
||||
else if (strncmp(argv[0], "print", 5) == 0 ||
|
||||
strncmp(argv[0], "list", 4) == 0)
|
||||
{
|
||||
if (argc > 1) {
|
||||
rc = __ipmi_fru_print(intf, strtol(argv[1], NULL, 0));
|
||||
} else {
|
||||
rc = ipmi_fru_print_all(intf);
|
||||
}
|
||||
}
|
||||
else if (!strncmp(argv[0], "read", 5))
|
||||
{
|
||||
unsigned char fruId=0;
|
||||
if((argc >= 3) && (strlen(argv[2]) > 0))
|
||||
{
|
||||
/* There is a file name in the parameters */
|
||||
if(strlen(argv[2]) < 512)
|
||||
{
|
||||
fruId = atoi(argv[1]);
|
||||
strcpy(fileName, argv[2]);
|
||||
if (verbose)
|
||||
{
|
||||
printf("Fru Id : %d\n", fruId);
|
||||
printf("Fru File : %s\n", fileName);
|
||||
}
|
||||
ipmi_fru_read_to_bin(intf,fileName,fruId);
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(stderr,"File name must be smaller than 512 bytes\n");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("fru read <fru id> <fru file>\n");
|
||||
}
|
||||
}
|
||||
else if (!strncmp(argv[0], "write", 5))
|
||||
{
|
||||
unsigned char fruId=0;
|
||||
if((argc >= 3) && (strlen(argv[2]) > 0))
|
||||
{
|
||||
/* There is a file name in the parameters */
|
||||
if(strlen(argv[2]) < 512)
|
||||
{
|
||||
fruId = atoi(argv[1]);
|
||||
strcpy(fileName, argv[2]);
|
||||
if (verbose)
|
||||
{
|
||||
printf("Fru Id : %d\n", fruId);
|
||||
printf("Fru File : %s\n", fileName);
|
||||
}
|
||||
ipmi_fru_write_from_bin(intf,fileName,fruId);
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(stderr,"File name must be smaller than 512 bytes\n");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(stderr,"A Fru Id and a path/file name must be specified\n");
|
||||
fprintf(stderr,"Ex.: ipmitool fru write 0 /root/fru.bin\n");
|
||||
}
|
||||
}
|
||||
else if(!strncmp(argv[0], "upgEkey", 7))
|
||||
{
|
||||
if((argc >= 3) && (strlen(argv[2]) > 0))
|
||||
{
|
||||
strcpy(fileName, argv[2]);
|
||||
ipmi_fru_upg_ekeying(intf,fileName,atoi(argv[1]));
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("fru upgEkey <fru id> <fru file>\n");
|
||||
}
|
||||
}
|
||||
else {
|
||||
lprintf(LOG_ERR, "Invalid FRU command: %s", argv[0]);
|
||||
lprintf(LOG_ERR, "FRU Commands: print");
|
||||
rc = -1;
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
static void ipmi_fru_read_to_bin(struct ipmi_intf * intf,unsigned char * pFileName, unsigned char fruId)
|
||||
static void
|
||||
ipmi_fru_read_to_bin(struct ipmi_intf * intf,
|
||||
unsigned char * pFileName,
|
||||
unsigned char fruId)
|
||||
{
|
||||
struct ipmi_rs * rsp;
|
||||
struct ipmi_rq req;
|
||||
unsigned char * fru_data;
|
||||
struct fru_info fru;
|
||||
unsigned char msg_data[4];
|
||||
|
||||
unsigned char * pFruBuf;
|
||||
unsigned int counter;
|
||||
unsigned int len;
|
||||
|
||||
msg_data[0] = fruId;
|
||||
|
||||
@ -1444,43 +1328,35 @@ static void ipmi_fru_read_to_bin(struct ipmi_intf * intf,unsigned char * pFileNa
|
||||
if (!rsp)
|
||||
return;
|
||||
|
||||
if(rsp->ccode)
|
||||
{
|
||||
if (rsp->ccode > 0) {
|
||||
if (rsp->ccode == 0xc3)
|
||||
printf (" Timeout accessing FRU info. (Device not present?)\n");
|
||||
printf(" Timeout accessing FRU info. (Device not present?)\n");
|
||||
return;
|
||||
}
|
||||
fru.size = (rsp->data[1] << 8) | rsp->data[0];
|
||||
fru.access = rsp->data[2] & 0x1;
|
||||
|
||||
if (verbose)
|
||||
{
|
||||
if (verbose) {
|
||||
printf("Fru Size = %d bytes\n",fru.size);
|
||||
printf("Fru Access = %xh\n", fru.access);
|
||||
}
|
||||
|
||||
pFruBuf = malloc(fru.size);
|
||||
if(pFruBuf != NULL)
|
||||
{
|
||||
if (pFruBuf != NULL) {
|
||||
printf("Fru Size : %d bytes\n",fru.size);
|
||||
read_fru_area(intf, &fru, fruId, 0, fru.size, pFruBuf);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
fprintf(stderr, "Cannot allocate %d bytes\n", fru.size);
|
||||
}
|
||||
|
||||
if(pFruBuf != NULL)
|
||||
if (pFruBuf != NULL)
|
||||
{
|
||||
FILE * pFile;
|
||||
pFile = fopen(pFileName,"wb");
|
||||
if(pFile!=NULL)
|
||||
{
|
||||
if (pFile) {
|
||||
fwrite(pFruBuf, fru.size, 1, pFile);
|
||||
printf("Done\n\r");
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Done\n");
|
||||
} else {
|
||||
fprintf(stderr, "Error opening file %s\n", pFileName);
|
||||
}
|
||||
fclose(pFile);
|
||||
@ -1488,15 +1364,15 @@ static void ipmi_fru_read_to_bin(struct ipmi_intf * intf,unsigned char * pFileNa
|
||||
free(pFruBuf);
|
||||
}
|
||||
|
||||
static void ipmi_fru_write_from_bin(struct ipmi_intf * intf,
|
||||
unsigned char * pFileName, unsigned char fruId)
|
||||
static void
|
||||
ipmi_fru_write_from_bin(struct ipmi_intf * intf,
|
||||
unsigned char * pFileName,
|
||||
unsigned char fruId)
|
||||
{
|
||||
struct ipmi_rs *rsp;
|
||||
struct ipmi_rq req;
|
||||
unsigned char *fru_data;
|
||||
struct fru_info fru;
|
||||
unsigned char msg_data[4];
|
||||
|
||||
unsigned char *pFruBuf;
|
||||
unsigned int len = 0;
|
||||
|
||||
@ -1514,8 +1390,7 @@ static void ipmi_fru_write_from_bin(struct ipmi_intf * intf,
|
||||
|
||||
if (rsp->ccode) {
|
||||
if (rsp->ccode == 0xc3)
|
||||
printf
|
||||
(" Timeout accessing FRU info. (Device not present?)\n");
|
||||
printf(" Timeout accessing FRU info. (Device not present?)\n");
|
||||
return;
|
||||
}
|
||||
fru.size = (rsp->data[1] << 8) | rsp->data[0];
|
||||
@ -1550,8 +1425,9 @@ static void ipmi_fru_write_from_bin(struct ipmi_intf * intf,
|
||||
free(pFruBuf);
|
||||
}
|
||||
|
||||
static int
|
||||
ipmi_fru_upg_ekeying(struct ipmi_intf * intf,unsigned char * pFileName,
|
||||
static void
|
||||
ipmi_fru_upg_ekeying(struct ipmi_intf * intf,
|
||||
unsigned char * pFileName,
|
||||
unsigned char fruId)
|
||||
{
|
||||
unsigned int retStatus = 0;
|
||||
@ -1561,15 +1437,12 @@ ipmi_fru_upg_ekeying(struct ipmi_intf * intf,unsigned char * pFileName,
|
||||
unsigned long fileMultiRecSize = 0;
|
||||
struct fru_info fruInfo;
|
||||
unsigned char *buf = NULL;
|
||||
retStatus =
|
||||
ipmi_fru_get_multirec_location_from_fru(intf, fruId, &fruInfo,
|
||||
retStatus = ipmi_fru_get_multirec_location_from_fru(intf, fruId, &fruInfo,
|
||||
&offFruMultiRec,
|
||||
&fruMultiRecSize);
|
||||
|
||||
if (verbose) {
|
||||
printf("FRU Size : %u\n\r", fruMultiRecSize);
|
||||
printf("Multi Rec offset: %u\n\r", offFruMultiRec);
|
||||
}
|
||||
lprintf(LOG_DEBUG, "FRU Size : %lu\n", fruMultiRecSize);
|
||||
lprintf(LOG_DEBUG, "Multi Rec offset: %lu\n", offFruMultiRec);
|
||||
|
||||
if (retStatus == 0) {
|
||||
retStatus =
|
||||
@ -1592,43 +1465,36 @@ ipmi_fru_upg_ekeying(struct ipmi_intf * intf,unsigned char * pFileName,
|
||||
}
|
||||
}
|
||||
|
||||
if(retStatus == 0)
|
||||
if (retStatus == 0)
|
||||
{
|
||||
ipmi_fru_get_adjust_size_from_buffer(buf, &fileMultiRecSize);
|
||||
}
|
||||
|
||||
if ((retStatus == 0) && (buf)) {
|
||||
if (buf)
|
||||
write_fru_area(intf, &fruInfo, fruId, 0, offFruMultiRec,
|
||||
fileMultiRecSize, buf);
|
||||
}
|
||||
|
||||
}
|
||||
if (buf) {
|
||||
free(buf);
|
||||
}
|
||||
if(retStatus == 0 )
|
||||
{
|
||||
if (retStatus == 0)
|
||||
lprintf(LOG_INFO, "Done");
|
||||
}
|
||||
else
|
||||
{
|
||||
lprintf(LOG_ERR, "Failed");
|
||||
}
|
||||
|
||||
if (buf)
|
||||
free(buf);
|
||||
}
|
||||
|
||||
static int ipmi_fru_get_multirec_size_from_file(unsigned char * pFileName,
|
||||
static int
|
||||
ipmi_fru_get_multirec_size_from_file(unsigned char * pFileName,
|
||||
unsigned long * pSize,
|
||||
unsigned long * pOffset)
|
||||
{
|
||||
struct fru_header header;
|
||||
FILE * pFile;
|
||||
unsigned char len = 0;
|
||||
unsigned long end;
|
||||
|
||||
unsigned long end = 0;
|
||||
*pSize = 0;
|
||||
|
||||
pFile = fopen(pFileName,"rb");
|
||||
if(pFile!=NULL)
|
||||
{
|
||||
if (pFile) {
|
||||
rewind(pFile);
|
||||
len = fread(&header, 1, 8, pFile);
|
||||
fseek(pFile, 0, SEEK_END);
|
||||
@ -1636,54 +1502,35 @@ static int ipmi_fru_get_multirec_size_from_file(unsigned char * pFileName,
|
||||
fclose(pFile);
|
||||
}
|
||||
|
||||
if(verbose)
|
||||
{
|
||||
printf("File Size = %lu\n", end);
|
||||
printf("Len = %lu\n", len);
|
||||
}
|
||||
lprintf(LOG_DEBUG, "File Size = %lu\n", end);
|
||||
lprintf(LOG_DEBUG, "Len = %u\n", len);
|
||||
|
||||
|
||||
if(len != 8)
|
||||
{
|
||||
if (len != 8) {
|
||||
printf("Error with file %s in getting size\n", pFileName);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (header.version != 0x01)
|
||||
{
|
||||
printf ("Unknown FRU header version %02x.\n", header.version);
|
||||
if (header.version != 0x01) {
|
||||
printf("Unknown FRU header version %02x.\n", header.version);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Retreive length */
|
||||
if(
|
||||
((header.offset.internal * 8) > (header.offset.internal * 8)) &&
|
||||
((header.offset.internal * 8) < end)
|
||||
)
|
||||
{
|
||||
if (((header.offset.internal * 8) > (header.offset.internal * 8)) &&
|
||||
((header.offset.internal * 8) < end))
|
||||
end = (header.offset.internal * 8);
|
||||
}
|
||||
if(
|
||||
((header.offset.chassis * 8) > (header.offset.chassis * 8)) &&
|
||||
((header.offset.chassis * 8) < end)
|
||||
)
|
||||
{
|
||||
|
||||
if (((header.offset.chassis * 8) > (header.offset.chassis * 8)) &&
|
||||
((header.offset.chassis * 8) < end))
|
||||
end = (header.offset.chassis * 8);
|
||||
}
|
||||
if(
|
||||
((header.offset.board * 8) > (header.offset.board * 8)) &&
|
||||
((header.offset.board * 8) < end)
|
||||
)
|
||||
{
|
||||
|
||||
if (((header.offset.board * 8) > (header.offset.board * 8)) &&
|
||||
((header.offset.board * 8) < end))
|
||||
end = (header.offset.board * 8);
|
||||
}
|
||||
if(
|
||||
((header.offset.product * 8) > (header.offset.product * 8)) &&
|
||||
((header.offset.product * 8) < end)
|
||||
)
|
||||
{
|
||||
|
||||
if (((header.offset.product * 8) > (header.offset.product * 8)) &&
|
||||
((header.offset.product * 8) < end))
|
||||
end = (header.offset.product * 8);
|
||||
}
|
||||
|
||||
*pSize = end - (header.offset.multi * 8);
|
||||
*pOffset = (header.offset.multi * 8);
|
||||
@ -1691,107 +1538,78 @@ static int ipmi_fru_get_multirec_size_from_file(unsigned char * pFileName,
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void ipmi_fru_get_adjust_size_from_buffer(unsigned char * fru_data,
|
||||
static void
|
||||
ipmi_fru_get_adjust_size_from_buffer(unsigned char * fru_data,
|
||||
unsigned long *pSize)
|
||||
{
|
||||
struct fru_multirec_header * head;
|
||||
unsigned int last_off;
|
||||
#define CHUNK_SIZE (255 + sizeof(struct fru_multirec_header))
|
||||
#define CHUNK_SIZE (255 + sizeof(struct fru_multirec_header))
|
||||
unsigned int count = 0;
|
||||
unsigned int status = 0;
|
||||
unsigned char counter;
|
||||
unsigned char checksum = 0;
|
||||
|
||||
do
|
||||
{
|
||||
do {
|
||||
checksum = 0;
|
||||
head = (struct fru_multirec_header *) (fru_data + count);
|
||||
|
||||
if(verbose )
|
||||
{
|
||||
if (verbose)
|
||||
printf("Adding (");
|
||||
}
|
||||
|
||||
for(
|
||||
counter = 0 ;
|
||||
counter < sizeof (struct fru_multirec_header);
|
||||
counter ++
|
||||
)
|
||||
{
|
||||
if(verbose )
|
||||
{
|
||||
for (counter = 0; counter < sizeof(struct fru_multirec_header); counter++) {
|
||||
if (verbose)
|
||||
printf(" %02X", *(fru_data + count + counter));
|
||||
}
|
||||
checksum += *(fru_data + count + counter);
|
||||
|
||||
}
|
||||
if( verbose )
|
||||
{
|
||||
|
||||
if (verbose)
|
||||
printf(")");
|
||||
}
|
||||
|
||||
if( checksum != 0)
|
||||
{
|
||||
if (checksum != 0) {
|
||||
printf("Bad checksum in Multi Records\n");
|
||||
status = -1;
|
||||
}
|
||||
else if ( verbose )
|
||||
{
|
||||
else if (verbose)
|
||||
printf("--> OK");
|
||||
}
|
||||
|
||||
if((verbose > 1 ) && (checksum == 0))
|
||||
{
|
||||
for(
|
||||
counter = 0 ;
|
||||
counter < head->len;
|
||||
counter ++
|
||||
)
|
||||
{
|
||||
if (verbose > 1 && checksum == 0) {
|
||||
for(counter = 0; counter < head->len; counter++) {
|
||||
printf(" %02X", *(fru_data + count + counter +
|
||||
sizeof(struct fru_multirec_header)));
|
||||
}
|
||||
}
|
||||
if(verbose )
|
||||
{
|
||||
|
||||
if (verbose)
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
count += head->len + sizeof (struct fru_multirec_header);
|
||||
} while( (!(head->format & 0x80)) && (status == 0));
|
||||
|
||||
} while ((!(head->format & 0x80)) && (status == 0));
|
||||
|
||||
*pSize = count;
|
||||
|
||||
if (verbose > 1)
|
||||
{
|
||||
printf("Size of multirec: %u\n\r", *pSize);
|
||||
}
|
||||
lprintf(LOG_DEBUG, "Size of multirec: %lu\n", *pSize);
|
||||
}
|
||||
|
||||
|
||||
static int ipmi_fru_get_multirec_from_file(unsigned char * pFileName,
|
||||
static int
|
||||
ipmi_fru_get_multirec_from_file(unsigned char * pFileName,
|
||||
unsigned char * pBufArea,
|
||||
unsigned long size,
|
||||
unsigned long offset)
|
||||
{
|
||||
struct fru_header header;
|
||||
FILE * pFile;
|
||||
unsigned long len = 0;
|
||||
|
||||
|
||||
pFile = fopen(pFileName,"rb");
|
||||
if(pFile!=NULL)
|
||||
{
|
||||
if (pFile) {
|
||||
fseek(pFile, offset,SEEK_SET);
|
||||
len = fread(pBufArea, size, 1, pFile);
|
||||
fclose(pFile);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
printf("Error opening file\n");
|
||||
}
|
||||
|
||||
if(len != 1)
|
||||
{
|
||||
if (len != 1) {
|
||||
printf("Error with file %s\n", pFileName);
|
||||
return -1;
|
||||
}
|
||||
@ -1799,9 +1617,8 @@ static int ipmi_fru_get_multirec_from_file(unsigned char * pFileName,
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static int ipmi_fru_get_multirec_location_from_fru(struct ipmi_intf * intf,
|
||||
static int
|
||||
ipmi_fru_get_multirec_location_from_fru(struct ipmi_intf * intf,
|
||||
unsigned char fruId,
|
||||
struct fru_info *pFruInfo,
|
||||
unsigned long * pRetLocation,
|
||||
@ -1809,12 +1626,8 @@ static int ipmi_fru_get_multirec_location_from_fru(struct ipmi_intf * intf,
|
||||
{
|
||||
struct ipmi_rs * rsp;
|
||||
struct ipmi_rq req;
|
||||
unsigned char * fru_data;
|
||||
unsigned char msg_data[4];
|
||||
int i, len;
|
||||
unsigned long end;
|
||||
|
||||
|
||||
struct fru_header header;
|
||||
|
||||
*pRetLocation = 0;
|
||||
@ -1829,30 +1642,28 @@ static int ipmi_fru_get_multirec_location_from_fru(struct ipmi_intf * intf,
|
||||
|
||||
rsp = intf->sendrecv(intf, &req);
|
||||
if (!rsp) {
|
||||
if (verbose > 1) {
|
||||
if (verbose > 1)
|
||||
printf("no response\n");
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(rsp->ccode)
|
||||
{
|
||||
if (rsp->ccode == 0xc3) {
|
||||
printf (" Timeout accessing FRU info. (Device not present?)\n");
|
||||
} else {
|
||||
printf (" CCODE = 0x%02x\n", rsp->ccode);
|
||||
}
|
||||
if (rsp->ccode > 0) {
|
||||
if (rsp->ccode == 0xc3)
|
||||
printf(" Timeout accessing FRU info. (Device not present?)\n");
|
||||
else
|
||||
printf(" CCODE = 0x%02x\n", rsp->ccode);
|
||||
return -1;
|
||||
}
|
||||
|
||||
pFruInfo->size = (rsp->data[1] << 8) | rsp->data[0];
|
||||
pFruInfo->access = rsp->data[2] & 0x1;
|
||||
|
||||
if (verbose > 1)
|
||||
printf("pFruInfo->size = %d bytes (accessed by %s)\n",
|
||||
pFruInfo->size, pFruInfo->access ? "words" : "bytes");
|
||||
if (!pFruInfo->size) {
|
||||
|
||||
if (!pFruInfo->size)
|
||||
return -1;
|
||||
}
|
||||
|
||||
msg_data[0] = fruId;
|
||||
msg_data[1] = 0;
|
||||
@ -1866,15 +1677,11 @@ static int ipmi_fru_get_multirec_location_from_fru(struct ipmi_intf * intf,
|
||||
req.msg.data_len = 4;
|
||||
|
||||
rsp = intf->sendrecv(intf, &req);
|
||||
|
||||
if (!rsp)
|
||||
return -1;
|
||||
|
||||
if(rsp->ccode)
|
||||
{
|
||||
if (rsp->ccode == 0xc3) {
|
||||
printf (" Timeout while reading FRU data. (Device not present?)\n");
|
||||
}
|
||||
if (rsp->ccode > 0) {
|
||||
if (rsp->ccode == 0xc3)
|
||||
printf(" Timeout while reading FRU data. (Device not present?)\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -1883,45 +1690,116 @@ static int ipmi_fru_get_multirec_location_from_fru(struct ipmi_intf * intf,
|
||||
|
||||
memcpy(&header, rsp->data + 1, 8);
|
||||
|
||||
if (header.version != 0x01)
|
||||
{
|
||||
printf (" Unknown FRU header version %02x.\n", header.version);
|
||||
if (header.version != 0x01) {
|
||||
printf(" Unknown FRU header version %02x.\n", header.version);
|
||||
return -1;
|
||||
}
|
||||
|
||||
end = pFruInfo->size;
|
||||
|
||||
/* Retreive length */
|
||||
if(
|
||||
((header.offset.internal * 8) > (header.offset.internal * 8)) &&
|
||||
((header.offset.internal * 8) < end)
|
||||
)
|
||||
{
|
||||
if (((header.offset.internal * 8) > (header.offset.internal * 8)) &&
|
||||
((header.offset.internal * 8) < end))
|
||||
end = (header.offset.internal * 8);
|
||||
}
|
||||
if(
|
||||
((header.offset.chassis * 8) > (header.offset.chassis * 8)) &&
|
||||
((header.offset.chassis * 8) < end)
|
||||
)
|
||||
{
|
||||
|
||||
if (((header.offset.chassis * 8) > (header.offset.chassis * 8)) &&
|
||||
((header.offset.chassis * 8) < end))
|
||||
end = (header.offset.chassis * 8);
|
||||
}
|
||||
if(
|
||||
((header.offset.board * 8) > (header.offset.board * 8)) &&
|
||||
((header.offset.board * 8) < end)
|
||||
)
|
||||
{
|
||||
|
||||
if (((header.offset.board * 8) > (header.offset.board * 8)) &&
|
||||
((header.offset.board * 8) < end))
|
||||
end = (header.offset.board * 8);
|
||||
}
|
||||
if(
|
||||
((header.offset.product * 8) > (header.offset.product * 8)) &&
|
||||
((header.offset.product * 8) < end)
|
||||
)
|
||||
{
|
||||
|
||||
if (((header.offset.product * 8) > (header.offset.product * 8)) &&
|
||||
((header.offset.product * 8) < end))
|
||||
end = (header.offset.product * 8);
|
||||
}
|
||||
|
||||
*pRetSize = end;
|
||||
*pRetLocation = 8 * header.offset.multi;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
ipmi_fru_main(struct ipmi_intf * intf, int argc, char ** argv)
|
||||
{
|
||||
int rc = 0;
|
||||
|
||||
if (argc == 0) {
|
||||
rc = ipmi_fru_print_all(intf);
|
||||
}
|
||||
else if (strncmp(argv[0], "help", 4) == 0) {
|
||||
lprintf(LOG_ERR, "FRU Commands: print read write upgEkey");
|
||||
}
|
||||
else if (strncmp(argv[0], "print", 5) == 0 ||
|
||||
strncmp(argv[0], "list", 4) == 0) {
|
||||
if (argc > 1) {
|
||||
rc = __ipmi_fru_print(intf, strtol(argv[1], NULL, 0));
|
||||
} else {
|
||||
rc = ipmi_fru_print_all(intf);
|
||||
}
|
||||
}
|
||||
else if (!strncmp(argv[0], "read", 5)) {
|
||||
unsigned char fruId=0;
|
||||
if((argc >= 3) && (strlen(argv[2]) > 0))
|
||||
{
|
||||
/* There is a file name in the parameters */
|
||||
if(strlen(argv[2]) < 512)
|
||||
{
|
||||
fruId = atoi(argv[1]);
|
||||
strcpy(fileName, argv[2]);
|
||||
if (verbose)
|
||||
{
|
||||
printf("Fru Id : %d\n", fruId);
|
||||
printf("Fru File : %s\n", fileName);
|
||||
}
|
||||
ipmi_fru_read_to_bin(intf,fileName,fruId);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
fprintf(stderr,"File name must be smaller than 512 bytes\n");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("fru read <fru id> <fru file>\n");
|
||||
}
|
||||
}
|
||||
else if (!strncmp(argv[0], "write", 5)) {
|
||||
unsigned char fruId = 0;
|
||||
|
||||
if ((argc >= 3) && (strlen(argv[2]) > 0)) {
|
||||
/* There is a file name in the parameters */
|
||||
if (strlen(argv[2]) < 512) {
|
||||
fruId = atoi(argv[1]);
|
||||
strcpy(fileName, argv[2]);
|
||||
if (verbose) {
|
||||
printf("Fru Id : %d\n", fruId);
|
||||
printf("Fru File : %s\n", fileName);
|
||||
}
|
||||
ipmi_fru_write_from_bin(intf,fileName,fruId);
|
||||
} else {
|
||||
fprintf(stderr,"File name must be smaller than 512 bytes\n");
|
||||
}
|
||||
} else {
|
||||
fprintf(stderr,"A Fru Id and a path/file name must be specified\n");
|
||||
fprintf(stderr,"Ex.: ipmitool fru write 0 /root/fru.bin\n");
|
||||
}
|
||||
}
|
||||
else if (!strncmp(argv[0], "upgEkey", 7)) {
|
||||
if ((argc >= 3) && (strlen(argv[2]) > 0)) {
|
||||
strcpy(fileName, argv[2]);
|
||||
ipmi_fru_upg_ekeying(intf,fileName,atoi(argv[1]));
|
||||
} else {
|
||||
printf("fru upgEkey <fru id> <fru file>\n");
|
||||
}
|
||||
}
|
||||
else {
|
||||
lprintf(LOG_ERR, "Invalid FRU command: %s", argv[0]);
|
||||
lprintf(LOG_ERR, "FRU Commands: print");
|
||||
rc = -1;
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user