[U-Boot] [PATCH 2/3] mips: add endianness support

Jean-Christophe PLAGNIOL-VILLARD plagnioj at jcrosoft.com
Sat May 23 21:42:37 CEST 2009


curently we need to specify the endian of each board in the LDS

in order to unify all of them add full endianness support

by default the mips platforms will be compiled as big-endian
to compile it as little-endian define CONFIG_CPU_LITTLE_ENDIAN

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj at jcrosoft.com>
---
 Makefile                   |    2 ++
 board/dbau1x00/u-boot.lds  |    5 +----
 board/gth2/u-boot.lds      |    5 +----
 board/incaip/u-boot.lds    |    5 +----
 board/pb1x00/u-boot.lds    |    5 +----
 board/purple/u-boot.lds    |    5 +----
 board/qemu-mips/u-boot.lds |    5 +----
 board/tb0229/u-boot.lds    |    3 +--
 cpu/mips/config.mk         |    8 --------
 examples/Makefile          |    1 +
 examples/mips.lds          |    5 +----
 mips_config.mk             |   25 +++++++++++++++++++++++++
 12 files changed, 36 insertions(+), 38 deletions(-)

diff --git a/Makefile b/Makefile
index 7f3776e..929cae7 100644
--- a/Makefile
+++ b/Makefile
@@ -3237,6 +3237,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
@@ -3247,6 +3248,7 @@ gth2_config		:	unconfig
 pb1000_config		:	unconfig
 	@mkdir -p $(obj)include
 	@echo "#define CONFIG_PB1000 1" >$(obj)include/config.h
+	@echo "#define CONFIG_CPU_LITTLE_ENDIAN" >>$(obj)include/config.h
 	@$(MKCONFIG) -a pb1x00 mips mips pb1x00
 
 qemu_mips_config	: unconfig
diff --git a/board/dbau1x00/u-boot.lds b/board/dbau1x00/u-boot.lds
index 9a6cd1b..93c06db 100644
--- a/board/dbau1x00/u-boot.lds
+++ b/board/dbau1x00/u-boot.lds
@@ -21,10 +21,7 @@
  * MA 02111-1307 USA
  */
 
-/*
-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..f3b2c85 100644
--- a/board/gth2/u-boot.lds
+++ b/board/gth2/u-boot.lds
@@ -21,10 +21,7 @@
  * MA 02111-1307 USA
  */
 
-/*
-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..93c06db 100644
--- a/board/incaip/u-boot.lds
+++ b/board/incaip/u-boot.lds
@@ -21,10 +21,7 @@
  * MA 02111-1307 USA
  */
 
-/*
-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..93c06db 100644
--- a/board/pb1x00/u-boot.lds
+++ b/board/pb1x00/u-boot.lds
@@ -21,10 +21,7 @@
  * MA 02111-1307 USA
  */
 
-/*
-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 04a641a..193d8b2 100644
--- a/board/purple/u-boot.lds
+++ b/board/purple/u-boot.lds
@@ -21,10 +21,7 @@
  * MA 02111-1307 USA
  */
 
-/*
-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..7f94b64 100644
--- a/board/qemu-mips/u-boot.lds
+++ b/board/qemu-mips/u-boot.lds
@@ -21,10 +21,7 @@
  * MA 02111-1307 USA
  */
 
-/*
-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/tb0229/u-boot.lds b/board/tb0229/u-boot.lds
index 56d7c25..6f21197 100644
--- a/board/tb0229/u-boot.lds
+++ b/board/tb0229/u-boot.lds
@@ -23,8 +23,7 @@
  * MA 02111-1307 USA
  */
 
-OUTPUT_FORMAT("elf32-tradlittlemips", "elf32-tradlittlemips", "elf32-tradlittlemips")
-
+OUTPUT_FORMAT("elf32-tradbigmips", "elf32-tradbigmips", "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/Makefile b/examples/Makefile
index dbcfa92..cf70d6d 100644
--- a/examples/Makefile
+++ b/examples/Makefile
@@ -43,6 +43,7 @@ endif
 
 ifeq ($(ARCH),mips)
 LOAD_ADDR = 0x80200000 -T mips.lds
+EX_LDFLAGS += $(PLATFORM_LDFLAGS)
 endif
 
 ifeq ($(ARCH),nios)
diff --git a/examples/mips.lds b/examples/mips.lds
index 717b201..9caff00 100644
--- a/examples/mips.lds
+++ b/examples/mips.lds
@@ -21,10 +21,7 @@
  * MA 02111-1307 USA
  */
 
-/*
-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/mips_config.mk b/mips_config.mk
index 05eb05d..423e216 100644
--- a/mips_config.mk
+++ b/mips_config.mk
@@ -46,3 +46,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
-- 
1.6.3.1



More information about the U-Boot mailing list