From 81631e49a608be93af0a473ec3f099cb556a2c8a Mon Sep 17 00:00:00 2001 From: =?utf8?q?Andreas=20F=C3=A4rber?= Date: Sun, 22 May 2016 00:41:15 +0200 Subject: [PATCH] contrib/loaders: Enforce Little Endian ARM machine code MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit arm-none-eabi target triplet defaults to Little Endian, and so far any submitted machine code snippets have been verified to be Little Endian. However a user might override [ARM_]CROSS_COMPILE with an armeb toolchain, potentially resulting in invalid machine code. Let's be safe and enforce Little Endian mode for assembler and compiler. Change-Id: I9cefe24689eaded25d60ffb1f254b254e8d76f9d Signed-off-by: Andreas Färber Reviewed-on: http://openocd.zylin.com/3498 Tested-by: jenkins Reviewed-by: Andreas Fritiofson --- contrib/loaders/checksum/Makefile | 6 ++++-- contrib/loaders/erase_check/Makefile | 6 ++++-- contrib/loaders/flash/fm4/Makefile | 4 +++- contrib/loaders/flash/kinetis_ke/Makefile | 4 +++- contrib/loaders/flash/xmc1xxx/Makefile | 4 +++- contrib/loaders/watchdog/Makefile | 4 +++- 6 files changed, 20 insertions(+), 8 deletions(-) diff --git a/contrib/loaders/checksum/Makefile b/contrib/loaders/checksum/Makefile index 34430e2f..b9f59b8d 100644 --- a/contrib/loaders/checksum/Makefile +++ b/contrib/loaders/checksum/Makefile @@ -4,10 +4,12 @@ ARM_CROSS_COMPILE ?= arm-none-eabi- ARM_AS ?= $(ARM_CROSS_COMPILE)as ARM_OBJCOPY ?= $(ARM_CROSS_COMPILE)objcopy +ARM_AFLAGS = -EL + arm: armv4_5_crc.inc armv7m_crc.inc armv4_5_%.elf: armv4_5_%.s - $(ARM_AS) $< -o $@ + $(ARM_AS) $(ARM_AFLAGS) $< -o $@ armv4_5_%.bin: armv4_5_%.elf $(ARM_OBJCOPY) -Obinary $< $@ @@ -16,7 +18,7 @@ armv4_5_%.inc: armv4_5_%.bin $(BIN2C) < $< > $@ armv7m_%.elf: armv7m_%.s - $(ARM_AS) $< -o $@ + $(ARM_AS) $(ARM_AFLAGS) $< -o $@ armv7m_%.bin: armv7m_%.elf $(ARM_OBJCOPY) -Obinary $< $@ diff --git a/contrib/loaders/erase_check/Makefile b/contrib/loaders/erase_check/Makefile index cd4d3221..01e62dea 100644 --- a/contrib/loaders/erase_check/Makefile +++ b/contrib/loaders/erase_check/Makefile @@ -4,10 +4,12 @@ ARM_CROSS_COMPILE ?= arm-none-eabi- ARM_AS ?= $(ARM_CROSS_COMPILE)as ARM_OBJCOPY ?= $(ARM_CROSS_COMPILE)objcopy +ARM_AFLAGS = -EL + arm: armv4_5_erase_check.inc armv7m_erase_check.inc armv7m_0_erase_check.inc armv4_5_%.elf: armv4_5_%.s - $(ARM_AS) $< -o $@ + $(ARM_AS) $(ARM_AFLAGS) $< -o $@ armv4_5_%.bin: armv4_5_%.elf $(ARM_OBJCOPY) -Obinary $< $@ @@ -16,7 +18,7 @@ armv4_5_%.inc: armv4_5_%.bin $(BIN2C) < $< > $@ armv7m_%.elf: armv7m_%.s - $(ARM_AS) $< -o $@ + $(ARM_AS) $(ARM_AFLAGS) $< -o $@ armv7m_%.bin: armv7m_%.elf $(ARM_OBJCOPY) -Obinary $< $@ diff --git a/contrib/loaders/flash/fm4/Makefile b/contrib/loaders/flash/fm4/Makefile index eb4cbd0c..207b9d0f 100644 --- a/contrib/loaders/flash/fm4/Makefile +++ b/contrib/loaders/flash/fm4/Makefile @@ -6,6 +6,8 @@ CC=$(CROSS_COMPILE)gcc OBJCOPY=$(CROSS_COMPILE)objcopy OBJDUMP=$(CROSS_COMPILE)objdump +CFLAGS = -static -nostartfiles -mlittle-endian -Wa,-EL + all: erase.inc write.inc .PHONY: clean @@ -15,7 +17,7 @@ all: erase.inc write.inc erase.elf write.elf: fm4.h %.elf: %.S - $(CC) -static -nostartfiles $< -o $@ + $(CC) $(CFLAGS) $< -o $@ %.lst: %.elf $(OBJDUMP) -S $< > $@ diff --git a/contrib/loaders/flash/kinetis_ke/Makefile b/contrib/loaders/flash/kinetis_ke/Makefile index a0331a2e..7d8dba8c 100644 --- a/contrib/loaders/flash/kinetis_ke/Makefile +++ b/contrib/loaders/flash/kinetis_ke/Makefile @@ -4,10 +4,12 @@ CROSS_COMPILE ?= arm-none-eabi- AS = $(CROSS_COMPILE)as OBJCOPY = $(CROSS_COMPILE)objcopy +AFLAGS = -EL + all: kinetis_ke_flash.inc kinetis_ke_watchdog.inc %.elf: %.s - $(AS) $< -o $@ + $(AS) $(AFLAGS) $< -o $@ %.bin: %.elf $(OBJCOPY) -Obinary $< $@ diff --git a/contrib/loaders/flash/xmc1xxx/Makefile b/contrib/loaders/flash/xmc1xxx/Makefile index 066466ef..b97c602d 100644 --- a/contrib/loaders/flash/xmc1xxx/Makefile +++ b/contrib/loaders/flash/xmc1xxx/Makefile @@ -6,6 +6,8 @@ CC=$(CROSS_COMPILE)gcc OBJCOPY=$(CROSS_COMPILE)objcopy OBJDUMP=$(CROSS_COMPILE)objdump +CFLAGS = -static -nostartfiles -mlittle-endian -Wa,-EL + all: erase.inc erase_check.inc write.inc .PHONY: clean @@ -15,7 +17,7 @@ all: erase.inc erase_check.inc write.inc erase.elf erase_check.elf write.elf: xmc1xxx.S %.elf: %.S - $(CC) -static -nostartfiles $< -o $@ + $(CC) $(CFLAGS) $< -o $@ %.lst: %.elf $(OBJDUMP) -S $< > $@ diff --git a/contrib/loaders/watchdog/Makefile b/contrib/loaders/watchdog/Makefile index d9ef1d2c..623e7440 100644 --- a/contrib/loaders/watchdog/Makefile +++ b/contrib/loaders/watchdog/Makefile @@ -4,10 +4,12 @@ ARM_CROSS_COMPILE ?= arm-none-eabi- ARM_AS ?= $(ARM_CROSS_COMPILE)as ARM_OBJCOPY ?= $(ARM_CROSS_COMPILE)objcopy +ARM_AFLAGS = -EL -mthumb + arm: armv7m_kinetis_wdog.inc armv7m_%.elf: armv7m_%.s - $(ARM_AS) -mthumb $< -o $@ + $(ARM_AS) $(ARM_AFLAGS) $< -o $@ armv7m_%.bin: armv7m_%.elf $(ARM_OBJCOPY) -Obinary $< $@ -- 2.39.5