riscv: start on work to allow big-endian build
Given we've been doing work on qemu and linux-kernel we started looking at u-boot too. I've done a quick test with our qemu and got a few patches going.
It looks like there are only a few updates to get the build working. The only question I have at the moment is with the read/write io macros which seem to be incosistently endian interested.
project at: https://gitlab.com/CodethinkLabs/riscv_bigendian
PATCH 1/2 riscv: add build support for big-endian
Add support to build code big-endian if the board supports it. Updates the makefile to pass the correct compiler and elf flags.
--- arch/riscv/config.mk | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-)
arch/riscv/config.mk +14 -4
@@ -10,19 +10,29 @@ # Rick Chen, Andes Technology Corporation <[email protected]> # -32bit-emul := elf32lriscv -64bit-emul := elf64lriscv +ifdef CONFIG_SYS_BIT_ENDIAN +small-endian := b +large-endian := big +else +small-endian := b +large-endian := big +PLATFORM_CPPFLAGS += -mbig-endian +KBUILD_LDFLAGS += -mbig-endian +endif + +32bit-emul := elf32$(small-endian)riscv +64bit-emul := elf64$(small-endian)riscv ifdef CONFIG_32BIT KBUILD_LDFLAGS += -m $(32bit-emul) EFI_LDS := elf_riscv32_efi.lds -PLATFORM_ELFFLAGS += -B riscv -O elf32-littleriscv +PLATFORM_ELFFLAGS += -B riscv -O elf32-$(large-endian)riscv endif ifdef CONFIG_64BIT KBUILD_LDFLAGS += -m $(64bit-emul) EFI_LDS := elf_riscv64_efi.lds -PLATFORM_ELFFLAGS += -B riscv -O elf64-littleriscv +PLATFORM_ELFFLAGS += -B riscv -O elf64-$(large-endian)riscv endif PLATFORM_CPPFLAGS += -ffixed-x3 -fpic
Signature · 1 line
2.37.2.352.g3c44437643
Re: [PATCH 1/2] riscv: add build support for big-endian
Quoted 14 lines · Ben Dooks
Add support to build code big-endian if the board supports it. Updates the makefile to pass the correct compiler and elf flags.
Signed-off-by Ben Dooks <[email protected]>--- arch/riscv/config.mk | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-)arch/riscv/config.mk +0
-0
arch/riscv/config.mk line 13
Quoted 6 lines
arch/riscv/config.mk +1
-2@@ -10,19 +10,29 @@ # Rick Chen, Andes Technology Corporation <[email protected]> # -32bit-emul := elf32lriscv -64bit-emul := elf64lriscv +ifdef CONFIG_SYS_BIT_ENDIAN
Typo, should be BIG not BIT.
arch/riscv/config.mk line 21
Quoted 8 lines
arch/riscv/config.mk +8
-0+small-endian := b +large-endian := big +else +small-endian := b +large-endian := big +PLATFORM_CPPFLAGS += -mbig-endian +KBUILD_LDFLAGS += -mbig-endian +endif
And then fix it so we can go back to little, too :)
Signature · 1 line
Tom
PATCH 2/2 riscv: byteorder: add test for big-endian
In reply to Ben DooksTest for big-endian either via __RISCVEB__ which migth be rather old, or check the BYTE_ORDER if the compiler defines it (which should be any modern gcc like v12)
--- arch/riscv/include/asm/byteorder.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/riscv/include/asm/byteorder.h +1 -1
@@ -26,7 +26,7 @@# define __SWAB_64_THRU_32__#endif -#ifdef __RISCVEB__ +#if defined(__RISCVEB__) || (defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)#include <linux/byteorder/big_endian.h> #else #include <linux/byteorder/little_endian.h>
Signature · 1 line
2.37.2.352.g3c44437643
Re: [PATCH 2/2] riscv: byteorder: add test for big-endian
Quoted 14 lines · Ben Dooks
Test for big-endian either via
__RISCVEB__which migth be rather old, or check theBYTE_ORDERif the compiler defines it (which should be any modern gcc like v12)Signed-off-by Ben Dooks <[email protected]>--- arch/riscv/include/asm/byteorder.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)arch/riscv/include/asm/byteorder.h +0
-0
arch/riscv/include/asm/byteorder.h line 32
Quoted 8 lines
arch/riscv/include/asm/byteorder.h +1
-1@@ -26,7 +26,7 @@# define __SWAB_64_THRU_32__#endif -#ifdef __RISCVEB__ +#if defined(__RISCVEB__) || (defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)#include <linux/byteorder/big_endian.h> #else #include <linux/byteorder/little_endian.h>
What's this look like in the linux kernel? We should likely just mirror that.
Signature · 1 line
Tom
Re: [PATCH 2/2] riscv: byteorder: add test for big-endian
Quoted 19 lines · Tom Rini
Quoted 17 lines · Ben Dooks
Test for big-endian either via
__RISCVEB__which migth be rather old, or check theBYTE_ORDERif the compiler defines it (which should be any modern gcc like v12)Signed-off-by Ben Dooks <[email protected]>--- arch/riscv/include/asm/byteorder.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)arch/riscv/include/asm/byteorder.h +0
-0@@ -26,7 +26,7 @@# define __SWAB_64_THRU_32__#endif
Quoted 8 lines
arch/riscv/include/asm/byteorder.h line 32
Quoted 5 lines
arch/riscv/include/asm/byteorder.h +1
-1-#ifdef __RISCVEB__ +#if defined(__RISCVEB__) || (defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)#include <linux/byteorder/big_endian.h> #else #include <linux/byteorder/little_endian.h> What's this look like in the linux kernel? We should likely just mirror that.
We're still looking at the kernel too.
I think we could just drop the __RISCVEB__ test, I don't think anything is defining it.
Signature · 4 lines
Ben Dooks http://www.codethink.co.uk/ Senior Engineer Codethink - Providing Genius https://www.codethink.co.uk/privacy.html