From: Lennart Poettering Date: Thu, 28 Jul 2022 08:47:05 +0000 (+0200) Subject: boot: add hexdump helper call X-Git-Tag: v252-rc1~542^2~6 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=257bc3ef60c7a35171aa5ed87891a19b8c67654b;p=thirdparty%2Fsystemd.git boot: add hexdump helper call 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. --- diff --git a/src/boot/efi/util.c b/src/boot/efi/util.c index 7603eb8f534..6fcf9b31211 100644 --- a/src/boot/efi/util.c +++ b/src/boot/efi/util.c @@ -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; diff --git a/src/boot/efi/util.h b/src/boot/efi/util.h index 4de799ea0e4..bb4bb64e0e2 100644 --- a/src/boot/efi/util.h +++ b/src/boot/efi/util.h @@ -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