]> git.ozlabs.org Git - petitboot/commitdiff
discover: Nicely format IPMI response buffers v1.9.2
authorSamuel Mendoza-Jonas <sam@mendozajonas.com>
Mon, 12 Nov 2018 01:01:05 +0000 (12:01 +1100)
committerSamuel Mendoza-Jonas <sam@mendozajonas.com>
Fri, 16 Nov 2018 02:55:29 +0000 (13:55 +1100)
A few places where we print out the response buffer from an IPMI command
weren't updated when log timestamps were added, resulting in very hard
to read output. Add a little helper to format buffers and use it to
print these with only one timestamp.

Example:

[04:59:01] ipmi_get_bmc_versions: BMC version resp [0][16]:
0x00 0x20 0x01 0x02 0x13 0x02 0xbf 0x00
0x00 0x00 0xbb 0xaa 0x58 0x98 0x01 0x00

Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
discover/ipmi.c
discover/platform-powerpc.c
lib/util/util.c
lib/util/util.h

index 840fdee5d6dada2e2bc959aaec340fefaa891040..ae02bb0a69291000fb9f204dc2a674a96e61c77c 100644 (file)
@@ -326,6 +326,7 @@ void ipmi_get_bmc_mac(struct ipmi *ipmi, uint8_t *buf)
        uint16_t resp_len = 8;
        uint8_t resp[8];
        uint8_t req[] = { 0x1, 0x5, 0x0, 0x0 };
+       char *debug_buf;
        int i, rc;
 
        rc = ipmi_transaction(ipmi, IPMI_NETFN_TRANSPORT,
@@ -334,14 +335,15 @@ void ipmi_get_bmc_mac(struct ipmi *ipmi, uint8_t *buf)
                        resp, &resp_len,
                        ipmi_timeout);
 
-       pb_debug_fn("BMC MAC resp [%d][%d]:\n", rc, resp_len);
+       debug_buf = format_buffer(ipmi, resp, resp_len);
+       pb_debug_fn("BMC MAC resp [%d][%d]:\n%s\n",
+                       rc, resp_len, debug_buf);
+       talloc_free(debug_buf);
 
        if (rc == 0 && resp_len > 0) {
                for (i = 2; i < resp_len; i++) {
-                       pb_debug(" %x", resp[i]);
                        buf[i - 2] = resp[i];
                }
-               pb_debug("\n");
        }
 
 }
@@ -354,7 +356,8 @@ void ipmi_get_bmc_versions(struct ipmi *ipmi, struct system_info *info)
 {
        uint16_t resp_len = 16;
        uint8_t resp[16], bcd;
-       int i, rc;
+       char *debug_buf;
+       int rc;
 
        /* Retrieve info from current side */
        rc = ipmi_transaction(ipmi, IPMI_NETFN_APP,
@@ -363,13 +366,10 @@ void ipmi_get_bmc_versions(struct ipmi *ipmi, struct system_info *info)
                        resp, &resp_len,
                        ipmi_timeout);
 
-       pb_debug_fn("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");
-       }
+       debug_buf = format_buffer(ipmi, resp, resp_len);
+       pb_debug_fn("BMC version resp [%d][%d]:\n%s\n",
+                       rc, resp_len, debug_buf);
+       talloc_free(debug_buf);
 
        if (rc == 0 && (resp_len == 12 || resp_len == 16)) {
                info->bmc_current = talloc_array(info, char *, 4);
@@ -407,13 +407,10 @@ void ipmi_get_bmc_versions(struct ipmi *ipmi, struct system_info *info)
                        resp, &resp_len,
                        ipmi_timeout);
 
-       pb_debug_fn("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");
-       }
+       debug_buf = format_buffer(ipmi, resp, resp_len);
+       pb_debug_fn("BMC golden resp [%d][%d]:\n%s\n",
+                       rc, resp_len, debug_buf);
+       talloc_free(debug_buf);
 
        if (rc == 0 && (resp_len == 12 || resp_len == 16)) {
                info->bmc_golden = talloc_array(info, char *, 4);
index 2929077edd7784b4ec980422e2ba214dbc9fed18..f8f33054648fc7fbb0ebc3c82095a6830d866785 100644 (file)
@@ -368,6 +368,7 @@ static int get_ipmi_bootdev_ipmi(struct platform_powerpc *platform,
 {
        uint16_t resp_len;
        uint8_t resp[8];
+       char *debug_buf;
        int rc;
        uint8_t req[] = {
                0x05, /* parameter selector: boot flags */
@@ -392,10 +393,9 @@ static int get_ipmi_bootdev_ipmi(struct platform_powerpc *platform,
                return -1;
        }
 
-       pb_debug("IPMI get_bootdev response:\n");
-       for (int i = 0; i < resp_len; i++)
-               pb_debug("%x ", resp[i]);
-       pb_debug("\n");
+       debug_buf = format_buffer(platform, resp, resp_len);
+       pb_debug_fn("IPMI get_bootdev response:\n%s\n", debug_buf);
+       talloc_free(debug_buf);
 
        if (resp[0] != 0) {
                pb_log("platform: non-zero completion code %d from IPMI req\n",
@@ -472,6 +472,7 @@ static void get_ipmi_network_override(struct platform_powerpc *platform,
        uint16_t min_len = 12, resp_len = 53, version;
        const uint32_t magic_value = 0x21706221;
        uint8_t resp[resp_len];
+       char *debug_buf;
        uint32_t cookie;
        bool persistent;
        int i, rc;
@@ -487,17 +488,9 @@ static void get_ipmi_network_override(struct platform_powerpc *platform,
                        resp, &resp_len,
                        ipmi_timeout);
 
-       pb_debug("IPMI net override resp [%d][%d]:\n", rc, resp_len);
-       if (resp_len > 0) {
-               for (i = 0; i < resp_len; i++) {
-                       pb_debug(" %02x", resp[i]);
-                       if (i && (i + 1) % 16 == 0 && i != resp_len - 1)
-                               pb_debug("\n");
-                       else if (i && (i + 1) % 8 == 0)
-                               pb_debug(" ");
-               }
-               pb_debug("\n");
-       }
+       debug_buf = format_buffer(platform, resp, resp_len);
+       pb_debug_fn("IPMI net override response:\n%s\n", debug_buf);
+       talloc_free(debug_buf);
 
        if (rc) {
                pb_debug("IPMI network config option unavailable\n");
index a18926c1ac74c9446629d0ad01199db467c9d449..36d45b8438b4961a9689c7ad2578fa4d0eaabd16 100644 (file)
@@ -19,6 +19,7 @@
 #include <assert.h>
 
 #include <util/util.h>
+#include <talloc/talloc.h>
 
 static const char hex[] = { '0', '1', '2', '3', '4', '5', '6', '7',
                            '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', };
@@ -47,3 +48,19 @@ void mac_str(uint8_t *mac, unsigned int maclen, char *buf, unsigned int buflen)
 
        return;
 }
+
+char *format_buffer(void *ctx, const uint8_t *buf, unsigned int len)
+{
+       char *str;
+       unsigned int i;
+
+       if (len == 0)
+               return "";
+
+       str = talloc_asprintf(ctx, "0x%02x%s", buf[0], len > 1 ? " " : "");
+       for (i = 1; i < len; i++)
+               str = talloc_asprintf_append(str, "0x%02x%s", buf[i],
+                       ((i + 1) % 8 == 0 && i != len - 1) ? "\n" : " ");
+
+       return str;
+}
index 39966d0b7b0a2586b7ce8d857871c5379d4ecb31..a579221a63276ce7b5d70887925324bf762638fd 100644 (file)
@@ -50,6 +50,7 @@
        do { (void)sizeof(char[(x)?1:-1]); } while (0)
 
 void mac_str(uint8_t *mac, unsigned int maclen, char *buf, unsigned int buflen);
+char *format_buffer(void *ctx, const uint8_t *buf, unsigned int len);
 
 #endif /* UTIL_H */