[U-Boot] [PATCH] [mips] add $(ENDIANNESS) option when link hello_world example

Hi
form the document about OUTPUT_FORMAT(default, big, little) If neither -EB nor -EL are used, output format will be the first argument. If -EB is used, the output format will be the second argument. If -EL is used, the output format will be the third argument.
so change the mips.lds third argument to little and add $(ENDIANNESS) to linker args.
this patch have tested with "./MAKEALL mips mips_el"
Signed-off-by: Xiangfu Liu xiangfu@openmobilefree.net --- arch/mips/config.mk | 2 +- examples/standalone/mips.lds | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/arch/mips/config.mk b/arch/mips/config.mk index aa06761..cc3719f 100644 --- a/arch/mips/config.mk +++ b/arch/mips/config.mk @@ -23,7 +23,7 @@
CROSS_COMPILE ?= mips_4KC-
-STANDALONE_LOAD_ADDR = 0x80200000 -T mips.lds +STANDALONE_LOAD_ADDR = 0x80200000 -T mips.lds $(ENDIANNESS)
PLATFORM_CPPFLAGS += -DCONFIG_MIPS -D__MIPS__
diff --git a/examples/standalone/mips.lds b/examples/standalone/mips.lds index 717b201..63a1c92 100644 --- a/examples/standalone/mips.lds +++ b/examples/standalone/mips.lds @@ -24,7 +24,7 @@ /* OUTPUT_FORMAT("elf32-bigmips", "elf32-bigmips", "elf32-bigmips") */ -OUTPUT_FORMAT("elf32-tradbigmips", "elf32-tradbigmips", "elf32-tradbigmips") +OUTPUT_FORMAT("elf32-tradbigmips", "elf32-tradbigmips", "elf32-tradlittlemips") OUTPUT_ARCH(mips) SECTIONS {

On 07/21/2010 07:27 PM, Xiangfu Liu wrote:
form the document about OUTPUT_FORMAT(default, big, little) If neither -EB nor -EL are used, output format will be the first argument. If -EB is used, the output format will be the second argument. If -EL is used, the output format will be the third argument.
so change the mips.lds third argument to little and add $(ENDIANNESS) to linker args.
this patch have tested with "./MAKEALL mips mips_el"
Little endian build is one of the outstanding issues for MIPS ports[1].
There are several technical issues, 1) lack of powerful configration infrastructure (it's drastically improved these days, so not a problem any more), 2) *LDFLAGS things are not propageted throughout the build system properly, especially through examples/standalone (it seems this issue is also addressed via distributed STANDALONE_LOAD_ADDR). Or in some cases, 3) you might want to generate u-boot image with different endiannness from toolchain's default (native build vs. non-native). And finally 4) ELDK toolchains vs. non-ELDK tools issues. As for #4, you'll see troublesome -dumpspecs outputs from ELDK toolchain[2].
[1] http://search.gmane.org/?query=mips+little+endian&group=gmane.comp.boot-... [2] http://thread.gmane.org/gmane.comp.boot-loaders.u-boot/31998
Anyway, to move discussion forward we need to sort out what's the most priority, what's next, what's nice to have, and what's not.
diff --git a/arch/mips/config.mk b/arch/mips/config.mk index aa06761..cc3719f 100644 --- a/arch/mips/config.mk +++ b/arch/mips/config.mk @@ -23,7 +23,7 @@
CROSS_COMPILE ?= mips_4KC-
-STANDALONE_LOAD_ADDR = 0x80200000 -T mips.lds +STANDALONE_LOAD_ADDR = 0x80200000 -T mips.lds $(ENDIANNESS)
PLATFORM_CPPFLAGS += -DCONFIG_MIPS -D__MIPS__
diff --git a/examples/standalone/mips.lds b/examples/standalone/mips.lds index 717b201..63a1c92 100644 --- a/examples/standalone/mips.lds +++ b/examples/standalone/mips.lds @@ -24,7 +24,7 @@ /* OUTPUT_FORMAT("elf32-bigmips", "elf32-bigmips", "elf32-bigmips") */ -OUTPUT_FORMAT("elf32-tradbigmips", "elf32-tradbigmips", "elf32-tradbigmips") +OUTPUT_FORMAT("elf32-tradbigmips", "elf32-tradbigmips", "elf32-tradlittlemips") OUTPUT_ARCH(mips) SECTIONS {
Attached is one of my holding patches for little endian builds. This looks mostly good and works for me, but won't work for ELDK toolchain.
Having additional hooks for ELDK tools somewhere in config.mk files would probably work, but I don't have enough spare time these days. Someone please cook it up into appropriate shape, please?
Shinya
--- Makefile | 1 + arch/mips/config.mk | 27 +++++++++++++++++++++++++-- arch/mips/cpu/config.mk | 8 -------- board/dbau1x00/u-boot.lds | 2 +- board/gth2/u-boot.lds | 2 +- board/incaip/u-boot.lds | 2 +- board/pb1x00/u-boot.lds | 2 +- board/purple/u-boot.lds | 2 +- board/qemu-mips/u-boot.lds | 2 +- examples/standalone/mips.lds | 2 +- include/configs/pb1x00.h | 2 ++ 11 files changed, 35 insertions(+), 17 deletions(-)
diff --git a/Makefile b/Makefile index 9cea069..5c9fb48 100644 --- a/Makefile +++ b/Makefile @@ -2306,6 +2306,7 @@ dbau1550_config : unconfig dbau1550_el_config : unconfig @mkdir -p $(obj)include @echo "#define CONFIG_DBAU1550 1" >$(obj)include/config.h + @echo "#define CONFIG_CPU_LITTLE_ENDIAN" >>$(obj)include/config.h @$(MKCONFIG) -a dbau1x00 mips mips dbau1x00
gth2_config : unconfig diff --git a/arch/mips/config.mk b/arch/mips/config.mk index aa06761..f5d9ac5 100644 --- a/arch/mips/config.mk +++ b/arch/mips/config.mk @@ -23,8 +23,6 @@
CROSS_COMPILE ?= mips_4KC-
-STANDALONE_LOAD_ADDR = 0x80200000 -T mips.lds - PLATFORM_CPPFLAGS += -DCONFIG_MIPS -D__MIPS__
# @@ -50,3 +48,28 @@ PLATFORM_CPPFLAGS += -DCONFIG_MIPS -D__MIPS__ PLATFORM_CPPFLAGS += -G 0 -mabicalls -fpic PLATFORM_CPPFLAGS += -msoft-float PLATFORM_LDFLAGS += -G 0 -static -n -nostdlib + +# +# We explicitly add the endianness specifier if needed, this allows +# to compile kernels with a toolchain for the other endianness. We +# carefully avoid to add it redundantly because gcc 3.3/3.4 complains +# when fed the toolchain default! +# +# Certain gcc versions upto gcc 4.1.1 (probably 4.2-subversion as of +# 2006-10-10 don't properly change the predefined symbols if -EB / -EL +# are used, so we kludge that here. A bug has been filed at +# http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29413. +# +UNDEF_ALL += -UMIPSEB -U_MIPSEB -U__MIPSEB -U__MIPSEB__ +UNDEF_ALL += -UMIPSEL -U_MIPSEL -U__MIPSEL -U__MIPSEL__ +PREDEF_BE += -DMIPSEB -D_MIPSEB -D__MIPSEB -D__MIPSEB__ +PREDEF_LE += -DMIPSEL -D_MIPSEL -D__MIPSEL -D__MIPSEL__ +ifdef CONFIG_CPU_LITTLE_ENDIAN +PLATFORM_CPPFLAGS += $(shell $(CC) -dumpmachine |grep -q 'mips.*el-.*' || echo -EL $(UNDEF_ALL) $(PREDEF_LE)) +PLATFORM_LDFLAGS += -EL +else +PLATFORM_CPPFLAGS += $(shell $(CC) -dumpmachine |grep -q 'mips.*el-.*' && echo -EB $(UNDEF_ALL) $(PREDEF_BE)) +PLATFORM_LDFLAGS += -EB +endif + +STANDALONE_LOAD_ADDR = 0x80200000 -T mips.lds $(PLATFORM_LDFLAGS) diff --git a/arch/mips/cpu/config.mk b/arch/mips/cpu/config.mk index a173c54..098d6c7 100644 --- a/arch/mips/cpu/config.mk +++ b/arch/mips/cpu/config.mk @@ -28,12 +28,4 @@ else \ echo "-march=4kc -mtune=4kc"; \ fi)
-ifneq (,$(findstring 4KCle,$(CROSS_COMPILE))) -ENDIANNESS = -EL -else -ENDIANNESS = -EB -endif - -MIPSFLAGS += $(ENDIANNESS) - PLATFORM_CPPFLAGS += $(MIPSFLAGS) diff --git a/board/dbau1x00/u-boot.lds b/board/dbau1x00/u-boot.lds index 9a6cd1b..3c4fbe3 100644 --- a/board/dbau1x00/u-boot.lds +++ b/board/dbau1x00/u-boot.lds @@ -24,7 +24,7 @@ /* OUTPUT_FORMAT("elf32-bigmips", "elf32-bigmips", "elf32-bigmips") */ -OUTPUT_FORMAT("elf32-tradbigmips", "elf32-tradbigmips", "elf32-tradbigmips") +OUTPUT_FORMAT("elf32-tradbigmips", "elf32-tradbigmips", "elf32-tradlittlemips") OUTPUT_ARCH(mips) ENTRY(_start) SECTIONS diff --git a/board/gth2/u-boot.lds b/board/gth2/u-boot.lds index e6eee9b..aeb0fcc 100644 --- a/board/gth2/u-boot.lds +++ b/board/gth2/u-boot.lds @@ -24,7 +24,7 @@ /* OUTPUT_FORMAT("elf32-bigmips", "elf32-bigmips", "elf32-bigmips") */ -OUTPUT_FORMAT("elf32-tradbigmips", "elf32-tradbigmips", "elf32-tradbigmips") +OUTPUT_FORMAT("elf32-tradbigmips", "elf32-tradbigmips", "elf32-tradlittlemips") OUTPUT_ARCH(mips) ENTRY(_start) SECTIONS diff --git a/board/incaip/u-boot.lds b/board/incaip/u-boot.lds index 9a6cd1b..3c4fbe3 100644 --- a/board/incaip/u-boot.lds +++ b/board/incaip/u-boot.lds @@ -24,7 +24,7 @@ /* OUTPUT_FORMAT("elf32-bigmips", "elf32-bigmips", "elf32-bigmips") */ -OUTPUT_FORMAT("elf32-tradbigmips", "elf32-tradbigmips", "elf32-tradbigmips") +OUTPUT_FORMAT("elf32-tradbigmips", "elf32-tradbigmips", "elf32-tradlittlemips") OUTPUT_ARCH(mips) ENTRY(_start) SECTIONS diff --git a/board/pb1x00/u-boot.lds b/board/pb1x00/u-boot.lds index 9a6cd1b..3c4fbe3 100644 --- a/board/pb1x00/u-boot.lds +++ b/board/pb1x00/u-boot.lds @@ -24,7 +24,7 @@ /* OUTPUT_FORMAT("elf32-bigmips", "elf32-bigmips", "elf32-bigmips") */ -OUTPUT_FORMAT("elf32-tradbigmips", "elf32-tradbigmips", "elf32-tradbigmips") +OUTPUT_FORMAT("elf32-tradbigmips", "elf32-tradbigmips", "elf32-tradlittlemips") OUTPUT_ARCH(mips) ENTRY(_start) SECTIONS diff --git a/board/purple/u-boot.lds b/board/purple/u-boot.lds index 1881e65..542601a 100644 --- a/board/purple/u-boot.lds +++ b/board/purple/u-boot.lds @@ -24,7 +24,7 @@ /* OUTPUT_FORMAT("elf32-bigmips", "elf32-bigmips", "elf32-bigmips") */ -OUTPUT_FORMAT("elf32-tradbigmips", "elf32-tradbigmips", "elf32-tradbigmips") +OUTPUT_FORMAT("elf32-tradbigmips", "elf32-tradbigmips", "elf32-tradlittlemips") OUTPUT_ARCH(mips) ENTRY(_start) SECTIONS diff --git a/board/qemu-mips/u-boot.lds b/board/qemu-mips/u-boot.lds index ad058ca..bd16786 100644 --- a/board/qemu-mips/u-boot.lds +++ b/board/qemu-mips/u-boot.lds @@ -24,7 +24,7 @@ /* OUTPUT_FORMAT("elf32-bigmips", "elf32-bigmips", "elf32-bigmips") */ -OUTPUT_FORMAT("elf32-tradbigmips", "elf32-tradbigmips", "elf32-tradbigmips") +OUTPUT_FORMAT("elf32-tradbigmips", "elf32-tradbigmips", "elf32-tradlittlemips") OUTPUT_ARCH(mips) ENTRY(_start) SECTIONS diff --git a/examples/standalone/mips.lds b/examples/standalone/mips.lds index 717b201..63a1c92 100644 --- a/examples/standalone/mips.lds +++ b/examples/standalone/mips.lds @@ -24,7 +24,7 @@ /* OUTPUT_FORMAT("elf32-bigmips", "elf32-bigmips", "elf32-bigmips") */ -OUTPUT_FORMAT("elf32-tradbigmips", "elf32-tradbigmips", "elf32-tradbigmips") +OUTPUT_FORMAT("elf32-tradbigmips", "elf32-tradbigmips", "elf32-tradlittlemips") OUTPUT_ARCH(mips) SECTIONS { diff --git a/include/configs/pb1x00.h b/include/configs/pb1x00.h index 5ad745e..49ca07c 100644 --- a/include/configs/pb1x00.h +++ b/include/configs/pb1x00.h @@ -28,6 +28,8 @@ #ifndef __CONFIG_H #define __CONFIG_H
+#define CONFIG_CPU_LITTLE_ENDIAN + #define CONFIG_MIPS32 1 /* MIPS32 CPU core */ #define CONFIG_PB1X00 1 #define CONFIG_SOC_AU1X00 1 /* alchemy series cpu */

Hi Shinya
thanks for the links and patch. comment inline :)
On 07/21/2010 10:08 PM, Shinya Kuribayashi wrote:
Little endian build is one of the outstanding issues for MIPS ports[1].
There are several technical issues, 1) lack of powerful configration infrastructure (it's drastically improved these days, so not a problem any more), 2) *LDFLAGS things are not propageted throughout the build system properly, especially through examples/standalone (it seems this issue is also addressed via distributed STANDALONE_LOAD_ADDR). Or in some cases, 3) you might want to generate u-boot image with different endiannness from toolchain's default (native build vs. non-native). And finally 4) ELDK toolchains vs. non-ELDK tools issues. As for #4, you'll see troublesome -dumpspecs outputs from ELDK toolchain[2].
[1] http://search.gmane.org/?query=mips+little+endian&group=gmane.comp.boot-... [2] http://thread.gmane.org/gmane.comp.boot-loaders.u-boot/31998
Anyway, to move discussion forward we need to sort out what's the most priority, what's next, what's nice to have, and what's not.
what about split this patch to two: one is all *.lds files, the other one is for the argument,
+UNDEF_ALL += -UMIPSEB -U_MIPSEB -U__MIPSEB -U__MIPSEB__ +UNDEF_ALL += -UMIPSEL -U_MIPSEL -U__MIPSEL -U__MIPSEL__ +PREDEF_BE += -DMIPSEB -D_MIPSEB -D__MIPSEB -D__MIPSEB__ +PREDEF_LE += -DMIPSEL -D_MIPSEL -D__MIPSEL -D__MIPSEL__ +ifdef CONFIG_CPU_LITTLE_ENDIAN +PLATFORM_CPPFLAGS += $(shell $(CC) -dumpmachine |grep -q 'mips.*el-.*' || echo -EL $(UNDEF_ALL) $(PREDEF_LE)) +PLATFORM_LDFLAGS += -EL +else +PLATFORM_CPPFLAGS += $(shell $(CC) -dumpmachine |grep -q 'mips.*el-.*'&& echo -EB $(UNDEF_ALL) $(PREDEF_BE)) +PLATFORM_LDFLAGS += -EB +endif
I have one question here. if we decete the board cpu by CONFIG_CPU_LITTLE_ENDIAN. why we need check the toolchina again. what about just like this? :
+PLATFORM_CPPFLAGS += -$(UNDEF_ALL) +ifdef CONFIG_CPU_LITTLE_ENDIAN +PLATFORM_CPPFLAGS += -EL $(PREDEF_LE)) +PLATFORM_LDFLAGS += -EL +else +PLATFORM_CPPFLAGS += -EB $(PREDEF_BE)) +PLATFORM_LDFLAGS += -EB +endif +
the original U-Boot is detect -EL/-EB by toolchain name. maybe the CONFIG_CPU_LITTLE_ENDIAN option is better.
this will not broken the ELDK compile.
Hi Shinya I will try to make those two patch tomorrow. test, then send again. what do you think. do you have any advice to me? :)
+STANDALONE_LOAD_ADDR = 0x80200000 -T mips.lds $(PLATFORM_LDFLAGS) diff --git a/arch/mips/cpu/config.mk b/arch/mips/cpu/config.mk index a173c54..098d6c7 100644 --- a/arch/mips/cpu/config.mk +++ b/arch/mips/cpu/config.mk @@ -28,12 +28,4 @@ else \ echo "-march=4kc -mtune=4kc"; \ fi)
-ifneq (,$(findstring 4KCle,$(CROSS_COMPILE))) -ENDIANNESS = -EL -else -ENDIANNESS = -EB -endif
-MIPSFLAGS += $(ENDIANNESS)
- PLATFORM_CPPFLAGS += $(MIPSFLAGS)
diff --git a/board/dbau1x00/u-boot.lds b/board/dbau1x00/u-boot.lds index 9a6cd1b..3c4fbe3 100644 --- a/board/dbau1x00/u-boot.lds +++ b/board/dbau1x00/u-boot.lds @@ -24,7 +24,7 @@ /* OUTPUT_FORMAT("elf32-bigmips", "elf32-bigmips", "elf32-bigmips") */ -OUTPUT_FORMAT("elf32-tradbigmips", "elf32-tradbigmips", "elf32-tradbigmips") +OUTPUT_FORMAT("elf32-tradbigmips", "elf32-tradbigmips", "elf32-tradlittlemips") OUTPUT_ARCH(mips) ENTRY(_start) SECTIONS diff --git a/board/gth2/u-boot.lds b/board/gth2/u-boot.lds index e6eee9b..aeb0fcc 100644 --- a/board/gth2/u-boot.lds +++ b/board/gth2/u-boot.lds @@ -24,7 +24,7 @@ /* OUTPUT_FORMAT("elf32-bigmips", "elf32-bigmips", "elf32-bigmips") */ -OUTPUT_FORMAT("elf32-tradbigmips", "elf32-tradbigmips", "elf32-tradbigmips") +OUTPUT_FORMAT("elf32-tradbigmips", "elf32-tradbigmips", "elf32-tradlittlemips") OUTPUT_ARCH(mips) ENTRY(_start) SECTIONS diff --git a/board/incaip/u-boot.lds b/board/incaip/u-boot.lds index 9a6cd1b..3c4fbe3 100644 --- a/board/incaip/u-boot.lds +++ b/board/incaip/u-boot.lds @@ -24,7 +24,7 @@ /* OUTPUT_FORMAT("elf32-bigmips", "elf32-bigmips", "elf32-bigmips") */ -OUTPUT_FORMAT("elf32-tradbigmips", "elf32-tradbigmips", "elf32-tradbigmips") +OUTPUT_FORMAT("elf32-tradbigmips", "elf32-tradbigmips", "elf32-tradlittlemips") OUTPUT_ARCH(mips) ENTRY(_start) SECTIONS diff --git a/board/pb1x00/u-boot.lds b/board/pb1x00/u-boot.lds index 9a6cd1b..3c4fbe3 100644 --- a/board/pb1x00/u-boot.lds +++ b/board/pb1x00/u-boot.lds @@ -24,7 +24,7 @@ /* OUTPUT_FORMAT("elf32-bigmips", "elf32-bigmips", "elf32-bigmips") */ -OUTPUT_FORMAT("elf32-tradbigmips", "elf32-tradbigmips", "elf32-tradbigmips") +OUTPUT_FORMAT("elf32-tradbigmips", "elf32-tradbigmips", "elf32-tradlittlemips") OUTPUT_ARCH(mips) ENTRY(_start) SECTIONS diff --git a/board/purple/u-boot.lds b/board/purple/u-boot.lds index 1881e65..542601a 100644 --- a/board/purple/u-boot.lds +++ b/board/purple/u-boot.lds @@ -24,7 +24,7 @@ /* OUTPUT_FORMAT("elf32-bigmips", "elf32-bigmips", "elf32-bigmips") */ -OUTPUT_FORMAT("elf32-tradbigmips", "elf32-tradbigmips", "elf32-tradbigmips") +OUTPUT_FORMAT("elf32-tradbigmips", "elf32-tradbigmips", "elf32-tradlittlemips") OUTPUT_ARCH(mips) ENTRY(_start) SECTIONS diff --git a/board/qemu-mips/u-boot.lds b/board/qemu-mips/u-boot.lds index ad058ca..bd16786 100644 --- a/board/qemu-mips/u-boot.lds +++ b/board/qemu-mips/u-boot.lds @@ -24,7 +24,7 @@ /* OUTPUT_FORMAT("elf32-bigmips", "elf32-bigmips", "elf32-bigmips") */ -OUTPUT_FORMAT("elf32-tradbigmips", "elf32-tradbigmips", "elf32-tradbigmips") +OUTPUT_FORMAT("elf32-tradbigmips", "elf32-tradbigmips", "elf32-tradlittlemips") OUTPUT_ARCH(mips) ENTRY(_start) SECTIONS diff --git a/examples/standalone/mips.lds b/examples/standalone/mips.lds index 717b201..63a1c92 100644 --- a/examples/standalone/mips.lds +++ b/examples/standalone/mips.lds @@ -24,7 +24,7 @@ /* OUTPUT_FORMAT("elf32-bigmips", "elf32-bigmips", "elf32-bigmips") */ -OUTPUT_FORMAT("elf32-tradbigmips", "elf32-tradbigmips", "elf32-tradbigmips") +OUTPUT_FORMAT("elf32-tradbigmips", "elf32-tradbigmips", "elf32-tradlittlemips") OUTPUT_ARCH(mips) SECTIONS { diff --git a/include/configs/pb1x00.h b/include/configs/pb1x00.h index 5ad745e..49ca07c 100644 --- a/include/configs/pb1x00.h +++ b/include/configs/pb1x00.h @@ -28,6 +28,8 @@ #ifndef __CONFIG_H #define __CONFIG_H
+#define CONFIG_CPU_LITTLE_ENDIAN
- #define CONFIG_MIPS32 1 /* MIPS32 CPU core */ #define CONFIG_PB1X00 1 #define CONFIG_SOC_AU1X00 1 /* alchemy series cpu */

On 7/27/10 12:06 AM, Xiangfu Liu wrote:
what about split this patch to two: one is all *.lds files, the other one is for the argument,
Sounds good.
I have one question here. if we decete the board cpu by CONFIG_CPU_LITTLE_ENDIAN. why we need check the toolchina again.
The answer is described right above:
+# We explicitly add the endianness specifier if needed, this allows +# to compile kernels with a toolchain for the other endianness. We +# carefully avoid to add it redundantly because gcc 3.3/3.4 complains +# when fed the toolchain default! +# +# Certain gcc versions upto gcc 4.1.1 (probably 4.2-subversion as of +# 2006-10-10 don't properly change the predefined symbols if -EB / -EL +# are used, so we kludge that here. A bug has been filed at +# http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29413.
This part is copied from Linux/MIPS kernel, and has been working with the wide range of GCC versions for years.
the original U-Boot is detect -EL/-EB by toolchain name. maybe the CONFIG_CPU_LITTLE_ENDIAN option is better.
True. CONFIG_CPU_LITTLE_ENDIAN (and CONFIG_CPU_BIG_ENDIAN) configs are also derived from Linux/MIPS kernel, and IMO they're right steps toward cross-endian build support. U-Boot, however, tends to think it less important, so don't hold your breath about this approach to be accepted. Cross-endian build is common practice for MIPS people, but might be uncommon for other architectures.
Note that CONFIG_CPU_LITTLE_ENDIAN works not only for cross-endian builds, but also toolchain default endian builds with non-ELDK tools. If CONFIG_CPU_LITTLE_ENDIAN is not accepted, we have to think an alternative way.
participants (2)
-
Shinya Kuribayashi
-
Xiangfu Liu