[U-Boot] [RFC][MIPS] Fix little-endian build with non-ELDK toolchains

Hi,
This is my proposal for outstanding MIPS little-endian build issue. I tested with ELDK 3.1.1 (GCC 3.3.3, mips_4KC-/mips_4KCle-) and a usual mipsel-linux-gcc toolchain prepared by buildroot.
Any comments are appreciated.
Thanks in advance,
================>
[MIPS] Fix little-endian build with non-ELDK toolchains
We've been in trouble for a long time when cross compiling with non-ELDK toolchains. This is caused by -EB passed to CPPFLAGS incorrectly, by the lack of an endian specifier to LDFLAGS, and by wrong OUTPUT_FORMATs.
We're going to implement two workarounds. One is the endianness specifier bugfix not to pass -EB / -EL to CPPFLAGS unless ELDK toolchain is used. Note that ELDK and non-ELDK toolchains know their default endianness, so the endianness specifier may not be necessary in principle.
The other is removal of OUTPUT_FORMAT in *.lds files. If we have this, it doesn't work unless an endianness specifier is added to LDFLAGS. As we haven't added that to LDFLAGS so far, it must have not worked properly, except ELDK; I don't know why and how ELDK works, though.
With these two changes, all objects will be generated and linked in the toolchain's default endianness. Then MAKEALL mips_el will work even with non-ELDK toolchain.
Note that Linux/MIPS kernel has CONFIG_CPU_BIG_ENDIAN and CONFIG_CPU_LITTLE_ENDIAN alternatives to allow users to compile kernels with a toolchain for the other endianness. But U-Boot does not have such feature for now, and it's another story.
Signed-off-by: Shinya Kuribayashi skuribay@ruby.dti.ne.jp --- board/dbau1x00/u-boot.lds | 4 ---- board/gth2/u-boot.lds | 4 ---- board/incaip/u-boot.lds | 4 ---- board/pb1x00/u-boot.lds | 4 ---- board/purple/u-boot.lds | 4 ---- board/qemu-mips/u-boot.lds | 4 ---- board/tb0229/u-boot.lds | 2 -- cpu/mips/config.mk | 8 -------- examples/mips.lds | 4 ---- mips_config.mk | 26 ++++++++++++++++++++++++++ 10 files changed, 26 insertions(+), 38 deletions(-)
diff --git a/board/dbau1x00/u-boot.lds b/board/dbau1x00/u-boot.lds index 1e1c559..28247be 100644 --- a/board/dbau1x00/u-boot.lds +++ b/board/dbau1x00/u-boot.lds @@ -21,10 +21,6 @@ * MA 02111-1307 USA */
-/* -OUTPUT_FORMAT("elf32-bigmips", "elf32-bigmips", "elf32-bigmips") -*/ -OUTPUT_FORMAT("elf32-tradbigmips", "elf32-tradbigmips", "elf32-tradbigmips") OUTPUT_ARCH(mips) ENTRY(_start) SECTIONS diff --git a/board/gth2/u-boot.lds b/board/gth2/u-boot.lds index 8265130..a8ec696 100644 --- a/board/gth2/u-boot.lds +++ b/board/gth2/u-boot.lds @@ -21,10 +21,6 @@ * MA 02111-1307 USA */
-/* -OUTPUT_FORMAT("elf32-bigmips", "elf32-bigmips", "elf32-bigmips") -*/ -OUTPUT_FORMAT("elf32-tradbigmips", "elf32-tradbigmips", "elf32-tradbigmips") OUTPUT_ARCH(mips) ENTRY(_start) SECTIONS diff --git a/board/incaip/u-boot.lds b/board/incaip/u-boot.lds index 1e1c559..28247be 100644 --- a/board/incaip/u-boot.lds +++ b/board/incaip/u-boot.lds @@ -21,10 +21,6 @@ * MA 02111-1307 USA */
-/* -OUTPUT_FORMAT("elf32-bigmips", "elf32-bigmips", "elf32-bigmips") -*/ -OUTPUT_FORMAT("elf32-tradbigmips", "elf32-tradbigmips", "elf32-tradbigmips") OUTPUT_ARCH(mips) ENTRY(_start) SECTIONS diff --git a/board/pb1x00/u-boot.lds b/board/pb1x00/u-boot.lds index 1e1c559..28247be 100644 --- a/board/pb1x00/u-boot.lds +++ b/board/pb1x00/u-boot.lds @@ -21,10 +21,6 @@ * MA 02111-1307 USA */
-/* -OUTPUT_FORMAT("elf32-bigmips", "elf32-bigmips", "elf32-bigmips") -*/ -OUTPUT_FORMAT("elf32-tradbigmips", "elf32-tradbigmips", "elf32-tradbigmips") OUTPUT_ARCH(mips) ENTRY(_start) SECTIONS diff --git a/board/purple/u-boot.lds b/board/purple/u-boot.lds index 972e6e7..f50bd06 100644 --- a/board/purple/u-boot.lds +++ b/board/purple/u-boot.lds @@ -21,10 +21,6 @@ * MA 02111-1307 USA */
-/* -OUTPUT_FORMAT("elf32-bigmips", "elf32-bigmips", "elf32-bigmips") -*/ -OUTPUT_FORMAT("elf32-tradbigmips", "elf32-tradbigmips", "elf32-tradbigmips") OUTPUT_ARCH(mips) ENTRY(_start) SECTIONS diff --git a/board/qemu-mips/u-boot.lds b/board/qemu-mips/u-boot.lds index c2a8566..e4a8b61 100644 --- a/board/qemu-mips/u-boot.lds +++ b/board/qemu-mips/u-boot.lds @@ -21,10 +21,6 @@ * MA 02111-1307 USA */
-/* -OUTPUT_FORMAT("elf32-bigmips", "elf32-bigmips", "elf32-bigmips") -*/ -OUTPUT_FORMAT("elf32-tradbigmips", "elf32-tradbigmips", "elf32-tradbigmips") OUTPUT_ARCH(mips) ENTRY(_start) SECTIONS diff --git a/board/tb0229/u-boot.lds b/board/tb0229/u-boot.lds index b18e6a6..3149ba0 100644 --- a/board/tb0229/u-boot.lds +++ b/board/tb0229/u-boot.lds @@ -23,8 +23,6 @@ * MA 02111-1307 USA */
-OUTPUT_FORMAT("elf32-tradlittlemips", "elf32-tradlittlemips", "elf32-tradlittlemips") - OUTPUT_ARCH(mips) ENTRY(_start) SECTIONS diff --git a/cpu/mips/config.mk b/cpu/mips/config.mk index a173c54..098d6c7 100644 --- a/cpu/mips/config.mk +++ b/cpu/mips/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/examples/mips.lds b/examples/mips.lds index aceb6e9..f558f7e 100644 --- a/examples/mips.lds +++ b/examples/mips.lds @@ -21,10 +21,6 @@ * MA 02111-1307 USA */
-/* -OUTPUT_FORMAT("elf32-bigmips", "elf32-bigmips", "elf32-bigmips") -*/ -OUTPUT_FORMAT("elf32-tradbigmips", "elf32-tradbigmips", "elf32-tradbigmips") OUTPUT_ARCH(mips) SECTIONS { diff --git a/mips_config.mk b/mips_config.mk index 05eb05d..b5cd38d 100644 --- a/mips_config.mk +++ b/mips_config.mk @@ -46,3 +46,29 @@ PLATFORM_CPPFLAGS += -DCONFIG_MIPS -D__MIPS__ PLATFORM_CPPFLAGS += -G 0 -mabicalls -fpic PLATFORM_CPPFLAGS += -msoft-float PLATFORM_LDFLAGS += -G 0 -static -n -nostdlib + +# +# A toolchain has its default endianness, so in principle, we don't +# need any endianness specifier as long as we compile U-Boot for that +# endianness. Furthermore, it's not a good practice to add it without +# giving it much thought. Here's hints from Linux' Makefile: +# +# We explicitly add the endianness specifier if needed, (snip) 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. +# +# Well, we've added the endianness specifier for years when compiling +# with ELDK. For this historical reason, and maintaining backward +# compatibility, we leave it as far as ELDK is used. +# +ifneq ($(findstring mips_4KC-,$(CROSS_COMPILE)),) +PLATFORM_CPPFLAGS += -EB +endif +ifneq ($(findstring mips_4KCle-,$(CROSS_COMPILE)),) +PLATFORM_CPPFLAGS += -EL +endif
participants (1)
-
Shinya Kuribayashi