Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compile newlib with -ffunction_sections and -Os #3

Merged
merged 1 commit into from
Nov 12, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions 9000-malloc-provided.patch

This file was deleted.

12 changes: 12 additions & 0 deletions 9000-newlib-flags.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
--- a/newlib/configure.host 2015-11-12 14:04:48.064467034 +0000
+++ b/newlib/configure.host 2015-11-12 14:07:45.645532708 +0000
@@ -285,7 +285,8 @@
xtensa)
libm_machine_dir=xtensa
machine_dir=xtensa
- newlib_cflags="${newlib_cflags} -mlongcalls"
+ newlib_cflags="${newlib_cflags} -mlongcalls -ffunction-sections -mtext-section-literals -Os"
+ newlib_cflags="${newlib_cflags} -DMALLOC_PROVIDED"
newlib_cflags="${newlib_cflags} -DREENTRANT_SYSCALLS_PROVIDED"
;;
z8k)
22 changes: 22 additions & 0 deletions 9001-newlib-strcmp-literals.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
--- a/newlib/libc/machine/xtensa/strcmp.S 2015-11-12 16:23:00.623220071 +0000
+++ b/newlib/libc/machine/xtensa/strcmp.S 2015-11-12 18:00:14.995375550 +0000
@@ -26,6 +26,8 @@
#define MASK4 0x40404040


+ .align 4
+ .literal_position
#if XCHAL_HAVE_L32R
.literal .Lmask0, MASK0
.literal .Lmask1, MASK1
@@ -33,10 +35,6 @@
.literal .Lmask3, MASK3
.literal .Lmask4, MASK4
#endif /* XCHAL_HAVE_L32R */
-
- .text
- .align 4
- .literal_position
.global strcmp
.type strcmp, @function
strcmp:
45 changes: 30 additions & 15 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,12 @@ VENDOR_SDK_ZIP_0.9.2 = esp_iot_sdk_v0.9.2_14_10_24.zip
VENDOR_SDK_DIR_0.9.2 = esp_iot_sdk_v0.9.2
STANDALONE = y

.PHONY: crosstool-NG toolchain libhal libcirom sdk
.PHONY: crosstool-NG toolchain libhal sdk

all: esptool libcirom standalone sdk sdk_patch $(TOOLCHAIN)/xtensa-lx106-elf/sysroot/usr/lib/libhal.a $(TOOLCHAIN)/bin/xtensa-lx106-elf-gcc
LIBHAL := $(TOOLCHAIN)/xtensa-lx106-elf/sysroot/usr/lib/libhal.a
LIBGCC := $(TOOLCHAIN)/lib/gcc/xtensa-lx106-elf/4.8.2/libgcc.a

all: esptool standalone sdk .sdk_patch $(LIBHAL) $(TOOLCHAIN)/bin/xtensa-lx106-elf-gcc
@echo
@echo "Xtensa toolchain is built, to use it:"
@echo
Expand All @@ -66,14 +69,14 @@ endif
esptool: toolchain
cp esptool/esptool.py $(TOOLCHAIN)/bin/

$(TOOLCHAIN)/xtensa-lx106-elf/sysroot/lib/libcirom.a: $(TOOLCHAIN)/xtensa-lx106-elf/sysroot/lib/libc.a $(TOOLCHAIN)/bin/xtensa-lx106-elf-gcc
@echo "Creating irom version of libc..."
$(TOOLCHAIN)/bin/xtensa-lx106-elf-objcopy --rename-section .text=.irom0.text \
--rename-section .literal=.irom0.literal $(<) $(@);

libcirom: $(TOOLCHAIN)/xtensa-lx106-elf/sysroot/lib/libcirom.a

sdk_patch: .sdk_patch_$(VENDOR_SDK)
.sdk_patch: .sdk_patch_$(VENDOR_SDK) $(TOOLCHAIN)/bin/xtensa-lx106-elf-gcc
for l in sdk/lib/lib*.a; do \
$(TOOLCHAIN)/bin/xtensa-lx106-elf-objcopy \
--rename-section .text=.fast.text \
--rename-section .irom0.text=.text \
$$l; \
done
@touch $@

.sdk_patch_1.4.1:
patch -N -d $(VENDOR_SDK_DIR_1.4.1) -p1 < c_types-c99.patch
Expand Down Expand Up @@ -166,7 +169,7 @@ empty_user_rf_pre_init.o: empty_user_rf_pre_init.c $(TOOLCHAIN)/bin/xtensa-lx106
cp FRM_ERR_PATCH/*.a $(VENDOR_SDK_DIR)/lib/
@touch $@

standalone: sdk sdk_patch toolchain
standalone: sdk .sdk_patch toolchain
ifeq ($(STANDALONE),y)
@echo "Installing vendor SDK headers into toolchain sysroot"
@cp -Rf sdk/include/* $(TOOLCHAIN)/xtensa-lx106-elf/sysroot/usr/include/
Expand Down Expand Up @@ -261,23 +264,35 @@ esp_iot_sdk_v0.9.3_14_11_21.zip:
esp_iot_sdk_v0.9.2_14_10_24.zip:
wget --content-disposition "http://bbs.espressif.com/download/file.php?id=9"

libhal: $(TOOLCHAIN)/xtensa-lx106-elf/sysroot/usr/lib/libhal.a
libhal: $(LIBHAL) .patch_libhal

$(TOOLCHAIN)/xtensa-lx106-elf/sysroot/usr/lib/libhal.a: $(TOOLCHAIN)/bin/xtensa-lx106-elf-gcc
$(LIBHAL): $(TOOLCHAIN)/bin/xtensa-lx106-elf-gcc
make -C lx106-hal -f ../Makefile _libhal

.patch_libhal: $(LIBHAL)
$(TOOLCHAIN)/bin/xtensa-lx106-elf-objcopy \
--rename-section .text=.fast.text \
$(LIBHAL)
@touch $@

_libhal:
autoreconf -i
PATH=$(TOOLCHAIN)/bin:$(PATH) ./configure --host=xtensa-lx106-elf --prefix=$(TOOLCHAIN)/xtensa-lx106-elf/sysroot/usr
PATH=$(TOOLCHAIN)/bin:$(PATH) make
PATH=$(TOOLCHAIN)/bin:$(PATH) make install


toolchain: $(TOOLCHAIN)/bin/xtensa-lx106-elf-gcc
toolchain: $(TOOLCHAIN)/bin/xtensa-lx106-elf-gcc .patch_libgcc

$(TOOLCHAIN)/bin/xtensa-lx106-elf-gcc: crosstool-NG/ct-ng
make -C crosstool-NG -f ../Makefile _toolchain

.patch_libgcc: $(TOOLCHAIN)/bin/xtensa-lx106-elf-gcc
$(TOOLCHAIN)/bin/xtensa-lx106-elf-objcopy \
--rename-section .text=.fast.text \
$(LIBGCC)
@touch $@

_toolchain:
./ct-ng xtensa-lx106-elf
sed -r -i.org s%CT_PREFIX_DIR=.*%CT_PREFIX_DIR="$(TOOLCHAIN)"% .config
Expand All @@ -289,7 +304,7 @@ _toolchain:
crosstool-NG: crosstool-NG/ct-ng

crosstool-NG/ct-ng: crosstool-NG/bootstrap
cp 9000-malloc-provided.patch crosstool-NG/local-patches/newlib/2.0.0
cp *-newlib-*.patch crosstool-NG/local-patches/newlib/2.0.0
make -C crosstool-NG -f ../Makefile _ct-ng

_ct-ng:
Expand Down