* Add big-endian build option for riscv
@ 2025-06-13 16:12 Ben Dooks
2025-06-13 16:12 ` [PATCH v2 1/2] riscv: add build support for big-endian Ben Dooks
2025-06-13 16:12 ` [PATCH v2 2/2] riscv: byteorder: add test " Ben Dooks
0 siblings, 2 replies; 5+ messages in thread
From: Ben Dooks @ 2025-06-13 16:12 UTC (permalink / raw)
To: rick, ycliang, u-boot
Cc: nazar.kazakov, joseph.baker, fran.redondo, lawrence.hunter,
ben.dooks, trini
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.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v2 1/2] riscv: add build support for big-endian
2025-06-13 16:12 Add big-endian build option for riscv Ben Dooks
@ 2025-06-13 16:12 ` Ben Dooks
2025-06-13 16:52 ` Tom Rini
2025-06-13 16:12 ` [PATCH v2 2/2] riscv: byteorder: add test " Ben Dooks
1 sibling, 1 reply; 5+ messages in thread
From: Ben Dooks @ 2025-06-13 16:12 UTC (permalink / raw)
To: rick, ycliang, u-boot
Cc: nazar.kazakov, joseph.baker, fran.redondo, lawrence.hunter,
ben.dooks, trini
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 <ben.dooks@codethink.co.uk>
---
v2:
- fixed issue with big v little endian build (+typos)
---
arch/riscv/config.mk | 18 ++++++++++++++----
1 file changed, 14 insertions(+), 4 deletions(-)
diff --git a/arch/riscv/config.mk b/arch/riscv/config.mk
index 9f16dda92a0..eddd6a3b9a2 100644
--- a/arch/riscv/config.mk
+++ b/arch/riscv/config.mk
@@ -10,19 +10,29 @@
# Rick Chen, Andes Technology Corporation <rick@andestech.com>
#
-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
--
2.37.2.352.g3c44437643
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v2 1/2] riscv: add build support for big-endian
2025-06-13 16:12 ` [PATCH v2 1/2] riscv: add build support for big-endian Ben Dooks
@ 2025-06-13 16:52 ` Tom Rini
0 siblings, 0 replies; 5+ messages in thread
From: Tom Rini @ 2025-06-13 16:52 UTC (permalink / raw)
To: Ben Dooks
Cc: rick, ycliang, u-boot, nazar.kazakov, joseph.baker, fran.redondo,
lawrence.hunter
[-- Attachment #1: Type: text/plain, Size: 317 bytes --]
On Fri, Jun 13, 2025 at 05:12:57PM +0100, Ben Dooks wrote:
> 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 <ben.dooks@codethink.co.uk>
Reviewed-by: Tom Rini <trini@konsulko.com>
--
Tom
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 659 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v2 2/2] riscv: byteorder: add test for big-endian
2025-06-13 16:12 Add big-endian build option for riscv Ben Dooks
2025-06-13 16:12 ` [PATCH v2 1/2] riscv: add build support for big-endian Ben Dooks
@ 2025-06-13 16:12 ` Ben Dooks
2025-07-03 8:26 ` Leo Liang
1 sibling, 1 reply; 5+ messages in thread
From: Ben Dooks @ 2025-06-13 16:12 UTC (permalink / raw)
To: rick, ycliang, u-boot
Cc: nazar.kazakov, joseph.baker, fran.redondo, lawrence.hunter,
ben.dooks, trini
Test 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)
Signed-off-by: Ben Dooks <ben.dooks@codethink.co.uk>
---
arch/riscv/include/asm/byteorder.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/riscv/include/asm/byteorder.h b/arch/riscv/include/asm/byteorder.h
index d26ac5688fa..3140c1f585e 100644
--- a/arch/riscv/include/asm/byteorder.h
+++ b/arch/riscv/include/asm/byteorder.h
@@ -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>
--
2.37.2.352.g3c44437643
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v2 2/2] riscv: byteorder: add test for big-endian
2025-06-13 16:12 ` [PATCH v2 2/2] riscv: byteorder: add test " Ben Dooks
@ 2025-07-03 8:26 ` Leo Liang
0 siblings, 0 replies; 5+ messages in thread
From: Leo Liang @ 2025-07-03 8:26 UTC (permalink / raw)
To: Ben Dooks
Cc: rick, u-boot, nazar.kazakov, joseph.baker, fran.redondo,
lawrence.hunter, trini
On Fri, Jun 13, 2025 at 05:12:58PM +0100, Ben Dooks wrote:
> Test 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)
>
> Signed-off-by: Ben Dooks <ben.dooks@codethink.co.uk>
> ---
> arch/riscv/include/asm/byteorder.h | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
Acked-by: Leo Yu-Chi Liang <ycliang@andestech.com>
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2025-07-03 8:26 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-13 16:12 Add big-endian build option for riscv Ben Dooks
2025-06-13 16:12 ` [PATCH v2 1/2] riscv: add build support for big-endian Ben Dooks
2025-06-13 16:52 ` Tom Rini
2025-06-13 16:12 ` [PATCH v2 2/2] riscv: byteorder: add test " Ben Dooks
2025-07-03 8:26 ` Leo Liang
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.