On 06/27/2016 06:43 PM, Cédric Le Goater wrote:
> This test uses the palmetto platform and the AST2400 SPI controller to
> test the m25p80 flash module device model. The flash model is defined
> by the platform (n25q256a) and it would be nice to find way to control
> it, using a property probably.
> 
> Signed-off-by: Cédric Le Goater <c...@kaod.org>
> Reviewed-by: Peter Maydell <peter.mayd...@linaro.org>
> ---
> 
>  Peter,
> 
>  This is failing miserably on a ppc64/be host ... The addresses
>  reaching the flash memory region are in the wrong endian. Should I be
>  using qtest_big_endian() ? 

Here is a possible solution tested on a fedora23/ppc64.

Thanks,

C.


From: Cédric Le Goater <c...@kaod.org>
Subject: [PATCH] tests: fix m25p80 test to run on a big endian host
Date: Mon, 27 Jun 2016 23:31:36 +0200
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

When running on a big endian host, the data read from or written to
the flash module memory mapping also needs byte-swapping.

Signed-off-by: Cédric Le Goater <c...@kaod.org>
---
 tests/m25p80-test.c |   20 +++++++++++++++-----
 1 file changed, 15 insertions(+), 5 deletions(-)

Index: qemu-ast2400-mainline.git/tests/m25p80-test.c
===================================================================
--- qemu-ast2400-mainline.git.orig/tests/m25p80-test.c
+++ qemu-ast2400-mainline.git/tests/m25p80-test.c
@@ -58,6 +58,16 @@ enum {
 
 #define PAGE_SIZE           256
 
+static inline uint32_t to_flash(uint32_t data)
+{
+    return bswap32(data);
+}
+
+static inline uint32_t from_flash(uint32_t data)
+{
+    return bswap32(data);
+}
+
 static void spi_conf(uint32_t value)
 {
     uint32_t conf = readl(AST2400_FMC_BASE + R_CONF);
@@ -109,11 +119,11 @@ static void read_page(uint32_t addr, uin
 
     writeb(AST2400_FLASH_BASE, EN_4BYTE_ADDR);
     writeb(AST2400_FLASH_BASE, READ);
-    writel(AST2400_FLASH_BASE, cpu_to_be32(addr));
+    writel(AST2400_FLASH_BASE, to_flash(addr));
 
     /* Continuous read are supported */
     for (i = 0; i < PAGE_SIZE / 4; i++) {
-        page[i] = be32_to_cpu(readl(AST2400_FLASH_BASE));
+        page[i] = from_flash(readl(AST2400_FLASH_BASE));
     }
     spi_ctrl_stop_user();
 }
@@ -130,7 +140,7 @@ static void test_erase_sector(void)
     writeb(AST2400_FLASH_BASE, WREN);
     writeb(AST2400_FLASH_BASE, EN_4BYTE_ADDR);
     writeb(AST2400_FLASH_BASE, ERASE_SECTOR);
-    writel(AST2400_FLASH_BASE, cpu_to_be32(some_page_addr));
+    writel(AST2400_FLASH_BASE, to_flash(some_page_addr));
     spi_ctrl_stop_user();
 
     /* Previous page should be full of zeroes as backend is not
@@ -186,11 +196,11 @@ static void test_write_page(void)
     spi_ctrl_start_user();
     writeb(AST2400_FLASH_BASE, EN_4BYTE_ADDR);
     writeb(AST2400_FLASH_BASE, PP);
-    writel(AST2400_FLASH_BASE, cpu_to_be32(my_page_addr));
+    writel(AST2400_FLASH_BASE, to_flash(my_page_addr));
 
     /* Fill the page with its own addresses */
     for (i = 0; i < PAGE_SIZE / 4; i++) {
-        writel(AST2400_FLASH_BASE, cpu_to_be32(my_page_addr + i * 4));
+        writel(AST2400_FLASH_BASE, to_flash(my_page_addr + i * 4));
     }
     spi_ctrl_stop_user();
 



Reply via email to