Add thumb support to buildroot for the ARM architecture
PATCH 1/1 Add thumb support to buildroot for the ARM architecture
Hi,
You'll find enclosed in this mail a patch that adds Thumb support for buildroot. It allows to generate an interworking-enabled toolchain, with an uClibc compiled in ARM mode, and then to compile userspace applications in Thumb mode.
More details are available in the patch description.
Of course, your comments, reviews and suggestions are welcome!
Thanks for developing such a great tool,
Sincerly,
Thomas
---
Add thumb support to buildroot for the ARM architecture
The Thumb instruction set is encoded on 16 bits opcode instead of 32 bits opcode for the regular ARM instruction set. It generally allows for greater code density, leading to reduced code size, which is nice on memory-constrained embedded systems.
Currently, uClibc cannot be fully compiled using the Thumb instruction set. Therefore, this patch still compile uClibc in regular ARM mode, but allows to enable interworking support for the toolchain. Interworking allows Thumb code to call ARM code and vice-versa, allowing a mixed Thumb/ARM userspace.
Enabling interworking at the toolchain level is done using the BR2_INTERWORKING_SUPPORT option, added by the patch. When enabled, it adds --enable-interwork to the binutils and gcc configure options, adds -mthumb-interwork to the CFLAGS during uClibc compilation, and enables the USE_BX config option of uClibc (bx is an ARM instruction that allows to switch between ARM and Thumb mode).
Once interworking is enabled, it is then possible to compile the userspace applications in Thumb mode. This is what the new BR2_THUMB_BINARIES option allows, by adding -mthumb to the CFLAGS used during the compilation of userspace applications.
--- Config.in | 8 ++++++++ package/Makefile.in | 4 ++++ toolchain/Config.in.2 | 12 ++++++++++++ toolchain/binutils/binutils.mk | 5 +++++ toolchain/gcc/Makefile.in | 4 ++++ toolchain/uClibc/uclibc.mk | 7 +++++++ 6 files changed, 40 insertions(+)
Config.in +8 -0
@@ -223,6 +223,14 @@ WARNING: This is highly experimental at the moment. +config BR2_THUMB_BINARIES + bool "generate Thumb binaries" + default n + depends on BR2_INTERWORKING_SUPPORT + help + Compile binaries in Thumb mode. Only valid for ARM + architecture. + config BR2_HAVE_MANPAGES bool "manpages on the target" default n
package/Makefile.in +4 -0
@@ -46,6 +46,10 @@ TARGET_CFLAGS+=-msoft-float endif +ifeq ($(BR2_THUMB_BINARIES),y) +TARGET_CFLAGS+=-mthumb +endif + # enable VIS for v9a and v9b ifeq ($(findstring y,$(BR2_sparc_v9a)$(BR2_sparc64_v9a)$(BR2_sparc_v9b)$(BR2_sparc64_v9b)),y) TARGET_CFLAGS+=-mvis
toolchain/Config.in.2 +12 -0
@@ -61,6 +61,18 @@ # bool "Use softfp" # default n +config BR2_INTERWORKING_SUPPORT + bool "Enable interworking support" + default n + depends on BR2_arm || BR2_armeb + depends on !BR2_generic_arm && !BR2_arm610 && !BR2_arm710 + help + Interworking allows Thumb userspace binaries to be linked + against the C standard library compiled in ARM mode. + + This is only possible on Thumb-aware architectures, i.e not + Generic ARM, ARM610 or ARM710. + config BR2_TARGET_OPTIMIZATION string "Target Optimizations" default "-Os -pipe"
toolchain/binutils/binutils.mk +5 -0
@@ -65,6 +65,10 @@ BINUTILS_TARGET_CONFIG_OPTIONS+=--with-mpfr="$(MPFR_TARGET_DIR)" endif +ifeq ($(BR2_INTERWORKING_SUPPORT),y) +INTERWORKING_CONFIG_OPTION=--enable-interwork +endif + BINUTILS_OFFICIAL_VERSION:=$(BINUTILS_VERSION)$(VENDOR_SUFFIX)$(VENDOR_BINUTILS_RELEASE) ifeq ($(BR2_TOOLCHAIN_BUILDROOT),y) BINUTILS_PATCH_DIR:=toolchain/binutils/$(BINUTILS_VERSION)
@@ -112,6 +116,7 @@ --disable-werror \ $(SOFT_FLOAT_CONFIG_OPTION) \ $(EXTRA_BINUTILS_CONFIG_OPTIONS) \ + $(INTERWORKING_CONFIG_OPTION) \ ) touch $@
toolchain/gcc/Makefile.in +4 -0
@@ -65,6 +65,10 @@ endif endif +ifeq ($(BR2_INTERWORKING_SUPPORT),y) +EXTRA_GCC_CONFIG_OPTIONS+=--enable-interwork +endif + # AVR32 GCC configuration ifeq ($(strip $(BR2_avr32)),y) EXTRA_GCC_CONFIG_OPTIONS+=--disable-libmudflap
toolchain/uClibc/uclibc.mk +7 -0
@@ -322,6 +322,13 @@ else $(SED) 's,^.*UCLIBC_HAS_WCHAR.*,UCLIBC_HAS_WCHAR=n,g' $(UCLIBC_DIR)/.oldconfig endif +ifeq ($(BR2_INTERWORKING_SUPPORT),y) + $(SED) 's,^.*USE_BX.*,USE_BX=y,g' $(UCLIBC_DIR)/.oldconfig + $(SED) 's,^.*UCLIBC_EXTRA_CFLAGS.*,UCLIBC_EXTRA_CFLAGS="-mthumb-interwork",g' $(UCLIBC_DIR)/.oldconfig +else + + $(SED) 's,^.*USE_BX.*,USE_BX=n,g' $(UCLIBC_DIR)/.oldconfig +endif ifeq ($(BR2_UCLIBC_PROGRAM_INVOCATION),y) $(SED) 's,^.*UCLIBC_HAS_PROGRAM_INVOCATION_NAME.*,UCLIBC_HAS_PROGRAM_INVOCATION_NAME=y,g' $(UCLIBC_DIR)/.oldconfig else
Signature · 11 lines
Thomas Petazzoni, Free Electrons Free Embedded Linux Training Materials on http://free-electrons.com/training (More than 1500 pages!) -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 189 bytes Desc: not available Url : http://busybox.net/lists/buildroot/attachments/20080312/09bfe59a/attachment.pgp
PATCH 1/1 Add thumb support to buildroot for the ARM architecture
Hi,
Any comments on that ? Are you interested in merging such a patch ?
Thanks,
Thomas
Le Wed, 12 Mar 2008 09:08:46 +0100,
Thomas Petazzoni <[email protected]> a ?crit :
Quoted 170 lines
Hi,
You'll find enclosed in this mail a patch that adds Thumb support for buildroot. It allows to generate an interworking-enabled toolchain, with an uClibc compiled in ARM mode, and then to compile userspace applications in Thumb mode.
More details are available in the patch description.
Of course, your comments, reviews and suggestions are welcome!
Thanks for developing such a great tool,
Sincerly,
Thomas
---
Add thumb support to buildroot for the ARM architectureThe Thumb instruction set is encoded on 16 bits opcode instead of 32 bits opcode for the regular ARM instruction set. It generally allows for greater code density, leading to reduced code size, which is nice on memory-constrained embedded systems.
Currently, uClibc cannot be fully compiled using the Thumb instruction set. Therefore, this patch still compile uClibc in regular ARM mode, but allows to enable interworking support for the toolchain. Interworking allows Thumb code to call ARM code and vice-versa, allowing a mixed Thumb/ARM userspace.
Enabling interworking at the toolchain level is done using the
BR2_INTERWORKING_SUPPORToption, added by the patch. When enabled, it adds --enable-interwork to the binutils and gcc configure options, adds -mthumb-interwork to the CFLAGS during uClibc compilation, and enables theUSE_BXconfig option of uClibc (bx is an ARM instruction that allows to switch between ARM and Thumb mode).Once interworking is enabled, it is then possible to compile the userspace applications in Thumb mode. This is what the new
BR2_THUMB_BINARIESoption allows, by adding -mthumb to the CFLAGS used during the compilation of userspace applications.Signed-off-by Thomas Petazzoni <[email protected]>--- Config.in | 8 ++++++++ package/Makefile.in | 4 ++++ toolchain/Config.in.2 | 12 ++++++++++++ toolchain/binutils/binutils.mk | 5 +++++ toolchain/gcc/Makefile.in | 4 ++++ toolchain/uClibc/uclibc.mk | 7 +++++++ 6 files changed, 40 insertions(+)Index: buildroot.new/Config.in
===================================================================Config.in +8
-0@@ -223,6 +223,14 @@ WARNING: This is highly experimental at the moment. +config BR2_THUMB_BINARIES + bool "generate Thumb binaries" + default n + depends on BR2_INTERWORKING_SUPPORT + help + Compile binaries in Thumb mode. Only valid for ARM + architecture. + config BR2_HAVE_MANPAGES bool "manpages on the target" default nIndex: buildroot.new/package/Makefile.in
===================================================================package/Makefile.in +4
-0@@ -46,6 +46,10 @@ TARGET_CFLAGS+=-msoft-float endif +ifeq ($(BR2_THUMB_BINARIES),y) +TARGET_CFLAGS+=-mthumb +endif + # enable VIS for v9a and v9b ifeq ($(findstring y,$(BR2_sparc_v9a)$(BR2_sparc64_v9a)$(BR2_sparc_v9b)$(BR2_sparc64_v9b)),y)TARGET_CFLAGS+=-mvis Index: buildroot.new/toolchain/Config.in.2
===================================================================toolchain/Config.in.2 +12
-0@@ -61,6 +61,18 @@ # bool "Use softfp" # default n +config BR2_INTERWORKING_SUPPORT + bool "Enable interworking support" + default n + depends on BR2_arm || BR2_armeb + depends on !BR2_generic_arm && !BR2_arm610 && !BR2_arm710 + help + Interworking allows Thumb userspace binaries to be linked + against the C standard library compiled in ARM mode. + + This is only possible on Thumb-aware architectures, i.e not + Generic ARM, ARM610 or ARM710. + config BR2_TARGET_OPTIMIZATION string "Target Optimizations" default "-Os -pipe"Index:
buildroot.new/toolchain/binutils/binutils.mk
===================================================================toolchain/binutils/binutils.mk +5
-0@@ -65,6 +65,10 @@ BINUTILS_TARGET_CONFIG_OPTIONS+=--with-mpfr="$(MPFR_TARGET_DIR)" endif +ifeq ($(BR2_INTERWORKING_SUPPORT),y) +INTERWORKING_CONFIG_OPTION=--enable-interwork +endif + BINUTILS_OFFICIAL_VERSION:=$(BINUTILS_VERSION)$(VENDOR_SUFFIX)$(VENDOR_BINUTILS_RELEASE) ifeq ($(BR2_TOOLCHAIN_BUILDROOT),y) BINUTILS_PATCH_DIR:=toolchain/binutils/$(BINUTILS_VERSION)@@ -112,6 +116,7 @@ --disable-werror \ $(SOFT_FLOAT_CONFIG_OPTION) \ $(EXTRA_BINUTILS_CONFIG_OPTIONS) \ + $(INTERWORKING_CONFIG_OPTION) \ ) touch $@Index: buildroot.new/toolchain/gcc/Makefile.in
===================================================================toolchain/gcc/Makefile.in +4
-0@@ -65,6 +65,10 @@ endif endif +ifeq ($(BR2_INTERWORKING_SUPPORT),y) +EXTRA_GCC_CONFIG_OPTIONS+=--enable-interwork +endif + # AVR32 GCC configuration ifeq ($(strip $(BR2_avr32)),y) EXTRA_GCC_CONFIG_OPTIONS+=--disable-libmudflapIndex:
buildroot.new/toolchain/uClibc/uclibc.mk
===================================================================toolchain/uClibc/uclibc.mk +0
-0@@ -322,6 +322,13 @@ else $(SED) 's,^.*UCLIBC_HAS_WCHAR.*,UCLIBC_HAS_WCHAR=n,g'$(UCLIBC_DIR)/.oldconfig endif
toolchain/uClibc/uclibc.mk +3
-0+ifeq ($(BR2_INTERWORKING_SUPPORT),y) + $(SED) 's,^.*USE_BX.*,USE_BX=y,g' $(UCLIBC_DIR)/.oldconfig + $(SED)'s,^.*UCLIBC_EXTRA_CFLAGS.*,UCLIBC_EXTRA_CFLAGS="-mthumb-interwork",g' $(UCLIBC_DIR)/.oldconfig +else +
toolchain/uClibc/uclibc.mk +2
-0+ $(SED) 's,^.*USE_BX.*,USE_BX=n,g' $(UCLIBC_DIR)/.oldconfig +endif ifeq ($(BR2_UCLIBC_PROGRAM_INVOCATION),y) $(SED)'s,^.*UCLIBC_HAS_PROGRAM_INVOCATION_NAME.*,UCLIBC_HAS_PROGRAM_INVOCATION_NAME=y,g' $(UCLIBC_DIR)/.oldconfig else
Signature · 11 lines
Thomas Petazzoni, Free Electrons Free Embedded Linux Training Materials on http://free-electrons.com/training (More than 1500 pages!) -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 189 bytes Desc: not available Url : http://busybox.net/lists/buildroot/attachments/20080314/20868ae7/attachment.pgp
PATCH 1/1 Add thumb support to buildroot for the ARM architecture
Quoted 8 lines · Thomas Petazzoni
Hi,
Any comments on that ? Are you interested in merging such a patch ?
Thanks,
Thomas
Hi Thomas!
Thanks for your excellent work! Before committing your patch I have a question:
have you tested it? on which CPU? which buildroot configs?
I'm asking this because for almost half of year I did not managed to build a good ARM EABI toolchain with buildroot. Toolchain seems emit invalid instructions when building busybox. So I managed only to run
very simple hello-world when set in cmdline init=hello-world, but not a busybox binary with shell, etc.
Boot process just hangs when busybox running. Magic-SysRq key shows that illegal instruction trap was involved. What is surprising that rootfs can be launched ok on qemu with versatilepb machine emulation, but as I told fails to run on real hardware S3C2440 CPU - 920T target.
Regards,
Ivan
PATCH 1/1 Add thumb support to buildroot for the ARM architecture
Le Fri, 14 Mar 2008 15:33:08 +0200,
Ivan Kuten <[email protected]> a ?crit :
Quoted 2 lines
Thanks for your excellent work! Before committing your patch I have a
question: have you tested it? on which CPU? which buildroot configs?
Yes, I tested it using Qemu versatilepb emulation. Enclosed is the buildroot configuration I used.
Quoted 9 lines
I'm asking this because for almost half of year I did not managed to build a good ARM EABI toolchain with buildroot. Toolchain seems emit invalid instructions when building busybox. So I managed only to run very simple hello-world when set in cmdline init=hello-world, but not a busybox binary with shell, etc. Boot process just hangs when busybox running. Magic-SysRq key shows that illegal instruction trap was involved. What is surprising that rootfs can be launched ok on qemu with versatilepb machine emulation, but as I told fails to run on real hardware S3C2440 CPU - 920T target.
I have not tested on real hardware, so I can't say. There might be remaining issues.
However, there is quite a big difference between your S3C2440 real hardware and the Qemu versatilepb emulation. S3C2440 is based on 920T as you say, which supports the ARMv4T ISA. But the versatilepb emulation of Qemu emulates an ARM926EJ-S CPU, which supports the ARMv5TEJ ISA. And as far as I understood, there are some differences in the ARM <-> Thumb switch capabilities between ARMv4T and ARMv5T.
For what exact CPU did you configure your buildroot ? What was the exact instruction causing the "Illegal instruction" exception ?
Sincerly,
Thomas
Signature · 18 lines
Thomas Petazzoni, Free Electrons Free Embedded Linux Training Materials on http://free-electrons.com/training (More than 1500 pages!) -------------- next part -------------- A non-text attachment was scrubbed... Name: buildroot-config-with-interworking-and-thumb-applications Type: application/octet-stream Size: 9648 bytes Desc: not available Url : http://busybox.net/lists/buildroot/attachments/20080314/2a9ee424/attachment.obj -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 189 bytes Desc: not available Url : http://busybox.net/lists/buildroot/attachments/20080314/2a9ee424/attachment.pgp
PATCH 1/1 Add thumb support to buildroot for the ARM architecture
Le Fri, 14 Mar 2008 14:19:29 +0100,
Thomas Petazzoni <[email protected]> a ?crit :
Quoted 6 lines
However, there is quite a big difference between your S3C2440 real hardware and the Qemu versatilepb emulation. S3C2440 is based on 920T as you say, which supports the ARMv4T ISA. But the versatilepb emulation of Qemu emulates an ARM926EJ-S CPU, which supports the ARMv5TEJ ISA. And as far as I understood, there are some differences in the ARM <-> Thumb switch capabilities between ARMv4T and ARMv5T.
In particular, from the ARM architecture manual:
?
BL (H == 10 and H == 11 forms) is in all T variants. BLX (H == 01 form) is in T variants of ARMv5 and above. ?
So on your S3C2440, the 'blx' instruction is not supported. And this instruction can especially be used to do interworking. So if gcc generated this instruction, it of course will fail with the "illegal instruction" exception.
Sincerly,
Thomas
Signature · 11 lines
Thomas Petazzoni, Free Electrons Free Embedded Linux Training Materials on http://free-electrons.com/training (More than 1500 pages!) -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 189 bytes Desc: not available Url : http://busybox.net/lists/buildroot/attachments/20080314/729ea7f3/attachment.pgp
PATCH 1/1 Add thumb support to buildroot for the ARM architecture
Hi Thomas,
I compiled for ARM_920T & EABI & SOFTFLOAT.
I checked busybox binary ( arm-linux-objdump ) - there is no blx instruction.
Seems all these ARM troubles were related to avr32 patches (see recent posts in mailing list) because yesterday finally I managed to build working rootfs. However busybox binary seems resulted
in OABI format because when in kernel disable OABI_COMPAT - rootfs does not boot.
BR,
Ivan
Quoted 31 lines
Le Fri, 14 Mar 2008 14:19:29 +0100,
Thomas Petazzoni <[email protected]> a ?crit :Quoted 6 lines
However, there is quite a big difference between your S3C2440 real hardware and the Qemu versatilepb emulation. S3C2440 is based on 920T as you say, which supports the ARMv4T ISA. But the versatilepb emulation of Qemu emulates an ARM926EJ-S CPU, which supports the ARMv5TEJ ISA. And as far as I understood, there are some differences in the ARM <-> Thumb switch capabilities between ARMv4T and ARMv5T.
In particular, from the ARM architecture manual:
?
BL (H == 10 and H == 11 forms) is in all T variants. BLX (H == 01 form) is in T variants of ARMv5 and above. ?So on your S3C2440, the 'blx' instruction is not supported. And this instruction can especially be used to do interworking. So if gcc generated this instruction, it of course will fail with the "illegal instruction" exception.
Sincerly,
Thomas
--
Thomas Petazzoni, Free Electrons
Free Embedded Linux Training Materials
on http://free-electrons.com/training
(More than 1500 pages!)
PATCH 1/1 Add thumb support to buildroot for the ARM architecture
Le Sat, 22 Mar 2008 13:06:58 +0200 (EET),
"Ivan Kuten" <[email protected]> a ?crit :
Quoted 5 lines
I compiled for
ARM_920T& EABI & SOFTFLOAT.
I checked busybox binary ( arm-linux-objdump ) - there is no blx instruction. Seems all these ARM troubles were related to avr32 patches (see recent posts in mailing list) because yesterday finally I managed to build working rootfs.
Hum, maybe.
Quoted 2 lines
However busybox binary seems resulted in OABI format because when in kernel disable
OABI_COMPAT- rootfs does not boot.
Do you have CONFIG_EABI=y in your buildroot config file ?
But anyway, do you confirm that my patch works ?
Sincerly,
Thomas
Signature · 11 lines
Thomas Petazzoni, Free Electrons Free Embedded Linux Training Materials on http://free-electrons.com/training (More than 1500 pages!) -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 189 bytes Desc: not available Url : http://busybox.net/lists/buildroot/attachments/20080322/17173df4/attachment.pgp
PATCH 1/1 Add thumb support to buildroot for the ARM architecture
Hi,
Sure I had CONFIG_EABI enabled.
I tried to apply your patch - when ucLibc is configured ( BR2_UCLIBC_CONFIG=toolchain/uClibc/uClibc-0.9.29.config ) it is asking Target File Format:
1. FDPIC ELF
2. STATIC FLAT
3. STATIC FLAT (sep-data)
4. SHARED FLAT
What did you choose? If I choose FDPIC ELF I'm getting unrecognized command line option "-mfdpic" - when arm-linux-gcc is trying to build uClibc.
Regards,
Ivan
Quoted 24 lines
Quoted 5 lines
I compiled for
ARM_920T& EABI & SOFTFLOAT.
I checked busybox binary ( arm-linux-objdump ) - there is no blx instruction. Seems all these ARM troubles were related to avr32 patches (see recent posts in mailing list) because yesterday finally I managed to build working rootfs.Hum, maybe.
Quoted 2 lines
However busybox binary seems resulted in OABI format because when in kernel disable
OABI_COMPAT- rootfs does not boot.Do you have
CONFIG_EABI=yin your buildroot config file ?But anyway, do you confirm that my patch works ?
Sincerly,
Thomas
--
Thomas Petazzoni, Free Electrons
Free Embedded Linux Training Materials
on http://free-electrons.com/training
(More than 1500 pages!)
PATCH 1/1 Add thumb support to buildroot for the ARM architecture
In reply to Thomas PetazzoniLe Fri, 14 Mar 2008 09:03:31 +0100,
Thomas Petazzoni <[email protected]> a ?crit :
Quoted 1 line
Any comments on that ? Are you interested in merging such a patch ?
Still no interest in this patch ? Is the patch wrong ?
I can work on an improved version if comments are made.
Thanks!
Thomas
Signature · 11 lines
Thomas Petazzoni, Free Electrons Free Embedded Linux Training Materials on http://free-electrons.com/training (More than 1500 pages!) -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 189 bytes Desc: not available Url : http://busybox.net/lists/buildroot/attachments/20080319/a6424067/attachment.pgp
PATCH 1/1 Add thumb support to buildroot for the ARM architecture
Le Wed, 19 Mar 2008 17:16:15 +0100,
Thomas Petazzoni <[email protected]> a ?crit :
Quoted 3 lines
Quoted 1 line
Any comments on that ? Are you interested in merging such a patch ?
Still no interest in this patch ? Is the patch wrong ?
Up again. Initial patch sent two months ago, on March, 12th. Please tell me something: ?doesn't work, please fix?, ?we don't care about your stuff, it's useless? or ? works, but we would like this and this to be improved?.
Thanks,
Thomas
Signature · 11 lines
Thomas Petazzoni, Free Electrons Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 189 bytes Desc: not available Url : http://busybox.net/lists/buildroot/attachments/20080515/5adb23a2/attachment.pgp