]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
boot: add hexdump helper call
authorLennart Poettering <lennart@poettering.net>
Thu, 28 Jul 2022 08:47:05 +0000 (10:47 +0200)
committerLennart Poettering <lennart@poettering.net>
Tue, 2 Aug 2022 08:28:49 +0000 (10:28 +0200)
This is not actually used (or even supposed to be used) in clean
codepaths, but is tremendously useful when verifying things work
correctly, as a debugging tool.

src/boot/efi/util.c
src/boot/efi/util.h

index 7603eb8f534a9fd2c31ad24cde9942aaf1a5fa14..6fcf9b3121180d3fec138b33d996806fdc3b2d61 100644 (file)
@@ -637,6 +637,31 @@ __attribute__((noinline)) void debug_break(void) {
 }
 #endif
 
+
+#ifdef EFI_DEBUG
+void hexdump(const char16_t *prefix, const void *data, UINTN size) {
+        static const char hex[16] = "0123456789abcdef";
+        _cleanup_free_ char16_t *buf = NULL;
+        const uint8_t *d = data;
+
+        assert(prefix);
+        assert(data || size == 0);
+
+        /* Debugging helper — please keep this around, even if not used */
+
+        buf = xnew(char16_t, size*2+1);
+
+        for (UINTN i = 0; i < size; i++) {
+                buf[i*2] = hex[d[i] >> 4];
+                buf[i*2+1] = hex[d[i] & 0x0F];
+        }
+
+        buf[size*2] = 0;
+
+        log_error_stall(L"%s[%" PRIuN "]: %s", prefix, size, buf);
+}
+#endif
+
 #if defined(__i386__) || defined(__x86_64__)
 static inline uint8_t inb(uint16_t port) {
         uint8_t value;
index 4de799ea0e4e937a99e4fdf024bb882ebc22aeeb..bb4bb64e0e20f3b918afd604b944e3fb9e103b04 100644 (file)
@@ -167,6 +167,10 @@ extern uint8_t _text, _data;
 #  define debug_hook(identity)
 #endif
 
+#ifdef EFI_DEBUG
+void hexdump(const char16_t *prefix, const void *data, UINTN size);
+#endif
+
 #if defined(__i386__) || defined(__x86_64__)
 void beep(UINTN beep_count);
 #else