From 604132155fd5242411f178b2afdd3b50d841956e Mon Sep 17 00:00:00 2001 From: Pridhiviraj Paidipeddi Date: Sat, 3 Mar 2018 13:27:58 +0530 Subject: [PATCH 2/3] lsmcode: Add product version string to firmware information OPAL adds version property under ibm,firmware-versions device tree node from POWER9 system onwards. So lets add this version property info to firmware version of lsmcode. And also add buildroot as fallback option when there is no version property. Example output with patch: lsmcode -A sys0!system: SUPERMICRO-P9DSU-V1.04-20180227-imp sg1 0:2:2:0 sdb !ST4000NM0075.4B543032 (KT02) sg0 0:2:0:0 sda !ST2000NM0045.4E303033 (N003) sg2 0:3:123:0 !Smart.3.80 net0 !.5.05 0x800029e1 1.1313.0 enP1p9s0f3 !.5.05 0x800029e1 1.1313.0 enP1p9s0f1 !.5.05 0x800029e1 1.1313.0 enP1p9s0f2 !.5.05 0x800029e1 1.1313.0 lsmcode Version of System Firmware : Product Name : OpenPOWER Firmware Product Version : SUPERMICRO-P9DSU-V1.04-20180227-imp Product Extra : occ-bf6e716 Product Extra : skiboot-v5.10-p5a05666 Product Extra : petitboot-v1.6.6-pb8314a9 Product Extra : sbe-9b78381 Product Extra : machine-xml-df58ab8 Product Extra : hostboot-fed203b Product Extra : linux-4.15.6-openpower1-p7c2030b Signed-off-by: Pridhiviraj Paidipeddi [Added comment on how we parse version property - Vasant] Signed-off-by: Vasant Hegde --- src/output/lsmcode.cpp | 48 ++++++++++++++++++++++++++++++++++-------------- 1 file changed, 34 insertions(+), 14 deletions(-) diff --git a/src/output/lsmcode.cpp b/src/output/lsmcode.cpp index 64ae59d..557c008 100644 --- a/src/output/lsmcode.cpp +++ b/src/output/lsmcode.cpp @@ -207,11 +207,13 @@ static string read_dt_property(const string& path, const string& attrName) /* Get system firmware information on BMC based system via device tree */ static string bmc_get_fw_dt_info(void) { - string fwdata, tag, val, prod_ver = "", prod_extra = ""; + string fwdata, tag, val, prod_ver = "", prod_extra = "", prop_ver = ""; struct dirent *ent; DIR * pDBdir = NULL; /* Properties to ignore from DT/ibm,firmware-versions node */ const char *ignore_dt[] = {"phandle", "name"}; + /* Properties to look for version string */ + const char *version_prop[] = {"version", "IBM", "open-power", "buildroot"}; int i; bool ignore_dt_flag = false; @@ -223,7 +225,36 @@ static string bmc_get_fw_dt_info(void) return string(""); } + /* Get the version property */ + for (i = 0; i < (int)(sizeof(version_prop)/sizeof(char *)); i++) { + string path = FW_VERSION_DT_NODE + string(version_prop[i]); + if (HelperFunctions::file_exists(path)) { + prop_ver = version_prop[i]; + break; + } + } + fwdata = string("\n Product Name : OpenPOWER Firmware\n"); + + /* + * Different BMCs uses different device tree property to display + * product name. On P9 system OPAL firmware takes care of parsing + * and it will add version property under device tree. But on older + * systems will have IBM or open-power or buildroot depending on + * who builds firmware image. + */ + if (prop_ver != string("")) { + tag = string(" Product Version : "); + prod_ver = read_dt_property(string(FW_VERSION_DT_NODE), prop_ver); + if (prod_ver != string("")) { + if (prop_ver.compare("version") == 0) + prod_ver = tag + prod_ver + string("\n"); + else + prod_ver = tag + prop_ver + string("-") + prod_ver + string("\n"); + } + } + + /* Form the product extra items using remaining properties */ while ((ent = readdir( pDBdir )) != NULL) { string fname = ent->d_name; for (i = 0; i < (int)(sizeof(ignore_dt)/sizeof(char *)); i++) { @@ -238,20 +269,9 @@ static string bmc_get_fw_dt_info(void) continue; } - /* - * Looks like some system has open-power property and some - * other has "IBM" property. Lets use one of these property - * for Product Version. - */ - if (fname.compare("IBM") == 0 || fname.compare("open-power") == 0) { - if (prod_ver == string("")) { - tag = string(" Product Version : "); - prod_ver = read_dt_property(string(FW_VERSION_DT_NODE), fname); - if (prod_ver == string("")) - continue; - prod_ver = tag + fname + string("-") + prod_ver + string("\n"); + if (prop_ver != string("")) { + if (fname.compare(prop_ver) == 0) continue; - } } tag = string(" Product Extra : \t"); -- 2.14.3