1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679
|
/*
* ifruset (copy of ifru.c with extended FRU writing)
*
* This tool reads the FRU configuration, and optionally sets the asset
* tag field in the FRU data. See IPMI v1.5 spec section 28.
* It can use either the Intel /dev/imb driver or VALinux /dev/ipmikcs.
*
* Author: Andy Cress arcress at users.sourceforge.net
*
* Copyright (c) 2009 Kontron America, Inc.
*
* 04/01/10 Andy Cress - created from ifru.c 2.6.1
*/
/*M*
Copyright (c) 2009 Kontron America, Inc.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
a.. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
b.. 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.
c.. Neither the name of Kontron 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.
*M*/
#ifdef WIN32
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "getopt.h"
#elif defined(DOS)
#include <dos.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "getopt.h"
#else
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#if defined(HPUX)
/* getopt is defined in stdio.h */
#elif defined(MACOS)
/* getopt is defined in unistd.h */
#include <unistd.h>
#else
#include <getopt.h>
#endif
#endif
#include <time.h>
#include "ipmicmd.h"
#include "ipicmg.h" // #define OEM_PICMG 12634
extern int get_LastError( void ); /* ipmilan.c */
extern int get_BiosVersion(char *str);
extern int get_SystemGuid(uchar *str);
extern void fmt_time(time_t etime, char *buf, int bufsz); /*see ievents.c*/
#define FIELD_LEN 24
#define NUM_BOARD_FIELDS 6
#define NUM_PRODUCT_FIELDS 8
#define NUM_CHASSIS_FIELDS 3
#define ERR_LENMAX -7 /*same as LAN_ERR_BADLENGTH */
#define ERR_LENMIN -10 /*same as LAN_ERR_TOO_SHORT */
#define ERR_OTHER -13 /*same as LAN_ERR_OTHER */
#define STRING_DATA_TYPE_BINARY 0x00
#define STRING_DATA_TYPE_BCD_PLUS 0x01
#define STRING_DATA_TYPE_SIX_BIT_ASCII 0x02
#define STRING_DATA_TYPE_LANG_DEPENDENT 0x03
#define FRUCHUNK_SZ 16
#define FRU_END 0xC1
#define FRU_EMPTY_FIELD 0xC0
#define FRU_TYPE_MASK 0xC0
#define FRU_LEN_MASK 0x3F
#define IPROD_MANUF 0
#define IPROD_NAME 1
#define IPROD_PART 2
#define IPROD_VERS 3
#define IPROD_SERNUM 4
#define IPROD_ASSET 5
#define IPROD_FRUID 6
#define IPROD_OEM 7
#ifdef METACOMMAND
extern char * progver; /*from ipmiutil.c*/
static char *progname = "ipmiutil fruset";
#else
static char * progver = "3.12";
static char *progname = "ifruset";
#endif
static char fdebug = 0;
static char fpicmg = 0;
static char fonlybase = 0;
static char fonlyhsc = 0;
static char fdevsdrs = 0;
static char fshowlen = 0;
static char fgetfru = 0;
static char fdoanyway = 0;
static char fset_mc = 0;
static char fcanonical = 0;
static char fdump = 0;
static char frestore = 0;
static int fwritefru = 0;
static int prod_id, vend_id = 0;
static char bdelim = ':';
static char *binfile = NULL;
static uchar bmc_sa = BMC_SA; /*defaults to 0x20*/
static uchar guid[17] = "";
static uchar *frubuf = NULL;
static uchar *newdata = NULL; /* new FRU data, including the product area */
/* usually 4*64 + 3 = 259 bytes */
static int sfru = 0;
static int chassis_offset = -1;
static int chassis_len = 0;
static char chassis_name[FIELD_LEN] = {0};
static int product_num = NUM_PRODUCT_FIELDS;
typedef struct {
int offset;
int len;
char tag[FIELD_LEN];
} FIELDTYPE;
static FIELDTYPE prodarea[NUM_PRODUCT_FIELDS] = {
-1, 0, {0},
-1, 0, {0},
-1, 0, {0},
-1, 0, {0},
-1, 0, {0},
-1, 0, {0},
-1, 0, {0},
-1, 0, {0} };
static FIELDTYPE prodnew[NUM_PRODUCT_FIELDS] = {
-1, 0, {0},
-1, 0, {0},
-1, 0, {0},
-1, 0, {0},
-1, 0, {0},
-1, 0, {0},
-1, 0, {0},
-1, 0, {0} };
static int maxprod = 0;
static int ctype;
static uchar g_bus = PUBLIC_BUS;
static uchar g_sa = 0;
static uchar g_lun = BMC_LUN;
static uchar g_addrtype = ADDR_SMI;
static uchar g_fruid = 0; /* default to fruid 0 */
static uchar g_frutype = 0;
/* g_frutype values (detected), see also FruTypeString
* --TAG---- FRU IPMB
* Baseboard = 0x0c 0x07
* PowerSply = 0x0a
* PowerCage = 0x15
* DIMM = 0x20
* HotSwapCt = 0x0f
* ME = 0x2e
* Component = * * (all others)
*/
#define MAX_CTYPE 26
char *ctypes[MAX_CTYPE] = { "", "Other", "Unknown", "Desktop",
"Low Profile Desktop", "Pizza Box", "Mini-Tower", "Tower",
"Portable", "Laptop", "Notebook", "Handheld", "Docking Station",
"All-in-One", "Sub-Notebook", "Space-saving", "Lunch Box",
"Main Server Chassis", "Expansion Chassis", "SubChassis",
"Bus Expansion Chassis", "Peripheral Chassis",
"RAID Chassis", /*0x17=23.*/ "Rack-Mount Chassis",
"New24" , "New25"};
/* what about bladed chassies? */
char *ctype_hdr =
"Chassis Type ";
char *chassis[NUM_CHASSIS_FIELDS] = {
"Chassis Part Number ",
"Chassis Serial Num ",
"Chassis OEM Field " };
char *board[NUM_BOARD_FIELDS] = {
"Board Manufacturer ",
"Board Product Name ",
"Board Serial Number ",
"Board Part Number ",
"Board FRU File ID ",
"Board OEM Field " };
char *product[NUM_PRODUCT_FIELDS] = {
"Product Manufacturer",
"Product Name ",
"Product Part Number ",
"Product Version ",
"Product Serial Num ",
"Product Asset Tag ",
"Product FRU File ID ",
"Product OEM Field " };
char *asset_hdr =
" Asset Tag Length ";
#if 0
typedef struct {
uchar len :6;
uchar type:2;
} TYPE_LEN; /*old, assumes lo-hi byte order*/
#else
typedef struct {
uchar len;
uchar type;
} TYPE_LEN;
#endif
void
free_fru(void)
{
if (frubuf != NULL) {
free(frubuf);
frubuf = NULL;
}
if (newdata != NULL) {
free(newdata);
newdata = NULL;
}
return;
}
int
load_fru(uchar sa, uchar frudev, uchar frutype)
{
int ret = 0;
uchar indata[FRUCHUNK_SZ];
uchar resp[18];
int sresp;
uchar cc;
int sz;
char fwords;
ushort fruoff = 0;
int i;
int chunk;
memset(indata, 0, sizeof(indata));
indata[0] = frudev;
sresp = sizeof(resp);
if (fdebug) printf("load_fru: sa = %02x, frudev = %02x\n",sa,frudev);
ret = ipmi_cmd_mc(GET_FRU_INV_AREA,indata,1,resp,&sresp,&cc,fdebug);
if (fdebug) printf("load_fru: inv ret = %d, cc = %x\n",ret,cc);
if (ret != 0) return(ret);
if (cc != 0) { ret = (cc & 0x00ff); return(ret); }
sz = resp[0] + (resp[1] << 8);
if (resp[2] & 0x01) { fwords = 1; sz = sz * 2; }
else fwords = 0;
frubuf = malloc(sz);
if (frubuf == NULL) return(get_errno());
sfru = sz;
/* Loop on READ_FRU_DATA */
for (i = 0, chunk=FRUCHUNK_SZ; i < sz; i+=chunk)
{
if ((i+chunk) >= sz) chunk = sz - i;
indata[0] = frudev; /* FRU Device ID */
if (fwords) {
indata[3] = chunk / 2;
fruoff = (i/2);
} else {
indata[3] = chunk;
fruoff = i;
}
indata[1] = fruoff & 0x00FF;
indata[2] = (fruoff & 0xFF00) >> 8;
sresp = sizeof(resp);
ret = ipmi_cmd_mc(READ_FRU_DATA,indata,4,resp,&sresp,&cc,fdebug);
if (ret != 0) break;
else if (cc != 0) {
if (i == 0) ret = cc & 0x00ff;
if (fdebug) printf("read_fru[%d]: ret = %d cc = %x\n",i,ret,cc);
break;
}
memcpy(&frubuf[i],&resp[1],chunk);
}
if ((frudev == 0) && (sa == bmc_sa)) { /*main system fru*/
sresp = sizeof(resp);
ret = ipmi_cmd_mc(GET_SYSTEM_GUID,indata,0,resp,&sresp,&cc,fdebug);
if ((ret != 0) && !is_remote()) { /* get UUID from SMBIOS */
cc = 0; sresp = 16;
ret = get_SystemGuid(resp);
}
if (fdebug) printf("system_guid: ret = %d, cc = %x\n",ret,cc);
if (ret == 0 && cc == 0) {
if (fdebug) {
printf("system guid (%d): ",sresp);
for (i=0; i<16; i++) printf("%02x ",resp[i]);
printf("\n");
}
memcpy(&guid,&resp,16);
guid[16] = 0;
}
} /*endif*/
return(ret);
}
static void decode_string(unsigned char type,
unsigned char language_code,
unsigned char *source,
int slen,
char *target,
int tsize)
{
static const char bcd_plus[] = "0123456789 -.:,_";
unsigned char *s = &source[0];
unsigned char *d = &target[0];
int len, i, j, k;
union { uint32_t bits; char chars[4]; } u;
if (slen == 0 || slen == 1) return;
switch(type) {
case STRING_DATA_TYPE_BINARY: /* 00: binary/unspecified */
len = (slen*2); break; /* hex dump -> 2x length */
case STRING_DATA_TYPE_SIX_BIT_ASCII: /*type 2 6-bit ASCII*/
/* 4 chars per group of 1-3 bytes */
len = ((((slen+2)*4)/3) & ~3); break;
case STRING_DATA_TYPE_LANG_DEPENDENT: /* 03 language dependent */
case STRING_DATA_TYPE_BCD_PLUS: /* 01b: BCD plus */
default:
len = slen; break;
}
if (len >= tsize) len = tsize - 1;
memset(target, 0, len);
if (type == STRING_DATA_TYPE_BCD_PLUS) { /*type 1 BCD plus*/
for (k=0; k<len; k++)
target[k] = bcd_plus[(s[k] & 0x0f)];
target[k] = '\0';
} else if (type == STRING_DATA_TYPE_SIX_BIT_ASCII) { /*type 2 6-bit ASCII*/
for (i=j=0; i<slen; i+=3) {
u.bits = 0;
k = ((slen-i) < 3 ? (slen-i) : 3);
#if WORDS_BIGENDIAN
u.chars[3] = s[i];
u.chars[2] = (k > 1 ? s[i+1] : 0);
u.chars[1] = (k > 2 ? s[i+2] : 0);
#define CHAR_IDX 3
#else
memcpy((void *)&u.bits, &s[i], k);
#define CHAR_IDX 0
#endif
for (k=0; k<4; k++) {
target[j++] = ((u.chars[CHAR_IDX] & 0x3f) + 0x20);
u.bits >>= 6;
}
}
target[j] = '\0';
} else if (type == STRING_DATA_TYPE_LANG_DEPENDENT) { /*type 3*/
if ((language_code == 0x00) || (language_code == 0x25) ||
(language_code == 0x19)) {
memcpy(target, source, len);
target[len] = 0x0;
} else {
printf("Language 0x%x dependent decode not supported\n",language_code);
}
} else if (type == STRING_DATA_TYPE_BINARY) { /* 00: binary/unspecified */
strncpy(target, buf2str(s, slen), len);
} else { /* other */
printf("Unable to decode type 0x%.2x\n",type);
}
return;
}
uchar calc_cksum(uchar *pbuf,int len)
{
int i;
uchar cksum;
uchar sum = 0;
for (i = 0; i < len; i++) sum += pbuf[i];
cksum = 0 - sum;
return(cksum);
}
static void dumpbuf(uchar *pbuf,int sz)
{
uchar line[17];
uchar a;
int i, j;
line[0] = 0; line[16] = 0;
j = 0;
for (i = 0; i < sz; i++) {
if (i % 16 == 0) { j = 0; printf("%s\n %04d: ",line,i); }
a = pbuf[i];
if (a < 0x20 || a > 0x7f) a = '.';
line[j++] = a;
printf("%02x ",pbuf[i]);
}
line[j] = 0;
printf("%s\n",line);
return;
}
#define NSPDMFG 7
static struct {
uchar id; char *str;
} spd_mfg[NSPDMFG] = { /* see JEDEC JEP106 doc */
{ 0x2c, "Micron" },
{ 0x15, "Philips Semi" },
{ 0x1c, "Mitsubishi" },
{ 0xce, "Samsung" },
{ 0xc1, "Infineon" },
{ 0x98, "Kingston" },
{ 0x89, "Intel" }
};
int ValidTL(uchar typelen)
{
if (vend_id != VENDOR_INTEL) return 1;
if ((typelen & 0xC0) == 0xC0) return 1;
else return 0;
}
char * FruTypeString(uchar frutype)
{
char *pstr;
switch (frutype) {
case 0x07: pstr = "Baseboard"; break; /*IPMB*/
case 0x0c: pstr = "Baseboard"; break; /*FRU*/
case 0x0a: pstr = "PowerSply"; break; /*FRU*/
case 0x15: pstr = "PowerCage"; break; /*FRU*/
case 0x20: pstr = "DIMM "; break; /*FRU*/
case 0x0f: pstr = "HotSwapCt"; break; /*IPMB*/
case 0x2e: pstr = "ME "; break; /*IPMB*/
default: pstr = "Component"; break;
}
return(pstr);
}
static void
show_spd(uchar *spd, int lenspd, uchar frudev, uchar frutype)
{
int sz;
char *pstr;
uchar mrev;
int i;
char devstr[20];
sz = spd[0]; /* sz should == lenspd */
if (fcanonical) devstr[0] = 0; /*default is empty string*/
else sprintf(devstr,"[%s,%02x] ",FruTypeString(frutype),frudev);
printf("%sMemory SPD Size %c %d\n",
devstr,bdelim,lenspd);
if (spd[2] == 0x07) pstr = "DDR";
else /* usu 0x04 */ pstr = "SDRAM";
printf("%sMemory Type %c %s\n",
devstr,bdelim,pstr);
printf("%sModule Density %c %d MB per bank\n",
devstr,bdelim, (spd[31] * 4));
printf("%sModule Banks %c %d banks\n",
devstr,bdelim,spd[5]);
printf("%sModule Rows, Cols %c %d rows, %d cols\n",
devstr,bdelim, spd[3], spd[4]);
if (spd[11] == 0x00) pstr = "Non-parity";
else /* usu 0x02 */ pstr = "ECC";
printf("%sDIMM Config Type %c %s\n",devstr,bdelim,pstr);
for (i = 0; i < NSPDMFG; i++)
if (spd_mfg[i].id == spd[64]) break;
if (i == NSPDMFG) pstr = ""; /* not found, use null string */
else pstr = spd_mfg[i].str;
printf("%sManufacturer ID %c %s (0x%02x)\n",
devstr,bdelim, pstr, spd[64]);
mrev = spd[91]; /* save this byte for later */
spd[91] = 0; /*stringify part number */
printf("%sManufacturer Part# %c %s\n",
devstr,bdelim,&spd[73]);
printf("%sManufacturer Rev %c %02x %02x\n",
devstr,bdelim,mrev,spd[92]);
printf("%sManufacturer Date %c year=%02d week=%02d\n",
devstr,bdelim,spd[93],spd[94]);
printf("%sAssembly Serial Num %c %02x%02x%02x%02x\n",
devstr,bdelim,spd[95], spd[96], spd[97], spd[98]);
spd[91] = mrev; /* restore byte, so ok to repeat later */
return;
}
void show_guid(uchar *pguid)
{
char *s;
int i;
for (i=0; i<16; i++) {
if ((i == 4) || (i == 6) || (i == 8) || (i == 10)) s = "-";
else s = "";
printf("%s%02x",s,pguid[i]);
}
}
static char *volt_desc(uchar b)
{
char *s;
switch(b) {
case 0x03: s = "5V"; break;
case 0x02: s = "3.3V"; break;
case 0x01: s = "-12V"; break;
case 0x00:
default: s = "12V"; break;
}
return(s);
}
static char *mgt_type(uchar b)
{
char *s;
switch(b) {
case 0x01: s = "SysMgt_URL"; break;
case 0x02: s = "SystemName"; break;
case 0x03: s = "SysPingAddr"; break;
case 0x04: s = "Compon_URL"; break;
case 0x05: s = "ComponName"; break;
case 0x06: s = "ComponPing"; break;
case 0x07:
default: s = "SysGUID"; break;
}
return(s);
}
static
void show_fru_multi(char *tag, int midx, uchar mtype, uchar *pdata, int dlen)
{
int vend, i;
char mystr[256];
char *s1, *s2;
int v1, v2, v3, v4, v5, v6, v7, v8;
uchar b1, b2;
if (fdebug) dumpbuf(pdata,dlen); /*multi-record area dump*/
sprintf(mystr,"%sMulti[%d] ",tag,midx);
i = strlen(mystr);
switch(mtype) {
case 0x00: /*Power Supply*/
printf("%sPower Supply Record %c \n",mystr,bdelim);
v1 = pdata[0] + ((pdata[1] & 0x0f) << 8);
printf("\t Capacity \t%c %d W\n",bdelim, v1);
v2 = pdata[2] + (pdata[3] << 8);
printf("\t Peak VA \t%c %d VA\n",bdelim, v2);
printf("\t Inrush Current\t%c %d A\n",bdelim, pdata[4]);
printf("\t Inrush Interval\t%c %d ms\n",bdelim, pdata[5]);
v3 = pdata[6] + (pdata[7] << 8);
v4 = pdata[8] + (pdata[9] << 8);
printf("\t Input Voltage Range1\t%c %d-%d V\n",
bdelim,v3/100,v4/100);
v3 = pdata[10] + (pdata[11] << 8);
v4 = pdata[12] + (pdata[13] << 8);
printf("\t Input Voltage Range2\t%c %d-%d V\n",
bdelim,v3/100,v4/100);
printf("\t Input Frequency Range\t%c %d-%d Hz\n",
bdelim,pdata[14],pdata[15]);
printf("\t AC Dropout Tolerance\t%c %d ms\n",bdelim, pdata[16]);
b1 = pdata[17];
b2 = (b1 & 0x01);
if (b2) { /*predictive fail*/
if (b1 & 0x10 != 0) s1 = "DeassertFail ";
else s1 = "AssertFail ";
} else {
if (b1 & 0x10 != 0) s1 = "2pulses/rot ";
else s1 = "1pulse/rot ";
}
printf("\t Flags \t%c %s%s%s%s%s\n",bdelim,
(b2 ? "PredictFail " : ""),
((b1 & 0x02 == 0) ? "" : "PowerFactorCorrect "),
((b1 & 0x04 == 0) ? "" : "AutoswitchVolt "),
((b1 & 0x08 == 0) ? "" : "Hotswap "), s1);
v5 = pdata[18] + ((pdata[19] & 0x0f) << 8);
v6 = (pdata[19] & 0xf0) >> 4;
printf("\t Peak Capacity \t%c %d W for %d s\n",bdelim, v5,v6);
if (pdata[20] == 0) {
printf("\t Combined Capacity\t%c not specified\n",bdelim);
} else {
b1 = pdata[20] & 0x0f;
b2 = (pdata[20] & 0xf0) >> 4;
v7 = pdata[21] + (pdata[22] << 8);
printf("\t Combined Capacity\t%c %d W (%s and %s)\n",
bdelim, v7,volt_desc(b1),volt_desc(b2));
}
if (b2) /*predictive fail*/
printf("\t Fan low threshold\t%c %d RPS\n",bdelim,pdata[23]);
break;
case 0x01: /*DC Output*/
b1 = pdata[0] & 0x0f;
b2 = (pdata[0] & 0x80 != 0);
printf("%sDC Output %c number %d\n",mystr,bdelim,b1);
printf("\t Standby power \t%c %s\n", bdelim,
(b2 ? "Yes" : "No"));
v1 = pdata[1] + (pdata[2] << 8);
printf("\t Nominal voltage \t%c %.2f V\n", bdelim, v1 / 100);
v2 = pdata[3] + (pdata[4] << 8);
v3 = pdata[5] + (pdata[6] << 8);
printf("\t Voltage deviation \t%c + %.2f V / - %.2f V\n",
bdelim, v3/100, v2/100);
v4 = pdata[7] + (pdata[8] << 8);
printf("\t Ripple and noise pk-pk \t%c %d mV\n", bdelim, v4);
v5 = pdata[9] + (pdata[10] << 8);
printf("\t Min current draw \t%c %.3f A\n", bdelim, v5/1000);
v6 = pdata[11] + (pdata[12] << 8);
printf("\t Max current draw \t%c %.3f A\n", bdelim, v6/1000);
break;
case 0x02: /*DC Load*/
b1 = pdata[0] & 0x0f;
printf("%sDC Load %c number %d\n",mystr,bdelim,b1);
v1 = pdata[1] + (pdata[2] << 8);
printf("\t Nominal voltage \t%c %.2f V\n", bdelim, v1 / 100);
v2 = pdata[3] + (pdata[4] << 8);
v3 = pdata[5] + (pdata[6] << 8);
printf("\t Min voltage allowed \t%c %.2f A\n", bdelim, v2);
printf("\t Max voltage allowed \t%c %.2f A\n", bdelim, v3);
v4 = pdata[7] + (pdata[8] << 8);
printf("\t Ripple and noise pk-pk \t%c %d mV\n", bdelim, v4);
v5 = pdata[9] + (pdata[10] << 8);
printf("\t Min current load \t%c %.3f A\n", bdelim, v5/1000);
v6 = pdata[11] + (pdata[12] << 8);
printf("\t Max current load \t%c %.3f A\n", bdelim, v6/1000);
break;
case 0x03: /*Management Access*/
b1 = pdata[0];
printf("%sManagemt Access %c %s ",mystr,bdelim,mgt_type(b1));
memcpy(mystr,&pdata[1],dlen-1);
mystr[dlen-1] = 0;
printf("%s\n",mystr);
break;
case 0x04: /*Base Compatibility*/
vend = pdata[0] + (pdata[1] << 8) + (pdata[2] << 16);
printf("%sBasic Compat %c %06x\n",mystr,bdelim,vend);
break;
case 0x05: /*Extended Compatibility*/
vend = pdata[0] + (pdata[1] << 8) + (pdata[2] << 16);
printf("%sExtended Compat %c %06x\n",mystr,bdelim,vend);
break;
case 0xC0: /*OEM Extension*/
vend = pdata[0] + (pdata[1] << 8) + (pdata[2] << 16);
if (vend == OEM_PICMG) {
printf("%sOEM PICMG %c \n", mystr,bdelim);
show_fru_picmg(pdata,dlen);
} else
printf("%sOEM Ext %c %06x %02x\n",
mystr,bdelim, vend, pdata[3]);
break;
default:
printf("%s %02x %c %02x\n", mystr,mtype,bdelim, pdata[0]);
break;
}
}
int
show_fru(uchar sa, uchar frudev, uchar frutype)
{
int ret = 0;
int i, j, n, sz;
uchar *pfru;
uchar lang;
TYPE_LEN tl;
char newstr[64];
int iaoff, ialen, bdoff, bdlen;
int proff, prlen, choff, chlen;
int moff, mlen;
char devstr[24];
char *pstr;
int extra = 0;
if (frubuf[0] == 0x80) { /* 0x80 = type for DIMMs (SPD) */
/* FRU Header: 80 08 07 0c 0a 01 48 00 (DIMM) */
sz = frubuf[0];
if (fdebug) {
printf("DIMM SPD Body (size=%d/%d): ",sz,sfru);
dumpbuf(frubuf,sfru);
}
show_spd(frubuf,sfru, frudev,frutype);
return(ret);
}
pstr = FruTypeString(frutype);
if (fcanonical) devstr[0] = 0; /*default is empty string*/
else sprintf(devstr,"[%s,%02x] ",pstr,frudev);
printf("%s%s FRU Size %c %d\n",devstr,pstr,bdelim,sfru);
/*
* FRU header:
* 0 = format_ver (01 is std, usu 0x80 if DIMM)
* 1 = internal_use offset
* 2 = chassis_info offset
* 3 = board_info offset (usu 6 fields)
* 4 = product_info offset (usu 8 fields)
* 5 = multirecord offset
* 6 = pad (00)
* 7 = header checksum (zero checksum)
* FRU Header: 01 01 02 09 13 00 00 e0 (BMC)
* FRU Header: 01 00 00 00 01 07 00 f7 (Power Cage)
*/
pfru = &frubuf[0];
sz = 8; /*minimum for common header*/
for (i = 1; i < 6; i++) { /* walk thru offsets */
if (frubuf[i] != 0) sz = frubuf[i] * 8;
}
if (sz > 8) { /* if have at least one section */
if (frubuf[5] != 0) j = 5 + frubuf[sz+2]; /*if multi-record area*/
else j = frubuf[sz+1] * 8; /* else add length of last section */
sz += j;
}
/* Now, sz = size used, sfru = total available size */
if (sz > sfru) {
if (fdebug) {
printf("FRU Header: ");
for (i = 0; i < 8; i++) printf("%02x ",frubuf[i]);
printf("\n");
}
printf("FRU size out of bounds: available=%d used=%d\n",sfru,sz);
printf("Please apply the correct FRU/SDR diskette\n");
if (fdoanyway) {
extra = sz - sfru;
sz = sfru;
} else return(ERR_OTHER);
}
/* internal area offset, length */
iaoff = frubuf[1] * 8;
ialen = frubuf[iaoff + 1] * 8;
/* chassis area offset, length */
choff = frubuf[2] * 8;
chlen = frubuf[choff + 1] * 8;
/* board area offset, length */
bdoff = frubuf[3] * 8;
bdlen = frubuf[bdoff + 1] * 8;
/* product area offset, length */
proff = frubuf[4] * 8;
prlen = frubuf[proff + 1] * 8;
if (extra > 0) { /*do fixup of extra in product area*/
prlen -= extra;
j = prlen / 8;
prlen = j * 8; /*resolve to 8-byte bound*/
frubuf[proff + 1] = j;
}
/* multi-record area offset, length */
moff = frubuf[5] * 8;
mlen = 0;
if (moff > 0) {
for (i = moff; i < sfru; ) {
if (frubuf[i] == 0 && frubuf[i+2] == 0) break; /*type/len invalid*/
j = 5 + frubuf[i+2];
mlen += j;
if (frubuf[i+1] & 0x80) break;
i += j;
}
}
if (fdebug) {
printf("FRU Header: ");
for (i = 0; i < 8; i++) printf("%02x ",frubuf[i]);
printf("\n");
printf("FRU Body (size=%d/%d): ",sz,sfru);
dumpbuf(frubuf,sfru);
printf("header, len=%d, cksum0 = %02x, cksum1 = %02x\n",
8,frubuf[7],calc_cksum(&frubuf[0],7));
printf("internal off=%d, len=%d, cksum = %02x\n",
iaoff,ialen,calc_cksum(&frubuf[iaoff],ialen-1));
printf("chassis off=%d, len=%d, cksum = %02x\n",
choff,chlen,calc_cksum(&frubuf[choff],chlen-1));
printf("board off=%d, len=%d, cksum = %02x\n",
bdoff,bdlen,calc_cksum(&frubuf[bdoff],bdlen-1));
printf("prod off=%d, len=%d, cksum = %02x\n",
proff,prlen,calc_cksum(&frubuf[proff],prlen-1));
/* Multi-record area */
printf("multi off=%d, len=%d, fru sz=%d\n", moff,mlen,sz);
} /*endif fdebug, show header*/
if (choff != 0) {
/* show Chassis area fields */
pfru = &frubuf[choff];
lang = 25; /* English */
ctype = pfru[2]; /*chassis type*/
if (fdebug) printf("ctype=%x\n",ctype);
if (ctype >= MAX_CTYPE) ctype = MAX_CTYPE - 1;
printf("%s%s%c %s\n",devstr, ctype_hdr,bdelim,ctypes[ctype]);
pfru += 3; /* skip chassis header */
for (i = 0; i < NUM_CHASSIS_FIELDS; i++)
{
if (pfru[0] == FRU_END) break; /*0xC1 = end of FRU area*/
if (!ValidTL(pfru[0]))
printf(" ERROR - Invalid Type/Length %02x for %s\n",
pfru[0],chassis[i]);
tl.type = (pfru[0] & FRU_TYPE_MASK) >> 6;
tl.len = pfru[0] & FRU_LEN_MASK;
if (i == 2) { /* OEM field for chassis_name */
chassis_offset = (int)(pfru - frubuf);
chassis_len = tl.len;
if (fdebug) printf("chassis oem dtype=%d lang=%d len=%d\n",
tl.type,lang,tl.len);
}
pfru++;
{
newstr[0] = 0;
decode_string(tl.type,lang,pfru,tl.len,newstr,sizeof(newstr));
printf("%s%s%c %s\n",devstr, chassis[i],bdelim,newstr);
}
pfru += tl.len;
}
if (fdebug) printf("num Chassis fields = %d\n",i);
}
if (bdoff != 0) {
long nMin, nSec;
time_t tsec;
/* show Board area fields */
pfru = &frubuf[bdoff];
lang = pfru[2];
/* Decode board mfg date-time (num minutes since 1/1/96) */
nMin = pfru[3] + (pfru[4] << 8) + (pfru[5] << 16);
/* 13674540 min from 1/1/70 to 1/1/96 */
nSec = (nMin + 13674540) * 60;
tsec = (time_t)(nSec & 0x0ffffffff);
// fmt_time(tsec,newstr,sizeof(newstr));
printf("%sBoard Mfg DateTime %c %s",devstr,bdelim,ctime(&tsec));
pfru += 6; /* skip board header */
for (i = 0; i < NUM_BOARD_FIELDS; i++)
{
if (pfru[0] == FRU_END) break; /*0xC1 = end*/
if (!ValidTL(pfru[0]))
printf(" ERROR - Invalid Type/Length %02x for %s\n",
pfru[0],board[i]);
tl.type = (pfru[0] & FRU_TYPE_MASK) >> 6;
tl.len = pfru[0] & FRU_LEN_MASK;
pfru++;
{
newstr[0] = 0;
decode_string(tl.type,lang,pfru,tl.len,newstr,sizeof(newstr));
printf("%s%s%c %s\n",devstr, board[i],bdelim,newstr);
}
pfru += tl.len;
}
if (fdebug) printf("num Board fields = %d\n",i);
}
if (proff != 0) {
/* show Product area fields */
pfru = &frubuf[proff];
maxprod = pfru[1] * 8;
lang = pfru[2];
pfru += 3; /* skip product header */
for (i = 0; i < NUM_PRODUCT_FIELDS; i++)
{
if (*pfru == FRU_END) { /*0xC1 = end*/
/* Wart for known Kontron 1-byte Product Version anomaly. */
if ((vend_id == VENDOR_KONTRON) && (i == 3)) ;
else break;
}
if (*pfru == 0) *pfru = FRU_EMPTY_FIELD; /* fix a broken table */
if (!ValidTL(pfru[0]))
printf(" ERROR - Invalid Type/Length %02x for %s\n",
pfru[0],product[i]);
tl.type = (pfru[0] & FRU_TYPE_MASK) >> 6;
tl.len = pfru[0] & FRU_LEN_MASK;
n = (int)(pfru - frubuf);
prodarea[i].offset = n;
prodarea[i].len = tl.len;
memcpy(prodarea[i].tag, &frubuf[n+1] ,tl.len);
pfru++;
{
newstr[0] = 0;
decode_string(tl.type,lang,pfru,tl.len,newstr,sizeof(newstr));
printf("%s%s%c %s\n",devstr, product[i],bdelim,newstr);
}
pfru += tl.len;
}
if (fdebug)
printf("num Product fields = %d, last=%x, max = %d\n",
i,*pfru,maxprod );
product_num = i; /*save number of existing product fields*/
if (*pfru == 0x00) *pfru = FRU_END; /* insert end char if broken */
}
if (moff != 0)
{
/* multi-record area may contain several record headers
* 0 = record type id
* 1 = 0x02 or 0x80 if End-of-List
* 2 = record len
* 3 = record chksum
* 4 = header chksum
*/
pfru = &frubuf[moff];
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);
j += (5 + n);
if (pfru[1] & 0x80) j = sz; /*0x80 = end of list*/
pfru += (5 + n);
}
}
if ((frudev == 0) && (sa == bmc_sa)) {
char *s;
printf("%sSystem GUID %c ",devstr,bdelim);
for (i=0; i<16; i++) {
if ((i == 4) || (i == 6) || (i == 8) || (i == 10)) s = "-";
else s = "";
printf("%s%02x",s,guid[i]);
}
printf("\n");
}
return(ret);
}
static int
write_fru_data(uchar id, ushort offset, uchar *data, int dlen, char fdebug)
{
int ret = -1;
int chunk;
ushort fruoff;
uchar req[FRUCHUNK_SZ+9];
uchar resp[16];
int sresp;
uchar cc;
int i, j;
/* Write the buffer in small 16-byte (FRUCHUNK_SZ) chunks */
req[0] = id; /* FRU Device ID (fruid) */
fruoff = offset;
chunk = FRUCHUNK_SZ;
for (i = 0; i < dlen; i += chunk) {
req[1] = fruoff & 0x00ff;
req[2] = (fruoff & 0xff00) >> 8;
if ((i + chunk) > dlen) chunk = dlen - i;
memcpy(&req[3],&data[i],chunk);
if (fdebug) {
printf("write_fru_data[%d] (len=%d): ",i,chunk+3);
for (j = 0; j < chunk+3; j++) printf("%02x ",req[j]);
printf("\n");
}
sresp = sizeof(resp);
ret = ipmi_cmd_mc(WRITE_FRU_DATA,req,(uchar)(chunk+3),resp,&sresp,
&cc,fdebug);
if ((ret == 0) && (cc != 0)) ret = cc & 0x00ff;
if (fdebug && ret == 0)
printf("write_fru_data[%d]: %d bytes written\n",i,resp[0]);
if (ret != 0) break;
fruoff += chunk;
}
return(ret);
}
/*
* write_product
* Updates the FRU Product area only.
* Note that this function will always provide >=8 product fields,
* even if the original had less than 8.
* inputs: prodnew = array of new strings to write
* frubuf = contains existing FRU data
* newdata = new product area buffer, malloc'd
* outputs: returns 0 if successful
*/
int
write_product(void)
{
int ret = -1;
uchar req[25];
uchar resp[16];
int sresp;
uchar cc;
ushort fruoff;
int alen, clen;
int snlen, verlen;
uchar *pfru0;
uchar *pfru;
uchar *pnew;
int i, j, k, n, plen, newlen, max, plimit;
int chas_offset;
int prod_offset;
int mult_offset, mult_len;
uchar chksum;
int chunk;
chas_offset = frubuf[2] * 8; // offset of chassis data
prod_offset = frubuf[4] * 8; // offset of product data
plen = frubuf[prod_offset+1] * 8; // length of product data
mult_offset = frubuf[5] * 8;
mult_len = 0;
if (mult_offset > 0) {
for (i = mult_offset; i < sfru; ) {
mult_len += (5 + frubuf[i+2]);
if (frubuf[i+1] & 0x80) break;
i = mult_len;
}
}
/* Check if asset tag will fit in product data area of FRU. */
if (fdebug)
printf("write_product: fru[4,p]=[%02x,%02x] prod_off=%d, plen=%d\n",
frubuf[4],frubuf[prod_offset+1],prod_offset,plen);
if (plen > sfru) return ERR_LENMAX; // product bigger than buffer
if (prodnew[IPROD_ASSET].len > plen) return ERR_LENMAX;
/* if asset bigger than product data, error. */
/* asset comes after sernum, so this check works for both */
newdata = malloc(sfru); /* but should not need more than plen bytes */
if (newdata == NULL) return(get_errno());
memset(newdata,0,sfru);
pnew = &newdata[0];
/* Set pointer to start of chassis area */
pfru = &frubuf[chas_offset];
/* Product Area Header (3 bytes):
[0] = 0x01; * format ver 1 *
[1] = 0x0a; *product area size (in 8-byte mult)*
[2] = 0x00; *lang=english *
Usually max product area is 3 + 8*32 = 259 mod 8 = 264.
*/
pfru0 = &frubuf[prod_offset];
pfru = &frubuf[prod_offset];
j = 3;
memcpy(pnew,pfru,j);
pfru += j;
pnew += j;
n = j;
if (mult_offset > 0) plimit = plen;
else plimit = sfru - prod_offset; /*plen can expand*/
for (i = 0; i < NUM_PRODUCT_FIELDS; i++)
{
j = prodarea[i].len; /*new len*/
k = pfru[0] & FRU_LEN_MASK; /*old len*/
if (k == 1) { /*was 0xC1 FRU_END*/
if ((vend_id == VENDOR_KONTRON) && (i == 3) && (j == 1)) {
/* fix Kontron 1-byte Version */
prodarea[i].tag[1] = ' ';
j++;
} else
k = 0;
}
/* check for product area overflow */
if (n + 2 >= plimit) {
if (fdebug) printf("Field %d is at %d, beyond product area size %d\n",
i+1,n+2,plimit);
break;
} else if ((n + 1 + j) >= plimit) {
if (fdebug) printf("Field %d at %d + %d, truncated, product size %d\n",
i+1,n+1,j,plimit);
j = 0;
}
pnew[0] = (j | FRU_TYPE_MASK); /*add type=3 to len*/
memcpy(&pnew[1],prodarea[i].tag,j);
if (fdebug) {
printf("i=%d frubuf[%d]: %02x %02x %02x, j=%d k=%d n=%d\n",
i,(pfru-frubuf),pfru[0],pfru[1],pfru[2],j,k,n);
if (i >= product_num)
printf("Field %d is beyond existing %d fields\n",i+1,product_num);
}
pnew += j + 1;
pfru += k + 1;
n += j + 1;
}
// n = (int)(pnew - newdata); /*new product area index*/
k = (int)(pfru - pfru0); /*old product area index*/
if (mult_offset > 0) /* do not expand if multi-record area there */
max = plen - k;
else /* nothing else, can expand product area, up to sfru */
max = sfru - (k + prod_offset);
if (fdebug)
printf("frubuf[%d]: %02x %02x %02x, j=%d k=%d n=%d remainder=%d\n",
(pfru-frubuf),pfru[0],pfru[1],pfru[2],j,k,n,max);
if (max < 0) max = 0;
/* copy trailing fru data from saved copy */
for (i = 0; i < max; i++) {
pnew[i] = pfru[i];
if (pfru[i] == FRU_END) { i++; break; } /*0xC1*/
}
if (i == max) { /*never found 0xC1 FRU_END*/
pnew[0] = FRU_END; /*mark this trailing field as empty*/
i = 1;
}
newlen = n + i;
if (fdebug) printf("newbuf[%d]: %02x %02x %02x, j=%d newlen=%d plen=%d\n",
n,pnew[0],pnew[1],pnew[2],j,newlen,plen);
/* round up to next 8-byte boundary */
/* need one more byte for checksum, so if j=0, add 8 anyway */
j = 8 - (newlen % 8);
for (i = 0; i < j; i++) newdata[newlen++] = 0;
if (newlen < plen) newlen = plen; /* don't shrink the product area */
newdata[1] = newlen / 8; // set length of product data
/* include new checksum (calc over Product area) */
chksum = calc_cksum(&newdata[0],newlen-1);
newdata[newlen-1] = chksum;
if (fdebug) {
printf("old prod_area buffer (%d):",plen);
dumpbuf(&frubuf[prod_offset],plen);
printf("new prod_area buffer (%d):",newlen);
dumpbuf(newdata,newlen);
}
if (prod_offset + newlen >= sfru) return ERR_LENMAX;
if ((mult_offset > 0) && (newlen > plen)) return ERR_LENMAX;
#ifdef TEST
newlen = 0; /*don't actually write the new data, if testing*/
#endif
ret = write_fru_data(g_fruid, prod_offset, newdata, newlen, fdebug);
return(ret);
}
#define CHUNKSZ 16
#define LAST_REC 0xffff
#define STR_OFF 16
int get_sdr(ushort recid, ushort resid, ushort *recnext,
uchar *sdr, int *slen, uchar *pcc)
{
uchar idata[6];
uchar rdata[64];
int sresp;
ushort cmd;
uchar cc = 0;
int len = 0;
int rc;
idata[0] = resid & 0x00ff;
idata[1] = (resid & 0xff00) >> 8;
idata[2] = recid & 0x00ff;
idata[3] = (recid & 0xff00) >> 8;
idata[4] = 0; /*offset*/
idata[5] = CHUNKSZ; /*bytes to read*/
if (fdevsdrs) cmd = GET_DEVICE_SDR;
else cmd = GET_SDR;
sresp = sizeof(rdata);
rc = ipmi_cmd_mc(cmd, idata, 6, rdata, &sresp,&cc, fdebug);
if (fdebug) printf("get_sdr[%x] ret = %d cc = %x sresp = %d\n",
recid,rc,cc,sresp);
if (rc == 0 && cc == 0xCA) {
idata[5] = 8; /*bytes to read*/
sresp = sizeof(rdata);
rc = ipmi_cmd_mc(cmd, idata, 6, rdata, &sresp,&cc, fdebug);
if (fdebug) printf("get_sdr[%x] ret = %d cc = %x sresp = %d\n",
recid,rc,cc,sresp);
}
*pcc = cc;
if (rc == 0 && cc == 0) {
*recnext = rdata[0] + (rdata[1] << 8);
memcpy(sdr,&rdata[2],sresp-2);
*slen = sdr[6] + 5; /*get actual SDR size*/
len = sresp-2;
/* if an SDR locator record, get the rest of it. */
if (sdr [3] == 0x11 || sdr[3] == 0x12)
if (*slen > CHUNKSZ) {
idata[0] = resid & 0x00ff;
idata[1] = (resid & 0xff00) >> 8;
idata[2] = recid & 0x00ff;
idata[3] = (recid & 0xff00) >> 8;
idata[4] = CHUNKSZ; /*offset*/
idata[5] = *slen - CHUNKSZ; /*bytes to read*/
sresp = sizeof(rdata);
rc = ipmi_cmd_mc(cmd, idata, 6, rdata, &sresp,&cc, fdebug);
if (fdebug) printf("get_sdr[%x] 2nd ret=%d cc=%x sresp=%d\n",
recid,rc,cc,sresp);
if (rc == 0 && cc == 0) {
sresp -= 2;
memcpy(&sdr[len],&rdata[2],sresp);
len += sresp;
}
}
*slen = len;
}
return(rc);
}
void show_loadfru_error(uchar sa, uchar fruid, int ret)
{
if (ret == 0) return;
switch(ret) {
case 0x081: printf("\tFRU(%x,%x) device busy\n",sa,fruid); break;
case 0x0C3: printf("\tFRU(%x,%x) timeout, not found\n",sa,fruid); break;
case 0x0CB: printf("\tFRU(%x,%x) not present\n",sa,fruid); break;
default: printf("load_fru(%x,%x) error = %d (0x%x)\n",
sa,fruid,ret,ret);
break;
}
return;
}
#ifdef METACOMMAND
int i_ifruset(int argc, char **argv)
#else
#ifdef WIN32
int __cdecl
#else
int
#endif
main(int argc, char **argv)
#endif
{
int ret;
int c;
char DevRecord[16];
ushort recid;
ushort nextid;
ushort rsvid;
uchar sdr[40];
char biosver[80];
uchar cc;
uchar sa;
uchar fruid = 0;
uchar frutype = 0;
int len, i;
char *s1;
FILE *fp;
printf("%s version %s\n",progname,progver);
parse_lan_options('V',"4",0); /*request admin priv by default*/
while ( (c = getopt( argc, argv,"a:bcd:h:i:f:m:n:o:p:r:s:u:v:xyz:T:V:J:EYF:P:N:R:U:Z:?")) != EOF )
switch(c) {
case 'x': fdebug = 1; break;
case 'y': fdoanyway = 1; break;
case 'b': fonlybase = 1;
g_frutype = 0x07; break;
case 'c': fcanonical = 1; bdelim = BDELIM; break;
#ifdef TEST
case 'h':
if (optarg) {
len = strlen(optarg);
if (len >= FIELD_LEN) len = FIELD_LEN - 1;
strncpy(chassis_name,optarg,len);
if (len == 1) { /* add a space */
chassis_name[1] = ' ';
chassis_name[2] = 0;
}
}
break;
#else
case 'h': fonlyhsc = 1; /* can use -m00c000s instead */
g_frutype = 0x0f; break;
#endif
case 'a':
fwritefru |= 0x01;
if (optarg) {
len = strlen(optarg);
if (len >= FIELD_LEN) len = FIELD_LEN - 1;
/* if (len == 1), handle it in write_product() */
strncpy(prodnew[IPROD_ASSET].tag,optarg,len);
prodnew[IPROD_ASSET].len = len;
}
break;
case 'f':
fwritefru |= 0x04;
if (optarg) {
len = strlen(optarg);
if (len >= FIELD_LEN) len = FIELD_LEN - 1;
/* if (len == 1), handle it in write_product() */
strncpy(prodnew[IPROD_FRUID].tag,optarg,len);
prodnew[IPROD_FRUID].len = len;
}
break;
case 'n':
fwritefru |= 0x20;
if (optarg) {
len = strlen(optarg);
if (len >= FIELD_LEN) len = FIELD_LEN - 1;
/* if (len == 1), handle it in write_product() */
strncpy(prodnew[IPROD_NAME].tag,optarg,len);
prodnew[IPROD_NAME].len = len;
}
break;
case 'o':
fwritefru |= 0x10;
if (optarg) {
len = strlen(optarg);
if (len >= FIELD_LEN) len = FIELD_LEN - 1;
/* if (len == 1), handle it in write_product() */
strncpy(prodnew[IPROD_OEM].tag,optarg,len);
prodnew[IPROD_OEM].len = len;
}
break;
case 'p':
fwritefru |= 0x40;
if (optarg) {
len = strlen(optarg);
if (len >= FIELD_LEN) len = FIELD_LEN - 1;
/* if (len == 1), handle it in write_product() */
strncpy(prodnew[IPROD_PART].tag,optarg,len);
prodnew[IPROD_PART].len = len;
}
break;
case 'u':
fwritefru |= 0x80;
if (optarg) {
len = strlen(optarg);
if (len >= FIELD_LEN) len = FIELD_LEN - 1;
/* if (len == 1), handle it in write_product() */
strncpy(prodnew[IPROD_MANUF].tag,optarg,len);
prodnew[IPROD_MANUF].len = len;
}
break;
case 's':
fwritefru |= 0x02;
if (optarg) {
len = strlen(optarg);
if (len >= FIELD_LEN) len = FIELD_LEN - 1;
/* if (len == 1), handle it in write_product() */
strncpy(prodnew[IPROD_SERNUM].tag,optarg,len);
prodnew[IPROD_SERNUM].len = len;
}
break;
case 'v':
fwritefru |= 0x08;
if (optarg) {
len = strlen(optarg);
if (len >= FIELD_LEN) len = FIELD_LEN - 1;
/* if (len == 1), handle it in write_product() */
strncpy(prodnew[IPROD_VERS].tag,optarg,len);
prodnew[IPROD_VERS].len = len;
}
break;
case 'm': /* specific IPMB MC, 3-byte address, e.g. "409600" */
g_bus = htoi(&optarg[0]); /*bus/channel*/
g_sa = htoi(&optarg[2]); /*device slave address*/
g_lun = htoi(&optarg[4]); /*LUN*/
g_addrtype = ADDR_IPMB;
if (optarg[6] == 's') {
g_addrtype = ADDR_SMI; s1 = "SMI";
} else { g_addrtype = ADDR_IPMB; s1 = "IPMB"; }
fset_mc = 1;
printf("set MC at %s bus=%x sa=%x lun=%x\n",
s1,g_bus,g_sa,g_lun);
break;
case 'z': /* set local IPMB MC sa */
sa = htoi(&optarg[0]); /*device slave address*/
ipmi_set_mymc(g_bus, sa, g_lun,ADDR_IPMB);
bmc_sa = sa;
case 'i': fonlybase = 1; /*specify a fru id*/
if (strncmp(optarg,"0x",2) == 0) g_fruid = htoi(&optarg[2]);
else g_fruid = htoi(optarg);
printf("Using FRU ID 0x%02x\n",g_fruid);
break;
case 'd': fdump = 1; /*dump fru to a file*/
binfile = optarg;
break;
case 'r': frestore = 1; /*restore fru from a file*/
fwritefru = 0x100;
binfile = optarg;
break;
case 'N': /* nodename */
case 'U': /* remote username */
case 'P': /* remote password */
case 'R': /* remote password */
case 'E': /* get password from IPMI_PASSWORD environment var */
case 'F': /* force driver type */
case 'T': /* auth type */
case 'J': /* cipher suite */
case 'V': /* priv level */
case 'Y': /* prompt for remote password */
parse_lan_options(c,optarg,fdebug);
break;
default:
printf("Usage: %s [-bcimxy -unpvsafo -NUPREFTVY]\n",progname);
printf(" -u manu Sets Product Manufacturer (0)\n");
printf(" -n name Sets Product Name (1)\n");
printf(" -p part Sets Product Part Number (2)\n");
printf(" -v vers Sets Product Version (3)\n");
printf(" -s snum Sets Product Serial Num (4)\n");
printf(" -a tag Sets Product Asset Tag (5)\n");
printf(" -f fru Sets Product FRU File ID (6)\n");
printf(" -o oem Sets Product OEM Field (7)\n");
// printf(" -h chname Sets the Chassis Name \n");
printf(" -b Only show Baseboard FRU data\n");
printf(" -c show Canonical, delimited output\n");
printf(" -d Dump FRU to a file\n");
printf(" -r Restore FRU from a file\n");
printf(" -i 00 Get/Set a specific FRU ID\n");
printf(" -m002000 specific MC (bus 00,sa 20,lun 00)\n");
printf(" -x Display extra debug messages\n");
printf(" -y Ignore the check for FRU size overflow\n");
print_lan_opt_usage(0);
ret = ERR_USAGE;
goto do_exit;
}
// if (is_remote() && fwritefru) parse_lan_options('V',"4",0);
ret = ipmi_getdeviceid( DevRecord, sizeof(DevRecord),fdebug);
if (ret == 0) {
uchar ipmi_maj, ipmi_min;
ipmi_maj = DevRecord[4] & 0x0f;
ipmi_min = DevRecord[4] >> 4;
vend_id = DevRecord[6] + (DevRecord[7] << 8) + (DevRecord[8] << 16);
prod_id = DevRecord[9] + (DevRecord[10] << 8);
show_devid( DevRecord[2], DevRecord[3], ipmi_maj, ipmi_min);
if ((DevRecord[1] & 0x80) == 0x80) fdevsdrs = 1;
if (vend_id == VENDOR_NEC) fdevsdrs = 0;
else if (vend_id == VENDOR_INTEL) {
if (prod_id == 0x003E) {
set_max_kcs_loops(URNLOOPS); /*longer for cmds (default 300)*/
}
}
} else {
goto do_exit;
}
ret = ipmi_getpicmg( DevRecord, sizeof(DevRecord),fdebug);
if (ret == 0) fpicmg = 1;
if ((vend_id == VENDOR_INTEL) && (!fpicmg))
fdevsdrs = 0; /* override, use SDR repository*/
if (fdebug) printf("bmc_sa = %02x fdevsdrs = %d\n",bmc_sa,fdevsdrs);
if (fset_mc) {
/* target a specific MC via IPMB (usu a picmg blade) */
if (fdebug) printf("set_mc: %02x:%02x:%02x type=%d\n",
g_bus,g_sa,g_lun,g_addrtype);
ipmi_set_mc(g_bus,g_sa,g_lun,g_addrtype);
fonlybase = 1; /*only show this MC*/
} else {
g_sa = bmc_sa; /* BMC_SA = 0x20 */
}
if (g_frutype == 0) {
g_frutype = 0x01; /* other = "Component" */
}
if (!fonlybase && !fonlyhsc) {
/* loop thru SDRs to find FRU devices */
#ifdef NOT_YET
{ /* get SDR Repository Info (needs to be copied here)*/
ret = GetSDRRepositoryInfo(&j,&fdevsdrs);
if (fdebug) printf("GetSDRRepositoryInfo: ret=%x nSDRs=%d\n",ret,j);
}
#endif
{ /* reserve the SDR repository */
uchar resp[16];
int sresp;
uchar cc;
ushort cmd;
sresp = sizeof(resp);
if (fdevsdrs) cmd = RESERVE_DEVSDR_REP;
else cmd = RESERVE_SDR_REP;
ret = ipmi_cmd_mc(cmd, NULL, 0, resp, &sresp, &cc, 0);
if (fdebug) printf("ipmi_cmd RESERVE status = %d, cc = %x\n",ret,cc);
rsvid = resp[0] + (resp[1] << 8);
}
recid = 0;
while (recid != LAST_REC)
{
char idstr[32];
int ilen;
len = sizeof(sdr); /*sizeof(sdr); get 32 sdr bytes*/
ret = get_sdr(recid,rsvid,&nextid,sdr,&len,&cc);
if ((ret != 0) || (cc != 0)) {
printf("SDR[%04x] error %d ccode = %x\n",recid,ret,cc);
break;
}
fgetfru = 0;
if ((sdr[3] == 0x11) || (sdr[3] == 0x12)) /* SDR FRU or IPMB type */
{
if (len > STR_OFF) {
ilen = len - STR_OFF;
if (ilen >= sizeof(idstr)) ilen = sizeof(idstr) - 1;
memcpy(idstr,&sdr[STR_OFF],ilen);
idstr[ilen] = 0;
} else idstr[0] = 0;
sa = sdr[5]; /* usu 0x20 for bmc_sa */
/* Get its FRU data */
if ((sdr[3] == 0x11) && (sdr[7] & 0x80)) { /* FRU SDRs */
/* It is a logical FRU device */
if (fcanonical)
printf("SDR[%04x] FRU %c %s\n", recid, bdelim, idstr);
else
printf("SDR[%04x] FRU %02x %02x %02x %02x %s\n", recid,
sdr[5],sdr[6],sdr[12],sdr[13],idstr);
fruid = sdr[6];
frutype = sdr[12];
if (sa == bmc_sa && fruid == 0) /*do this below*/;
else
switch(sdr[12]) /*FRU entity id*/
{
case 0x0a: /*Power Supply*/
case 0x20: /*DIMM*/
case 0x15: /*Power Cage*/
default:
fgetfru = 1;
break;
}
} else if (sdr[3] == 0x12) { /* IPMB SDRs (DLRs for MCs) */
if (fcanonical)
printf("SDR[%04x] IPMB %c %s\n", recid, bdelim, idstr);
else
printf("SDR[%04x] IPMB %02x %02x %02x %02x %s\n", recid,
sdr[5],sdr[6],sdr[12],sdr[13],idstr);
fruid = 0; /*every MC must have fruid 0*/
frutype = sdr[12];
if (sa == bmc_sa && fruid == 0) { /*do bmc_sa,0 below*/
if (fdebug) printf("do bmc_sa %02x below\n",sa);
g_frutype = frutype;
} else if (frutype == 0x2e) { /*skip ME*/
if (fdebug) printf("skipping ME sa %02x, %02x\n",sa,fruid);
} else if (sa == 0x28) { /*do nothing for Bridge Ctlr sa=0x28*/
if (fdebug) printf("skipping IPMB sa %02x, %02x\n",sa,fruid);
} else if (sa == 0xC0) { /* HotSwap Backplane (sa=0xC0) */
/* Note: Loading sa 0xC0 over ipmi lan gives a timeout
* error, but it works locally. */
fgetfru = 1;
} else { /* other misc sa,fruid */
fgetfru = 1;
}
}
if (fgetfru) {
uchar adrtype;
adrtype = g_addrtype;
if (fdebug) printf("set_mc %02x:%02x:%02x type=%d fruid=%02x\n",
g_bus,sa,g_lun,adrtype,fruid);
ipmi_set_mc(g_bus, sa, g_lun,adrtype);
ret = load_fru(sa,fruid,frutype);
if (ret != 0) {
show_loadfru_error(sa,fruid,ret);
free_fru();
} else {
ret = show_fru(sa,fruid,frutype);
if (ret != 0) printf("show_fru error = %d\n",ret);
free_fru();
}
ipmi_restore_mc();
}
} /*endif FRU/IPMB SDR */
recid = nextid;
} /*end while sdrs*/
} /*endif not fonlybase*/
/* load the FRU data for Baseboard (address 0x20) */
printf("\n");
sa = g_sa; /* bmc_sa = BMC_SA = 0x20 */
if (fonlyhsc) { sa = 0xC0; g_addrtype = ADDR_SMI;
ipmi_set_mc(g_bus,sa,g_lun,g_addrtype);
}
if (g_addrtype == ADDR_IPMB)
ipmi_set_mc(g_bus,sa,g_lun,g_addrtype);
ret = load_fru(sa,g_fruid,g_frutype);
if (ret != 0) {
show_loadfru_error(sa,g_fruid,ret);
free_fru();
goto do_exit;
}
/* display the Baseboard FRU data */
ret = show_fru(sa,g_fruid,g_frutype);
if (ret != 0) printf("show_fru error = %d\n",ret);
if (!is_remote()) {
char devstr[24];
if (fcanonical) devstr[0] = 0; /*default is empty string*/
else sprintf(devstr,"[%s,%02x] ",FruTypeString(g_frutype),g_fruid);
i = get_BiosVersion(biosver);
if (i == 0)
printf("%sBIOS Version %c %s\n",devstr,bdelim,biosver);
}
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);
} else {
printf("Writing FRU size %d to %s ...\n",sfru,binfile);
len = fwrite(frubuf, 1, sfru, fp);
fclose(fp);
if (len <= 0) {
ret = get_LastError();
printf("Error %d writing file %s\n",ret,binfile);
} else ret = 0;
}
} 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();
printf("Cannot open file %s, error %d\n",binfile,ret);
} else {
ret = 0;
/* sfru and frubuf were set from load_fru above. */
len = fread(frubuf, 1, sfru, fp);
if (len <= 0) {
ret = get_LastError();
printf("Error %d reading file %s\n",ret,binfile);
sfru = 0; /*for safety*/
}
fclose(fp);
if (fdebug) {
printf("FRU buffer from file (%d):",sfru);
dumpbuf(frubuf,sfru);
}
/* Do some validation of the FRU buffer header */
cksum = calc_cksum(&frubuf[0],7);
if (fdebug)
printf("header, len=8, cksum0 = %02x, cksum1 = %02x\n",
frubuf[7],cksum);
if (frubuf[7] != cksum) {
printf("Not a valid FRU file\n");
ret = ERR_BAD_FORMAT;
free_fru();
}
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();
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);
if (ret != 0) show_loadfru_error(sa,g_fruid,ret);
else ret = show_fru(sa,g_fruid,g_frutype);
free_fru();
}
}
}
} /*end-else frestore */
else if ((fwritefru != 0) && ret == 0) {
printf("\nWriting new product data (%s,%s,%s,%s,%s,%s,%s,%s) ...\n",
prodnew[0].tag, prodnew[1].tag, prodnew[2].tag,
prodnew[3].tag, prodnew[4].tag, prodnew[5].tag,
prodnew[6].tag, prodnew[7].tag);
for (i = 0; i < NUM_PRODUCT_FIELDS; i++) {
len = prodnew[i].len;
if (len > 0) {
if (len >= FIELD_LEN) len = FIELD_LEN - 1;
if (len == 1) {
prodnew[i].tag[1] = ' ';
len++;
}
prodarea[i].len = len;
memcpy(prodarea[i].tag,prodnew[i].tag,len);
}
}
ret = write_product();
free_fru();
if (ret != 0) printf("write_product error %d (0x%02x)\n",ret,ret);
else { /* successful, show new data */
ret = load_fru(sa,g_fruid,g_frutype);
if (ret != 0) show_loadfru_error(sa,g_fruid,ret);
else ret = show_fru(sa,g_fruid,g_frutype);
free_fru();
}
}
else
free_fru();
do_exit:
ipmi_close_();
show_outcome(progname,ret);
return(ret);
}
/* end ifruset.c */
|