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

Enable libstdc++ #144

Closed
wants to merge 12 commits into from
Closed
15 changes: 13 additions & 2 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,14 +1,25 @@
[submodule "crosstool-NG"]
path = crosstool-NG
url = https://github.com/jcmvbkbc/crosstool-NG
branch = lx106-g++
branch = xtensa-1.22.x
[submodule "lx106-hal"]
path = lx106-hal
url = https://github.com/tommie/lx106-hal
[submodule "esptool"]
path = esptool
url = https://github.com/pfalcon/esptool
url = https://github.com/themadinventor/esptool.git
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't plan to switch to upstream repo. See espressif/esptool#89 (comment) why.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, i see the reason. Does this mean that your esptool fork stays where it is not pulling changes from the origin? What about quite useful ones like cooking OTA images?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Of course no, I pull changes in (from time to time, especially after prodding), maintain my own changes on top from time to time, and hope to never need to revert anything (but still reserve a room for). I just pulled bunch of changes, would like to test them first before pulling the rest.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it. Looking forward to other comments.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The "--version=2" changes are needed. Without them there is no way to create a >512KB image (like the one sgi tests produce). Of course we could create a linker script which would create canonical 0x00000/0x40000 image of 1MB+ size but using OTA images and 1/2/4MB linker scripts already provided by Espressif seems to be a better solution, doesn't it?

[submodule "esp-open-lwip"]
path = esp-open-lwip
url = https://github.com/pfalcon/esp-open-lwip
branch = sdk-1.5.0
[submodule "esp_newlib_port"]
path = esp_newlib_port
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This patch should probably be split into three, each doing one thing:

  • add stdcpp port
  • fix ld-script-irom.patch
  • add sgi stl tests.

url = https://github.com/Sermus/esp_newlib_port.git
branch = lx106
[submodule "examples/esp8266_sgi_stl_tests"]
path = examples/esp8266_sgi_stl_tests
url = https://github.com/Sermus/esp8266_sgi_stl_tests.git
[submodule "esp_stdcpp_port"]
path = esp_stdcpp_port
url = https://github.com/Sermus/esp_stdcpp_port.git
branch = lx106
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably be folded into the patch adding esp_stdcpp_port

43 changes: 37 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ TOOLCHAIN = $(TOP)/xtensa-lx106-elf
# for supported versions.
VENDOR_SDK = 1.5.2

.PHONY: crosstool-NG toolchain libhal libcirom sdk

.PHONY: crosstool-NG toolchain libhal libcirom libstdc++irom libnlport libstdc++port sdk


TOP = $(PWD)
Expand Down Expand Up @@ -65,7 +64,7 @@ VENDOR_SDK_DIR_0.9.2 = esp_iot_sdk_v0.9.2



all: esptool libcirom standalone sdk sdk_patch $(TOOLCHAIN)/xtensa-lx106-elf/sysroot/usr/lib/libhal.a $(TOOLCHAIN)/bin/xtensa-lx106-elf-gcc lwip
all: esptool libcirom libstdc++irom libnlport libstdc++port standalone sdk sdk_patch $(TOOLCHAIN)/xtensa-lx106-elf/sysroot/usr/lib/libhal.a $(TOOLCHAIN)/bin/xtensa-lx106-elf-gcc lwip
@echo
@echo "Xtensa toolchain is built, to use it:"
@echo
Expand All @@ -90,13 +89,19 @@ ifeq ($(STANDALONE),y)
@cp -Rf sdk/lib/* $(TOOLCHAIN)/xtensa-lx106-elf/sysroot/usr/lib/
@echo "Installing vendor SDK linker scripts into toolchain sysroot"
@sed -e 's/\r//' sdk/ld/eagle.app.v6.ld | sed -e s@../ld/@@ >$(TOOLCHAIN)/xtensa-lx106-elf/sysroot/usr/lib/eagle.app.v6.ld
@sed -e 's/\r//' sdk/ld/eagle.app.v6.irom.ld | sed -e s@../ld/@@ >$(TOOLCHAIN)/xtensa-lx106-elf/sysroot/usr/lib/eagle.app.v6.irom.ld
@sed -e 's/\r//' sdk/ld/eagle.app.v6.new.2048.ld | sed -e s@../ld/@@ >$(TOOLCHAIN)/xtensa-lx106-elf/sysroot/usr/lib/eagle.app.v6.new.2048.ld
@sed -e 's/\r//' sdk/ld/eagle.app.v6.new.2048.irom.ld | sed -e s@../ld/@@ >$(TOOLCHAIN)/xtensa-lx106-elf/sysroot/usr/lib/eagle.app.v6.new.2048.irom.ld
@sed -e 's/\r//' sdk/ld/eagle.rom.addr.v6.ld >$(TOOLCHAIN)/xtensa-lx106-elf/sysroot/usr/lib/eagle.rom.addr.v6.ld
@echo "Installing port lib headers into toolchain sysroot"
@cp -Rf esp_stdcpp_port/cpp_routines.h $(TOOLCHAIN)/xtensa-lx106-elf/sysroot/usr/include/cpp_routines.h
endif

clean: clean-sdk
make -C crosstool-NG clean MAKELEVEL=0
make -C esp_newlib_port clean MAKELEVEL=0
-rm -rf crosstool-NG/.build/src
-rm -f crosstool-NG/local-patches/gcc/4.8.2/1000-*
-rm -f crosstool-NG/local-patches/gcc/4.8.5/1000-*
-rm -rf $(TOOLCHAIN)


Expand All @@ -107,7 +112,7 @@ esptool: toolchain
toolchain: $(TOOLCHAIN)/bin/xtensa-lx106-elf-gcc

$(TOOLCHAIN)/bin/xtensa-lx106-elf-gcc: crosstool-NG/ct-ng
cp -f 1000-mforce-l32.patch crosstool-NG/local-patches/gcc/4.8.2/
cp -f 1000-mforce-l32.patch crosstool-NG/local-patches/gcc/4.8.5/
make -C crosstool-NG -f ../Makefile _toolchain

_toolchain:
Expand Down Expand Up @@ -143,9 +148,16 @@ $(TOOLCHAIN)/xtensa-lx106-elf/sysroot/lib/libcirom.a: $(TOOLCHAIN)/xtensa-lx106-
$(TOOLCHAIN)/bin/xtensa-lx106-elf-objcopy --rename-section .text=.irom0.text \
--rename-section .literal=.irom0.literal $(<) $(@);

libstdc++irom: $(TOOLCHAIN)/xtensa-lx106-elf/sysroot/lib/libstdc++irom.a

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

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

$(TOOLCHAIN)/xtensa-lx106-elf/sysroot/usr/lib/libhal.a: $(TOOLCHAIN)/bin/xtensa-lx106-elf-gcc
$(TOOLCHAIN)/xtensa-lx106-elf/sysroot/usr/lib/libhal.a: $(TOOLCHAIN)/bin/xtensa-lx106-elf-gcc
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stray whitespace change

make -C lx106-hal -f ../Makefile _libhal

_libhal:
Expand All @@ -154,7 +166,23 @@ _libhal:
PATH=$(TOOLCHAIN)/bin:$(PATH) make
PATH=$(TOOLCHAIN)/bin:$(PATH) make install

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

$(TOOLCHAIN)/xtensa-lx106-elf/sysroot/usr/lib/libnlport.a: $(TOOLCHAIN)/bin/xtensa-lx106-elf-gcc sdk sdk_patch toolchain standalone
make -C esp_newlib_port -f ../Makefile _libnlport
cp -f esp_newlib_port/libnlport.a $(TOOLCHAIN)/xtensa-lx106-elf/sysroot/usr/lib/libnlport.a

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This patch should probably be folded into the "Build procedure for libnlport.a. esp_newlib_port switched to lx106 branch".

_libnlport:
PATH=$(TOOLCHAIN)/bin:$(PATH) make

libstdc++port: $(TOOLCHAIN)/xtensa-lx106-elf/sysroot/usr/lib/libstdc++port.a

$(TOOLCHAIN)/xtensa-lx106-elf/sysroot/usr/lib/libstdc++port.a: $(TOOLCHAIN)/bin/xtensa-lx106-elf-gcc sdk sdk_patch toolchain standalone
make -C esp_stdcpp_port -f ../Makefile _libstdc++port
cp -f esp_stdcpp_port/libstdc++port.a $(TOOLCHAIN)/xtensa-lx106-elf/sysroot/usr/lib/libstdc++port.a

_libstdc++port:
PATH=$(TOOLCHAIN)/bin:$(PATH) make

sdk: $(VENDOR_SDK_DIR)/.dir
ln -snf $(VENDOR_SDK_DIR) sdk
Expand All @@ -169,6 +197,9 @@ sdk_patch: $(VENDOR_SDK_DIR)/.dir .sdk_patch_$(VENDOR_SDK)
.sdk_patch_1.5.2:
echo -e "#undef ESP_SDK_VERSION\n#define ESP_SDK_VERSION 010502" >>$(VENDOR_SDK_DIR)/include/esp_sdk_ver.h
$(PATCH) -d $(VENDOR_SDK_DIR) -p1 < c_types-c99.patch
cp -f $(VENDOR_SDK_DIR)/ld/eagle.app.v6.ld $(VENDOR_SDK_DIR)/ld/eagle.app.v6.irom.ld
cp -f $(VENDOR_SDK_DIR)/ld/eagle.app.v6.new.2048.ld $(VENDOR_SDK_DIR)/ld/eagle.app.v6.new.2048.irom.ld
$(PATCH) -d $(VENDOR_SDK_DIR) -p1 < ld-script-irom.patch
cd $(VENDOR_SDK_DIR)/lib; mkdir -p tmp; cd tmp; $(TOOLCHAIN)/bin/xtensa-lx106-elf-ar x ../libcrypto.a; cd ..; $(TOOLCHAIN)/bin/xtensa-lx106-elf-ar rs libwpa.a tmp/*.o
@touch $@

Expand Down
2 changes: 1 addition & 1 deletion crosstool-NG
Submodule crosstool-NG updated 1032 files
1 change: 1 addition & 0 deletions esp_newlib_port
Submodule esp_newlib_port added at ba654a
1 change: 1 addition & 0 deletions esp_stdcpp_port
Submodule esp_stdcpp_port added at c03814
2 changes: 1 addition & 1 deletion esptool
1 change: 1 addition & 0 deletions examples/esp8266_sgi_stl_tests
Submodule esp8266_sgi_stl_tests added at 98101d
119 changes: 119 additions & 0 deletions ld-script-irom.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
--- esp_iot_sdk_v1.5.2/ld/eagle.app.v6.irom.ld.orig 2016-03-28 16:48:11.422256241 +0300
+++ esp_iot_sdk_v1.5.2/ld/eagle.app.v6.irom.ld 2016-03-29 07:47:48.860099060 +0300
PHDRS
@@ -102,11 +102,14 @@
*(.gnu.linkonce.e.*)
*(.gnu.version_r)
*(.eh_frame)
+ . = (. + 3) & ~ 3;
/* C++ constructor and destructor tables, properly ordered: */
+ __init_array_start = ABSOLUTE(.);
KEEP (*crtbegin.o(.ctors))
KEEP (*(EXCLUDE_FILE (*crtend.o) .ctors))
KEEP (*(SORT(.ctors.*)))
KEEP (*(.ctors))
+ __init_array_end = ABSOLUTE(.);
KEEP (*crtbegin.o(.dtors))
KEEP (*(EXCLUDE_FILE (*crtend.o) .dtors))
KEEP (*(SORT(.dtors.*)))
@@ -151,6 +154,15 @@
} >dram0_0_seg :dram0_0_bss_phdr
/* __stack = 0x3ffc8000; */

+ .irom0.text : ALIGN(4)
+ {
+ _irom0_text_start = ABSOLUTE(.);
+ *(.irom0.literal .irom.literal .irom.text.literal .irom0.text .irom.text)
+ *(.literal.* .text.*)
+ *libm.a:(.literal .text .literal.* .text.*)
+ _irom0_text_end = ABSOLUTE(.);
+ } >irom0_0_seg :irom0_0_phdr
+
.text : ALIGN(4)
{
_stext = .;
@@ -182,7 +194,7 @@
*(.entry.text)
*(.init.literal)
*(.init)
- *(.literal .text .literal.* .text.* .stub .gnu.warning .gnu.linkonce.literal.* .gnu.linkonce.t.*.literal .gnu.linkonce.t.*)
+ *(.literal .text .stub .gnu.warning .gnu.linkonce.literal.* .gnu.linkonce.t.*.literal .gnu.linkonce.t.*)
*(.fini.literal)
*(.fini)
*(.gnu.version)
@@ -198,14 +210,8 @@
*(.gnu.linkonce.lit4.*)
_lit4_end = ABSOLUTE(.);
} >iram1_0_seg :iram1_0_phdr
-
- .irom0.text : ALIGN(4)
- {
- _irom0_text_start = ABSOLUTE(.);
- *(.irom0.literal .irom.literal .irom.text.literal .irom0.text .irom.text)
- _irom0_text_end = ABSOLUTE(.);
- } >irom0_0_seg :irom0_0_phdr
}

/* get ROM code address */
INCLUDE "../ld/eagle.rom.addr.v6.ld"
+

--- esp_iot_sdk_v1.5.2/ld/eagle.app.v6.new.2048.irom.ld.orig 2016-03-28 16:48:11.422256241 +0300
+++ esp_iot_sdk_v1.5.2/ld/eagle.app.v6.new.2048.irom.ld 2016-03-29 07:47:48.860099060 +0300
PHDRS
@@ -102,11 +102,14 @@
*(.gnu.linkonce.e.*)
*(.gnu.version_r)
*(.eh_frame)
+ . = (. + 3) & ~ 3;
/* C++ constructor and destructor tables, properly ordered: */
+ __init_array_start = ABSOLUTE(.);
KEEP (*crtbegin.o(.ctors))
KEEP (*(EXCLUDE_FILE (*crtend.o) .ctors))
KEEP (*(SORT(.ctors.*)))
KEEP (*(.ctors))
+ __init_array_end = ABSOLUTE(.);
KEEP (*crtbegin.o(.dtors))
KEEP (*(EXCLUDE_FILE (*crtend.o) .dtors))
KEEP (*(SORT(.dtors.*)))
@@ -151,6 +154,15 @@
} >dram0_0_seg :dram0_0_bss_phdr
/* __stack = 0x3ffc8000; */

+ .irom0.text : ALIGN(4)
+ {
+ _irom0_text_start = ABSOLUTE(.);
+ *(.irom0.literal .irom.literal .irom.text.literal .irom0.text .irom.text)
+ *(.literal.* .text.*)
+ *libm.a:(.literal .text .literal.* .text.*)
+ _irom0_text_end = ABSOLUTE(.);
+ } >irom0_0_seg :irom0_0_phdr
+
.text : ALIGN(4)
{
_stext = .;
@@ -182,7 +194,7 @@
*(.entry.text)
*(.init.literal)
*(.init)
- *(.literal .text .literal.* .text.* .stub .gnu.warning .gnu.linkonce.literal.* .gnu.linkonce.t.*.literal .gnu.linkonce.t.*)
+ *(.literal .text .stub .gnu.warning .gnu.linkonce.literal.* .gnu.linkonce.t.*.literal .gnu.linkonce.t.*)
*(.fini.literal)
*(.fini)
*(.gnu.version)
@@ -198,14 +210,8 @@
*(.gnu.linkonce.lit4.*)
_lit4_end = ABSOLUTE(.);
} >iram1_0_seg :iram1_0_phdr
-
- .irom0.text : ALIGN(4)
- {
- _irom0_text_start = ABSOLUTE(.);
- *(.irom0.literal .irom.literal .irom.text.literal .irom0.text .irom.text)
- _irom0_text_end = ABSOLUTE(.);
- } >irom0_0_seg :irom0_0_phdr
}

/* get ROM code address */
INCLUDE "../ld/eagle.rom.addr.v6.ld"
+