Skip to contentSkip to conversation

arm: support Thumb-1 with CONFIG_SYS_THUMB_BUILD

PATCH Superseded Stefan Roese 2 participants 4 messages Sep 2, 2015 – Sep 12, 2015

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH v6 1/1 arm: support Thumb-1 with CONFIG_SYS_THUMB_BUILD

From: Albert ARIBAUD <[email protected]>

When building a Thumb-1-only target with CONFIG_SYS_THUMB_BUILD, some files fail to build, most of the time because they include mcr instructions, which only exist for Thumb-2.

This patch introduces a Kconfig option CONFIG_THUMB2 and uses it to select between Thumb-2 and ARM mode for the aforementioned files.

---
This patch is necessary for the SPEAr600 x600 U-Boot port to fit into the onboard NOR flash again. Reducing the size by about 200KiB. So, if nothing is really missing here, then please let's apply it after the v2015.10 release.

Thanks,
Stefan

Here the original comment from Albert, from v5:
This patch has been build-tested and run-tested on ED Mini V2, above the "edmini: switch to SPL" patch, and found to reduce U-Boot size by 25% and SPL size by 14%... and to run fine.

This patch has also been tested against side effects on the non-Thumb wireless_space target. The binaries produced with and without this patch were found to differ only by their version string.

Changes in v6 (by Stefan):
- Rebased on top of current mainline U-Boot Changes in v5: None
Changes in v4: None
Changes in v3:
- added arch/arm/lib/mem{set,cpy}.S to the list of modules which should always be built in ARM state.
- Selected HAS_THUMB2 for CPU_V7M.
- Fixed invalidate_l2_cache() when building for Thumb-1.

Changes in v2:
- fixed a typo in the commit message
- added file arch/arm/thumb1/include/asm/proc-armv/system.h, which overrides arch/arm/include/asm/proc-armv/system.h when building for Thumb-1 and provides non-functional but Thumb-compilable IRQ and FIQ related macros and functions.

 Makefile                                       |  2 +
 arch/arm/Kconfig                               |  5 ++
 arch/arm/cpu/arm926ejs/Makefile                | 11 ++++
 arch/arm/cpu/arm926ejs/cache.c                 |  5 ++
 arch/arm/include/asm/cache.h                   |  4 ++
 arch/arm/lib/Makefile                          | 24 +++++++++
 arch/arm/lib/cache.c                           | 11 ++++
 arch/arm/lib/memcpy.S                          |  4 +-
 arch/arm/lib/memset.S                          |  2 +-
 arch/arm/mach-orion5x/Makefile                 | 10 ++++
 arch/arm/thumb1/include/asm/proc-armv/system.h | 69 ++++++++++++++++++++++++++
 examples/standalone/Makefile                   | 10 ++++
 12 files changed, 154 insertions(+), 3 deletions(-)
 create mode 100644 arch/arm/thumb1/include/asm/proc-armv/system.h
Makefile +2 -0
index 4fe1d88..4393e41 100644
@@ -605,6 +605,8 @@ KBUILD_CFLAGS += $(KCFLAGS)
 UBOOTINCLUDE    := \
 		-Iinclude \
 		$(if $(KBUILD_SRC), -I$(srctree)/include) \
+		$(if $(CONFIG_SYS_THUMB_BUILD), $(if $(CONFIG_HAS_THUMB2),, \
+			-I$(srctree)/arch/$(ARCH)/thumb1/include),) \
 		-I$(srctree)/arch/$(ARCH)/include \
 		-include $(srctree)/include/linux/kconfig.h
 
arch/arm/Kconfig +5 -0
index cd88df4..0753fcf 100644
@@ -10,6 +10,9 @@ config ARM64
 config HAS_VBAR
         bool
 
+config HAS_THUMB2
+        bool
+
 config CPU_ARM720T
         bool
 
@@ -32,9 +35,11 @@ config CPU_ARM1176
 config CPU_V7
         bool
         select HAS_VBAR
+        select HAS_THUMB2
 
 config CPU_V7M
 	bool
+        select HAS_THUMB2
 
 config CPU_PXA
         bool
arch/arm/cpu/arm926ejs/Makefile +11 -0
index 63fa159..fe78922 100644
@@ -20,3 +20,14 @@ obj-$(CONFIG_MX25) += mx25/
 obj-$(CONFIG_MX27) += mx27/
 obj-$(if $(filter mxs,$(SOC)),y) += mxs/
 obj-$(if $(filter spear,$(SOC)),y) += spear/
+
+# some files can only build in ARM or THUMB2, not THUMB1
+
+ifdef CONFIG_SYS_THUMB_BUILD
+ifndef CONFIG_HAS_THUMB2
+
+CFLAGS_cpu.o := -marm
+CFLAGS_cache.o := -marm
+
+endif
+endif
arch/arm/cpu/arm926ejs/cache.c +5 -0
index e5c1a6a..2839c86 100644
@@ -82,4 +82,9 @@ void flush_dcache_all(void)
 /*
  * Stub implementations for l2 cache operations
  */
+
 __weak void l2_cache_disable(void) {}
+
+#if defined CONFIG_SYS_THUMB_BUILD
+__weak void invalidate_l2_cache(void) {}
+#endif
arch/arm/include/asm/cache.h +4 -0
index a836e9f..1f63127 100644
@@ -16,6 +16,9 @@
 /*
  * Invalidate L2 Cache using co-proc instruction
  */
+#ifdef CONFIG_SYS_THUMB_BUILD
+void invalidate_l2_cache(void);
+#else
 static inline void invalidate_l2_cache(void)
 {
 	unsigned int val=0;
@@ -24,6 +27,7 @@ static inline void invalidate_l2_cache(void)
 		: : "r" (val) : "cc");
 	isb();
 }
+#endif
 
 void l2_cache_enable(void);
 void l2_cache_disable(void);
arch/arm/lib/Makefile +24 -0
index 31a5c8d..4c7e3f9 100644
@@ -60,3 +60,27 @@ obj-$(CONFIG_DEBUG_LL)	+= debug.o
 ifneq (,$(findstring -mabi=aapcs-linux,$(PLATFORM_CPPFLAGS)))
 extra-y	+= eabi_compat.o
 endif
+
+# some files can only build in ARM or THUMB2, not THUMB1
+
+ifdef CONFIG_SYS_THUMB_BUILD
+ifndef CONFIG_HAS_THUMB2
+
+# for C files, just apend -marm, which will override previous -mthumb*
+
+CFLAGS_cache.o := -marm
+CFLAGS_cache-cp15.o := -marm
+
+# For .S, drop -mthumb* and other thumb-related options.
+# CFLAGS_REMOVE_* would not have an effet, so AFLAGS_REMOVE_*
+# was implemented and is used here.
+# Also, define ${target}_NO_THUMB_BUILD for these two targets
+# so that the code knows it should not use Thumb.
+
+AFLAGS_REMOVE_memset.o := -mthumb -mthumb-interwork
+AFLAGS_REMOVE_memcpy.o := -mthumb -mthumb-interwork
+AFLAGS_memset.o := -DMEMSET_NO_THUMB_BUILD
+AFLAGS_memcpy.o := -DMEMCPY_NO_THUMB_BUILD
+
+endif
+endif
arch/arm/lib/cache.c +11 -0
index cd13db3..3bd8710 100644
@@ -88,3 +88,14 @@ phys_addr_t noncached_alloc(size_t size, size_t align)
 	return next;
 }
 #endif /* CONFIG_SYS_NONCACHED_MEMORY */
+
+#if defined(CONFIG_SYS_THUMB_BUILD)
+void invalidate_l2_cache(void)
+{
+	unsigned int val = 0;
+
+	asm volatile("mcr p15, 1, %0, c15, c11, 0 @ invl l2 cache"
+		: : "r" (val) : "cc");
+	isb();
+}
+#endif
arch/arm/lib/memcpy.S +2 -2
index eeaf003..7d9fc0f 100644
@@ -13,7 +13,7 @@
 #include <linux/linkage.h>
 #include <asm/assembler.h>
 
-#ifdef CONFIG_SYS_THUMB_BUILD
+#if defined(CONFIG_SYS_THUMB_BUILD) && !defined(MEMCPY_NO_THUMB_BUILD)
 #define W(instr)	instr.w
 #else
 #define W(instr)	instr
@@ -62,7 +62,7 @@
 
 /* Prototype: void *memcpy(void *dest, const void *src, size_t n); */
 	.syntax unified
-#ifdef CONFIG_SYS_THUMB_BUILD
+#if defined(CONFIG_SYS_THUMB_BUILD) && !defined(MEMCPY_NO_THUMB_BUILD)
 	.thumb
 	.thumb_func
 #endif
arch/arm/lib/memset.S +1 -1
index 7208f20..df053a3 100644
@@ -16,7 +16,7 @@
 	.align	5
 
 	.syntax unified
-#ifdef CONFIG_SYS_THUMB_BUILD
+#if defined(CONFIG_SYS_THUMB_BUILD) && !defined(MEMSET_NO_THUMB_BUILD)
 	.thumb
 	.thumb_func
 #endif
arch/arm/mach-orion5x/Makefile +10 -0
index 546ebcb..33dcad4 100644
@@ -16,3 +16,13 @@ obj-y	+= timer.o
 ifndef CONFIG_SKIP_LOWLEVEL_INIT
 obj-y	+= lowlevel_init.o
 endif
+
+# some files can only build in ARM or THUMB2, not THUMB1
+
+ifdef CONFIG_SYS_THUMB_BUILD
+ifndef CONFIG_HAS_THUMB2
+
+CFLAGS_cpu.o := -marm
+
+endif
+endif
arch/arm/thumb1/include/asm/proc-armv/system.h new file +69 -0

69 lines not on this page · raw message

examples/standalone/Makefile +10 -0
index 0863a8c..5a6ae00 100644
@@ -73,3 +73,13 @@ $(obj)/%.srec: $(obj)/% FORCE
 $(obj)/%.bin: OBJCOPYFLAGS := -O binary
 $(obj)/%.bin: $(obj)/% FORCE
 	$(call if_changed,objcopy)
+
+# some files can only build in ARM or THUMB2, not THUMB1
+
+ifdef CONFIG_SYS_THUMB_BUILD
+ifndef CONFIG_HAS_THUMB2
+
+CFLAGS_stubs.o := -marm
+
+endif
+endif
Signature · 1 line
2.5.1
#1 lore raw

PATCH v6 1/1 arm: support Thumb-1 with CONFIG_SYS_THUMB_BUILD

Hello Stefan,

Quoted 12 lines · Stefan Roese

From: Albert ARIBAUD <[email protected]>

When building a Thumb-1-only target with CONFIG_SYS_THUMB_BUILD, some files fail to build, most of the time because they include mcr instructions, which only exist for Thumb-2.

This patch introduces a Kconfig option CONFIG_THUMB2 and uses it to select between Thumb-2 and ARM mode for the aforementioned files.

Quoted 8 lines

---
This patch is necessary for the SPEAr600 x600 U-Boot port to fit into the onboard NOR flash again. Reducing the size by about 200KiB. So, if nothing is really missing here, then please let's apply it after the v2015.10 release.

Thanks,
Stefan

Did you change anything from v5 of this patch? Otherwise, I would prefer to apply the whole series.

Amicalement,

Signature · 1 line
Albert.
#2 lore raw

PATCH v6 1/1 arm: support Thumb-1 with CONFIG_SYS_THUMB_BUILD

Hi Albert,
No real change. Only rebased since v5 did not apply for me. Feel free to pick up any version you prefer.
Thanks,
Stefan

Am 12.09.2015 9:21 vorm. schrieb "Albert ARIBAUD" <[email protected]

Quoted 36 lines

:

Hello Stefan,

Quoted 12 lines · Stefan Roese

From: Albert ARIBAUD <[email protected]>

When building a Thumb-1-only target with CONFIG_SYS_THUMB_BUILD, some files fail to build, most of the time because they include mcr instructions, which only exist for Thumb-2.

This patch introduces a Kconfig option CONFIG_THUMB2 and uses it to select between Thumb-2 and ARM mode for the aforementioned files.

Quoted 8 lines

---
This patch is necessary for the SPEAr600 x600 U-Boot port to fit into the onboard NOR flash again. Reducing the size by about 200KiB. So, if nothing is really missing here, then please let's apply it after the v2015.10 release.

Thanks,
Stefan

Did you change anything from v5 of this patch? Otherwise, I would prefer to apply the whole series.

Amicalement,
--
Albert.
_______________________________________________
U-Boot mailing list
U-Boot at lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot

#3 lore raw

PATCH v6 1/1 arm: support Thumb-1 with CONFIG_SYS_THUMB_BUILD

Hello Stefan,

Quoted 3 lines · Stefan Roese

Hi Albert,
No real change. Only rebased since v5 did not apply for me. Feel free to pick up any version you prefer.

Thanks. I'll rebase and apply the v5 series.

Quoted 2 lines

Thanks,
Stefan

Amicalement,

Signature · 1 line
Albert.