Add big-endian build option for riscv
Add the option to allow building a RISC-V system big-endian.
This has been tested against our big-endian qemu/cva6 system and is the minimal base to allow a system to run big-endian.
We don't yet address IO endian which has been an interesting issue, as some code seems to assume big-endian means big-endian IO.
PATCH v2 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.
---
v2:
- fixed issue with big v little endian build (+typos)
--- 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_BIG_ENDIAN +small-endian := b +large-endian := big +PLATFORM_CPPFLAGS += -mbig-endian +KBUILD_LDFLAGS += -mbig-endian +else +small-endian := l +large-endian := little +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 v2 1/2] riscv: add build support for big-endian
Quoted 5 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]>
Signature · 1 line
Tom
PATCH v2 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 v2 2/2] riscv: byteorder: add test for big-endian
Quoted 8 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(-)