From e0786c3f94996bef0dc291131f14f3590c867976 Mon Sep 17 00:00:00 2001 From: Geert Uytterhoeven Date: Tue, 19 Jan 2021 14:28:24 +0100 Subject: [PATCH 01/14] software/include/base: Check __LP64__ instead of __WORDSIZE __WORDSIZE is defined by glibc, not by the compiler. Hence it is never defined for us, and checking __WORDSIZE to determine the size of "long" thus causes subtle misbehavings. Fix this by checking for the presence of __LP64__ instead. Signed-off-by: Geert Uytterhoeven --- litex/soc/software/include/base/inttypes.h | 2 +- litex/soc/software/include/base/lfsr.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/litex/soc/software/include/base/inttypes.h b/litex/soc/software/include/base/inttypes.h index 4afd04b62..bc22376a6 100644 --- a/litex/soc/software/include/base/inttypes.h +++ b/litex/soc/software/include/base/inttypes.h @@ -24,7 +24,7 @@ #include -# if __WORDSIZE == 64 +# ifdef __LP64__ # define __PRI64_PREFIX "l" # define __PRIPTR_PREFIX "l" # else diff --git a/litex/soc/software/include/base/lfsr.h b/litex/soc/software/include/base/lfsr.h index 50dfccfc7..8326b811a 100644 --- a/litex/soc/software/include/base/lfsr.h +++ b/litex/soc/software/include/base/lfsr.h @@ -65,7 +65,7 @@ static inline unsigned long lfsr(unsigned long bits, unsigned long prev) 0x20000029, 0x48000000, 0x80200003, -#if __WORDSIZE == 64 +#ifdef __LP64__ 0x100080000, 0x204000003, 0x500000000, From 1710c5f1ef30973a414350ad82676d829a19c5cd Mon Sep 17 00:00:00 2001 From: Geert Uytterhoeven Date: Tue, 19 Jan 2021 14:37:26 +0100 Subject: [PATCH 02/14] software/include/base/limits: Fix ULONG_MAX on 64-bit The value of ULONG_MAX should depend on the size of "long". While at it: - Add missing "UL" and "U" suffixes to large unsigned values, - Make INT_MIN and SHRT_MIN explicitly negative, - Use decimal instead of hexadecimal values, for easier comparison with /usr/include/limits.h. Signed-off-by: Geert Uytterhoeven --- litex/soc/software/include/base/limits.h | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/litex/soc/software/include/base/limits.h b/litex/soc/software/include/base/limits.h index 49ac6ffe6..fd5888c3b 100644 --- a/litex/soc/software/include/base/limits.h +++ b/litex/soc/software/include/base/limits.h @@ -5,17 +5,21 @@ extern "C" { #endif -#define ULONG_MAX 0xffffffff +#ifdef __LP64__ +#define ULONG_MAX 18446744073709551615UL +#else +#define ULONG_MAX 4294967295UL +#endif -#define UINT_MAX 0xffffffff -#define INT_MIN 0x80000000 -#define INT_MAX 0x7fffffff +#define UINT_MAX 4294967295U +#define INT_MIN (-INT_MAX - 1) +#define INT_MAX 2147483647 -#define USHRT_MAX 0xffff -#define SHRT_MIN 0x8000 -#define SHRT_MAX 0x7fff +#define USHRT_MAX 65535 +#define SHRT_MIN (-32768) +#define SHRT_MAX 32767 -#define UCHAR_MAX 0xff +#define UCHAR_MAX 255 #define CHAR_BIT 8 From 91c91926269b00f82f688011c81fb7ad6633b81d Mon Sep 17 00:00:00 2001 From: Geert Uytterhoeven Date: Tue, 19 Jan 2021 14:45:53 +0100 Subject: [PATCH 03/14] software/include/base: Fix size_t, ptrdiff_t, and (u)intptr_t As per convention, the types of size_t, ptrdiff_t, intptr_t, and uintptr_t should be based on "long" or "int" depending on the platform (32-bit or 64-bit). This fixes compiler warnings of the following type: litex/soc/software/liblitesdcard/sdcard.c: In function 'sdcard_read': litex/soc/software/liblitesdcard/sdcard.c:476:39: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast] sdblock2mem_dma_base_write((uint64_t)(uintptr_t) buf); ^ Reported-by: Gabriel Somlo Signed-off-by: Geert Uytterhoeven --- litex/soc/software/include/base/stddef.h | 5 +++++ litex/soc/software/include/base/stdint.h | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/litex/soc/software/include/base/stddef.h b/litex/soc/software/include/base/stddef.h index 4f9a211f7..858d70b3e 100644 --- a/litex/soc/software/include/base/stddef.h +++ b/litex/soc/software/include/base/stddef.h @@ -11,8 +11,13 @@ extern "C" { #define NULL ((void *)0) #endif +#ifdef __LP64__ typedef unsigned long size_t; typedef long ptrdiff_t; +#else +typedef unsigned int size_t; +typedef int ptrdiff_t; +#endif #define offsetof(type, member) __builtin_offsetof(type, member) diff --git a/litex/soc/software/include/base/stdint.h b/litex/soc/software/include/base/stdint.h index bff5d0983..a17e1739a 100644 --- a/litex/soc/software/include/base/stdint.h +++ b/litex/soc/software/include/base/stdint.h @@ -5,8 +5,13 @@ extern "C" { #endif +#ifdef __LP64__ +typedef long intptr_t; +typedef unsigned long uintptr_t; +#else typedef int intptr_t; typedef unsigned int uintptr_t; +#endif typedef unsigned long long uint64_t; typedef unsigned int uint32_t; From bff23b8f7347e2f199d3f664bd01fa2505f22694 Mon Sep 17 00:00:00 2001 From: Geert Uytterhoeven Date: Fri, 15 Jan 2021 11:31:39 +0100 Subject: [PATCH 04/14] software/libbase/vsnprintf: Prefix pointers by "0x" Set the PRINTF_SPECIAL flag when printing pointers, so they are prefixed by "0x", to match glibc behavior. Signed-off-by: Geert Uytterhoeven --- litex/soc/software/libbase/vsnprintf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/litex/soc/software/libbase/vsnprintf.c b/litex/soc/software/libbase/vsnprintf.c index 1785676f3..1ac2e18cd 100644 --- a/litex/soc/software/libbase/vsnprintf.c +++ b/litex/soc/software/libbase/vsnprintf.c @@ -186,7 +186,7 @@ int vsnprintf(char *buf, size_t size, const char *fmt, va_list args) case 'p': if (field_width == -1) { field_width = 2*sizeof(void *); - flags |= PRINTF_ZEROPAD; + flags |= PRINTF_ZEROPAD | PRINTF_SPECIAL; } str = number(str, end, (unsigned long) va_arg(args, void *), From b979e699345c040235b2ec9c812e40e22ffe86ff Mon Sep 17 00:00:00 2001 From: Geert Uytterhoeven Date: Fri, 15 Jan 2021 11:46:01 +0100 Subject: [PATCH 05/14] software/libbase: Remove empty printf statements To fix compiler warnings of the following type: warning: zero-length gnu_printf format string [-Wformat-zero-length] Signed-off-by: Geert Uytterhoeven --- litex/soc/software/libbase/exception.c | 1 - litex/soc/software/libbase/progress.c | 2 -- 2 files changed, 3 deletions(-) diff --git a/litex/soc/software/libbase/exception.c b/litex/soc/software/libbase/exception.c index 74a0ed14f..853e956a1 100644 --- a/litex/soc/software/libbase/exception.c +++ b/litex/soc/software/libbase/exception.c @@ -156,7 +156,6 @@ static void gdb_stub(unsigned long pc, unsigned long sr, } default: - snprintf(buf, sizeof(buf), ""); break; } diff --git a/litex/soc/software/libbase/progress.c b/litex/soc/software/libbase/progress.c index 829f07f0e..2c5bac3b4 100644 --- a/litex/soc/software/libbase/progress.c +++ b/litex/soc/software/libbase/progress.c @@ -61,6 +61,4 @@ void init_progression_bar(int max) spin = 0; if (progress_max && progress_max != FILESIZE_MAX) printf("[%*s]\r[", HASHES_PER_LINE, ""); - else - printf(""); } From 84e3a7772414814b200b49cb93fc9cd4514f5bbe Mon Sep 17 00:00:00 2001 From: Geert Uytterhoeven Date: Fri, 15 Jan 2021 11:47:38 +0100 Subject: [PATCH 06/14] software/liblitedram: Use "%u" to format uint32_t values To fix compiler warnings of the following type: warning: format '%lu' expects argument of type 'long unsigned int', but argument has type 'unsigned int' [-Wformat=] Signed-off-by: Geert Uytterhoeven --- litex/soc/software/liblitedram/bist.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/litex/soc/software/liblitedram/bist.c b/litex/soc/software/liblitedram/bist.c index 65e2dcf4c..63446d11a 100644 --- a/litex/soc/software/liblitedram/bist.c +++ b/litex/soc/software/liblitedram/bist.c @@ -130,7 +130,7 @@ void sdram_bist_loop(uint32_t loop, uint32_t burst_length, uint32_t random) { static uint32_t compute_speed_mibs(uint32_t length, uint32_t ticks) { uint32_t speed; - //printf("(%lu, %lu)", length, ticks); + //printf("(%u, %u)", length, ticks); speed = length*(CONFIG_CLOCK_FREQUENCY/(1024*1024))/ticks; return speed; } From 857ef69b3f0cacdb9bb84f6ccbc7d62c5a28a65d Mon Sep 17 00:00:00 2001 From: Geert Uytterhoeven Date: Tue, 19 Jan 2021 11:46:40 +0100 Subject: [PATCH 07/14] software/bios/boot: Fix cast to pointer from integer of different size warnings On 64-bit: litex/soc/software/bios/boot.c: In function 'serialboot': litex/soc/software/bios/boot.c:216:20: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast] writepointer = (char *) get_uint32(&frame.payload[0]); ^ When casting from a 32-bit integer to a pointer (32-bit or 64-bit, depending on the platform), an intermediate cast to "uintptr_t" should be used to avoid warnings like the above. Note that using a 32-bit integer is OK, even on 64-bit, as this is specified by the boot protocol. Signed-off-by: Geert Uytterhoeven --- litex/soc/software/bios/boot.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/litex/soc/software/bios/boot.c b/litex/soc/software/bios/boot.c index 7516c0dd6..67aaf1417 100644 --- a/litex/soc/software/bios/boot.c +++ b/litex/soc/software/bios/boot.c @@ -212,7 +212,7 @@ int serialboot(void) char *writepointer; failed = 0; - writepointer = (char *) get_uint32(&frame.payload[0]); + writepointer = (char *)(uintptr_t) get_uint32(&frame.payload[0]); for(i=4;i Date: Tue, 19 Jan 2021 11:51:29 +0100 Subject: [PATCH 08/14] software/bios/cmds/cmd_bios: Make crc command 64-bit clean On 64-bit: litex/soc/software/bios/cmds/cmd_bios.c: In function 'crc_handler': litex/soc/software/bios/cmds/cmd_bios.c:110:30: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast] printf("CRC32: %08x", crc32((unsigned char *)addr, length)); ^ Fix this by using the appropriate types (uintptr_t and size_t) for memory addresses and sizes, which are defined to 32-bit or 64-bit, depending on the platform. Note that the specified length must still be smaller than 4 GiB on 64-bit, or it will be truncated, as the crc32() function is currently limited to a 32-bit size anyway. Signed-off-by: Geert Uytterhoeven --- litex/soc/software/bios/cmds/cmd_bios.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/litex/soc/software/bios/cmds/cmd_bios.c b/litex/soc/software/bios/cmds/cmd_bios.c index 2163a7e2a..873468db2 100644 --- a/litex/soc/software/bios/cmds/cmd_bios.c +++ b/litex/soc/software/bios/cmds/cmd_bios.c @@ -87,8 +87,8 @@ define_command(uptime, uptime_handler, "Uptime of the system since power-up", SY static void crc_handler(int nb_params, char **params) { char *c; - unsigned int addr; - unsigned int length; + uintptr_t addr; + size_t length; if (nb_params < 2) { printf("crc
"); From ab8cee1b5e9a34731e59c052651d8d31e55f9825 Mon Sep 17 00:00:00 2001 From: Geert Uytterhoeven Date: Tue, 19 Jan 2021 12:21:19 +0100 Subject: [PATCH 09/14] software/bios/cmds/cmd_i2c: Use "%zu" to format size_t The sizeof operator returns "size_t", which is defined to be "unsigned int" on 32-bit, and "unsigned long" on 64-bit. Format it using "%zu", to fix compiler warnings of the following type on 64-bit: warning: format '%d' expects argument of type 'int', but argument has type 'long unsigned int' [-Wformat=] Signed-off-by: Geert Uytterhoeven --- litex/soc/software/bios/cmds/cmd_i2c.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/litex/soc/software/bios/cmds/cmd_i2c.c b/litex/soc/software/bios/cmds/cmd_i2c.c index 2319f3762..0e294397d 100644 --- a/litex/soc/software/bios/cmds/cmd_i2c.c +++ b/litex/soc/software/bios/cmds/cmd_i2c.c @@ -40,7 +40,7 @@ static void i2c_write_handler(int nb_params, char **params) } if (nb_params - 1 > sizeof(write_params)) { - printf("Max data length is %d", sizeof(write_params)); + printf("Max data length is %zu", sizeof(write_params)); return; } @@ -98,7 +98,7 @@ static void i2c_read_handler(int nb_params, char **params) return; } if (len > sizeof(buf)) { - printf("Max data count is %d", sizeof(buf)); + printf("Max data count is %zu", sizeof(buf)); return; } From 5474f563c874ae485f0da213743f2fb19321890e Mon Sep 17 00:00:00 2001 From: Geert Uytterhoeven Date: Tue, 19 Jan 2021 11:30:08 +0100 Subject: [PATCH 10/14] software/bios/readline: Use unsigned int for small numbers There is no need to use "unsigned long" for small numbers related to the number of characters in a line. Use "unsigned int" instead. This allows us to drop the casts when calling putnstr(), and fixes compiler warnings on 64-bit for callsites where the casts were missing: warning: field precision specifier '.*' expects argument of type 'int', but argument 2 has type 'long unsigned int' Reported-by: Gabriel Somlo Signed-off-by: Geert Uytterhoeven --- litex/soc/software/bios/readline.c | 18 +++++++++--------- litex/soc/software/bios/readline.h | 2 +- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/litex/soc/software/bios/readline.c b/litex/soc/software/bios/readline.c index 48d8f1a6c..f507f1a65 100644 --- a/litex/soc/software/bios/readline.c +++ b/litex/soc/software/bios/readline.c @@ -150,10 +150,10 @@ void hist_init(void) } #endif -static void cread_add_char(char ichar, int insert, unsigned long *num, - unsigned long *eol_num, char *buf, unsigned long len) +static void cread_add_char(char ichar, int insert, unsigned int *num, + unsigned int *eol_num, char *buf, unsigned int len) { - unsigned long wlen; + unsigned int wlen; if (insert || *num == *eol_num) { if (*eol_num > len - 1) { @@ -186,9 +186,9 @@ static void cread_add_char(char ichar, int insert, unsigned long *num, int readline(char *buf, int len) { - unsigned long num = 0; - unsigned long eol_num = 0; - unsigned long wlen; + unsigned int num = 0; + unsigned int eol_num = 0; + unsigned int wlen; int insert = 1; char ichar; @@ -254,7 +254,7 @@ int readline(char *buf, int len) wlen = eol_num - num - 1; if (wlen) { memmove(&buf[num], &buf[num+1], wlen); - putnstr(buf + num, (int)wlen); + putnstr(buf + num, wlen); } getcmd_putch(' '); @@ -286,7 +286,7 @@ int readline(char *buf, int len) num--; memmove(buf + num, buf + num + 1, wlen); getcmd_putch(CTL_BACKSPACE); - putnstr(buf + num, (int)wlen); + putnstr(buf + num, wlen); getcmd_putch(' '); do { getcmd_putch(CTL_BACKSPACE); @@ -298,7 +298,7 @@ int readline(char *buf, int len) if (num < eol_num) { wlen = eol_num - num; memmove(buf + num, buf + num + 1, wlen); - putnstr(buf + num, (int)(wlen - 1)); + putnstr(buf + num, wlen - 1); getcmd_putch(' '); do { getcmd_putch(CTL_BACKSPACE); diff --git a/litex/soc/software/bios/readline.h b/litex/soc/software/bios/readline.h index f1284c5d1..290b2e2c0 100644 --- a/litex/soc/software/bios/readline.h +++ b/litex/soc/software/bios/readline.h @@ -72,7 +72,7 @@ struct esc_cmds { #define REFRESH_TO_EOL() { \ if (num < eol_num) { \ wlen = eol_num - num; \ - putnstr(buf + num, (int)wlen); \ + putnstr(buf + num, wlen); \ num = eol_num; \ } \ } From a2389c71eaa446923617da97f56ffa4c6dec410c Mon Sep 17 00:00:00 2001 From: Geert Uytterhoeven Date: Thu, 14 Jan 2021 16:24:31 +0100 Subject: [PATCH 11/14] software: Fix cast from pointer to integer of different size warnings litex/soc/software/liblitesdcard/sdcard.c: In function 'sdcard_read': litex/soc/software/liblitesdcard/sdcard.c:476:29: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast] sdblock2mem_dma_base_write((uint64_t) buf); ^ litex/soc/software/liblitesdcard/sdcard.c: In function 'sdcard_write': litex/soc/software/liblitesdcard/sdcard.c:507:30: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast] sdmem2block_dma_base_write((uint64_t) buf); ^ When casting a pointer (32-bit or 64-bit, depending on the platform) to a 64-bit integer, an intermediate cast to "uintptr_t" should be used to avoid warnings like the above. Signed-off-by: Geert Uytterhoeven --- litex/soc/software/liblitesata/sata.c | 4 ++-- litex/soc/software/liblitesdcard/sdcard.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/litex/soc/software/liblitesata/sata.c b/litex/soc/software/liblitesata/sata.c index 3e8250373..90477e3b5 100644 --- a/litex/soc/software/liblitesata/sata.c +++ b/litex/soc/software/liblitesata/sata.c @@ -51,7 +51,7 @@ void sata_read(uint32_t sector, uint32_t count, uint8_t* buf) for (i=0; i Date: Fri, 15 Jan 2021 11:36:48 +0100 Subject: [PATCH 12/14] software: Use "l" length modifier to format long values To fix compiler warnings of the following type: warning: format '%x' expects argument of type 'unsigned int', but argument has type 'long unsigned int' [-Wformat=] Signed-off-by: Geert Uytterhoeven --- litex/soc/software/bios/boot.c | 8 ++++---- litex/soc/software/bios/helpers.c | 2 +- litex/soc/software/libbase/exception.c | 8 ++++---- litex/soc/software/liblitedram/sdram.c | 2 +- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/litex/soc/software/bios/boot.c b/litex/soc/software/bios/boot.c index 67aaf1417..34d10fcab 100644 --- a/litex/soc/software/bios/boot.c +++ b/litex/soc/software/bios/boot.c @@ -50,7 +50,7 @@ extern void boot_helper(unsigned long r1, unsigned long r2, unsigned long r3, un static void __attribute__((noreturn)) boot(unsigned long r1, unsigned long r2, unsigned long r3, unsigned long addr) { - printf("Executing booted program at 0x%08x\n\n", addr); + printf("Executing booted program at 0x%08lx\n\n", addr); printf("--============= \e[1mLiftoff!\e[0m ===============--\n"); uart_sync(); #ifdef CONFIG_CPU_HAS_INTERRUPT @@ -428,7 +428,7 @@ static int copy_image_from_flash_to_ram(unsigned int flash_address, unsigned lon length = check_image_in_flash(flash_address); if(length > 0) { - printf("Copying 0x%08x to 0x%08x (%d bytes)...\n", flash_address, ram_address, length); + printf("Copying 0x%08x to 0x%08lx (%d bytes)...\n", flash_address, ram_address, length); offset = 0; init_progression_bar(length); while (length > 0) { @@ -500,7 +500,7 @@ static int copy_file_from_sdcard_to_ram(const char * filename, unsigned long ram } length = f_size(&file); - printf("Copying %s to 0x%08x (%d bytes)...\n", filename, ram_address, length); + printf("Copying %s to 0x%08lx (%d bytes)...\n", filename, ram_address, length); init_progression_bar(length); offset = 0; for (;;) { @@ -675,7 +675,7 @@ static int copy_file_from_sata_to_ram(const char * filename, unsigned long ram_a } length = f_size(&file); - printf("Copying %s to 0x%08x (%d bytes)...\n", filename, ram_address, length); + printf("Copying %s to 0x%08lx (%d bytes)...\n", filename, ram_address, length); init_progression_bar(length); offset = 0; for (;;) { diff --git a/litex/soc/software/bios/helpers.c b/litex/soc/software/bios/helpers.c index fad464192..746a792c3 100644 --- a/litex/soc/software/bios/helpers.c +++ b/litex/soc/software/bios/helpers.c @@ -25,7 +25,7 @@ void dump_bytes(unsigned int *ptr, int count, unsigned long addr) (count > NUMBER_OF_BYTES_ON_A_LINE)? NUMBER_OF_BYTES_ON_A_LINE : count; - printf("\n0x%08x ", addr); + printf("\n0x%08lx ", addr); for (i = 0; i < line_bytes; i++) printf("%02x ", *(unsigned char *)(data+i)); diff --git a/litex/soc/software/libbase/exception.c b/litex/soc/software/libbase/exception.c index 853e956a1..a0c775682 100644 --- a/litex/soc/software/libbase/exception.c +++ b/litex/soc/software/libbase/exception.c @@ -76,9 +76,9 @@ static void gdb_stub(unsigned long pc, unsigned long sr, case 'g': { snprintf(buf, sizeof(buf), - "%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x" - "%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x" - "%08x%08x%08x", + "%08x%08lx%08lx%08lx%08lx%08lx%08lx%08lx%08lx%08lx%08lx%08lx%08lx%08lx%08lx%08lx" + "%08lx%08lx%08lx%08lx%08lx%08lx%08lx%08lx%08lx%08lx%08lx%08lx%08lx%08lx%08lx%08lx" + "%08lx%08lx%08lx", 0, r1, regs[2], regs[3], regs[4], regs[5], regs[6], regs[7], regs[8], regs[9], regs[10], regs[11], regs[12], regs[13], regs[14], regs[15], regs[16], regs[17], regs[18], regs[19], regs[20], regs[21], regs[22], regs[23], @@ -120,7 +120,7 @@ static void gdb_stub(unsigned long pc, unsigned long sr, snprintf(buf, sizeof(buf), "E01"); break; } - snprintf(buf, sizeof(buf), "%08x", value); + snprintf(buf, sizeof(buf), "%08lx", value); break; } diff --git a/litex/soc/software/liblitedram/sdram.c b/litex/soc/software/liblitedram/sdram.c index e42462173..e9a3320cb 100644 --- a/litex/soc/software/liblitedram/sdram.c +++ b/litex/soc/software/liblitedram/sdram.c @@ -1008,7 +1008,7 @@ int sdram_init(void) _sdram_write_leveling_cmd_scan = 0; _sdram_write_leveling_cmd_delay = SDRAM_PHY_CMD_DELAY; #endif - printf("Initializing SDRAM @0x%08x...\n", MAIN_RAM_BASE); + printf("Initializing SDRAM @0x%08lx...\n", MAIN_RAM_BASE); sdram_software_control_on(); #if CSR_DDRPHY_RST_ADDR ddrphy_rst_write(1); From c3dea1b9fd0c50cf05f25de695b4cd3ff7f356ae Mon Sep 17 00:00:00 2001 From: Geert Uytterhoeven Date: Fri, 15 Jan 2021 11:41:05 +0100 Subject: [PATCH 13/14] software: Use "%p" to format pointer values To fix compiler warnings of the following type: warning: format '%x' expects argument of type 'unsigned int', but argument 2 has type 'foo *' [-Wformat=] Signed-off-by: Geert Uytterhoeven --- litex/soc/software/bios/boot.c | 2 +- litex/soc/software/libbase/memtest.c | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/litex/soc/software/bios/boot.c b/litex/soc/software/bios/boot.c index 34d10fcab..bb565fd65 100644 --- a/litex/soc/software/bios/boot.c +++ b/litex/soc/software/bios/boot.c @@ -273,7 +273,7 @@ static int copy_file_from_tftp_to_ram(unsigned int ip, unsigned short server_por const char *filename, char *buffer) { int size; - printf("Copying %s to 0x%08x... ", filename, buffer); + printf("Copying %s to %p... ", filename, buffer); size = tftp_get(ip, server_port, filename, buffer); if(size > 0) printf("(%d bytes)", size); diff --git a/litex/soc/software/libbase/memtest.c b/litex/soc/software/libbase/memtest.c index d6f112614..ae604fe9e 100644 --- a/litex/soc/software/libbase/memtest.c +++ b/litex/soc/software/libbase/memtest.c @@ -53,7 +53,7 @@ int memtest_access(unsigned int *addr) array[0] = ZEROONE; array[1] = array[0]; if (ctrl_bus_errors_read() - bus_errors) { - printf("memtest_access error @ 0x%0x, exiting memtest.\n", addr); + printf("memtest_access error @ %p, exiting memtest.\n", addr); return 1; } @@ -83,7 +83,7 @@ int memtest_bus(unsigned int *addr, unsigned long size) if(rdata != ONEZERO) { errors++; #ifdef MEMTEST_BUS_DEBUG - printf("memtest_bus error @ 0x%0x: 0x%08x vs 0x%08x\n", addr + i, rdata, ONEZERO); + printf("memtest_bus error @ %p: 0x%08x vs 0x%08x\n", addr + i, rdata, ONEZERO); #endif } } @@ -103,7 +103,7 @@ int memtest_bus(unsigned int *addr, unsigned long size) if(rdata != ZEROONE) { errors++; #ifdef MEMTEST_BUS_DEBUG - printf("memtest_bus error @ 0x%0x:: 0x%08x vs 0x%08x\n", addr + i, rdata, ZEROONE); + printf("memtest_bus error @ %p:: 0x%08x vs 0x%08x\n", addr + i, rdata, ZEROONE); #endif } } @@ -139,7 +139,7 @@ int memtest_addr(unsigned int *addr, unsigned long size, int random) if(rdata != i) { errors++; #ifdef MEMTEST_ADDR_DEBUG - printf("memtest_addr error @ 0x%0x: 0x%08x vs 0x%08x\n", addr + i, rdata, i); + printf("memtest_addr error @ %p: 0x%08x vs 0x%08x\n", addr + i, rdata, i); #endif } } @@ -202,7 +202,7 @@ int memtest_data(unsigned int *addr, unsigned long size, int random) if(rdata != seed_32) { errors++; #ifdef MEMTEST_DATA_DEBUG - printf("memtest_data error @%0x: 0x%08x vs 0x%08x\n", addr + i, rdata, seed_32); + printf("memtest_data error @%p: 0x%08x vs 0x%08x\n", addr + i, rdata, seed_32); #endif } if (i%0x8000 == 0) From 0f28bc489d467172e33182d3b27b21a1eefe38d0 Mon Sep 17 00:00:00 2001 From: Geert Uytterhoeven Date: Fri, 15 Jan 2021 11:51:22 +0100 Subject: [PATCH 14/14] software/include/base/stdio: Enable printf format strings checks Now all format issues are fixed, tag all functions taking printf()-style format specifiers with "__attribute__((format(printf, ...))", enabling format string checks ("-Wall" includes "-Wformat"). Signed-off-by: Geert Uytterhoeven --- litex/soc/software/include/base/stdio.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/litex/soc/software/include/base/stdio.h b/litex/soc/software/include/base/stdio.h index 5e872d64e..f070cf123 100644 --- a/litex/soc/software/include/base/stdio.h +++ b/litex/soc/software/include/base/stdio.h @@ -10,11 +10,11 @@ extern "C" { int putchar(int c); int puts(const char *s); -int snprintf(char *buf, size_t size, const char *fmt, ...); -int scnprintf(char *buf, size_t size, const char *fmt, ...); -int sprintf(char *buf, const char *fmt, ...); +int snprintf(char *buf, size_t size, const char *fmt, ...) __attribute__((format(printf, 3, 4))); +int scnprintf(char *buf, size_t size, const char *fmt, ...) __attribute__((format(printf, 3, 4))); +int sprintf(char *buf, const char *fmt, ...) __attribute__((format(printf, 2, 3))); -int printf(const char *fmt, ...); +int printf(const char *fmt, ...) __attribute__((format(printf, 1, 2))); /* Not sure this belongs here... */ typedef long long loff_t; @@ -53,7 +53,7 @@ extern FILE *stdin; extern FILE *stdout; extern FILE *stderr; -int fprintf(FILE *stream, const char *format, ...); +int fprintf(FILE *stream, const char *format, ...) __attribute__((format(printf, 2, 3))); int fflush(FILE *stream); FILE *fopen(const char *path, const char *mode);