From 798b3d7ba41567bf4f1f8671448d85f59062d9ea Mon Sep 17 00:00:00 2001
From: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Date: Wed, 8 Jul 2020 13:17:48 +1000
Subject: [PATCH 1/3] memtest: Fix integer size/type printf errors

In a couple of places, memtest uses %x to print a pointer which
is illegal (and could be problematic on 64-bit). Use %p instead.

Additionally, use %ld when printing longs

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
---
 litex/soc/software/libbase/memtest.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/litex/soc/software/libbase/memtest.c b/litex/soc/software/libbase/memtest.c
index 9ab59f90c..df528d55d 100644
--- a/litex/soc/software/libbase/memtest.c
+++ b/litex/soc/software/libbase/memtest.c
@@ -172,7 +172,7 @@ void memspeed(unsigned int *addr, unsigned long size, bool read_only)
 	__attribute__((unused)) unsigned long data;
 	const unsigned int sz = sizeof(unsigned long);
 
-	printf("Memspeed at 0x%08x...\n", addr);
+	printf("Memspeed at 0x%p...\n", addr);
 
 	/* init timer */
 	timer0_en_write(0);
@@ -221,16 +221,16 @@ int memtest(unsigned int *addr, unsigned long maxsize)
 	unsigned long addr_size = MEMTEST_ADDR_SIZE < maxsize ? MEMTEST_ADDR_SIZE : maxsize;
 	unsigned long data_size = MEMTEST_DATA_SIZE < maxsize ? MEMTEST_DATA_SIZE : maxsize;
 
-	printf("Memtest at 0x%08x...\n", addr);
+	printf("Memtest at 0x%p...\n", addr);
 
 	bus_errors  = memtest_bus(addr, bus_size);
 	addr_errors = memtest_addr(addr, addr_size, MEMTEST_ADDR_RANDOM);
 	data_errors = memtest_data(addr, data_size, MEMTEST_DATA_RANDOM);
 
 	if(bus_errors + addr_errors + data_errors != 0) {
-		printf("- bus errors:  %d/%d\n", bus_errors,  2*bus_size/4);
-		printf("- addr errors: %d/%d\n", addr_errors, addr_size/4);
-		printf("- data errors: %d/%d\n", data_errors, data_size/4);
+		printf("- bus errors:  %d/%ld\n", bus_errors,  2*bus_size/4);
+		printf("- addr errors: %d/%ld\n", addr_errors, addr_size/4);
+		printf("- data errors: %d/%ld\n", data_errors, data_size/4);
 		printf("Memtest KO\n");
 		return 0;
 	}

From c0b948d4f9c1e0e14d95e1df9c1ffb5391ba3bed Mon Sep 17 00:00:00 2001
From: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Date: Wed, 8 Jul 2020 13:21:45 +1000
Subject: [PATCH 2/3] memtest: Fix memspeed access size

The move to libbase reverted the type of the pointer
from long to int.

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
---
 litex/soc/software/libbase/memtest.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/litex/soc/software/libbase/memtest.c b/litex/soc/software/libbase/memtest.c
index df528d55d..2fd5aedcb 100644
--- a/litex/soc/software/libbase/memtest.c
+++ b/litex/soc/software/libbase/memtest.c
@@ -164,7 +164,7 @@ int memtest_data(unsigned int *addr, unsigned long size, int random)
 
 void memspeed(unsigned int *addr, unsigned long size, bool read_only)
 {
-	volatile unsigned int *array = addr;
+	volatile unsigned long *array = (unsigned long *)addr;
 	int i;
 	unsigned int start, end;
 	unsigned long write_speed = 0;

From 83d24d087d4c7856d672f3316a492adbf48205fd Mon Sep 17 00:00:00 2001
From: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Date: Wed, 8 Jul 2020 17:13:37 +1000
Subject: [PATCH 3/3] memspeed: Write a fixed value

Otherwise we have at least an extra addition in the loop
which squews the result compared to the read loop.

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
---
 litex/soc/software/libbase/memtest.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/litex/soc/software/libbase/memtest.c b/litex/soc/software/libbase/memtest.c
index 2fd5aedcb..2067d5e43 100644
--- a/litex/soc/software/libbase/memtest.c
+++ b/litex/soc/software/libbase/memtest.c
@@ -185,7 +185,7 @@ void memspeed(unsigned int *addr, unsigned long size, bool read_only)
 		timer0_update_value_write(1);
 		start = timer0_value_read();
 		for(i = 0; i < size/sz; i++) {
-			array[i] = i;
+			array[i] = -1ul;
 		}
 		timer0_update_value_write(1);
 		end = timer0_value_read();