[U-Boot] [PATCH v2] arm: build arch memset/memcpy in Thumb2 mode

Bill Pringlemeir bpringlemeir at nbsps.com
Wed Dec 3 16:44:41 CET 2014


I tested these changes on several compilers and binutils.  4.3.3, 4.6.3,
4.7.2, 4.8.2 and 4.9.2 gcc with binutils 2.19, 2.21-24 in both THUMB and
ARM on the Vybrid.  It seem we must have an image <= 224kB which is the
IRAM bank0 size - 0x8000 of u-boot base; u-boot since v2014.04 will not
boot for me as the QSPI seemed to take it over this boundary.

The attached patches are meant to be attached as they aren't meant to be
taken by patchworks, etc but just to show the small changes I made to
minimize the image to less than 224kB.

[build script]
# File sizes similar because of 'mkimage' padding+hdr for 'imx'.
# 2nd size is for the 'thumb2' builds.
set -e

## (Sourcery CodeBench Lite 2012.03-56) 4.6.3
## (Sourcery CodeBench Lite 2012.03-56) 2.21.53.20110905
# 227092 Dec  1 15:20 u-boot.imx
# 173844 Dec  1 15:36 u-boot.imx
export PATH=$PATH:$HOME/x-tools/arm-2012.03/bin

## 4.7.4 20130913 (release) [ARM/embedded-4_7-branch revision 202601]
## GNU assembler (GNU Binutils) 2.23.2
# 222996 Dec  1 15:19 u-boot.imx
# 173844 Dec  1 15:35 u-boot.imx
#export PATH=$PATH:$HOME/x-tools/arm-2013.q3/bin

## (crosstool-NG hg+default-9838aecd6340) 4.8.2
## (GNU Binutils) 2.23.2
# 222996 Dec  1 15:18 u-boot.imx
# 173844 Dec  1 15:34 u-boot.imx
#export PATH=$PATH:$HOME/x-tools/arm-none-eabi/bin

## (Sourcery G++ Lite 2009q1-161) 4.3.3
## (Sourcery G++ Lite 2009q1-161) 2.19.51.20090205
# 218900 Dec  1 15:17 u-boot.imx - no CONFIG_SYS_LONGHELP
# GCC does not produce working THUMB binaries.
#export PATH=$PATH:/opt/arm-2009q1/bin
NAME=arm-none-eabi-

## (crosstool-NG 1.20.0) 4.9.2
## (crosstool-NG 1.20.0) 2.24
# 222996 Dec  1 15:21 u-boot.imx
# 173844 Dec  1 15:32 u-boot.imx
#export PATH=$PATH:$HOME/x-tools/arm-none-linux-gnueabi-vybrid-4.9.2/bin/

## (crosstool-NG hg+default-2a773bd38e71) 4.7.3
## (crosstool-NG hg+default-2a773bd38e71) 2.22
# 222996 Dec  1 15:22 u-boot.imx
# 173844 Dec  1 15:31 u-boot.imx
#export PATH=$PATH:$HOME/x-tools/arm-none-linux-gnueabi-4.7.2/bin

## (crosstool-NG hg+-c7fa97debb36) 4.6.3
## (crosstool-NG hg+-c7fa97debb36) 2.21.1
# 227092 Dec  1 15:24 u-boot.imx
# 173844 Dec  1 15:30 u-boot.imx
#export PATH=$PATH:$HOME/x-tools/arm-none-linux-gnueabi.gcc4.6.3/bin
#NAME=arm-none-linux-gnueabi-

## (Timesys 20130708) 4.7.3
## (Timesys 20130708) 2.23.2
# 227092 Dec  1 15:25 u-boot.imx
# 173844 Dec  1 15:29 u-boot.imx
#export PATH=$PATH:$HOME/x-tools/armv7l-timesys-linux-gnueabi/bin
#NAME=armv7l-timesys-linux-gnueabi-

## (crosstool-NG linaro-1.13.1-4.8-2013.10 - Linaro GCC 2013.10) 4.8.2 20131014
## (crosstool-NG linaro-1.13.1-4.8-2013.10 - Linaro GCC 2013.10) 2.23.2.20130610 Linaro 2013.10-4
# 222996 Dec  1 15:26 u-boot.imx
# 173844 Dec  1 15:28 u-boot.imx
#export PATH=$PATH:$HOME/x-tools/gcc-linaro-arm-linux-gnueabihf-4.8-2013.10_linux/bin
#NAME=arm-linux-gnueabihf-

make CROSS_COMPILE=$NAME vf610twr_config
make CROSS_COMPILE=$NAME $* u-boot.imx
cp u-boot.imx /srv/tftp

[end script]

I applied Stefan's memcpy/thumb patch, reverted c6150aaf and applied
'fs/ext4/ext4fs.c, fs/fs.c fs/fat/fat_write.c: Adjust 64bit math
methods' by Tom Rini <trini at ti.com> (it has a little whitespace fat in
it).  All of the images booted on a Vybrid Tower (Rev H) from an SD
card.  Only issue is that I think the 'AFLAGS_NOWARN' can be removed as
per below...

On 21 Nov 2014, stefan at agner.ch wrote:

> Resynchronize memcpy/memset with kernel and build them explicitly
> in Thumb2 mode (unified syntax). Those assembler files can be
> built and linked in ARM mode too, however when calling them from
> Thumb2 built code, the stack got corrupted and the copy did not
> succeed (the exact details have not been traced back). Hoever,
> the Linux kernel builds those files in Thumb2 mode. Hence U-Boot
> should build them in Thumb2 mode too when CONFIG_SYS_THUMB_BUILD
> is set.

> To build the files without warning, some assembler instructions
> had to be replaced with their UAL compliant variant (thanks
> Jeroen for this input).

> To build the file in Thumb2 mode the implicit-it=always option need
> to be set to generate Thumb2 compliant IT instructions where needed.
> We add this option to the general AFLAGS when building for Thumb2.

> Signed-off-by: Stefan Agner <stefan at agner.ch>
> ---
> Changes since v1: - Don't set auto-it in AFLAGS - Removed
> "no-warn-deprecated" warning suppression - Converted non-UAL assembler
> instructions to their UAL compliant variants

> Tested in ARM and Thumb2 mode on Vybrid SoC. Disassembled the memset/
> memcpy object files before and after converting the instructions to
> UAL, the output was identical.
>
> arch/arm/config.mk | 4 +- arch/arm/include/asm/assembler.h | 33
> ++++++++++-- arch/arm/lib/memcpy.S | 80 +++++++++++++++++++---------
> arch/arm/lib/memset.S | 112 ++++++++++++++++++++------------------- 4
> files changed, 142 insertions(+), 87 deletions(-)
>
> diff --git a/arch/arm/config.mk b/arch/arm/config.mk
> index f0eafd6..14f4e9f 100644
> --- a/arch/arm/config.mk
> +++ b/arch/arm/config.mk
> @@ -26,7 +26,9 @@ PLATFORM_CPPFLAGS += -D__ARM__
>
> # Choose between ARM/Thumb instruction sets ifeq
> ($(CONFIG_SYS_THUMB_BUILD),y) -PF_CPPFLAGS_ARM := $(call cc-option,
> -mthumb -mthumb-interwork,\ +AFLAGS_IMPLICIT_IT := $(call
> as-option,-Wa$(comma)-mimplicit-it=always) +PF_CPPFLAGS_ARM :=
> $(AFLAGS_IMPLICIT_IT) $(AFLAGS_NOWARN) \ + $(call cc-option, -mthumb

I don't think we need the '$(AFLAGS_NOWARN)' as you fixed that?  I
removed it during my tests and didn't see anything.  Especially all
builds produced output.  I guess this is copy/paste from a Linux
Makefile as I don't even see where it is set in U-Boot.

> -mthumb-interwork,\ $(call cc-option,-marm,)\ $(call
> cc-option,-mno-thumb-interwork,)\ ) diff --git
> a/arch/arm/include/asm/assembler.h b/arch/arm/include/asm/assembler.h
> index 5e4789b..11b80fb 100644 --- a/arch/arm/include/asm/assembler.h
> +++ b/arch/arm/include/asm/assembler.h @@ -14,12 +14,14 @@ * assembler
> source.  */

[snip]

Tested-by: Bill Pringlemeir <bpringlemeir at nbsps.com>

-------------- next part --------------
A non-text attachment was scrubbed...
Name: thumb-mode.patch
Type: text/x-diff
Size: 1155 bytes
Desc: patches to 2015.01-rc2
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20141203/fdc2d39f/attachment.patch>


More information about the U-Boot mailing list