Skip to content

Commit

Permalink
switch to a single board build
Browse files Browse the repository at this point in the history
  • Loading branch information
tve committed Nov 19, 2015
1 parent 0e55306 commit 60a1698
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 153 deletions.
145 changes: 36 additions & 109 deletions Makefile
Expand Up @@ -48,11 +48,7 @@
# MINISTM32_STRIVE=1
# MINISTM32_ANGLED_VE=1
# MINISTM32_ANGLED_VG=1
# ESP8266_BOARD=1 # Same as ESP8266_512KB
# ESP8266_4MB=1 # ESP8266 with 4MB flash: 512KB+512KB firmware + 3MB SPIFFS
# ESP8266_2MB=1 # ESP8266 with 2MB flash: 512KB+512KB firmware + 3MB SPIFFS
# ESP8266_1MB=1 # ESP8266 with 1MB flash: 512KB+512KB firmware + 32KB SPIFFS
# ESP8266_512KB=1 # ESP8266 with 512KB flash: 512KB firmware + 32KB SPIFFS
# ESP8266_BOARD=1 # ESP8266
# EMW3165 # MXCHIP EMW3165: STM32F411CE, BCM43362, 512KB flash 128KB RAM
# Or nothing for standard linux compile
#
Expand All @@ -72,11 +68,6 @@ ifndef SINGLETHREAD
MAKEFLAGS=-j5 # multicore
endif

# backwards compatibility
ifdef ESP8266_BOARD
ESP8266_512KB=1
endif

INCLUDE=-I$(ROOT) -I$(ROOT)/targets -I$(ROOT)/src -I$(ROOT)/gen
LIBS=
DEFINES=
Expand Down Expand Up @@ -508,75 +499,44 @@ STLIB=STM32F10X_MD
PRECOMPILED_OBJS+=$(ROOT)/targetlibs/stm32f1/lib/startup_stm32f10x_md.o
OPTIMIZEFLAGS+=-Os

else ifdef ESP8266_512KB
# esp8266 with 512KB flash chip, we're using the "none boot" layout, which doesn't support
# OTA update and allows for a firmware that almost fills the 512KB. The first 64KB are loaded
# into ram (dram+iram) and the last 16KB are reserved for the SDK. That leaves 432KB (0x6C000).
else ifdef ESP8266_BOARD
EMBEDDED=1
USE_NET=1
#USE_FILESYSTEM=1
BOARD=ESP8266_BOARD
# We have to disable inlining to keep code size in check
OPTIMIZEFLAGS+=-Os -fno-inline-functions -std=gnu11 -fgnu89-inline -Wl,--allow-multiple-definition
ESP_FLASH_SIZE ?= 0 # 0->512KB
ESP_FLASH_MODE ?= 0 # 0->QIO
ESP_FLASH_FREQ_DIV ?= 0 # 0->40Mhz
ESP_FLASH_MAX ?= 442368 # max irom0 size for 512KB flash: 432KB
ET_FS ?= 4m # 4Mbit (512KB) flash size in esptool flash command
ET_FF ?= 40m # 40Mhz flash speed in esptool flash command
ET_BLANK ?= 0x7E000 # where to flash blank.bin to erase wireless settings

else ifdef ESP8266_4MB
# esp8266 with 4MB flash chip with OTA support: we get 492KB in the first 512, 492 KB in the
# second 512KB for firmware; and then we have 3MB-16KB for SPIFFS
EMBEDDED=1
USE_NET=1
BOARD=ESP8266_12
# Enable link-time optimisations (inlining across files) but don't go beyond -O2 'cause of
# code size explosion, also -DLINK_TIME_OPTIMISATION leads to too big a firmware
OPTIMIZEFLAGS+=-O2 -std=gnu11 -fgnu89-inline -flto -fno-fat-lto-objects -Wl,--allow-multiple-definition
OPTIMIZEFLAGS+=-Os -std=gnu11 -fgnu89-inline -flto -fno-fat-lto-objects -Wl,--allow-multiple-definition
ESP_FLASH_MAX ?= 491520 # max bin file: 480KB

ifdef FLASH_4MB
ESP_FLASH_SIZE ?= 4 # 4->4MB (512KB+512KB)
ESP_FLASH_MODE ?= 0 # 0->QIO, 2->DIO
ESP_FLASH_FREQ_DIV ?= 15 # 15->80Mhz
ESP_FLASH_MAX ?= 503808 # max bin file for 512KB flash partition: 492KB
ET_FS ?= 32m # 32Mbit (4MB) flash size in esptool flash command
ET_FF ?= 80m # 80Mhz flash speed in esptool flash command
ET_BLANK ?= 0x3FE000 # where to flash blank.bin to erase wireless settings

else ifdef ESP8266_2MB
# *** WARNING: THIS FLASH SIZE HAS NOT BEEN TESTED ***
# esp8266 with 2MB flash chip with OTA support: same as 4MB except we have 1MB-16KB for SPIFFS
EMBEDDED=1
USE_NET=1
BOARD=ESP8266_12
# Enable link-time optimisations (inlining across files)
OPTIMIZEFLAGS+=-O3 -std=gnu11 -fgnu89-inline -flto -fno-fat-lto-objects -Wl,--allow-multiple-definition
DEFINES += -DLINK_TIME_OPTIMISATION
else ifdef 2MB
ESP_FLASH_SIZE ?= 3 # 3->2MB (512KB+512KB)
ESP_FLASH_MODE ?= 0 # 0->QIO, 2->DIO
ESP_FLASH_FREQ_DIV ?= 15 # 15->80Mhz
ESP_FLASH_MAX ?= 503808 # max bin file for 512KB flash partition: 492KB
ET_FS ?= 16m # 16Mbit (2MB) flash size in esptool flash command
ET_FF ?= 80m # 80Mhz flash speed in esptool flash command
ET_BLANK ?= 0x1FE000 # where to flash blank.bin to erase wireless settings

else ifdef ESP8266_1MB
# *** WARNING: THIS FLASH SIZE HAS NOT BEEN TESTED ***
# esp8266 with 1MB flash chip with OTA support: this is a mix between the 512KB and 2MB versions:
# we get two partitions for firmware but we need to turn optimization off to leave some space
# for SPIFFS
EMBEDDED=1
USE_NET=1
BOARD=ESP8266_12
# We have to disable inlining to keep code size in check
OPTIMIZEFLAGS+=-O2 -fno-inline-functions -std=gnu11 -fgnu89-inline -Wl,--allow-multiple-definition
else ifdef 1MB
ESP_FLASH_SIZE ?= 2 # 2->1MB (512KB+512KB)
ESP_FLASH_MODE ?= 0 # 0->QIO, 2->DIO
ESP_FLASH_FREQ_DIV ?= 15 # 15->80Mhz
ESP_FLASH_MAX ?= 503808 # max bin file for 512KB flash partition: 492KB
ET_FS ?= 8m # 8Mbit (1MB) flash size in esptool flash command
ET_FF ?= 80m # 80Mhz flash speed in esptool flash command
ET_BLANK ?= 0xFE000 # where to flash blank.bin to erase wireless settings
else # 512KB
ESP_FLASH_SIZE ?= 0 # 0->512KB
ESP_FLASH_MODE ?= 0 # 0->QIO
ESP_FLASH_FREQ_DIV ?= 0 # 0->40Mhz
ET_FS ?= 4m # 4Mbit (512KB) flash size in esptool flash command
ET_FF ?= 40m # 40Mhz flash speed in esptool flash command
ET_BLANK ?= 0x7E000 # where to flash blank.bin to erase wireless settings
endif

else
ifeq ($(shell uname -m),armv6l)
Expand Down Expand Up @@ -1351,7 +1311,7 @@ ifeq ($(FAMILY),ESP8266)
DEFINES += -DUSE_OPTIMIZE_PRINTF
DEFINES += -D__ETS__ -DICACHE_FLASH -DXTENSA -DUSE_US_TIMER
ESP8266=1
LIBS += -lc -lgcc -lhal -lphy -lpp -lnet80211 -llwip_536 -lwpa -lmain
LIBS += -lc -lgcc -lhal -lphy -lpp -lnet80211 -llwip_536 -lwpa -lmain -lpwm
CFLAGS+= -fno-builtin -fno-strict-aliasing \
-Wno-maybe-uninitialized -Wno-old-style-declaration -Wno-conversion -Wno-unused-variable \
-Wno-unused-parameter -Wno-ignored-qualifiers -Wno-discarded-qualifiers -Wno-float-conversion \
Expand Down Expand Up @@ -1494,11 +1454,12 @@ ifdef ESP8266
# The Root of the ESP8266_SDK distributed by Espressif
# This must be supplied as a Make environment variable.
ifndef ESP8266_SDK_ROOT
$(error, "The ESP8266_SDK_ROOT variable must be set")
$(error "The ESP8266_SDK_ROOT variable must be set")
endif

# The pefix for the xtensa toolchain
CCPREFIX=xtensa-lx106-elf-
DEFINES += -DESP8266

# Extra flags passed to the linker
LDFLAGS += -L$(ESP8266_SDK_ROOT)/lib \
Expand All @@ -1515,10 +1476,8 @@ SOURCES += targets/esp8266/uart.c \
targets/esp8266/i2c_master.c \
targets/esp8266/esp8266_board_utils.c \
libs/network/esp8266/network_esp8266.c
# if using the hw_timer: targets/esp8266/hw_timer.c \

# The tool used for building the firmware and flashing
ESPTOOL_CK ?= esptool-ck
ESPTOOL ?= $(ESP8266_SDK_ROOT)/esptool/esptool.py

# Extra include directories specific to the ESP8266
Expand Down Expand Up @@ -1604,51 +1563,22 @@ $(PROJ_NAME): $(OBJS)
@echo $($(quiet_)link)
@$(call link)

else ifdef ESP8266_512KB
# for the 512KB flash we generate non-OTA binaries
proj: $(PROJ_NAME).elf $(PROJ_NAME)_0x00000.bin $(PROJ_NAME)_0x10000.bin $(PROJ_NAME).lst

# linking is complicated. The Espruino source files get compiled into the .text section. The
else ifdef ESP8266
# Linking the esp8266... The Espruino source files get compiled into the .text section. The
# Espressif SDK libraries have .text and .irom0 sections. We need to put the libraries' .text into
# .iram0 (32KB on chip instruction ram) and we need to put the Esprunio .text and the libraries'
# .irom0 into .irom0 (demand-cached from flash). We do this dance by pre-linking the Espruino
# objects, then renaming .text to .irom0, and then finally linking with the SDK libraries.
# Note that a previous method of renaming .text to .irom0 in each object file doesn't work when
# we enable the link-time optimizer for inlining because it generates fresh code that all ends
# up in .iram0.
$(PROJ_NAME).elf: $(OBJS) $(LINKER_FILE)
$(Q)$(LD) $(OPTIMIZEFLAGS) -nostdlib -Wl,--no-check-sections -Wl,-static -r -o partial.o $(OBJS)
$(Q)$(OBJCOPY) --rename-section .text=.irom0.text --rename-section .literal=.irom0.literal partial.o
$(Q)$(OBJCOPY) --rename-section .force.text=.text partial.o
$(Q)$(LD) $(LDFLAGS) -Ttargets/esp8266/eagle.app.v6.0x10000.ld -o $@ partial.o -Wl,--start-group $(LIBS) -Wl,--end-group
$(Q)rm partial.o
$(Q)$(OBJDUMP) --headers -j .irom0.text -j .text $(PROJ_NAME).elf | tail -n +4
@echo To disassemble: $(OBJDUMP) -d -l -x $(PROJ_NAME).elf

# binary image for idata0&iram0
$(PROJ_NAME)_0x00000.bin: $(PROJ_NAME).elf
# Note that ESPTOOL_CK always returns non zero, ignore errors
$(Q)$(ESPTOOL_CK) -eo $< -bo $@ -bs .text -bs .data -bs .rodata -bs .iram0.text -bc -ec || true

# binary image for irom0
$(PROJ_NAME)_0x10000.bin: $(PROJ_NAME).elf
# Note that ESPTOOL_CK always returns non zero, ignore errors
$(Q)$(ESPTOOL_CK) -eo $< -es .irom0.text $@ -ec || true

# Generate a symbol table file for subsequent debugging where we know an exception address.
$(PROJ_NAME).lst : $(PROJ_NAME).elf
$(Q)@echo "Building Symbol table (.lst) file"
$(Q)$(call obj_dump)

flash: all $(PROJ_NAME)_0x00000.bin $(PROJ_NAME)_0x10000.bin
ifndef COMPORT
$(error, "In order to flash, we need to have the COMPORT variable defined")
endif
-$(Q)$(ESPTOOL) --port $(COMPORT) --baud 115200 write_flash --flash_freq 40m --flash_mode qio --flash_size 4m 0x00000 $(PROJ_NAME)_0x00000.bin 0x10000 $(PROJ_NAME)_0x10000.bin

else ifdef ESP8266
# for the non-512KB flash we generate a single OTA binary, but we generate two of them, one per
# OTA partition (Espressif calls these user1.bin and user2.bin)
# We generate two binaries in order to support over-the-air updates, one per
# OTA partition (Espressif calls these user1.bin and user2.bin). In the 512KB flash case, there
# is only space for the first binary and updates are not possible. So we're really abusing the
# flash layout in that case because we tell the SDK that we have two 256KB partitions when in
# reality we're using one 512KB partition. This works out because the SDK doesn't use the
# user setting area that sits between the two 256KB partitions, so we can merrily use it for
# code.
USER1_BIN = $(PROJ_NAME)_user1.bin
USER2_BIN = $(PROJ_NAME)_user2.bin
USER1_ELF = $(PROJ_NAME)_user1.elf
Expand All @@ -1662,15 +1592,6 @@ INIT_DATA = $(ESP8266_SDK_ROOT)/bin/esp_init_data_default.bin

proj: $(USER1_BIN) $(USER2_BIN)

# linking is complicated. The Espruino source files get compiled into the .text section. The
# Espressif SDK libraries have .text and .irom0 sections. We need to put the libraries' .text into
# .iram0 (32KB on chip instruction ram) and we need to put the Esprunio .text and the libraries'
# .irom0 into .irom0 (demand-cached from flash). We do this dance by pre-linking the Espruino
# objects, then renaming .text to .irom0, and then finally linking with the SDK libraries.
# Note that a previous method of renaming .text to .irom0 in each object file doesn't work when
# we enable the link-time optimizer for inlining because it generates fresh code that all ends
# up in .iram0.

# generate partially linked .o with all Esprunio source files linked
$(PROJ_NAME)_partial.o: $(OBJS) $(LINKER_FILE)
@echo LD $@
Expand Down Expand Up @@ -1717,9 +1638,15 @@ $(USER2_BIN): $(USER2_ELF) $(USER1_BIN)

flash: all $(USER1_BIN) $(USER2_BIN)
ifndef COMPORT
$(error, "In order to flash, we need to have the COMPORT variable defined")
$(error "In order to flash, we need to have the COMPORT variable defined")
endif
-$(ESPTOOL) --port $(COMPORT) --baud 460800 write_flash --flash_freq $(ET_FF) --flash_mode qio --flash_size $(ET_FS) 0x0000 "$(BOOTLOADER)" 0x1000 $(USER1_BIN) $(ET_BLANK) $(BLANK)

wiflash: all $(USER1_BIN) $(USER2_BIN)
ifndef ESPHOSTNAME
$(error "In order to flash over wifi, we need to have the ESPHOSTNAME variable defined")
endif
-$(Q)$(ESPTOOL) --port $(COMPORT) --baud 460800 write_flash --flash_freq $(ET_FF) --flash_mode qio --flash_size $(ET_FS) 0x0000 "$(BOOTLOADER)" 0x1000 $(USER1_BIN) $(ET_BLANK) $(BLANK)
./scripts/wiflash $(ESPHOSTNAME) $(USER1_BIN) $(USER2_BIN)

#else ifdef WICED
#
Expand Down
2 changes: 1 addition & 1 deletion boards/ESP8266_12.py
Expand Up @@ -24,7 +24,7 @@
'name' : "ESP8266-12",
'espruino_page_link' : 'EspruinoESP8266',
'default_console' : "EV_SERIAL1",
'default_console_baudrate' : "115200",
'default_console_baudrate' : "230400",
'variables' : 1023,
'binary_name' : 'espruino_esp8266_12',
};
Expand Down
14 changes: 8 additions & 6 deletions boards/ESP8266_BOARD.py
Expand Up @@ -15,19 +15,19 @@

import pinutils;
info = {
'name' : "ESP8266 512KB",
'name' : "ESP8266",
'espruino_page_link' : 'EspruinoESP8266',
'default_console' : "EV_SERIAL1",
'default_console_baudrate' : "115200",
'default_console_baudrate' : "230400",
'variables' : 1023,
'binary_name' : 'espruino_esp8266_board',
'binary_name' : 'espruino_esp8266',
};
chip = {
'part' : "ESP8266",
'family' : "ESP8266",
'package' : "",
'ram' : 80,
'flash' : 512,
'flash' : 0,
'speed' : 80,
'usart' : 1,
'spi' : 1,
Expand Down Expand Up @@ -125,7 +125,9 @@

def get_pins():
pins = pinutils.generate_pins(0,15)
pinutils.findpin(pins, "PD1", True)["functions"]["USART1_TX"]=0;
pinutils.findpin(pins, "PD3", True)["functions"]["USART1_RX"]=0;
pinutils.findpin(pins, "PD0", True)["functions"]["LED_1"]=0;
pinutils.findpin(pins, "PD1", True)["functions"]["USART0_TX"]=0;
pinutils.findpin(pins, "PD2", True)["functions"]["USART1_TX"]=0;
pinutils.findpin(pins, "PD3", True)["functions"]["USART0_RX"]=0;
# just fake pins D0 .. D15
return pins
21 changes: 14 additions & 7 deletions src/jsinteractive.c
Expand Up @@ -31,6 +31,10 @@

#define CTRL_C_TIME_FOR_BREAK jshGetTimeFromMilliseconds(100)

#ifdef ESP8266
extern void jshPrintBanner(void); // prints a debugging banner while we're in beta
#endif

// ----------------------------------------------------------------------------
typedef enum {
IS_NONE,
Expand Down Expand Up @@ -244,10 +248,10 @@ void jsiConsoleEraseStringVarBackwards(JsVar *v) {
}
for (i=0;i<chars;i++) jsiConsolePrintChar(' '); // move cursor forwards and wipe out
for (i=0;i<chars;i++) jsiConsolePrintChar(0x08); // move cursor back
if (line>1) {
if (line>1) {
// clear the character before - this would have had a colon
jsiConsolePrint("\x08 ");
// move cursor up
// move cursor up
jsiConsolePrint("\x1B[A"); // 27,91,65 - up
}
}
Expand Down Expand Up @@ -719,6 +723,9 @@ void jsiSemiInit(bool autoLoad) {
"|_____|___| _|_| |___|_|_|_|___|\n"
" |_| http://espruino.com\n"
" "JS_VERSION" Copyright 2015 G.Williams\n");
#ifdef ESP8266
jshPrintBanner();
#endif
}
jsiConsolePrint("\n"); // output new line
inputLineRemoved = true; // we need to put the input line back...
Expand Down Expand Up @@ -789,7 +796,7 @@ int jsiCountBracketsInInput() {
jslKill(&lex);

return brackets;
}
}

/// Tries to get rid of some memory (by clearing command history). Returns true if it got rid of something, false if it didn't.
bool jsiFreeMoreMemory() {
Expand Down Expand Up @@ -1369,13 +1376,13 @@ void jsiHandleChar(char ch) {
Espruino uses DLE on the start of a line to signal that just the line in
question should be executed without echo */
jsiStatus |= JSIS_ECHO_OFF_FOR_LINE;
} else {
} else {
inputState = IS_NONE;
if (ch == 0x08 || ch == 0x7F /*delete*/) {
jsiHandleDelete(true /*backspace*/);
} else if (ch == '\n' && inputState == IS_HAD_R) {
inputState = IS_NONE; // ignore \ r\n - we already handled it all on \r
} else if (ch == '\r' || ch == '\n') {
} else if (ch == '\r' || ch == '\n') {
if (ch == '\r') inputState = IS_HAD_R;
jsiHandleNewLine(true);
#ifndef SAVE_ON_FLASH
Expand Down Expand Up @@ -1710,7 +1717,7 @@ void jsiIdle() {
}

// Reset Flow control if it was set...
if (jshGetEventsUsed() < IOBUFFER_XON) {
if (jshGetEventsUsed() < IOBUFFER_XON) {
jshSetFlowControlXON(EV_USBSERIAL, true);
int i;
for (i=0;i<USART_COUNT;i++)
Expand Down Expand Up @@ -1832,7 +1839,7 @@ void jsiIdle() {
* changed. It's not a big deal because it could only have changed because a timer
* got executed - so `wasBusy` got set and we know we're going to go around the
* loop again before sleeping.
*/
*/

// Check for events that might need to be processed from other libraries
if (jswIdle()) wasBusy = true;
Expand Down

0 comments on commit 60a1698

Please sign in to comment.