]> git.ozlabs.org Git - petitboot/blobdiff - discover/platform-powerpc.c
Retrieve BMC version info via IPMI
[petitboot] / discover / platform-powerpc.c
index 46f81d201a403bec565bb735d728aa1e661fbcc1..78b76d303471dbde2d4c07f0764e18e946a9dff2 100644 (file)
@@ -1023,6 +1023,94 @@ static void get_ipmi_bmc_mac(struct platform *p, uint8_t *buf)
                }
                pb_debug("\n");
        }
                }
                pb_debug("\n");
        }
+
+}
+
+/*
+ * Retrieve info from the "Get Device ID" IPMI commands.
+ * See Chapter 20.1 in the IPMIv2 specification.
+ */
+static void get_ipmi_bmc_versions(struct platform *p, struct system_info *info)
+{
+       struct platform_powerpc *platform = p->platform_data;
+       uint16_t resp_len = 16;
+       uint8_t resp[16], bcd;
+       uint32_t aux_version;
+       int i, rc;
+
+       /* Retrieve info from current side */
+       rc = ipmi_transaction(platform->ipmi, IPMI_NETFN_APP,
+                       IPMI_CMD_APP_GET_DEVICE_ID,
+                       NULL, 0,
+                       resp, &resp_len,
+                       ipmi_timeout);
+
+       pb_debug("BMC version resp [%d][%d]:\n", rc, resp_len);
+       if (resp_len > 0) {
+               for (i = 0; i < resp_len; i++) {
+                       pb_debug(" %x", resp[i]);
+               }
+               pb_debug("\n");
+       }
+
+       if (rc == 0 && resp_len == 16) {
+               info->bmc_current = talloc_array(info, char *, 4);
+               info->n_bmc_current = 4;
+
+               info->bmc_current[0] = talloc_asprintf(info, "Device ID: 0x%x",
+                                               resp[1]);
+               info->bmc_current[1] = talloc_asprintf(info, "Device Rev: 0x%x",
+                                               resp[2]);
+               bcd = resp[4] & 0x0f;
+               bcd += 10 * (resp[4] >> 4);
+               memcpy(&aux_version, &resp[12], sizeof(aux_version));
+               info->bmc_current[2] = talloc_asprintf(info,
+                                               "Firmware version: %u.%u.%u",
+                                               resp[3], bcd, aux_version);
+               bcd = resp[5] & 0x0f;
+               bcd += 10 * (resp[5] >> 4);
+               info->bmc_current[3] = talloc_asprintf(info, "IPMI version: %u",
+                                               bcd);
+       } else
+               pb_log("Failed to retrieve Device ID from IPMI\n");
+
+       /* Retrieve info from golden side */
+       memset(resp, 0, sizeof(resp));
+       resp_len = 16;
+       rc = ipmi_transaction(platform->ipmi, IPMI_NETFN_AMI,
+                       IPMI_CMD_APP_GET_DEVICE_ID_GOLDEN,
+                       NULL, 0,
+                       resp, &resp_len,
+                       ipmi_timeout);
+
+       pb_debug("BMC golden resp [%d][%d]:\n", rc, resp_len);
+       if (resp_len > 0) {
+               for (i = 0; i < resp_len; i++) {
+                       pb_debug(" %x", resp[i]);
+               }
+               pb_debug("\n");
+       }
+
+       if (rc == 0 && resp_len == 16) {
+               info->bmc_golden = talloc_array(info, char *, 4);
+               info->n_bmc_golden = 4;
+
+               info->bmc_golden[0] = talloc_asprintf(info, "Device ID: 0x%x",
+                                               resp[1]);
+               info->bmc_golden[1] = talloc_asprintf(info, "Device Rev: 0x%x",
+                                               resp[2]);
+               bcd = resp[4] & 0x0f;
+               bcd += 10 * (resp[4] >> 4);
+               memcpy(&aux_version, &resp[12], sizeof(aux_version));
+               info->bmc_golden[2] = talloc_asprintf(info,
+                                               "Firmware version: %u.%u.%u",
+                                               resp[3], bcd, aux_version);
+               bcd = resp[5] & 0x0f;
+               bcd += 10 * (resp[5] >> 4);
+               info->bmc_golden[3] = talloc_asprintf(info, "IPMI version: %u",
+                                               bcd);
+       } else
+               pb_log("Failed to retrieve Golden Device ID from IPMI\n");
 }
 
 static int load_config(struct platform *p, struct config *config)
 }
 
 static int load_config(struct platform *p, struct config *config)
@@ -1097,6 +1185,9 @@ static int get_sysinfo(struct platform *p, struct system_info *sysinfo)
        if (platform->ipmi)
                get_ipmi_bmc_mac(p, sysinfo->bmc_mac);
 
        if (platform->ipmi)
                get_ipmi_bmc_mac(p, sysinfo->bmc_mac);
 
+       if (platform->ipmi)
+               get_ipmi_bmc_versions(p, sysinfo);
+
        if (platform->get_platform_versions)
                platform->get_platform_versions(sysinfo);
 
        if (platform->get_platform_versions)
                platform->get_platform_versions(sysinfo);