fix formatting and compile warnings

This commit is contained in:
Duncan Laurie 2006-05-16 23:06:38 +00:00
parent 78f8f0793f
commit 12a6554416

View File

@ -55,30 +55,21 @@
*/ */
#define LIMIT_ALL_REQUEST_SIZE 1 #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]; 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); 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 /* 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; break;
} }
if (size < 1) if (size < 1) {
{
*offset = off; *offset = off;
return NULL; 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) if (fru->access && fru_data_rqst_size > 16)
#endif #endif
fru_data_rqst_size = 16; fru_data_rqst_size = 16;
do
{ do {
/* real destination offset */ /* real destination offset */
tmp = fru->access ? (doffset+off) >> 1 : (doffset+off); tmp = fru->access ? (doffset+off) >> 1 : (doffset+off);
msg_data[0] = id; msg_data[0] = id;
msg_data[1] = (unsigned char)tmp; msg_data[1] = (unsigned char)tmp;
msg_data[2] = (unsigned char)(tmp >> 8); msg_data[2] = (unsigned char)(tmp >> 8);
tmp = finish - (doffset+off); /* bytes remaining */ tmp = finish - (doffset+off); /* bytes remaining */
if (tmp > 16) if (tmp > 16) {
{
lprintf(LOG_INFO,"Writting 16 bytes"); 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; req.msg.data_len = 16 + 3;
} }
else else {
{
lprintf(LOG_INFO,"Writting %d bytes", tmp); 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; req.msg.data_len = tmp + 3;
} }
writeLength = req.msg.data_len-3; writeLength = req.msg.data_len - 3;
rsp = intf->sendrecv(intf, &req); rsp = intf->sendrecv(intf, &req);
if (!rsp) if (!rsp) {
break; 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); lprintf(LOG_NOTICE,"Bad CC -> %x\n", rsp->ccode);
break; /*continue;*/ break; /*continue;*/
} }
if (rsp->ccode) if (rsp->ccode > 0)
break; break;
off += writeLength; off += writeLength;
} while ((doffset+off) < finish); } while ((doffset+off) < finish);
return ((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) if (fru->access && fru_data_rqst_size > 16)
#endif #endif
fru_data_rqst_size = 16; fru_data_rqst_size = 16;
do { do {
tmp = fru->access ? off >> 1 : off; tmp = fru->access ? off >> 1 : off;
msg_data[0] = id; 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, ipmi_fru_picmg_ext_print(fru_data,
i + sizeof(struct fru_multirec_header), i + sizeof(struct fru_multirec_header),
h->len); h->len);
break; break;
} }
i += h->len + sizeof (struct fru_multirec_header); 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: case FRU_PICMG_BACKPLANE_P2P:
{ {
unsigned char index, index2; unsigned char index;
struct fru_picmgext_slot_desc * slot_d struct fru_picmgext_slot_desc * slot_d
= (struct fru_picmgext_slot_desc*) &fru_data[offset]; = (struct fru_picmgext_slot_desc*) &fru_data[offset];
offset += sizeof(struct fru_picmgext_slot_desc); offset += sizeof(struct fru_picmgext_slot_desc);
printf(" FRU_PICMG_BACKPLANE_P2P\n"); printf(" FRU_PICMG_BACKPLANE_P2P\n");
for ( ; offset <= (start_offset+length) ; ) while (offset <= (start_offset+length)) {
{
printf("\n"); printf("\n");
printf(" Channel Type: "); printf(" Channel Type: ");
switch ( slot_d -> chan_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(" Slot Addr. : %02x\n", slot_d -> slot_addr );
printf(" Channel Count: %i\n", slot_d -> chn_count); 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 * d
= (struct fru_picmgext_chn_desc *) &fru_data[offset]; = (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: case FRU_PICMG_BOARD_P2P:
printf(" FRU_PICMG_BOARD_P2P\n"); printf(" FRU_PICMG_BOARD_P2P\n");
guid_count = fru_data[offset]; guid_count = fru_data[offset];
printf(" GUID count: %2d\n", guid_count); 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); printf(" GUID %2d:\n", i);
offset += sizeof(struct fru_picmgext_guid); offset += sizeof(struct fru_picmgext_guid);
} }
for ( for (++offset;
++offset; offset < (off + length);
offset < off + length; offset += sizeof(struct fru_picmgext_link_desc)) {
offset += sizeof(struct fru_picmgext_link_desc)
)
{
struct fru_picmgext_link_desc * d = struct fru_picmgext_link_desc * d =
(struct fru_picmgext_link_desc *) &fru_data[offset]; (struct fru_picmgext_link_desc *) &fru_data[offset];
printf(" Link Grouping ID: 0x%02x\n", d->grouping); printf(" Link Grouping ID: 0x%02x\n", d->grouping);
printf(" Link Type Extension: 0x%02x\n", d->ext); printf(" Link Type Extension: 0x%02x\n", d->ext);
printf(" Link Type: "); printf(" Link Type: ");
if (d->type == 0 || d->type == 0xff) if (d->type == 0 || d->type == 0xff) {
{
printf("Reserved\n"); printf("Reserved\n");
} }
else if (d->type >= 0x06 && d->type <= 0xef) else if (d->type >= 0x06 && d->type <= 0xef) {
{
printf("Reserved\n"); printf("Reserved\n");
} }
else if (d->type >= 0xf0 && d->type <= 0xfe) else if (d->type >= 0xf0 && d->type <= 0xfe) {
{
printf("OEM GUID Definition\n"); printf("OEM GUID Definition\n");
} }
else else {
{
switch (d->type) switch (d->type)
{ {
case FRU_PICMGEXT_LINK_TYPE_BASE: 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(" Channel Number: 0x%02x\n", d->designator & 0x1f);
printf("\n"); printf("\n");
} }
break; break;
case FRU_AMC_CURRENT: 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];
max_current |= fru_data[++offset]<<8; max_current |= fru_data[++offset]<<8;
printf(" Maximum Internal Current(@12V): %i A\n", max_current / 10); printf(" Maximum Internal Current(@12V): %i A\n", max_current / 10);
printf(" Module Activation Rediness: %i sec.\n", fru_data[++offset]); printf(" Module Activation Rediness: %i sec.\n", fru_data[++offset]);
printf(" Descriptor Count: %i\n", fru_data[++offset]); printf(" Descriptor Count: %i\n", fru_data[++offset]);
printf("\n"); 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 * a =
(struct fru_picmgext_activation_record *) &fru_data[offset]; (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; 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 * h =
(struct fru_picmgext_carrier_p2p_record *) &fru_data[offset]; (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); printf("[ local ID: %02d ]\n", d->remote_resource_id & 0x07);
offset += sizeof(struct fru_picmgext_carrier_p2p_descriptor); offset += sizeof(struct fru_picmgext_carrier_p2p_descriptor);
} }
} }
} }
@ -1325,112 +1304,17 @@ ipmi_fru_print_all(struct ipmi_intf * intf)
return rc; return rc;
} }
int
ipmi_fru_main(struct ipmi_intf * intf, int argc, char ** argv)
{
int rc = 0;
if (argc == 0) static void
rc = ipmi_fru_print_all(intf); ipmi_fru_read_to_bin(struct ipmi_intf * intf,
else if (strncmp(argv[0], "help", 4) == 0) unsigned char * pFileName,
lprintf(LOG_ERR, "FRU Commands: print read write upgEkey"); unsigned char fruId)
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)
{ {
struct ipmi_rs * rsp; struct ipmi_rs * rsp;
struct ipmi_rq req; struct ipmi_rq req;
unsigned char * fru_data;
struct fru_info fru; struct fru_info fru;
unsigned char msg_data[4]; unsigned char msg_data[4];
unsigned char * pFruBuf; unsigned char * pFruBuf;
unsigned int counter;
unsigned int len;
msg_data[0] = fruId; msg_data[0] = fruId;
@ -1444,43 +1328,35 @@ static void ipmi_fru_read_to_bin(struct ipmi_intf * intf,unsigned char * pFileNa
if (!rsp) if (!rsp)
return; return;
if(rsp->ccode) if (rsp->ccode > 0) {
{
if (rsp->ccode == 0xc3) if (rsp->ccode == 0xc3)
printf (" Timeout accessing FRU info. (Device not present?)\n"); printf(" Timeout accessing FRU info. (Device not present?)\n");
return; return;
} }
fru.size = (rsp->data[1] << 8) | rsp->data[0]; fru.size = (rsp->data[1] << 8) | rsp->data[0];
fru.access = rsp->data[2] & 0x1; fru.access = rsp->data[2] & 0x1;
if (verbose) if (verbose) {
{
printf("Fru Size = %d bytes\n",fru.size); printf("Fru Size = %d bytes\n",fru.size);
printf("Fru Access = %xh\n", fru.access); printf("Fru Access = %xh\n", fru.access);
} }
pFruBuf = malloc(fru.size); pFruBuf = malloc(fru.size);
if(pFruBuf != NULL) if (pFruBuf != NULL) {
{
printf("Fru Size : %d bytes\n",fru.size); printf("Fru Size : %d bytes\n",fru.size);
read_fru_area(intf, &fru, fruId, 0, fru.size, pFruBuf); read_fru_area(intf, &fru, fruId, 0, fru.size, pFruBuf);
} } else {
else
{
fprintf(stderr, "Cannot allocate %d bytes\n", fru.size); fprintf(stderr, "Cannot allocate %d bytes\n", fru.size);
} }
if(pFruBuf != NULL) if (pFruBuf != NULL)
{ {
FILE * pFile; FILE * pFile;
pFile = fopen(pFileName,"wb"); pFile = fopen(pFileName,"wb");
if(pFile!=NULL) if (pFile) {
{
fwrite(pFruBuf, fru.size, 1, pFile); fwrite(pFruBuf, fru.size, 1, pFile);
printf("Done\n\r"); printf("Done\n");
} } else {
else
{
fprintf(stderr, "Error opening file %s\n", pFileName); fprintf(stderr, "Error opening file %s\n", pFileName);
} }
fclose(pFile); fclose(pFile);
@ -1488,15 +1364,15 @@ static void ipmi_fru_read_to_bin(struct ipmi_intf * intf,unsigned char * pFileNa
free(pFruBuf); free(pFruBuf);
} }
static void ipmi_fru_write_from_bin(struct ipmi_intf * intf, static void
unsigned char * pFileName, unsigned char fruId) ipmi_fru_write_from_bin(struct ipmi_intf * intf,
unsigned char * pFileName,
unsigned char fruId)
{ {
struct ipmi_rs *rsp; struct ipmi_rs *rsp;
struct ipmi_rq req; struct ipmi_rq req;
unsigned char *fru_data;
struct fru_info fru; struct fru_info fru;
unsigned char msg_data[4]; unsigned char msg_data[4];
unsigned char *pFruBuf; unsigned char *pFruBuf;
unsigned int len = 0; 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) {
if (rsp->ccode == 0xc3) if (rsp->ccode == 0xc3)
printf printf(" Timeout accessing FRU info. (Device not present?)\n");
(" Timeout accessing FRU info. (Device not present?)\n");
return; return;
} }
fru.size = (rsp->data[1] << 8) | rsp->data[0]; 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); free(pFruBuf);
} }
static int static void
ipmi_fru_upg_ekeying(struct ipmi_intf * intf,unsigned char * pFileName, ipmi_fru_upg_ekeying(struct ipmi_intf * intf,
unsigned char * pFileName,
unsigned char fruId) unsigned char fruId)
{ {
unsigned int retStatus = 0; unsigned int retStatus = 0;
@ -1561,15 +1437,12 @@ ipmi_fru_upg_ekeying(struct ipmi_intf * intf,unsigned char * pFileName,
unsigned long fileMultiRecSize = 0; unsigned long fileMultiRecSize = 0;
struct fru_info fruInfo; struct fru_info fruInfo;
unsigned char *buf = NULL; unsigned char *buf = NULL;
retStatus = retStatus = ipmi_fru_get_multirec_location_from_fru(intf, fruId, &fruInfo,
ipmi_fru_get_multirec_location_from_fru(intf, fruId, &fruInfo,
&offFruMultiRec, &offFruMultiRec,
&fruMultiRecSize); &fruMultiRecSize);
if (verbose) { lprintf(LOG_DEBUG, "FRU Size : %lu\n", fruMultiRecSize);
printf("FRU Size : %u\n\r", fruMultiRecSize); lprintf(LOG_DEBUG, "Multi Rec offset: %lu\n", offFruMultiRec);
printf("Multi Rec offset: %u\n\r", offFruMultiRec);
}
if (retStatus == 0) { if (retStatus == 0) {
retStatus = 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); ipmi_fru_get_adjust_size_from_buffer(buf, &fileMultiRecSize);
} if (buf)
if ((retStatus == 0) && (buf)) {
write_fru_area(intf, &fruInfo, fruId, 0, offFruMultiRec, write_fru_area(intf, &fruInfo, fruId, 0, offFruMultiRec,
fileMultiRecSize, buf); fileMultiRecSize, buf);
}
} if (retStatus == 0)
if (buf) {
free(buf);
}
if(retStatus == 0 )
{
lprintf(LOG_INFO, "Done"); lprintf(LOG_INFO, "Done");
}
else else
{
lprintf(LOG_ERR, "Failed"); 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 * pSize,
unsigned long * pOffset) unsigned long * pOffset)
{ {
struct fru_header header; struct fru_header header;
FILE * pFile; FILE * pFile;
unsigned char len = 0; unsigned char len = 0;
unsigned long end; unsigned long end = 0;
*pSize = 0; *pSize = 0;
pFile = fopen(pFileName,"rb"); pFile = fopen(pFileName,"rb");
if(pFile!=NULL) if (pFile) {
{
rewind(pFile); rewind(pFile);
len = fread(&header, 1, 8, pFile); len = fread(&header, 1, 8, pFile);
fseek(pFile, 0, SEEK_END); fseek(pFile, 0, SEEK_END);
@ -1636,54 +1502,35 @@ static int ipmi_fru_get_multirec_size_from_file(unsigned char * pFileName,
fclose(pFile); fclose(pFile);
} }
if(verbose) lprintf(LOG_DEBUG, "File Size = %lu\n", end);
{ lprintf(LOG_DEBUG, "Len = %u\n", len);
printf("File Size = %lu\n", end);
printf("Len = %lu\n", len);
}
if (len != 8) {
if(len != 8)
{
printf("Error with file %s in getting size\n", pFileName); printf("Error with file %s in getting size\n", pFileName);
return -1; return -1;
} }
if (header.version != 0x01) if (header.version != 0x01) {
{ printf("Unknown FRU header version %02x.\n", header.version);
printf ("Unknown FRU header version %02x.\n", header.version);
return -1; return -1;
} }
/* Retreive length */ /* Retreive length */
if( if (((header.offset.internal * 8) > (header.offset.internal * 8)) &&
((header.offset.internal * 8) > (header.offset.internal * 8)) && ((header.offset.internal * 8) < end))
((header.offset.internal * 8) < end)
)
{
end = (header.offset.internal * 8); end = (header.offset.internal * 8);
}
if( if (((header.offset.chassis * 8) > (header.offset.chassis * 8)) &&
((header.offset.chassis * 8) > (header.offset.chassis * 8)) && ((header.offset.chassis * 8) < end))
((header.offset.chassis * 8) < end)
)
{
end = (header.offset.chassis * 8); end = (header.offset.chassis * 8);
}
if( if (((header.offset.board * 8) > (header.offset.board * 8)) &&
((header.offset.board * 8) > (header.offset.board * 8)) && ((header.offset.board * 8) < end))
((header.offset.board * 8) < end)
)
{
end = (header.offset.board * 8); end = (header.offset.board * 8);
}
if( if (((header.offset.product * 8) > (header.offset.product * 8)) &&
((header.offset.product * 8) > (header.offset.product * 8)) && ((header.offset.product * 8) < end))
((header.offset.product * 8) < end)
)
{
end = (header.offset.product * 8); end = (header.offset.product * 8);
}
*pSize = end - (header.offset.multi * 8); *pSize = end - (header.offset.multi * 8);
*pOffset = (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; 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) unsigned long *pSize)
{ {
struct fru_multirec_header * head; 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 count = 0;
unsigned int status = 0; unsigned int status = 0;
unsigned char counter; unsigned char counter;
unsigned char checksum = 0; unsigned char checksum = 0;
do do {
{
checksum = 0; checksum = 0;
head = (struct fru_multirec_header *) (fru_data + count); head = (struct fru_multirec_header *) (fru_data + count);
if(verbose ) if (verbose)
{
printf("Adding ("); printf("Adding (");
}
for( for (counter = 0; counter < sizeof(struct fru_multirec_header); counter++) {
counter = 0 ; if (verbose)
counter < sizeof (struct fru_multirec_header);
counter ++
)
{
if(verbose )
{
printf(" %02X", *(fru_data + count + counter)); printf(" %02X", *(fru_data + count + counter));
}
checksum += *(fru_data + count + counter); checksum += *(fru_data + count + counter);
} }
if( verbose )
{ if (verbose)
printf(")"); printf(")");
}
if( checksum != 0) if (checksum != 0) {
{
printf("Bad checksum in Multi Records\n"); printf("Bad checksum in Multi Records\n");
status = -1; status = -1;
} }
else if ( verbose ) else if (verbose)
{
printf("--> OK"); printf("--> OK");
}
if((verbose > 1 ) && (checksum == 0)) if (verbose > 1 && checksum == 0) {
{ for(counter = 0; counter < head->len; counter++) {
for(
counter = 0 ;
counter < head->len;
counter ++
)
{
printf(" %02X", *(fru_data + count + counter + printf(" %02X", *(fru_data + count + counter +
sizeof(struct fru_multirec_header))); sizeof(struct fru_multirec_header)));
} }
} }
if(verbose )
{ if (verbose)
printf("\n"); printf("\n");
}
count += head->len + sizeof (struct fru_multirec_header); count += head->len + sizeof (struct fru_multirec_header);
} while( (!(head->format & 0x80)) && (status == 0));
} while ((!(head->format & 0x80)) && (status == 0));
*pSize = count; *pSize = count;
if (verbose > 1) lprintf(LOG_DEBUG, "Size of multirec: %lu\n", *pSize);
{
printf("Size of multirec: %u\n\r", *pSize);
}
} }
static int
static int ipmi_fru_get_multirec_from_file(unsigned char * pFileName, ipmi_fru_get_multirec_from_file(unsigned char * pFileName,
unsigned char * pBufArea, unsigned char * pBufArea,
unsigned long size, unsigned long size,
unsigned long offset) unsigned long offset)
{ {
struct fru_header header;
FILE * pFile; FILE * pFile;
unsigned long len = 0; unsigned long len = 0;
pFile = fopen(pFileName,"rb"); pFile = fopen(pFileName,"rb");
if(pFile!=NULL) if (pFile) {
{
fseek(pFile, offset,SEEK_SET); fseek(pFile, offset,SEEK_SET);
len = fread(pBufArea, size, 1, pFile); len = fread(pBufArea, size, 1, pFile);
fclose(pFile); fclose(pFile);
} } else {
else
{
printf("Error opening file\n"); printf("Error opening file\n");
} }
if(len != 1) if (len != 1) {
{
printf("Error with file %s\n", pFileName); printf("Error with file %s\n", pFileName);
return -1; return -1;
} }
@ -1799,9 +1617,8 @@ static int ipmi_fru_get_multirec_from_file(unsigned char * pFileName,
return 0; 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, unsigned char fruId,
struct fru_info *pFruInfo, struct fru_info *pFruInfo,
unsigned long * pRetLocation, 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_rs * rsp;
struct ipmi_rq req; struct ipmi_rq req;
unsigned char * fru_data;
unsigned char msg_data[4]; unsigned char msg_data[4];
int i, len;
unsigned long end; unsigned long end;
struct fru_header header; struct fru_header header;
*pRetLocation = 0; *pRetLocation = 0;
@ -1829,30 +1642,28 @@ static int ipmi_fru_get_multirec_location_from_fru(struct ipmi_intf * intf,
rsp = intf->sendrecv(intf, &req); rsp = intf->sendrecv(intf, &req);
if (!rsp) { if (!rsp) {
if (verbose > 1) { if (verbose > 1)
printf("no response\n"); printf("no response\n");
}
return -1; return -1;
} }
if(rsp->ccode) if (rsp->ccode > 0) {
{ if (rsp->ccode == 0xc3)
if (rsp->ccode == 0xc3) { printf(" Timeout accessing FRU info. (Device not present?)\n");
printf (" Timeout accessing FRU info. (Device not present?)\n"); else
} else { printf(" CCODE = 0x%02x\n", rsp->ccode);
printf (" CCODE = 0x%02x\n", rsp->ccode);
}
return -1; return -1;
} }
pFruInfo->size = (rsp->data[1] << 8) | rsp->data[0]; pFruInfo->size = (rsp->data[1] << 8) | rsp->data[0];
pFruInfo->access = rsp->data[2] & 0x1; pFruInfo->access = rsp->data[2] & 0x1;
if (verbose > 1) if (verbose > 1)
printf("pFruInfo->size = %d bytes (accessed by %s)\n", printf("pFruInfo->size = %d bytes (accessed by %s)\n",
pFruInfo->size, pFruInfo->access ? "words" : "bytes"); pFruInfo->size, pFruInfo->access ? "words" : "bytes");
if (!pFruInfo->size) {
if (!pFruInfo->size)
return -1; return -1;
}
msg_data[0] = fruId; msg_data[0] = fruId;
msg_data[1] = 0; 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; req.msg.data_len = 4;
rsp = intf->sendrecv(intf, &req); rsp = intf->sendrecv(intf, &req);
if (!rsp) if (!rsp)
return -1; return -1;
if (rsp->ccode > 0) {
if(rsp->ccode) if (rsp->ccode == 0xc3)
{ printf(" Timeout while reading FRU data. (Device not present?)\n");
if (rsp->ccode == 0xc3) {
printf (" Timeout while reading FRU data. (Device not present?)\n");
}
return -1; 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); memcpy(&header, rsp->data + 1, 8);
if (header.version != 0x01) if (header.version != 0x01) {
{ printf(" Unknown FRU header version %02x.\n", header.version);
printf (" Unknown FRU header version %02x.\n", header.version);
return -1; return -1;
} }
end = pFruInfo->size; end = pFruInfo->size;
/* Retreive length */ /* Retreive length */
if( if (((header.offset.internal * 8) > (header.offset.internal * 8)) &&
((header.offset.internal * 8) > (header.offset.internal * 8)) && ((header.offset.internal * 8) < end))
((header.offset.internal * 8) < end)
)
{
end = (header.offset.internal * 8); end = (header.offset.internal * 8);
}
if( if (((header.offset.chassis * 8) > (header.offset.chassis * 8)) &&
((header.offset.chassis * 8) > (header.offset.chassis * 8)) && ((header.offset.chassis * 8) < end))
((header.offset.chassis * 8) < end)
)
{
end = (header.offset.chassis * 8); end = (header.offset.chassis * 8);
}
if( if (((header.offset.board * 8) > (header.offset.board * 8)) &&
((header.offset.board * 8) > (header.offset.board * 8)) && ((header.offset.board * 8) < end))
((header.offset.board * 8) < end)
)
{
end = (header.offset.board * 8); end = (header.offset.board * 8);
}
if( if (((header.offset.product * 8) > (header.offset.product * 8)) &&
((header.offset.product * 8) > (header.offset.product * 8)) && ((header.offset.product * 8) < end))
((header.offset.product * 8) < end)
)
{
end = (header.offset.product * 8); end = (header.offset.product * 8);
}
*pRetSize = end; *pRetSize = end;
*pRetLocation = 8 * header.offset.multi; *pRetLocation = 8 * header.offset.multi;
return 0; 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;
}