diff --git a/.travis.yml b/.travis.yml index ba070ade..bcbc3cdf 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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: diff --git a/code/eagle.flash.1m0m1s.ld b/code/eagle.flash.1m0m1s.ld deleted file mode 100644 index 4102c750..00000000 --- a/code/eagle.flash.1m0m1s.ld +++ /dev/null @@ -1,19 +0,0 @@ -/* Flash Split for 1M chips, no SPIFFS, 1 sector for EEPROM */ -/* sketch 999KB */ -/* eeprom 4KB */ -/* reserved 16KB */ - -MEMORY -{ - dport0_0_seg : org = 0x3FF00000, len = 0x10 - dram0_0_seg : org = 0x3FFE8000, len = 0x14000 - iram1_0_seg : org = 0x40100000, len = 0x8000 - irom0_0_seg : org = 0x40201010, len = 0xf9ff0 -} - -PROVIDE ( _SPIFFS_start = 0x402FB000 ); -PROVIDE ( _SPIFFS_end = 0x402FB000 ); -PROVIDE ( _SPIFFS_page = 0x0 ); -PROVIDE ( _SPIFFS_block = 0x0 ); - -INCLUDE "../ld/eagle.app.v6.common.ld" diff --git a/code/eagle.flash.1m0m2s.ld b/code/eagle.flash.1m0m2s.ld deleted file mode 100644 index 069f337d..00000000 --- a/code/eagle.flash.1m0m2s.ld +++ /dev/null @@ -1,19 +0,0 @@ -/* Flash Split for 1M chips, no SPIFFS, 2 sectors for EEPROM */ -/* sketch 995KB */ -/* eeprom 8KB */ -/* reserved 16KB */ - -MEMORY -{ - dport0_0_seg : org = 0x3FF00000, len = 0x10 - dram0_0_seg : org = 0x3FFE8000, len = 0x14000 - iram1_0_seg : org = 0x40100000, len = 0x8000 - irom0_0_seg : org = 0x40201010, len = 0xf8ff0 -} - -PROVIDE ( _SPIFFS_start = 0x402FA000 ); -PROVIDE ( _SPIFFS_end = 0x402FA000 ); -PROVIDE ( _SPIFFS_page = 0x0 ); -PROVIDE ( _SPIFFS_block = 0x0 ); - -INCLUDE "../ld/eagle.app.v6.common.ld" diff --git a/code/eagle.flash.512k0m1s.ld b/code/eagle.flash.512k0m1s.ld deleted file mode 100644 index 79d17352..00000000 --- a/code/eagle.flash.512k0m1s.ld +++ /dev/null @@ -1,19 +0,0 @@ -/* Flash Split for 512K chips, no SPIFFS, 1 sector for EEPROM */ -/* sketch 487KB */ -/* eeprom 4KB */ -/* reserved 16KB */ - -MEMORY -{ - dport0_0_seg : org = 0x3FF00000, len = 0x10 - dram0_0_seg : org = 0x3FFE8000, len = 0x14000 - iram1_0_seg : org = 0x40100000, len = 0x8000 - irom0_0_seg : org = 0x40201010, len = 0x79ff0 -} - -PROVIDE ( _SPIFFS_start = 0x4027B000 ); -PROVIDE ( _SPIFFS_end = 0x4027B000 ); -PROVIDE ( _SPIFFS_page = 0x0 ); -PROVIDE ( _SPIFFS_block = 0x0 ); - -INCLUDE "../ld/eagle.app.v6.common.ld" diff --git a/code/extra_script_libdeps.py b/code/extra_script_pre.py similarity index 78% rename from code/extra_script_libdeps.py rename to code/extra_script_pre.py index d3f758fe..7f809a5e 100644 --- a/code/extra_script_libdeps.py +++ b/code/extra_script_pre.py @@ -7,6 +7,7 @@ import sys TRAVIS = os.environ.get("TRAVIS") +PIO_PLATFORM = env.PioPlatform() class ExtraScriptError(Exception): @@ -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 diff --git a/code/extra_scripts.py b/code/extra_scripts.py index 6fa667e9..eaca0e7a 100644 --- a/code/extra_scripts.py +++ b/code/extra_scripts.py @@ -8,6 +8,9 @@ import click Import("env", "projenv") +PIO_PLATFORM = env.PioPlatform() +FRAMEWORK_DIR = PIO_PLATFORM.get_package_dir("framework-arduinoespressif8266") + # ------------------------------------------------------------------------------ # Utils # ------------------------------------------------------------------------------ @@ -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(): + + # espressif8266@1.5.0 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 # ------------------------------------------------------------------------------ @@ -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" @@ -130,6 +156,7 @@ projenv.ProcessUnFlags("-w") # 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) diff --git a/code/platformio.ini b/code/platformio.ini index 397477a0..70b7102e 100644 --- a/code/platformio.ini +++ b/code/platformio.ini @@ -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 @@ -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} diff --git a/dist/arduino_ide/2.3.0/boards.local.txt b/dist/arduino_ide/2.3.0/boards.local.txt new file mode 100644 index 00000000..394d3b9b --- /dev/null +++ b/dist/arduino_ide/2.3.0/boards.local.txt @@ -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 diff --git a/dist/arduino_ide/README.md b/dist/arduino_ide/README.md new file mode 100644 index 00000000..931d8d91 --- /dev/null +++ b/dist/arduino_ide/README.md @@ -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/` +- Linux (git): `~/Arduino/hardware/esp8266com/esp8266/` +- Windows (boards manager): `%LOCALAPPDATA%\Arduino15\packages\esp8266\hardware\esp8266\` +- Windows (git): `~\Documents\Arduino\hardware\esp8266com\esp8266\` +- macOS (boards manager): `~/Library/Arduino15/packages/esp2866/hardware/esp8266/` +- macOS (git): `/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 diff --git a/dist/arduino_ide/latest/boards.local.txt b/dist/arduino_ide/latest/boards.local.txt new file mode 100644 index 00000000..66dd024b --- /dev/null +++ b/dist/arduino_ide/latest/boards.local.txt @@ -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 diff --git a/dist/boards_local_txt.py b/dist/boards_local_txt.py new file mode 100755 index 00000000..ff4e72b9 --- /dev/null +++ b/dist/boards_local_txt.py @@ -0,0 +1,181 @@ +#!/usr/bin/env python + +# adapted boards.txt.py from esp8266/Arduino +# - single board definition, ldscripts +# - portable boards.local.txt for 2.3.0 and up + +import os +import argparse +import sys +import collections + +# TODO: drop after platform.io supports python 3 +if sys.version < (3, 2): + import string + + _format = string.Formatter().vformat + + def format_map(tmpl, f_map): + return _format(tmpl, None, f_map) + + +else: + + def format_map(tmpl, f_map): + return tmpl.format_map(f_map) + + +class VersionedSubstitution(collections.MutableMapping): + def __init__(self, substitutions, targets, *args, **kwargs): + self._targets = targets + self._version = None + self._store = substitutions.copy() + self.update(dict(*args, **kwargs)) + + def set_version(self, version): + self._version = version + + def __getitem__(self, key): + if self._version in self._targets: + return self._store[key] + return key + + def __setitem__(self, key, value): + self._store[key] = value + + def __delitem__(self, key): + del self._store[key] + + def __iter__(self): + return iter(self._store) + + def __len__(self): + return len(self._store) + + +BOARDS_LOCAL = { + "global": collections.OrderedDict( + [("menu.float_support", "scanf and printf float support")] + ), + "flash_size": collections.OrderedDict( + [ + (".menu.{eesz}.1M1S", "1M (1 EEPROM Sector, no SPIFFS)"), + (".menu.{eesz}.1M1S.build.flash_size", "1M"), + (".menu.{eesz}.1M1S.build.flash_size_bytes", "0x100000"), + (".menu.{eesz}.1M1S.build.flash_ld", "eagle.flash.1m0m1s.ld"), + (".menu.{eesz}.1M1S.build.spiffs_pagesize", "256"), + (".menu.{eesz}.1M1S.upload.maximum_size", "1023984"), + (".menu.{eesz}.1M1S.build.rfcal_addr", "0xFC000"), + (".menu.{eesz}.2M4S", "2M (4 EEPROM Sectors, 1M SPIFFS)"), + (".menu.{eesz}.2M4S.build.flash_size", "2M"), + (".menu.{eesz}.2M4S.build.flash_size_bytes", "0x200000"), + (".menu.{eesz}.2M4S.build.flash_ld", "eagle.flash.2m1m4s.ld"), + (".menu.{eesz}.2M4S.build.spiffs_pagesize", "256"), + (".menu.{eesz}.2M4S.upload.maximum_size", "1044464"), + (".menu.{eesz}.2M4S.build.rfcal_addr", "0x1FC000"), + (".menu.{eesz}.4M1M4S", "4M (4 EEPROM Sectors, 1M SPIFFS)"), + (".menu.{eesz}.4M1M4S.build.flash_size", "4M"), + (".menu.{eesz}.4M1M4S.build.flash_size_bytes", "0x400000"), + (".menu.{eesz}.4M1M4S.build.flash_ld", "eagle.flash.4m1m4s.ld"), + (".menu.{eesz}.4M1M4S.build.spiffs_pagesize", "256"), + (".menu.{eesz}.4M1M4S.upload.maximum_size", "1044464"), + (".menu.{eesz}.4M1M4S.build.rfcal_addr", "0x3FC000"), + (".menu.{eesz}.4M3M4S", "4M (4 EEPROM Sectors, 3M SPIFFS)"), + (".menu.{eesz}.4M3M4S.build.flash_size", "4M"), + (".menu.{eesz}.4M3M4S.build.flash_size_bytes", "0x400000"), + (".menu.{eesz}.4M3M4S.build.flash_ld", "eagle.flash.4m3m4s.ld"), + (".menu.{eesz}.4M3M4S.build.spiffs_pagesize", "256"), + (".menu.{eesz}.4M3M4S.upload.maximum_size", "1044464"), + (".menu.{eesz}.4M3M4S.build.rfcal_addr", "0x3FC000"), + ] + ), + "float_support": collections.OrderedDict( + [ + (".menu.float_support.disabled", "Disabled (Recommended)"), + (".menu.float_support.disabled.build.float", ""), + (".menu.float_support.enabled", "Enabled"), + ( + ".menu.float_support.enabled.build.float", + "-u _printf_float -u _scanf_float", + ), + ] + ), +} + + +BOARD = "generic" +MENUS = ["flash_size", "float_support"] + + +CORE_VERSIONS = ["2.3.0", "latest"] + +EXTRA_FLAGS = [ + (".compiler.cpp.extra_flags", "-DNO_GLOBAL_EEPROM -DMQTT_MAX_PACKET_SIZE=400") +] + + +SUBSTITUTIONS = VersionedSubstitution( + dict(eesz="FlashSize", wipe="FlashErase", baud="UploadSpeed", vt="VTable"), + ["2.3.0"], +) + + +def generate_boards_txt(args, sub=SUBSTITUTIONS): + + versions = args.versions + if args.version: + versions = [args.version] + + for version in versions: + + sub.set_version(version) + + result = ["#version={}\n\n".format(version)] + result.extend("{}={}\n".format(k, v) for k, v in BOARDS_LOCAL["global"].items()) + result.append("\n") + + # print("{} unused:".format(version, set(BOARDS_LOCAL.keys()) - set(MENUS[version]))) + # continue + + for menu in MENUS: + section = [] + for k, v in BOARDS_LOCAL[menu].items(): + k = format_map(k, sub) + section.append(BOARD + "=".join([k, v])) + result.append("\n".join(section)) + result.append("\n\n") + + if EXTRA_FLAGS: + result.extend(("{}{}={}".format(BOARD, k, v)) for k, v in EXTRA_FLAGS) + + f_path = os.path.join(args.directory, version, "boards.local.txt") + f_dir, _ = os.path.split(f_path) + if not os.path.exists(f_dir): + os.makedirs(f_dir) + + with open(f_path, "w") as f: + for part in result: + f.write(part) + f.write("\n") + + +def print_versions(args): + for version in CORE_VERSIONS: + print("- {}".format(version)) + + +if __name__ == "__main__": + + parser = argparse.ArgumentParser() + parser.add_argument("-d", "--directory", default="arduino_ide") + + subparsers = parser.add_subparsers(title="commands") + parser_versions = subparsers.add_parser("versions", help="list supported versions") + parser_versions.set_defaults(command=print_versions) + + parser_generate = subparsers.add_parser("generate", help="") + parser_generate.add_argument("version", nargs="?") + parser_generate.set_defaults(command=generate_boards_txt, versions=CORE_VERSIONS) + + args = parser.parse_args() + args.command(args) diff --git a/dist/ld/README.md b/dist/ld/README.md new file mode 100644 index 00000000..d1a55a39 --- /dev/null +++ b/dist/ld/README.md @@ -0,0 +1,8 @@ +# ESP8266 linker scripts with additional EEPROM sectors + +### Installation + +Depending on ESP8266 version, use files from either `Pre 2.5.0` or `latest` +Reference [../arduino_ide/README.md](../arduino_ide/README.md) about ESP8266 package location + +Copy all \*.ld files into the `/tools/sdk/ld` directory diff --git a/dist/ld/latest/eagle.flash.1m0m1s.ld b/dist/ld/latest/eagle.flash.1m0m1s.ld new file mode 100644 index 00000000..617bc064 --- /dev/null +++ b/dist/ld/latest/eagle.flash.1m0m1s.ld @@ -0,0 +1,30 @@ +/* +sketch: 999KB +fs: 0KB +eeprom: 4KB +*/ + +MEMORY +{ + dport0_0_seg : org = 0x3FF00000, len = 0x10 + dram0_0_seg : org = 0x3FFE8000, len = 0x14000 + iram1_0_seg : org = 0x40100000, len = 0x8000 + irom0_0_seg : org = 0x40201010, len = 0xf9ff0 +} + +/* +Provide both _SPIFFS_ and _FS_ to be compatible with 2.3.0...2.6.0+ and +any library that is using old _SPIFFS_... +*/ + +PROVIDE ( _SPIFFS_start = 0x402fb000 ); +PROVIDE ( _SPIFFS_end = 0x402fb000 ); +PROVIDE ( _SPIFFS_page = 0x0 ); +PROVIDE ( _SPIFFS_block = 0x0 ); + +PROVIDE ( _FS_start = _SPIFFS_start ); +PROVIDE ( _FS_end = _SPIFFS_end ); +PROVIDE ( _FS_page = _SPIFFS_page ); +PROVIDE ( _FS_block = _SPIFFS_block ); + +INCLUDE "local.eagle.app.v6.common.ld" diff --git a/dist/ld/latest/eagle.flash.1m0m2s.ld b/dist/ld/latest/eagle.flash.1m0m2s.ld new file mode 100644 index 00000000..a6236bf7 --- /dev/null +++ b/dist/ld/latest/eagle.flash.1m0m2s.ld @@ -0,0 +1,30 @@ +/* +sketch: 995KB +fs: 0KB +eeprom: 8KB +*/ + +MEMORY +{ + dport0_0_seg : org = 0x3FF00000, len = 0x10 + dram0_0_seg : org = 0x3FFE8000, len = 0x14000 + iram1_0_seg : org = 0x40100000, len = 0x8000 + irom0_0_seg : org = 0x40201010, len = 0xf8ff0 +} + +/* +Provide both _SPIFFS_ and _FS_ to be compatible with 2.3.0...2.6.0+ and +any library that is using old _SPIFFS_... +*/ + +PROVIDE ( _SPIFFS_start = 0x402fa000 ); +PROVIDE ( _SPIFFS_end = 0x402fa000 ); +PROVIDE ( _SPIFFS_page = 0x0 ); +PROVIDE ( _SPIFFS_block = 0x0 ); + +PROVIDE ( _FS_start = _SPIFFS_start ); +PROVIDE ( _FS_end = _SPIFFS_end ); +PROVIDE ( _FS_page = _SPIFFS_page ); +PROVIDE ( _FS_block = _SPIFFS_block ); + +INCLUDE "local.eagle.app.v6.common.ld" diff --git a/dist/ld/latest/eagle.flash.2m1m4s.ld b/dist/ld/latest/eagle.flash.2m1m4s.ld new file mode 100644 index 00000000..e26de54d --- /dev/null +++ b/dist/ld/latest/eagle.flash.2m1m4s.ld @@ -0,0 +1,30 @@ +/* +sketch: 1019KB +fs: 992KB +eeprom: 16KB +*/ + +MEMORY +{ + dport0_0_seg : org = 0x3FF00000, len = 0x10 + dram0_0_seg : org = 0x3FFE8000, len = 0x14000 + iram1_0_seg : org = 0x40100000, len = 0x8000 + irom0_0_seg : org = 0x40201010, len = 0xfeff0 +} + +/* +Provide both _SPIFFS_ and _FS_ to be compatible with 2.3.0...2.6.0+ and +any library that is using old _SPIFFS_... +*/ + +PROVIDE ( _SPIFFS_start = 0x40300000 ); +PROVIDE ( _SPIFFS_end = 0x403f8000 ); +PROVIDE ( _SPIFFS_page = 0x100 ); +PROVIDE ( _SPIFFS_block = 0x2000 ); + +PROVIDE ( _FS_start = _SPIFFS_start ); +PROVIDE ( _FS_end = _SPIFFS_end ); +PROVIDE ( _FS_page = _SPIFFS_page ); +PROVIDE ( _FS_block = _SPIFFS_block ); + +INCLUDE "local.eagle.app.v6.common.ld" diff --git a/dist/ld/latest/eagle.flash.4m1m4s.ld b/dist/ld/latest/eagle.flash.4m1m4s.ld new file mode 100644 index 00000000..c203f1cd --- /dev/null +++ b/dist/ld/latest/eagle.flash.4m1m4s.ld @@ -0,0 +1,30 @@ +/* +sketch: 1019KB +fs: 992KB +eeprom: 16KB +*/ + +MEMORY +{ + dport0_0_seg : org = 0x3FF00000, len = 0x10 + dram0_0_seg : org = 0x3FFE8000, len = 0x14000 + iram1_0_seg : org = 0x40100000, len = 0x8000 + irom0_0_seg : org = 0x40201010, len = 0xfeff0 +} + +/* +Provide both _SPIFFS_ and _FS_ to be compatible with 2.3.0...2.6.0+ and +any library that is using old _SPIFFS_... +*/ + +PROVIDE ( _SPIFFS_start = 0x40500000 ); +PROVIDE ( _SPIFFS_end = 0x405f8000 ); +PROVIDE ( _SPIFFS_page = 0x100 ); +PROVIDE ( _SPIFFS_block = 0x2000 ); + +PROVIDE ( _FS_start = _SPIFFS_start ); +PROVIDE ( _FS_end = _SPIFFS_end ); +PROVIDE ( _FS_page = _SPIFFS_page ); +PROVIDE ( _FS_block = _SPIFFS_block ); + +INCLUDE "local.eagle.app.v6.common.ld" diff --git a/dist/ld/latest/eagle.flash.4m3m4s.ld b/dist/ld/latest/eagle.flash.4m3m4s.ld new file mode 100644 index 00000000..97b1c3bf --- /dev/null +++ b/dist/ld/latest/eagle.flash.4m3m4s.ld @@ -0,0 +1,30 @@ +/* +sketch: 1019KB +fs: 3040KB +eeprom: 16KB +*/ + +MEMORY +{ + dport0_0_seg : org = 0x3FF00000, len = 0x10 + dram0_0_seg : org = 0x3FFE8000, len = 0x14000 + iram1_0_seg : org = 0x40100000, len = 0x8000 + irom0_0_seg : org = 0x40201010, len = 0xfeff0 +} + +/* +Provide both _SPIFFS_ and _FS_ to be compatible with 2.3.0...2.6.0+ and +any library that is using old _SPIFFS_... +*/ + +PROVIDE ( _SPIFFS_start = 0x40300000 ); +PROVIDE ( _SPIFFS_end = 0x405f8000 ); +PROVIDE ( _SPIFFS_page = 0x100 ); +PROVIDE ( _SPIFFS_block = 0x2000 ); + +PROVIDE ( _FS_start = _SPIFFS_start ); +PROVIDE ( _FS_end = _SPIFFS_end ); +PROVIDE ( _FS_page = _SPIFFS_page ); +PROVIDE ( _FS_block = _SPIFFS_block ); + +INCLUDE "local.eagle.app.v6.common.ld" diff --git a/dist/ld/latest/eagle.flash.512k0m1s.ld b/dist/ld/latest/eagle.flash.512k0m1s.ld new file mode 100644 index 00000000..288bcab8 --- /dev/null +++ b/dist/ld/latest/eagle.flash.512k0m1s.ld @@ -0,0 +1,30 @@ +/* +sketch: 487KB +fs: 0KB +eeprom: 4KB +*/ + +MEMORY +{ + dport0_0_seg : org = 0x3FF00000, len = 0x10 + dram0_0_seg : org = 0x3FFE8000, len = 0x14000 + iram1_0_seg : org = 0x40100000, len = 0x8000 + irom0_0_seg : org = 0x40201010, len = 0x79ff0 +} + +/* +Provide both _SPIFFS_ and _FS_ to be compatible with 2.3.0...2.6.0+ and +any library that is using old _SPIFFS_... +*/ + +PROVIDE ( _SPIFFS_start = 0x4027b000 ); +PROVIDE ( _SPIFFS_end = 0x4027b000 ); +PROVIDE ( _SPIFFS_page = 0x0 ); +PROVIDE ( _SPIFFS_block = 0x0 ); + +PROVIDE ( _FS_start = _SPIFFS_start ); +PROVIDE ( _FS_end = _SPIFFS_end ); +PROVIDE ( _FS_page = _SPIFFS_page ); +PROVIDE ( _FS_block = _SPIFFS_block ); + +INCLUDE "local.eagle.app.v6.common.ld" diff --git a/dist/ld/pre_2.5.0/eagle.flash.1m0m1s.ld b/dist/ld/pre_2.5.0/eagle.flash.1m0m1s.ld new file mode 100644 index 00000000..e9c1c377 --- /dev/null +++ b/dist/ld/pre_2.5.0/eagle.flash.1m0m1s.ld @@ -0,0 +1,30 @@ +/* +sketch: 999KB +fs: 0KB +eeprom: 4KB +*/ + +MEMORY +{ + dport0_0_seg : org = 0x3FF00000, len = 0x10 + dram0_0_seg : org = 0x3FFE8000, len = 0x14000 + iram1_0_seg : org = 0x40100000, len = 0x8000 + irom0_0_seg : org = 0x40201010, len = 0xf9ff0 +} + +/* +Provide both _SPIFFS_ and _FS_ to be compatible with 2.3.0...2.6.0+ and +any library that is using old _SPIFFS_... +*/ + +PROVIDE ( _SPIFFS_start = 0x402fb000 ); +PROVIDE ( _SPIFFS_end = 0x402fb000 ); +PROVIDE ( _SPIFFS_page = 0x0 ); +PROVIDE ( _SPIFFS_block = 0x0 ); + +PROVIDE ( _FS_start = _SPIFFS_start ); +PROVIDE ( _FS_end = _SPIFFS_end ); +PROVIDE ( _FS_page = _SPIFFS_page ); +PROVIDE ( _FS_block = _SPIFFS_block ); + +INCLUDE "eagle.app.v6.common.ld" diff --git a/dist/ld/pre_2.5.0/eagle.flash.1m0m2s.ld b/dist/ld/pre_2.5.0/eagle.flash.1m0m2s.ld new file mode 100644 index 00000000..80258bcd --- /dev/null +++ b/dist/ld/pre_2.5.0/eagle.flash.1m0m2s.ld @@ -0,0 +1,30 @@ +/* +sketch: 995KB +fs: 0KB +eeprom: 8KB +*/ + +MEMORY +{ + dport0_0_seg : org = 0x3FF00000, len = 0x10 + dram0_0_seg : org = 0x3FFE8000, len = 0x14000 + iram1_0_seg : org = 0x40100000, len = 0x8000 + irom0_0_seg : org = 0x40201010, len = 0xf8ff0 +} + +/* +Provide both _SPIFFS_ and _FS_ to be compatible with 2.3.0...2.6.0+ and +any library that is using old _SPIFFS_... +*/ + +PROVIDE ( _SPIFFS_start = 0x402fa000 ); +PROVIDE ( _SPIFFS_end = 0x402fa000 ); +PROVIDE ( _SPIFFS_page = 0x0 ); +PROVIDE ( _SPIFFS_block = 0x0 ); + +PROVIDE ( _FS_start = _SPIFFS_start ); +PROVIDE ( _FS_end = _SPIFFS_end ); +PROVIDE ( _FS_page = _SPIFFS_page ); +PROVIDE ( _FS_block = _SPIFFS_block ); + +INCLUDE "eagle.app.v6.common.ld" diff --git a/code/eagle.flash.2m1m4s.ld b/dist/ld/pre_2.5.0/eagle.flash.2m1m4s.ld similarity index 51% rename from code/eagle.flash.2m1m4s.ld rename to dist/ld/pre_2.5.0/eagle.flash.2m1m4s.ld index 9d300dd1..ef9d7d0d 100644 --- a/code/eagle.flash.2m1m4s.ld +++ b/dist/ld/pre_2.5.0/eagle.flash.2m1m4s.ld @@ -1,8 +1,8 @@ -/* Flash Split for 2M chips, ~1M SPIFFS, 4 sectors for EEPROM */ -/* sketch 1019KB */ -/* spiffs 992KB */ -/* eeprom 16KB */ -/* reserved 16KB */ +/* +sketch: 1019KB +fs: 992KB +eeprom: 16KB +*/ MEMORY { @@ -12,9 +12,19 @@ MEMORY irom0_0_seg : org = 0x40201010, len = 0xfeff0 } +/* +Provide both _SPIFFS_ and _FS_ to be compatible with 2.3.0...2.6.0+ and +any library that is using old _SPIFFS_... +*/ + PROVIDE ( _SPIFFS_start = 0x40300000 ); -PROVIDE ( _SPIFFS_end = 0x403F8000 ); +PROVIDE ( _SPIFFS_end = 0x403f8000 ); PROVIDE ( _SPIFFS_page = 0x100 ); PROVIDE ( _SPIFFS_block = 0x2000 ); -INCLUDE "../ld/eagle.app.v6.common.ld" +PROVIDE ( _FS_start = _SPIFFS_start ); +PROVIDE ( _FS_end = _SPIFFS_end ); +PROVIDE ( _FS_page = _SPIFFS_page ); +PROVIDE ( _FS_block = _SPIFFS_block ); + +INCLUDE "eagle.app.v6.common.ld" diff --git a/code/eagle.flash.4m1m4s.ld b/dist/ld/pre_2.5.0/eagle.flash.4m1m4s.ld similarity index 51% rename from code/eagle.flash.4m1m4s.ld rename to dist/ld/pre_2.5.0/eagle.flash.4m1m4s.ld index 0812c369..21485a9b 100644 --- a/code/eagle.flash.4m1m4s.ld +++ b/dist/ld/pre_2.5.0/eagle.flash.4m1m4s.ld @@ -1,9 +1,8 @@ -/* Flash Split for 4M chips, ~1M for SPIFFS, 4 sectors for EEPROM */ -/* sketch 1019KB */ -/* empty/ota? 2048KB */ -/* spiffs 992KB */ -/* eeprom 16KB */ -/* reserved 16KB */ +/* +sketch: 1019KB +fs: 992KB +eeprom: 16KB +*/ MEMORY { @@ -13,9 +12,19 @@ MEMORY irom0_0_seg : org = 0x40201010, len = 0xfeff0 } +/* +Provide both _SPIFFS_ and _FS_ to be compatible with 2.3.0...2.6.0+ and +any library that is using old _SPIFFS_... +*/ + PROVIDE ( _SPIFFS_start = 0x40500000 ); -PROVIDE ( _SPIFFS_end = 0x405F8000 ); +PROVIDE ( _SPIFFS_end = 0x405f8000 ); PROVIDE ( _SPIFFS_page = 0x100 ); PROVIDE ( _SPIFFS_block = 0x2000 ); -INCLUDE "../ld/eagle.app.v6.common.ld" +PROVIDE ( _FS_start = _SPIFFS_start ); +PROVIDE ( _FS_end = _SPIFFS_end ); +PROVIDE ( _FS_page = _SPIFFS_page ); +PROVIDE ( _FS_block = _SPIFFS_block ); + +INCLUDE "eagle.app.v6.common.ld" diff --git a/code/eagle.flash.4m3m4e.ld b/dist/ld/pre_2.5.0/eagle.flash.4m3m4s.ld similarity index 51% rename from code/eagle.flash.4m3m4e.ld rename to dist/ld/pre_2.5.0/eagle.flash.4m3m4s.ld index f25a3874..27836238 100644 --- a/code/eagle.flash.4m3m4e.ld +++ b/dist/ld/pre_2.5.0/eagle.flash.4m3m4s.ld @@ -1,8 +1,8 @@ -/* Flash Split for 4M chips, ~3M for SPIFFS, 4 sectors for EEPROM */ -/* sketch 1019KB */ -/* spiffs 3040KB */ -/* eeprom 16KB */ -/* reserved 16KB */ +/* +sketch: 1019KB +fs: 3040KB +eeprom: 16KB +*/ MEMORY { @@ -12,9 +12,19 @@ MEMORY irom0_0_seg : org = 0x40201010, len = 0xfeff0 } +/* +Provide both _SPIFFS_ and _FS_ to be compatible with 2.3.0...2.6.0+ and +any library that is using old _SPIFFS_... +*/ + PROVIDE ( _SPIFFS_start = 0x40300000 ); -PROVIDE ( _SPIFFS_end = 0x405F8000 ); +PROVIDE ( _SPIFFS_end = 0x405f8000 ); PROVIDE ( _SPIFFS_page = 0x100 ); PROVIDE ( _SPIFFS_block = 0x2000 ); -INCLUDE "../ld/eagle.app.v6.common.ld" +PROVIDE ( _FS_start = _SPIFFS_start ); +PROVIDE ( _FS_end = _SPIFFS_end ); +PROVIDE ( _FS_page = _SPIFFS_page ); +PROVIDE ( _FS_block = _SPIFFS_block ); + +INCLUDE "eagle.app.v6.common.ld" diff --git a/dist/ld/pre_2.5.0/eagle.flash.512k0m1s.ld b/dist/ld/pre_2.5.0/eagle.flash.512k0m1s.ld new file mode 100644 index 00000000..953ef4cc --- /dev/null +++ b/dist/ld/pre_2.5.0/eagle.flash.512k0m1s.ld @@ -0,0 +1,30 @@ +/* +sketch: 487KB +fs: 0KB +eeprom: 4KB +*/ + +MEMORY +{ + dport0_0_seg : org = 0x3FF00000, len = 0x10 + dram0_0_seg : org = 0x3FFE8000, len = 0x14000 + iram1_0_seg : org = 0x40100000, len = 0x8000 + irom0_0_seg : org = 0x40201010, len = 0x79ff0 +} + +/* +Provide both _SPIFFS_ and _FS_ to be compatible with 2.3.0...2.6.0+ and +any library that is using old _SPIFFS_... +*/ + +PROVIDE ( _SPIFFS_start = 0x4027b000 ); +PROVIDE ( _SPIFFS_end = 0x4027b000 ); +PROVIDE ( _SPIFFS_page = 0x0 ); +PROVIDE ( _SPIFFS_block = 0x0 ); + +PROVIDE ( _FS_start = _SPIFFS_start ); +PROVIDE ( _FS_end = _SPIFFS_end ); +PROVIDE ( _FS_page = _SPIFFS_page ); +PROVIDE ( _FS_block = _SPIFFS_block ); + +INCLUDE "eagle.app.v6.common.ld" diff --git a/dist/ldscript_gen.py b/dist/ldscript_gen.py new file mode 100755 index 00000000..911b0312 --- /dev/null +++ b/dist/ldscript_gen.py @@ -0,0 +1,181 @@ +#!/usr/bin/env python + +import os +import argparse +import logging +from collections import defaultdict +from math import trunc + +FORMAT = "%(asctime)-15s %(message)s" +log = logging.getLogger("ldscript-get") +logging.basicConfig(format=FORMAT) + +# mapping from esp8266/tools/boards.txt.py: +# sketch | reserved | empty | fs | eeprom | rf-cal | sdk-wifi-settings +# ...... | 4112B | ..... | ...... | ...... | 16 KB + +IROM0_SPI_FLASH_START = 0x40200000 +IROM0_RESERVED_SKETCH_SIZE = 0x1010 +IROM0_RESERVED_SDK_SIZE = 0x4000 + +SIZE = {512: 0x80000, 1024: 0x100000, 2048: 0x200000, 3072: 0x300000, 4096: 0x400000} + +# supported sizes +# flash (bytes), fs (bytes), eeprom (sectors) +VARIANTS = [ + [SIZE[512], 0, 1], + [SIZE[1024], 0, 1], + [SIZE[1024], 0, 2], + [SIZE[2048], SIZE[1024], 4], + [SIZE[4096], SIZE[1024], 4], + [SIZE[4096], SIZE[3072], 4], +] + + +def size_suffix(size): + if size >= SIZE[1024] or not size: + size = trunc(size / SIZE[1024]) + suffix = "m" + else: + size = trunc(size / 1024) + suffix = "k" + + return size, suffix + + +def variant_name(variant): + tmpl = "{flash_size}{flash_suffix}{fs_size}{fs_suffix}{sectors}s" + + flash_size, fs_size, sectors = variant + + flash_size, flash_suffix = size_suffix(flash_size) + fs_size, fs_suffix = size_suffix(fs_size) + + return tmpl.format( + flash_size=flash_size, + flash_suffix=flash_suffix, + fs_size=fs_size, + fs_suffix=fs_suffix, + sectors=sectors, + ) + + +TEMPLATE = """\ +/* +sketch: {size_kb}KB +fs: {fs_size_kb}KB +eeprom: {eeprom_size_kb}KB +*/ + +MEMORY +{{ + dport0_0_seg : org = 0x3FF00000, len = 0x10 + dram0_0_seg : org = 0x3FFE8000, len = 0x14000 + iram1_0_seg : org = 0x40100000, len = 0x8000 + irom0_0_seg : org = 0x40201010, len = {size:#x} +}} + +/* +Provide both _SPIFFS_ and _FS_ to be compatible with 2.3.0...2.6.0+ and +any library that is using old _SPIFFS_... +*/ + +PROVIDE ( _SPIFFS_start = {fs_start:#x} ); +PROVIDE ( _SPIFFS_end = {fs_end:#x} ); +PROVIDE ( _SPIFFS_page = {fs_page:#x} ); +PROVIDE ( _SPIFFS_block = {fs_block:#x} ); + +PROVIDE ( _FS_start = _SPIFFS_start ); +PROVIDE ( _FS_end = _SPIFFS_end ); +PROVIDE ( _FS_page = _SPIFFS_page ); +PROVIDE ( _FS_block = _SPIFFS_block ); + +INCLUDE \"{include}\" +""" + + +def flash_map(flashsize, fs, sectors): + reserved = IROM0_RESERVED_SKETCH_SIZE + sdk_reserved = IROM0_RESERVED_SDK_SIZE + eeprom_size = 0x1000 * sectors + + fs_end = IROM0_SPI_FLASH_START + (flashsize - sdk_reserved - eeprom_size) + fs_page = 0x100 + if flashsize <= SIZE[1024]: + max_upload_size = (flashsize - (fs + eeprom_size + sdk_reserved)) - reserved + fs_start = IROM0_SPI_FLASH_START + fs_end - fs + fs_block = 4096 + else: + max_upload_size = 1024 * 1024 - reserved + fs_start = IROM0_SPI_FLASH_START + (flashsize - fs) + if fs < SIZE[512]: + fs_block = 4096 + else: + fs_block = 8192 + + if not fs: + fs_block = 0 + fs_page = 0 + fs_start = fs_end + + # Adjust FS_end to be a multiple of the block size + # ref: https://github.com/esp8266/Arduino/pull/5989 + if fs: + fs_end = fs_block * ((fs_end - fs_start) // fs_block) + fs_start + + result = { + "size": max_upload_size, + "size_kb": int(max_upload_size / 1024), + "eeprom_size_kb": int(eeprom_size / 1024), + "fs_size_kb": int((fs_end - fs_start) / 1024), + "fs_start": fs_start, + "fs_end": fs_end, + "fs_page": fs_page, + "fs_block": fs_block, + } + + return result + + +def render(variant, legacy): + name = variant_name(variant) + name = "eagle.flash.{}.ld".format(name) + + ld_include = "local.eagle.app.v6.common.ld" + ld_dir = "ld/latest" + if legacy: + ld_include = "eagle.app.v6.common.ld" + ld_dir = "ld/pre_2.5.0" + + path = os.path.join(ld_dir, name) + + log.info("render %s (INCLUDE %s)", name, ld_include) + + with open(path, "w") as f: + f.write(TEMPLATE.format(include=ld_include, **flash_map(*variant))) + + +def render_all(): + for variant in VARIANTS: + render(variant, True) + render(variant, False) + + +if __name__ == "__main__": + variants = {variant_name(x): x for x in VARIANTS} + choices = ["all"] + choices.extend(variants.keys()) + + parser = argparse.ArgumentParser() + parser.add_argument("--legacy", action="store_true", default=False) + parser.add_argument("--verbose", action="store_true", default=False) + parser.add_argument("variant", choices=choices) + + args = parser.parse_args() + if args.verbose: + log.setLevel(logging.DEBUG) + + if args.variant == "all": + render_all() + else: + render(variants[args.variant], args.legacy) diff --git a/pre-commit b/pre-commit index 3bf202d7..896d4b1b 100755 --- a/pre-commit +++ b/pre-commit @@ -27,6 +27,7 @@ except ImportError: from fileinput import FileInput +# TODO: drop after platform.io supports python 3 # https://github.com/python/cpython/commit/6cb7b659#diff-78790b53ff259619377058acd4f74672 if sys.version_info[0] < 3: class FileInputCtx(FileInput):