diff --git a/bare-metal.c b/bare-metal.c index 9ee6b63..eec65a6 100644 --- a/bare-metal.c +++ b/bare-metal.c @@ -594,6 +594,29 @@ void uart0_puts(const char *s) } } +void uart0_puthex(unsigned long hex, bool new_line) +{ + unsigned int chunks = sizeof(hex) * 2; + unsigned int i; + + uart0_puts("0x"); + + for (i = 0; i < chunks; i++) { + unsigned int offset = (chunks - 1 - i) * 4; + unsigned int extract = (hex & (0xf << offset)) >> offset; + + if (extract >= 0xa) + uart0_putc('a' + (extract - 0xa)); + else + uart0_putc('0' + extract); + } + + if (new_line) { + uart0_putc('\r'); + uart0_putc('\n'); + } +} + int get_boot_device(const struct soc_info *soc) { u32 *spl_signature = (void *)soc->sram.a1_base + 0x4; diff --git a/bare-metal.h b/bare-metal.h index de21d5c..e13992b 100644 --- a/bare-metal.h +++ b/bare-metal.h @@ -56,6 +56,7 @@ typedef unsigned int u32; typedef unsigned short int u16; typedef unsigned char u8; +typedef int bool; #ifndef NULL #define NULL ((void*)0) @@ -219,6 +220,7 @@ void jtag_init(const struct soc_info *soc); void uart0_init(const struct soc_info *soc); void uart0_putc(char c); void uart0_puts(const char *s); +void uart0_puthex(unsigned long hex, bool new_line); int get_boot_device(const struct soc_info *soc); #endif