Skip to content

Commit

Permalink
.ld scripts refactoring (#1559)
Browse files Browse the repository at this point in the history
* initial ldscripts refactoring

* add missing menu options

* board for 2.3.0 and 2.4.2

* test with core 2.5.0

* typo

* ...same typo in other boards.local.txt

* generate boards.local.txt from common template

* Depend on file presence instead of platform version

* sdk selection

* Override only relevant entries

* generate ldscripts

* formatting

* unused

* fix section scope

* fix linker script comment and build getting stuck

* py2 compat

platformio from pip still does not support py3

* add TODO for py3

* chmod +x, remove leading newline

* comment with real spiffs size

* fixup! chmod +x, remove leading newline

* regenerate all ldscripts

* Preventive fix of spiffs_end calculation

* update arg parsing

* generate only 2.3.0 and latest

* readme for boards.local.txt

* Update ldscript readme

* unique flash sizes

* fix sub

* line break

* correct way to get framework path

* Alias for _FS_... symbols

* unused 2m1m1s

* bump?

* show travis logs

* ensure latest toolchain for travis

* check platform packages when building
  • Loading branch information
mcspr authored Aug 5, 2019
1 parent 8d009a6 commit 437424a
Show file tree
Hide file tree
Showing 26 changed files with 844 additions and 87 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ cache:
- "~/.platformio"
install:
- pip install -U platformio
- pio platform update -p
- npm install -g npm@latest
- cd code && npm ci && cd ..
env:
Expand Down
19 changes: 0 additions & 19 deletions code/eagle.flash.1m0m1s.ld

This file was deleted.

19 changes: 0 additions & 19 deletions code/eagle.flash.1m0m2s.ld

This file was deleted.

19 changes: 0 additions & 19 deletions code/eagle.flash.512k0m1s.ld

This file was deleted.

16 changes: 15 additions & 1 deletion code/extra_script_libdeps.py → code/extra_script_pre.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@


TRAVIS = os.environ.get("TRAVIS")
PIO_PLATFORM = env.PioPlatform()


class ExtraScriptError(Exception):
Expand Down Expand Up @@ -57,11 +58,24 @@ def get_shared_libdeps_dir(section, name):
opt = cfg.get(section, name)

if not opt in env.GetProjectOption("lib_extra_dirs"):
raise ExtraScriptError("lib_extra_dirs must contain {}.{}".format(section, name))
raise ExtraScriptError(
"lib_extra_dirs must contain {}.{}".format(section, name)
)

return os.path.join(env["PROJECT_DIR"], opt)


def ensure_platform_updated():
if PIO_PLATFORM.are_outdated_packages():
print("updating platform packages", file=sys.stderr)
PIO_PLATFORM.update_packages()


# latest toolchain is still optional with PIO (TODO: recheck after 2.6.0!)
ensure_platform_updated()


# to speed-up build process, install libraries in either global or local shared storage
if os.environ.get("ESPURNA_PIO_SHARED_LIBRARIES"):
if TRAVIS:
storage = None
Expand Down
37 changes: 32 additions & 5 deletions code/extra_scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

Import("env", "projenv")

PIO_PLATFORM = env.PioPlatform()
FRAMEWORK_DIR = PIO_PLATFORM.get_package_dir("framework-arduinoespressif8266")

# ------------------------------------------------------------------------------
# Utils
# ------------------------------------------------------------------------------
Expand Down Expand Up @@ -44,6 +47,31 @@ def print_filler(fill, color=Color.WHITE, err=False):
out = sys.stderr if err else sys.stdout
print(clr(color, fill * width), file=out)

def ldscript_inject_libpath():

# [email protected] did not append this directory into the LIBPATH
libpath_sdk = os.path.join(FRAMEWORK_DIR, "tools", "sdk", "ld")
env.Append(LIBPATH=[libpath_sdk])

libpath_base = os.path.join("$PROJECT_DIR", "..", "dist", "ld")
env.Append(LIBPATH=[
os.path.join(libpath_base, "pre_2.5.0")
])

# local.eagle.app.v6.common.ld exists only with Core >2.5.0
def check_local_ld(target ,source, env):
local_ld = env.subst(os.path.join("$BUILD_DIR", "ld", "local.eagle.app.v6.common.ld"))
if os.path.exists(local_ld):
env.Prepend(LIBPATH=[
os.path.join(libpath_base, "latest")
])

env.AddPreAction(
os.path.join("$BUILD_DIR", "firmware.elf"),
check_local_ld
)


# ------------------------------------------------------------------------------
# Callbacks
# ------------------------------------------------------------------------------
Expand Down Expand Up @@ -97,18 +125,16 @@ def patch_lwip():
if "lwip_gcc" not in env["LIBS"]:
return

platform = env.PioPlatform()
framework_dir = platform.get_package_dir("framework-arduinoespressif8266")
toolchain_prefix = os.path.join(platform.get_package_dir("toolchain-xtensa"), "bin", "xtensa-lx106-elf-")
toolchain_prefix = os.path.join(PIO_PLATFORM.get_package_dir("toolchain-xtensa"), "bin", "xtensa-lx106-elf-")

patch_action = env.VerboseAction(" ".join([
"-patch", "-u", "-N", "-d",
os.path.join(framework_dir, "tools", "sdk", "lwip"),
os.path.join(FRAMEWORK_DIR, "tools", "sdk", "lwip"),
os.path.join("src", "core", "tcp_out.c"),
env.subst(os.path.join("$PROJECT_DIR", "..", "dist", "patches", "lwip_mtu_issue_1610.patch"))
]), "Patching lwip source")
build_action = env.VerboseAction(" ".join([
"make", "-C", os.path.join(framework_dir, "tools", "sdk", "lwip", "src"),
"make", "-C", os.path.join(FRAMEWORK_DIR, "tools", "sdk", "lwip", "src"),
"install",
"TOOLS_PATH={}".format(toolchain_prefix),
"LWIP_LIB=liblwip_gcc.a"
Expand All @@ -130,6 +156,7 @@ def patch_lwip():

# 2.4.0 and up
remove_float_support()
ldscript_inject_libpath()

# two-step update hint when using 1MB boards
env.AddPostAction("$BUILD_DIR/${PROGNAME}.bin", check_size)
Expand Down
4 changes: 2 additions & 2 deletions code/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ arduino_core_develop = https://github.com/platformio/platform-espressif8266#deve
arduino_core_git = https://github.com/platformio/platform-espressif8266#feature/stage

platform = ${common.arduino_core_2_3_0}
platform_latest = ${common.arduino_core_2_4_2}
platform_latest = ${common.arduino_core_2_5_2}

# ------------------------------------------------------------------------------
# FLAGS: DEBUG
Expand Down Expand Up @@ -90,7 +90,7 @@ framework = arduino
board_build.flash_mode = dout
monitor_speed = 115200
upload_speed = 115200
extra_scripts = pre:extra_script_libdeps.py, extra_scripts.py
extra_scripts = pre:extra_script_pre.py, extra_scripts.py
lib_extra_dirs =
${common.shared_libdeps_dir}

Expand Down
39 changes: 39 additions & 0 deletions dist/arduino_ide/2.3.0/boards.local.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#version=2.3.0

menu.float_support=scanf and printf float support

generic.menu.FlashSize.1M1S=1M (1 EEPROM Sector, no SPIFFS)
generic.menu.FlashSize.1M1S.build.flash_size=1M
generic.menu.FlashSize.1M1S.build.flash_size_bytes=0x100000
generic.menu.FlashSize.1M1S.build.flash_ld=eagle.flash.1m0m1s.ld
generic.menu.FlashSize.1M1S.build.spiffs_pagesize=256
generic.menu.FlashSize.1M1S.upload.maximum_size=1023984
generic.menu.FlashSize.1M1S.build.rfcal_addr=0xFC000
generic.menu.FlashSize.2M4S=2M (4 EEPROM Sectors, 1M SPIFFS)
generic.menu.FlashSize.2M4S.build.flash_size=2M
generic.menu.FlashSize.2M4S.build.flash_size_bytes=0x200000
generic.menu.FlashSize.2M4S.build.flash_ld=eagle.flash.2m1m4s.ld
generic.menu.FlashSize.2M4S.build.spiffs_pagesize=256
generic.menu.FlashSize.2M4S.upload.maximum_size=1044464
generic.menu.FlashSize.2M4S.build.rfcal_addr=0x1FC000
generic.menu.FlashSize.4M1M4S=4M (4 EEPROM Sectors, 1M SPIFFS)
generic.menu.FlashSize.4M1M4S.build.flash_size=4M
generic.menu.FlashSize.4M1M4S.build.flash_size_bytes=0x400000
generic.menu.FlashSize.4M1M4S.build.flash_ld=eagle.flash.4m1m4s.ld
generic.menu.FlashSize.4M1M4S.build.spiffs_pagesize=256
generic.menu.FlashSize.4M1M4S.upload.maximum_size=1044464
generic.menu.FlashSize.4M1M4S.build.rfcal_addr=0x3FC000
generic.menu.FlashSize.4M3M4S=4M (4 EEPROM Sectors, 3M SPIFFS)
generic.menu.FlashSize.4M3M4S.build.flash_size=4M
generic.menu.FlashSize.4M3M4S.build.flash_size_bytes=0x400000
generic.menu.FlashSize.4M3M4S.build.flash_ld=eagle.flash.4m3m4s.ld
generic.menu.FlashSize.4M3M4S.build.spiffs_pagesize=256
generic.menu.FlashSize.4M3M4S.upload.maximum_size=1044464
generic.menu.FlashSize.4M3M4S.build.rfcal_addr=0x3FC000

generic.menu.float_support.disabled=Disabled (Recommended)
generic.menu.float_support.disabled.build.float=
generic.menu.float_support.enabled=Enabled
generic.menu.float_support.enabled.build.float=-u _printf_float -u _scanf_float

generic.compiler.cpp.extra_flags=-DNO_GLOBAL_EEPROM -DMQTT_MAX_PACKET_SIZE=400
24 changes: 24 additions & 0 deletions dist/arduino_ide/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# boards.local.txt for ESPurna

Additional flash layouts to support multiple EEPROM sectors

### Installation

Place boards.local.txt into Arduino hardware directory, in the same directory as the boards.txt file. Depending on platform and ESP8266 installation method, it is one of:

- Linux (boards manager): `~/.arduino15/packages/esp8266/hardware/esp8266/<version>`
- Linux (git): `~/Arduino/hardware/esp8266com/esp8266/`
- Windows (boards manager): `%LOCALAPPDATA%\Arduino15\packages\esp8266\hardware\esp8266\<version>`
- Windows (git): `~\Documents\Arduino\hardware\esp8266com\esp8266\`
- macOS (boards manager): `~/Library/Arduino15/packages/esp2866/hardware/esp8266/<version>`
- macOS (git): `<application-directory>/Arduino.app/Contents/Java/hardware/esp8266com/esp8266`

Use `2.3.0/boards.local.txt` for Core version 2.3.0
Use `latest/boards.local.txt` for all the others


### Arduino documentation

https://arduino-esp8266.readthedocs.io/en/latest/installing.html
https://www.arduino.cc/en/Hacking/Preferences
https://github.com/arduino/Arduino/wiki/Arduino-IDE-1.5-3rd-party-Hardware-specification#boardslocaltxt
39 changes: 39 additions & 0 deletions dist/arduino_ide/latest/boards.local.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#version=latest

menu.float_support=scanf and printf float support

generic.menu.eesz.1M1S=1M (1 EEPROM Sector, no SPIFFS)
generic.menu.eesz.1M1S.build.flash_size=1M
generic.menu.eesz.1M1S.build.flash_size_bytes=0x100000
generic.menu.eesz.1M1S.build.flash_ld=eagle.flash.1m0m1s.ld
generic.menu.eesz.1M1S.build.spiffs_pagesize=256
generic.menu.eesz.1M1S.upload.maximum_size=1023984
generic.menu.eesz.1M1S.build.rfcal_addr=0xFC000
generic.menu.eesz.2M4S=2M (4 EEPROM Sectors, 1M SPIFFS)
generic.menu.eesz.2M4S.build.flash_size=2M
generic.menu.eesz.2M4S.build.flash_size_bytes=0x200000
generic.menu.eesz.2M4S.build.flash_ld=eagle.flash.2m1m4s.ld
generic.menu.eesz.2M4S.build.spiffs_pagesize=256
generic.menu.eesz.2M4S.upload.maximum_size=1044464
generic.menu.eesz.2M4S.build.rfcal_addr=0x1FC000
generic.menu.eesz.4M1M4S=4M (4 EEPROM Sectors, 1M SPIFFS)
generic.menu.eesz.4M1M4S.build.flash_size=4M
generic.menu.eesz.4M1M4S.build.flash_size_bytes=0x400000
generic.menu.eesz.4M1M4S.build.flash_ld=eagle.flash.4m1m4s.ld
generic.menu.eesz.4M1M4S.build.spiffs_pagesize=256
generic.menu.eesz.4M1M4S.upload.maximum_size=1044464
generic.menu.eesz.4M1M4S.build.rfcal_addr=0x3FC000
generic.menu.eesz.4M3M4S=4M (4 EEPROM Sectors, 3M SPIFFS)
generic.menu.eesz.4M3M4S.build.flash_size=4M
generic.menu.eesz.4M3M4S.build.flash_size_bytes=0x400000
generic.menu.eesz.4M3M4S.build.flash_ld=eagle.flash.4m3m4s.ld
generic.menu.eesz.4M3M4S.build.spiffs_pagesize=256
generic.menu.eesz.4M3M4S.upload.maximum_size=1044464
generic.menu.eesz.4M3M4S.build.rfcal_addr=0x3FC000

generic.menu.float_support.disabled=Disabled (Recommended)
generic.menu.float_support.disabled.build.float=
generic.menu.float_support.enabled=Enabled
generic.menu.float_support.enabled.build.float=-u _printf_float -u _scanf_float

generic.compiler.cpp.extra_flags=-DNO_GLOBAL_EEPROM -DMQTT_MAX_PACKET_SIZE=400
Loading

0 comments on commit 437424a

Please sign in to comment.