Skip to content

Commit

Permalink
Revive target: ESP8266
Browse files Browse the repository at this point in the history
This patch updates ESP8266 build system and code base as well.
 - Removed unnecessary files.
 - Decreased code size.
 - Refactored jerry_{port, extapi, run}.c to make it more easy to handle.
 - Readme.md is updated as well which contains detailed step by step description about how to set up environment and use JerryScript.

Finally, it solves the related issue #1375.

JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik [email protected]
  • Loading branch information
rerobika authored and yichoi committed Nov 8, 2017
1 parent bdcd2d8 commit c3a9821
Show file tree
Hide file tree
Showing 18 changed files with 324 additions and 915 deletions.
55 changes: 36 additions & 19 deletions targets/esp8266/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,16 @@ SPECIAL_MKTARGETS=$(APP_MKTARGETS)
SUBDIRS= user
endif # } PDIR

# path to the JERRYSCRIPT directory
JERRYDIR ?= $(CURDIR)/../../..

LDDIR = $(SDK_PATH)/ld

#############################################################
# JerryScript requires a modified linker script with specified alignments
# so we use it instead of the original one from SDK.
JERRY_LD_FILE = $(CURDIR)/ld/eagle.app.v6.ld

CCFLAGS += -Os
#CCFLAGS += -O0

Expand All @@ -52,53 +60,61 @@ TARGET_LDFLAGS = \
--text-section-literals

ifeq ($(FLAVOR),debug)
TARGET_LDFLAGS += -O0
TARGET_LDFLAGS += -O0 -g
endif

ifeq ($(FLAVOR),release)
TARGET_LDFLAGS += -Os
endif

COMPONENTS_eagle.app.v6 = \
user/libuser.a \

user/libuser.a

LINKFLAGS_eagle.app.v6 = \
-L$(SDK_PATH)/lib \
-Wl,--gc-sections \
-Wl,-Map,output.map \
-nostdlib \
-T$(LD_FILE) \
-T$(JERRY_LD_FILE) \
-Wl,--no-check-sections \
-u call_user_start \
-Wl,-static \
-Wl,--start-group \
-lminic \
-lcirom \
-lcrypto \
-lespconn \
-lespnow \
-lfreertos \
-lgcc \
-lhal \
-ljson \
-llwip \
-ldriver \
-lmain \
-lmesh \
-lmirom \
-lnet80211 \
-lnopoll \
-lphy \
-lpp \
-lnet80211 \
-lpwm \
-lsmartconfig \
-lspiffs \
-lssl \
-lwpa \
-lmain \
-lfreertos \
-llwip \
-lwps \
-L./libs \
-ljerrycore \
-ljerryentry \
-ljerrylibm \
-ljerry-core \
-ljerry-libm \
$(DEP_LIBS_eagle.app.v6) \
./libs/lib_a-setjmp.o \
-Wl,--end-group


DEPENDS_eagle.app.v6 = \
$(LD_FILE) \
$(JERRY_LD_FILE) \
$(LDDIR)/eagle.rom.addr.v6.ld \
./source/jerry-targetjs.h \
./libs/libjerrylibm.a \
./libs/libjerrycore.a \
./libs/libjerryentry.a
./include/jerry-targetjs.h \
./libs/libjerry-core.a \
./libs/libjerry-libm.a


#############################################################
Expand Down Expand Up @@ -138,6 +154,7 @@ DDEFINES += \
# Required for each makefile to inherit from the parent
#

INCLUDES := -I $(JERRYDIR)/jerry-core/include
INCLUDES := $(INCLUDES) -I $(PDIR)include -I $(PDIR)source
sinclude $(SDK_PATH)/Makefile

Expand Down
86 changes: 25 additions & 61 deletions targets/esp8266/Makefile.esp8266
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.

# use TAB-8

CURDIR = `pwd`
ESP_SDK_PATH ?= $(SDK_PATH)
ESP_INC = $(ESP_SDK_PATH)/extra_include
ESP_INC2 = $(ESP_SDK_PATH)/include
ESP_LIB = $(ESP_SDK_PATH)/lib
TYPE = release
INTERM = build/obj-esp8266
OUTPUT = build/bin/$(TYPE).esp8266
SRCPATH = targets/esp8266/source
ESP_LIB = $(SDK_PATH)/lib
BUILD_DIR = build/obj-esp8266
COPYTARGET = targets/esp8266/libs
USBDEVICE ?= /dev/ttyUSB0
JERRYHEAP ?= 20
Expand All @@ -31,76 +23,50 @@ ESPTOOL ?= /opt/Espressif/esptool-py/esptool.py
# compile flags
ESP_CFLAGS := -D__TARGET_ESP8266 -D__attr_always_inline___=

MFORCE32 = `xtensa-lx106-elf-gcc --help=target | grep mforce-l32`
MFORCE32 = $(shell xtensa-lx106-elf-gcc --help=target | grep mforce-l32)

ifneq ($(MFORCE32),)
# Your compiler supports the -mforce-l32 flag which means that
# constants can be placed in ROM to free additional RAM
ESP_CFLAGS += -DJERRY_CONST_DATA="__attribute__((aligned(4))) __attribute__((section(\".irom.text\")))"
ESP_CFLAGS += -mforce-l32
endif

ESP_CFLAGS += -Wl,-EL -fno-inline-functions
ESP_CFLAGS += -ffunction-sections -fdata-sections
ESP_CFLAGS += -mlongcalls -mtext-section-literals -mno-serialize-volatile
ifneq ($(MFORCE32),)
ESP_CFLAGS += -mforce-l32
endif

# include path
ESP_LIBS_INC :=$(CURDIR)/targets/esp8266/include
ESP_LIBS_INC :=$(ESP_LIBS_INC);$(ESP_INC2)
ESP_LIBS_INC :=$(ESP_LIBS_INC);$(ESP_INC2)/espressif
ESP_LIBS_INC :=$(ESP_LIBS_INC);$(ESP_INC2)/freertos
ESP_LIBS_INC :=$(ESP_LIBS_INC);$(ESP_INC2)/json
ESP_LIBS_INC :=$(ESP_LIBS_INC);$(ESP_INC2)/lwip
ESP_LIBS_INC :=$(ESP_LIBS_INC);$(ESP_INC2)/ssl

# jerry related source files
JERRY_BUILD_FILES := $(SRCPATH)/jerry_extapi.c
JERRY_BUILD_FILES := $(JERRY_BUILD_FILES);$(SRCPATH)/jerry_run.c


.PHONY: jerry js2c mkbin check-env flash clean


all: check-env jerry js2c mkbin


jerry:
mkdir -p $(INTERM)
mkdir -p $(OUTPUT)
mkdir -p $(BUILD_DIR)
mkdir -p $(COPYTARGET)
cmake -B$(INTERM) -H./ \
cmake -B$(BUILD_DIR) -H./ \
-DENABLE_LTO=OFF \
-DENABLE_VALGRIND=OFF \
-DCMAKE_TOOLCHAIN_FILE=build/configs/toolchain_external.cmake \
-DFEATURE_VALGRIND=OFF \
-DCMAKE_TOOLCHAIN_FILE=cmake/toolchain_external.cmake \
-DEXTERNAL_CMAKE_SYSTEM_PROCESSOR=xtensia-lx106 \
-DEXTERNAL_CMAKE_C_COMPILER=xtensa-lx106-elf-gcc \
-DEXTERNAL_CMAKE_C_COMPILER_ID=GNU \
-DEXTERNAL_BUILD_ENTRY_FILE="$(JERRY_BUILD_FILES)" \
-DJERRY_LIBC=OFF \
-DJERRY_LIBM=ON \
-DJERRY_CMDLINE=OFF \
-DENABLE_ALL_IN_ONE=ON \
-DEXTERNAL_COMPILE_FLAGS="$(ESP_CFLAGS)" \
-DEXTERNAL_LIBC_INTERFACE="$(ESP_INC)" \
-DEXTERNAL_LIBS_INTERFACE="$(ESP_LIBS_INC)" \
-DEXTERNAL_MEM_HEAP_SIZE_KB=$(JERRYHEAP)

make -C $(INTERM) $(TYPE).external
cp `cat $(INTERM)/$(TYPE).external/list` $(OUTPUT)/.
cp $(OUTPUT)/lib$(TYPE).jerry-core.a $(COPYTARGET)/libjerrycore.a
cp $(OUTPUT)/lib$(TYPE).jerry-libm.lib.a $(COPYTARGET)/libjerrylibm.a
cp $(INTERM)/lib$(TYPE).external-entry.a $(OUTPUT)/.
cp $(OUTPUT)/lib$(TYPE).external-entry.a $(COPYTARGET)/libjerryentry.a
-DMEM_HEAP_SIZE_KB=$(JERRYHEAP)

make -C$(BUILD_DIR) jerry-core jerry-libm
cp $(BUILD_DIR)/lib/libjerry-core.a $(COPYTARGET)/
cp $(BUILD_DIR)/lib/libjerry-libm.a $(COPYTARGET)/

js2c:
cd targets/esp8266; ../../tools/js2c.py

tools/js2c.py --dest targets/esp8266/include --js-source targets/esp8266/js

mkbin:
cd targets/esp8266; \
make clean; \
BOOT=new APP=1 SPI_SPEED=40 SPI_MODE=QIO SPI_SIZE_MAP=3 make; \
BOOT=new APP=2 SPI_SPEED=40 SPI_MODE=QIO SPI_SIZE_MAP=3 make

make -Ctargets/esp8266 clean
make -Ctargets/esp8266 BOOT=new APP=0 SPI_SPEED=40 SPI_MODE=DIO SPI_SIZE_MAP=4

check-env:
ifndef SDK_PATH
Expand All @@ -110,16 +76,14 @@ ifndef BIN_PATH
$(error BIN_PATH is undefined for ESP8266)
endif


flash:
$(ESPTOOL) --port $(USBDEVICE) write_flash \
0x00000 $(SDK_PATH)/bin/"boot_v1.4(b1).bin" \
0x01000 $(BIN_PATH)/upgrade/user1.2048.new.3.bin \
0x81000 $(BIN_PATH)/upgrade/user2.2048.new.3.bin \
0x1FC000 $(SDK_PATH)/bin/esp_init_data_default.bin \
0x1FE000 $(SDK_PATH)/bin/blank.bin
0x00000 $(BIN_PATH)/eagle.flash.bin \
0x20000 $(BIN_PATH)/eagle.irom0text.bin \
0x3FC000 $(SDK_PATH)/bin/esp_init_data_default.bin

erase_flash:
$(ESPTOOL) --port $(USBDEVICE) erase_flash

clean:
rm -rf $(INTERM)
rm -rf $(OUTPUT)
rm -rf $(BUILD_DIR)
75 changes: 0 additions & 75 deletions targets/esp8266/docs/ESP-PATCHFORJERRYSCRIPT.md

This file was deleted.

32 changes: 14 additions & 18 deletions targets/esp8266/docs/ESP-PREREQUISITES.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,24 @@ I've slightly changed the step to use SDK from Espressif official SDK

##### Toolchain:

dependencies for x86
dependencies
```
sudo apt-get install git autoconf build-essential gperf \
bison flex texinfo libtool libncurses5-dev wget \
gawk libc6-dev-i386 python-serial libexpat-dev
bison flex texinfo libtool libtool-bin libncurses5-dev wget \
gawk python-serial libexpat-dev
sudo mkdir /opt/Espressif
sudo chown $USER /opt/Espressif/
```

dependencies for x64
dependency specific to x86:
```
sudo apt-get install git autoconf build-essential gperf \
bison flex texinfo libtool libncurses5-dev wget \
gawk libc6-dev-amd64 python-serial libexpat-dev
sudo mkdir /opt/Espressif
sudo chown $USER /opt/Espressif/
sudo apt-get install libc6-dev-i386
```

dependency specific to x64:
```
sudo apt-get install libc6-dev-amd64
```

crosstool-NG
Expand All @@ -56,14 +58,10 @@ PATH=$PWD/builds/xtensa-lx106-elf/bin:$PATH
cd /opt/Esprissif
git clone https://github.com/espressif/ESP8266_RTOS_SDK.git ESP8266_RTOS_SDK.git
ln -s ESP8266_RTOS_SDK.git ESP8266_SDK
cd ESP8266_SDK
git checkout -b jerry a2b413ad2996450fe2f173b6afab243f6e1249aa
git checkout -b jerry 2fab9e23d779cdd6e5900b8ba2b588e30d9b08c4
```

We use SDK 1.2.0 version which has stdlib.h and others. Latest 1.3.0 version,
as of writing this document, doesn't have it.
(If anyone knows how to use latest version, please add an issue or send a PR.)

This verison is tested and works properly.

set two environment variables such as in .profile
```
Expand Down Expand Up @@ -126,7 +124,7 @@ make BOOT=new APP=0 SPI_SPEED=80 SPI_MODE=QIO SPI_SIZE_MAP=2
```
sudo /opt/Espressif/esptool-py/esptool.py \
--port /dev/ttyUSB0 write_flash \
0x00000 $SDK_PATH/bin/"boot_v1.4(b1).bin" \
0x00000 $SDK_PATH/bin/"boot_v1.7.bin" \
0x01000 $BIN_PATH/upgrade/user1.2048.new.5.bin \
0x101000 $BIN_PATH/upgrade/user2.2048.new.5.bin \
0x3FE000 $SDK_PATH/bin/blank.bin \
Expand All @@ -146,5 +144,3 @@ sudo /opt/Espressif/esptool-py/esptool.py \
* disconnect GPIO0 so that it is floating
* connect GPIO2 with serial of 470 Ohm + LED and to GND
* power On

LED should blink on and off every second
Loading

0 comments on commit c3a9821

Please sign in to comment.