Display VERSION partition info on BMC machines
authorSamuel Mendoza-Jonas <sam.mj@au1.ibm.com>
Tue, 8 Dec 2015 23:32:41 +0000 (10:32 +1100)
committerSam Mendoza-Jonas <sam@mendozajonas.com>
Tue, 9 Feb 2016 02:40:15 +0000 (13:40 +1100)
On supported platforms read the VERSION partition on startup and display
the available versions strings in the System Information screen.

This adds a skeleton hostboot.c to support possible additional BMC
platform support.

Signed-off-by: Sam Mendoza-Jonas <sam@mendozajonas.com>
discover/Makefile.am
discover/hostboot.c [new file with mode: 0644]
discover/hostboot.h [new file with mode: 0644]
discover/platform-powerpc.c
lib/pb-protocol/pb-protocol.c
lib/types/types.h
ui/ncurses/nc-sysinfo.c

index 1672035fdacc45ab7b74c0cf0425844fc53a971a..f55f1cd39b77471bdb870914eef238c6ed78bd3b 100644 (file)
@@ -79,7 +79,21 @@ discover_platform_ro_SOURCES = \
        discover/ipmi.h \
        discover/dt.c \
        discover/dt.h \
+       discover/hostboot.h \
        discover/platform-powerpc.c
 
+discover_platform_ro_CPPFLAGS = \
+       $(AM_CPPFLAGS)
+
+if ENABLE_MTD
+discover_platform_ro_SOURCES += \
+       discover/hostboot.c
+
+discover_platform_ro_LDFLAGS = \
+       $(core_lib) \
+       $(UDEV_LIBS)
+
+endif
+
 discover_platform_ro_LINK = \
        $(LD) -r -o $@
diff --git a/discover/hostboot.c b/discover/hostboot.c
new file mode 100644 (file)
index 0000000..9a27b0f
--- /dev/null
@@ -0,0 +1,26 @@
+#include <string.h>
+#include <stdlib.h>
+#include <errno.h>
+
+#include <log/log.h>
+#include <talloc/talloc.h>
+#include <flash/flash.h>
+
+#include "hostboot.h"
+
+void hostboot_load_versions(struct system_info *info)
+{
+       int n = 0;
+
+       n = flash_parse_version(info, &info->platform_current, true);
+       if (n < 0)
+               pb_log("Failed to read platform versions for current side\n");
+       else
+               info->n_current = n;
+
+       n = flash_parse_version(info, &info->platform_other, false);
+       if (n < 0)
+               pb_log("Failed to read platform versions for other side\n");
+       else
+               info->n_other = n;
+}
diff --git a/discover/hostboot.h b/discover/hostboot.h
new file mode 100644 (file)
index 0000000..cb1e497
--- /dev/null
@@ -0,0 +1,15 @@
+#ifndef HOSTBOOT_H
+#define HOSTBOOT_H
+
+#include "config.h"
+#include <types/types.h>
+
+#ifdef MTD_SUPPORT
+void hostboot_load_versions(struct system_info *info);
+#else
+static inline void hostboot_load_versions(struct system_info *info)
+{
+       (void)info;
+}
+#endif
+#endif /* HOSTBOOT_H */
index 992123e58a92bb3cc9ba161bcfd1e8356fb48118..46f81d201a403bec565bb735d728aa1e661fbcc1 100644 (file)
@@ -14,7 +14,9 @@
 #include <list/list.h>
 #include <log/log.h>
 #include <process/process.h>
+#include <types/types.h>
 
+#include "hostboot.h"
 #include "platform.h"
 #include "ipmi.h"
 #include "dt.h"
@@ -43,6 +45,7 @@ struct platform_powerpc {
                                bool persistent);
        int             (*set_os_boot_sensor)(
                                struct platform_powerpc *platform);
+       void            (*get_platform_versions)(struct system_info *info);
 };
 
 static const char *known_params[] = {
@@ -1094,6 +1097,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->get_platform_versions)
+               platform->get_platform_versions(sysinfo);
+
        return 0;
 }
 
@@ -1131,6 +1137,10 @@ static bool probe(struct platform *p, void *ctx)
                pb_log("platform: no IPMI parameter support\n");
        }
 
+       rc = stat("/proc/device-tree/bmc", &statbuf);
+       if (!rc)
+               platform->get_platform_versions = hostboot_load_versions;
+
        return true;
 }
 
index 42506e218fad289e51c934f6ad5d5643b5004918..e99ce86292c90baf111efd84865e7b8aa48a5197 100644 (file)
@@ -225,6 +225,13 @@ int pb_protocol_system_info_len(const struct system_info *sysinfo)
                4 + optional_strlen(sysinfo->identifier) +
                4 + 4;
 
+       len +=  4;
+       for (i = 0; i < sysinfo->n_current; i++)
+               len += 4 + optional_strlen(sysinfo->platform_current[i]);
+       len +=  4;
+       for (i = 0; i < sysinfo->n_other; i++)
+               len += 4 + optional_strlen(sysinfo->platform_other[i]);
+
        for (i = 0; i < sysinfo->n_interfaces; i++) {
                struct interface_info *if_info = sysinfo->interfaces[i];
                len +=  4 + if_info->hwaddr_size +
@@ -395,6 +402,16 @@ int pb_protocol_serialise_system_info(const struct system_info *sysinfo,
        pos += pb_protocol_serialise_string(pos, sysinfo->type);
        pos += pb_protocol_serialise_string(pos, sysinfo->identifier);
 
+       *(uint32_t *)pos = __cpu_to_be32(sysinfo->n_current);
+       pos += sizeof(uint32_t);
+       for (i = 0; i < sysinfo->n_current; i++)
+               pos += pb_protocol_serialise_string(pos, sysinfo->platform_current[i]);
+
+       *(uint32_t *)pos = __cpu_to_be32(sysinfo->n_other);
+       pos += sizeof(uint32_t);
+       for (i = 0; i < sysinfo->n_other; i++)
+               pos += pb_protocol_serialise_string(pos, sysinfo->platform_other[i]);
+
        *(uint32_t *)pos = __cpu_to_be32(sysinfo->n_interfaces);
        pos += sizeof(uint32_t);
 
@@ -798,6 +815,7 @@ int pb_protocol_deserialise_system_info(struct system_info *sysinfo,
        unsigned int len, i;
        const char *pos;
        int rc = -1;
+       char *tmp;
 
        len = message->payload_len;
        pos = message->payload;
@@ -809,6 +827,27 @@ int pb_protocol_deserialise_system_info(struct system_info *sysinfo,
        if (read_string(sysinfo, &pos, &len, &sysinfo->identifier))
                goto out;
 
+       /* versions strings for openpower platforms */
+       if (read_u32(&pos, &len, &sysinfo->n_current))
+               goto out;
+       sysinfo->platform_current = talloc_array(sysinfo, char *,
+                                               sysinfo->n_current);
+       for (i = 0; i < sysinfo->n_current; i++) {
+               if (read_string(sysinfo, &pos, &len, &tmp))
+                       goto out;
+               sysinfo->platform_current[i] = talloc_strdup(sysinfo, tmp);
+       }
+
+       if (read_u32(&pos, &len, &sysinfo->n_other))
+               goto out;
+       sysinfo->platform_other = talloc_array(sysinfo, char *,
+                                               sysinfo->n_other);
+       for (i = 0; i < sysinfo->n_other; i++) {
+               if (read_string(sysinfo, &pos, &len, &tmp))
+                       goto out;
+               sysinfo->platform_other[i] = talloc_strdup(sysinfo, tmp);
+       }
+
        /* number of interfaces */
        if (read_u32(&pos, &len, &sysinfo->n_interfaces))
                goto out;
index c2de8a5bab215ec31cbc399e8e5cabb625a86f4e..db4d8922d981e084af9764e034209aadbd59a3b4 100644 (file)
@@ -93,6 +93,10 @@ struct blockdev_info {
 struct system_info {
        char                    *type;
        char                    *identifier;
+       char                    **platform_current;
+       char                    **platform_other;
+       unsigned int            n_current;
+       unsigned int            n_other;
        uint8_t                 *bmc_mac;
        struct interface_info   **interfaces;
        unsigned int            n_interfaces;
index 5ced871127b33a2ea01391a07a04e892a5af9e75..c01b35275ea6572bb0ad481673321f8712f124db 100644 (file)
@@ -65,6 +65,22 @@ static void sysinfo_screen_populate(struct sysinfo_screen *screen,
        line("%-12s %s", _("System type:"), sysinfo->type ?: "");
        line("%-12s %s", _("System id:"),   sysinfo->identifier ?: "");
 
+       if (sysinfo->n_current) {
+               line(NULL);
+               line("%s", _("Current platform versions:"));
+               for (i = 0; i < sysinfo->n_current; i++) {
+                       line("\t%s", sysinfo->platform_current[i] ?: "");
+               }
+       }
+
+       if (sysinfo->n_other) {
+               line(NULL);
+               line("%s", _("Alternate platform versions:"));
+               for (i = 0; i < sysinfo->n_other; i++) {
+                       line("\t%s", sysinfo->platform_other[i] ?: "");
+               }
+       }
+
        if (sysinfo->n_blockdevs) {
                line(NULL);
                line(_("Storage devices"));