summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSamuel Mendoza-Jonas <sam@mendozajonas.com>2018-11-12 12:01:05 +1100
committerSamuel Mendoza-Jonas <sam@mendozajonas.com>2018-11-16 13:55:29 +1100
commitcf30fdd3100a425f2f01214ca726f0641f844eec (patch)
tree579c4082794e909d71ea172a1948ed553ed19b17
parent2bc0df4aa35a89c5af7e54f459e2bbde20ca6a7e (diff)
downloadtalos-petitboot-cf30fdd3100a425f2f01214ca726f0641f844eec.tar.gz
talos-petitboot-cf30fdd3100a425f2f01214ca726f0641f844eec.zip
discover: Nicely format IPMI response buffersv1.9.2
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>
-rw-r--r--discover/ipmi.c33
-rw-r--r--discover/platform-powerpc.c23
-rw-r--r--lib/util/util.c17
-rw-r--r--lib/util/util.h1
4 files changed, 41 insertions, 33 deletions
diff --git a/discover/ipmi.c b/discover/ipmi.c
index 840fdee..ae02bb0 100644
--- a/discover/ipmi.c
+++ b/discover/ipmi.c
@@ -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);
diff --git a/discover/platform-powerpc.c b/discover/platform-powerpc.c
index 2929077..f8f3305 100644
--- a/discover/platform-powerpc.c
+++ b/discover/platform-powerpc.c
@@ -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");
diff --git a/lib/util/util.c b/lib/util/util.c
index a18926c..36d45b8 100644
--- a/lib/util/util.c
+++ b/lib/util/util.c
@@ -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;
+}
diff --git a/lib/util/util.h b/lib/util/util.h
index 39966d0..a579221 100644
--- a/lib/util/util.h
+++ b/lib/util/util.h
@@ -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 */
OpenPOWER on IntegriCloud