summaryrefslogtreecommitdiff
path: root/util/ifru.c
diff options
context:
space:
mode:
Diffstat (limited to 'util/ifru.c')
-rw-r--r--util/ifru.c45
1 files changed, 28 insertions, 17 deletions
diff --git a/util/ifru.c b/util/ifru.c
index 86e47bf..9b51aad 100644
--- a/util/ifru.c
+++ b/util/ifru.c
@@ -847,30 +847,31 @@ show_fru(uchar sa, uchar frudev, uchar frutype, uchar *pfrubuf)
pfru0 = &pfrubuf[0]; /*pointer to fru start*/
pfru = &pfrubuf[0];
sz = 8; /*minimum for common header*/
- for (i = 1; i < 6; i++) /* walk thru offsets */
- if (pfrubuf[i] != 0) sz = pfrubuf[i] * 8;
+ for (i = 1; i < 6; i++) { /* walk thru offsets */
+ if (pfrubuf[i] != 0) sz = pfrubuf[i] * 8;
+ }
if (sz > 8) { /* if have at least one section */
- if (pfrubuf[5] != 0) j = 5 + pfrubuf[sz+2]; /*if multi-record area*/
- else j = pfrubuf[sz+1] * 8; /* else add length of last section */
- sz += j;
+ if (pfrubuf[5] != 0) j = 5 + pfrubuf[sz+2]; /*if multi-record area*/
+ else j = pfrubuf[sz+1] * 8; /* else add length of last section */
+ sz += j;
}
/* Now, sz = size used, sfru = total available size */
if (sz > sfru) {
if (fdebug) {
- uchar hsum;
+ uchar hsum;
printf("FRU Header: ");
for (i = 0; i < 8; i++) printf("%02x ",pfrubuf[i]);
printf("\n");
hsum = calc_cksum(&pfrubuf[0],7);
- if (pfrubuf[7] != hsum)
+ if (pfrubuf[7] != hsum)
printf("FRU Header checksum mismatch (%x != %x)\n",pfrubuf[7],hsum);
}
printf("FRU size used=%d > available=%d\n",sz,sfru);
if (fpicmg || fdoanyway) sz = sfru; /*do it anyway*/
else {
printf("Please apply the correct FRU/SDR diskette\n");
- return(ERR_OTHER);
+ return(ERR_OTHER);
}
}
/* internal area offset, length */
@@ -890,10 +891,11 @@ show_fru(uchar sa, uchar frudev, uchar frutype, uchar *pfrubuf)
mlen = 0;
if (moff > 0) {
for (i = moff; i < sfru; ) {
+ if (pfrubuf[i] == 0 && pfrubuf[i+2] == 0) break; /*type/len invalid*/
j = 5 + pfrubuf[i+2];
- mlen += j;
+ mlen += j;
if (pfrubuf[i+1] & 0x80) break;
- i += j;
+ i += j;
}
}
@@ -1057,8 +1059,9 @@ show_fru(uchar sa, uchar frudev, uchar frutype, uchar *pfrubuf)
j = moff;
for (i = 0; j < sz ; i++)
{
+ if (pfru[0] == 0 && pfru[2] == 0) break; /*type/len invalid*/
n = pfru[2]; /* len of this record */
- show_fru_multi(devstr,i,pfru[0],&pfru[5],n);
+ show_fru_multi(devstr,i,pfru[0],&pfru[5],n);
j += (5 + n);
if (pfru[1] & 0x80) j = sz; /*0x80 = last in list, break*/
pfru += (5 + n);
@@ -1770,7 +1773,7 @@ int i_fru(int argc, char **argv)
parse_lan_options(c,optarg,fdebug);
break;
default:
- printf("Usage: %s [-bceikmtvx -a asset_tag -s ser_num -NUPREFTVY]\n",
+ printf("Usage: %s [-bceikmtvx -a asset_tag -s ser_num -NUPREFTVYZ]\n",
progname);
printf(" -a tag Sets the Product Asset Tag\n");
printf(" -b Only show Baseboard FRU data\n");
@@ -2030,7 +2033,11 @@ int i_fru(int argc, char **argv)
if (fdump && ret == 0) {
/* Dump FRU to a binary file */
+#ifdef WIN32
+ fp = fopen(binfile,"wb");
+#else
fp = fopen(binfile,"w");
+#endif
if (fp == NULL) {
ret = get_LastError();
printf("Cannot open file %s, error %d\n",binfile,ret);
@@ -2048,9 +2055,13 @@ int i_fru(int argc, char **argv)
else if (frestore) {
uchar cksum;
/* Restore FRU from a binary file */
+#ifdef WIN32
+ fp = fopen(binfile,"rb");
+#else
fp = fopen(binfile,"r");
+#endif
if (fp == NULL) {
- ret = get_LastError();
+ ret = get_LastError();
printf("Cannot open file %s, error %d\n",binfile,ret);
} else {
ret = 0;
@@ -2077,10 +2088,10 @@ int i_fru(int argc, char **argv)
free_fru(frubuf);
}
if (ret == 0) { /*successfully read data*/
- printf("Writing FRU size %d from %s ...\n",sfru,binfile);
- ret = write_fru_data(g_fruid, 0, frubuf, sfru, fdebug);
- free_fru(frubuf);
- if (ret != 0) printf("write_fru error %d (0x%02x)\n",ret,ret);
+ printf("Writing FRU size %d from %s ...\n",sfru,binfile);
+ ret = write_fru_data(g_fruid, 0, frubuf, sfru, fdebug);
+ free_fru(frubuf);
+ if (ret != 0) printf("write_fru error %d (0x%02x)\n",ret,ret);
else { /* successful, show new data */
ret = load_fru(sa,g_fruid,g_frutype,&pfru);
if (ret != 0) show_loadfru_error(sa,g_fruid,ret);