2016-10-22 02:20:57 +03:00
|
|
|
# Copyright 2014-present PlatformIO <contact@platformio.org>
|
|
|
|
|
#
|
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
|
#
|
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
#
|
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
|
# limitations under the License.
|
|
|
|
|
|
2019-05-11 22:13:26 +03:00
|
|
|
import re
|
2018-05-07 23:40:34 +03:00
|
|
|
import sys
|
|
|
|
|
from os.path import isfile, join
|
2016-10-24 20:23:25 +03:00
|
|
|
|
2019-05-28 14:09:26 +03:00
|
|
|
from SCons.Script import (
|
|
|
|
|
ARGUMENTS, COMMAND_LINE_TARGETS, AlwaysBuild, Builder, Default,
|
|
|
|
|
DefaultEnvironment)
|
2016-10-24 20:23:25 +03:00
|
|
|
|
2022-04-13 18:49:20 +03:00
|
|
|
from platformio.util import get_serial_ports
|
|
|
|
|
|
2018-05-26 01:13:54 +03:00
|
|
|
#
|
|
|
|
|
# Helpers
|
|
|
|
|
#
|
|
|
|
|
|
2018-05-31 21:11:12 +03:00
|
|
|
|
2022-04-13 18:49:20 +03:00
|
|
|
def BeforeUpload(target, source, env):
|
|
|
|
|
upload_options = {}
|
|
|
|
|
if "BOARD" in env:
|
|
|
|
|
upload_options = env.BoardConfig().get("upload", {})
|
|
|
|
|
|
|
|
|
|
env.AutodetectUploadPort()
|
|
|
|
|
|
|
|
|
|
before_ports = get_serial_ports()
|
|
|
|
|
if upload_options.get("use_1200bps_touch", False):
|
|
|
|
|
env.TouchSerialPort("$UPLOAD_PORT", 1200)
|
|
|
|
|
|
|
|
|
|
if upload_options.get("wait_for_upload_port", False):
|
|
|
|
|
env.Replace(UPLOAD_PORT=env.WaitForNewSerialPort(before_ports))
|
|
|
|
|
|
|
|
|
|
|
2016-10-24 20:23:25 +03:00
|
|
|
def _get_board_f_flash(env):
|
|
|
|
|
frequency = env.subst("$BOARD_F_FLASH")
|
|
|
|
|
frequency = str(frequency).replace("L", "")
|
|
|
|
|
return str(int(int(frequency) / 1000000)) + "m"
|
|
|
|
|
|
|
|
|
|
|
2021-11-05 14:48:05 +02:00
|
|
|
def _get_board_flash_mode(env):
|
|
|
|
|
mode = env.subst("$BOARD_FLASH_MODE")
|
|
|
|
|
if mode == "qio":
|
|
|
|
|
return "dio"
|
|
|
|
|
elif mode == "qout":
|
|
|
|
|
return "dout"
|
|
|
|
|
return mode
|
|
|
|
|
|
|
|
|
|
|
2022-05-16 13:18:16 +03:00
|
|
|
def _get_board_boot_mode(env):
|
|
|
|
|
return env.BoardConfig().get("build.boot", "$BOARD_FLASH_MODE")
|
|
|
|
|
|
|
|
|
|
|
2018-05-26 01:13:54 +03:00
|
|
|
def _parse_size(value):
|
2018-05-31 21:11:12 +03:00
|
|
|
if isinstance(value, int):
|
|
|
|
|
return value
|
|
|
|
|
elif value.isdigit():
|
2018-05-26 01:13:54 +03:00
|
|
|
return int(value)
|
|
|
|
|
elif value.startswith("0x"):
|
|
|
|
|
return int(value, 16)
|
2018-06-15 21:35:03 +03:00
|
|
|
elif value[-1].upper() in ("K", "M"):
|
|
|
|
|
base = 1024 if value[-1].upper() == "K" else 1024 * 1024
|
2018-05-26 01:13:54 +03:00
|
|
|
return int(value[:-1]) * base
|
|
|
|
|
return value
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _parse_partitions(env):
|
|
|
|
|
partitions_csv = env.subst("$PARTITIONS_TABLE_CSV")
|
|
|
|
|
if not isfile(partitions_csv):
|
|
|
|
|
sys.stderr.write("Could not find the file %s with partitions "
|
|
|
|
|
"table.\n" % partitions_csv)
|
|
|
|
|
env.Exit(1)
|
2018-05-30 00:25:12 +03:00
|
|
|
return
|
2018-05-26 01:13:54 +03:00
|
|
|
|
|
|
|
|
result = []
|
2018-05-31 21:11:12 +03:00
|
|
|
next_offset = 0
|
2018-05-26 01:13:54 +03:00
|
|
|
with open(partitions_csv) as fp:
|
|
|
|
|
for line in fp.readlines():
|
|
|
|
|
line = line.strip()
|
|
|
|
|
if not line or line.startswith("#"):
|
|
|
|
|
continue
|
2018-05-31 21:11:12 +03:00
|
|
|
tokens = [t.strip() for t in line.split(",")]
|
2018-05-26 01:13:54 +03:00
|
|
|
if len(tokens) < 5:
|
|
|
|
|
continue
|
2018-05-31 21:11:12 +03:00
|
|
|
partition = {
|
2018-05-26 01:13:54 +03:00
|
|
|
"name": tokens[0],
|
|
|
|
|
"type": tokens[1],
|
|
|
|
|
"subtype": tokens[2],
|
2018-05-31 21:11:12 +03:00
|
|
|
"offset": tokens[3] or next_offset,
|
2018-05-26 01:13:54 +03:00
|
|
|
"size": tokens[4],
|
|
|
|
|
"flags": tokens[5] if len(tokens) > 5 else None
|
2018-05-31 21:11:12 +03:00
|
|
|
}
|
|
|
|
|
result.append(partition)
|
2021-11-05 14:45:37 +02:00
|
|
|
next_offset = _parse_size(partition["offset"]) + _parse_size(
|
|
|
|
|
partition["size"]
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
bound = 0x10000 if partition["type"] in ("0", "app") else 4
|
|
|
|
|
next_offset = (next_offset + bound - 1) & ~(bound - 1)
|
|
|
|
|
|
2018-05-26 01:13:54 +03:00
|
|
|
return result
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _update_max_upload_size(env):
|
|
|
|
|
if not env.get("PARTITIONS_TABLE_CSV"):
|
|
|
|
|
return
|
|
|
|
|
sizes = [
|
2022-05-16 13:18:16 +03:00
|
|
|
_parse_size(p["size"]) for p in _parse_partitions(env)
|
|
|
|
|
if p["type"] in ("0", "app")
|
2018-05-26 01:13:54 +03:00
|
|
|
]
|
|
|
|
|
if sizes:
|
2019-06-13 20:48:15 +03:00
|
|
|
board.update("upload.maximum_size", max(sizes))
|
2018-05-26 01:13:54 +03:00
|
|
|
|
|
|
|
|
|
2018-12-26 02:07:03 +02:00
|
|
|
def _to_unix_slashes(path):
|
2022-04-17 23:58:10 +03:00
|
|
|
return path.replace("\\", "/")
|
2018-12-26 02:07:03 +02:00
|
|
|
|
|
|
|
|
|
2018-05-11 02:16:58 +03:00
|
|
|
#
|
2022-04-17 23:58:10 +03:00
|
|
|
# Filesystem helpers
|
2018-05-11 02:16:58 +03:00
|
|
|
#
|
|
|
|
|
|
2018-05-31 21:11:12 +03:00
|
|
|
|
2022-04-17 23:58:10 +03:00
|
|
|
def fetch_fs_size(env):
|
|
|
|
|
fs = None
|
2018-05-26 01:13:54 +03:00
|
|
|
for p in _parse_partitions(env):
|
2022-04-17 23:58:10 +03:00
|
|
|
if p["type"] == "data" and p["subtype"] in ("spiffs", "fat"):
|
|
|
|
|
fs = p
|
|
|
|
|
if not fs:
|
2018-05-26 01:13:54 +03:00
|
|
|
sys.stderr.write(
|
2022-04-17 23:58:10 +03:00
|
|
|
"Could not find the any filesystem section in the partitions "
|
2021-01-21 13:46:21 +02:00
|
|
|
"table %s\n" % env.subst("$PARTITIONS_TABLE_CSV")
|
|
|
|
|
)
|
2018-05-30 00:25:12 +03:00
|
|
|
env.Exit(1)
|
|
|
|
|
return
|
2022-04-17 23:58:10 +03:00
|
|
|
env["FS_START"] = _parse_size(fs["offset"])
|
|
|
|
|
env["FS_SIZE"] = _parse_size(fs["size"])
|
|
|
|
|
env["FS_PAGE"] = int("0x100", 16)
|
|
|
|
|
env["FS_BLOCK"] = int("0x1000", 16)
|
2018-05-11 02:16:58 +03:00
|
|
|
|
2022-04-17 23:58:10 +03:00
|
|
|
# FFat specific offsets, see:
|
|
|
|
|
# https://github.com/lorol/arduino-esp32fatfs-plugin#notes-for-fatfs
|
|
|
|
|
if filesystem == "fatfs":
|
|
|
|
|
env["FS_START"] += 4096
|
|
|
|
|
env["FS_SIZE"] -= 4096
|
2018-05-11 02:16:58 +03:00
|
|
|
|
2022-04-17 23:58:10 +03:00
|
|
|
|
|
|
|
|
def __fetch_fs_size(target, source, env):
|
|
|
|
|
fetch_fs_size(env)
|
2018-05-11 02:16:58 +03:00
|
|
|
return (target, source)
|
|
|
|
|
|
|
|
|
|
|
2022-07-30 21:09:01 +03:00
|
|
|
def merge_binaries(source, target, env, for_signature):
|
|
|
|
|
return " ".join([
|
|
|
|
|
'"$PYTHONEXE"',
|
|
|
|
|
join(platform.get_package_dir("tool-esptoolpy") or "", "esptool.py"),
|
|
|
|
|
"--chip", mcu, "merge_bin",
|
|
|
|
|
"-o", "$TARGET",
|
|
|
|
|
"--flash_mode", "$BOARD_FLASH_MODE",
|
2022-07-30 22:50:59 +03:00
|
|
|
"--flash_size", board.get("upload.flash_size", "4MB"),
|
2022-07-30 21:09:01 +03:00
|
|
|
"$ESP32_APP_OFFSET", "$SOURCES"
|
|
|
|
|
] + ['"%s"' % itm for img in env.get("FLASH_EXTRA_IMAGES", []) for itm in img])
|
|
|
|
|
|
|
|
|
|
|
2016-10-24 20:23:25 +03:00
|
|
|
env = DefaultEnvironment()
|
|
|
|
|
platform = env.PioPlatform()
|
2019-06-13 20:48:15 +03:00
|
|
|
board = env.BoardConfig()
|
2020-05-11 21:17:48 +03:00
|
|
|
mcu = board.get("build.mcu", "esp32")
|
2021-06-23 12:32:55 +03:00
|
|
|
toolchain_arch = "xtensa-%s" % mcu
|
2022-04-17 23:58:10 +03:00
|
|
|
filesystem = board.get("build.filesystem", "spiffs")
|
2021-06-23 12:32:55 +03:00
|
|
|
if mcu == "esp32c3":
|
|
|
|
|
toolchain_arch = "riscv32-esp"
|
2016-10-24 20:23:25 +03:00
|
|
|
|
2022-07-30 21:09:01 +03:00
|
|
|
# Arduino core v2.0.4 contains updated bootloader images that have innacurate default
|
|
|
|
|
# headers. This results in bootloops if firmware is flashed via OpenOCD (e.g. debugging
|
|
|
|
|
# or uploading via debug tools). For this reason, before uploading or debugging we need
|
|
|
|
|
# to merge binaries via esptoolpy so that the image headers will be adjusted according to
|
|
|
|
|
# --flash-size and --flash-mode arguments.
|
|
|
|
|
# Note: This behavior doesn't occur if uploading is done via esptoolpy, as esptoolpy
|
|
|
|
|
# overrides the binary image headers before flashing.
|
|
|
|
|
firmware_merge_required = bool(
|
|
|
|
|
env.get("PIOFRAMEWORK", []) == ["arduino"]
|
|
|
|
|
and (
|
|
|
|
|
"debug" in env.GetBuildType()
|
|
|
|
|
or env.subst("$UPLOAD_PROTOCOL") in board.get("debug.tools", {})
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
|
2022-07-29 17:53:19 +03:00
|
|
|
if "INTEGRATION_EXTRA_DATA" not in env:
|
|
|
|
|
env["INTEGRATION_EXTRA_DATA"] = {}
|
|
|
|
|
|
2016-10-24 20:23:25 +03:00
|
|
|
env.Replace(
|
2022-05-16 13:18:16 +03:00
|
|
|
__get_board_boot_mode=_get_board_boot_mode,
|
2016-10-24 20:23:25 +03:00
|
|
|
__get_board_f_flash=_get_board_f_flash,
|
2021-11-05 14:48:05 +02:00
|
|
|
__get_board_flash_mode=_get_board_flash_mode,
|
2018-06-02 15:58:00 +03:00
|
|
|
|
2021-06-23 12:32:55 +03:00
|
|
|
AR="%s-elf-ar" % toolchain_arch,
|
|
|
|
|
AS="%s-elf-as" % toolchain_arch,
|
|
|
|
|
CC="%s-elf-gcc" % toolchain_arch,
|
|
|
|
|
CXX="%s-elf-g++" % toolchain_arch,
|
|
|
|
|
GDB="%s-elf-gdb" % toolchain_arch,
|
2016-10-29 19:31:23 +03:00
|
|
|
OBJCOPY=join(
|
|
|
|
|
platform.get_package_dir("tool-esptoolpy") or "", "esptool.py"),
|
2021-06-23 12:32:55 +03:00
|
|
|
RANLIB="%s-elf-ranlib" % toolchain_arch,
|
|
|
|
|
SIZETOOL="%s-elf-size" % toolchain_arch,
|
2018-06-02 15:58:00 +03:00
|
|
|
|
2017-08-22 16:01:28 +03:00
|
|
|
ARFLAGS=["rc"],
|
2018-06-09 01:00:20 +03:00
|
|
|
|
2018-07-02 15:33:43 +03:00
|
|
|
SIZEPROGREGEXP=r"^(?:\.iram0\.text|\.iram0\.vectors|\.dram0\.data|\.flash\.text|\.flash\.rodata|)\s+([0-9]+).*",
|
|
|
|
|
SIZEDATAREGEXP=r"^(?:\.dram0\.data|\.dram0\.bss|\.noinit)\s+([0-9]+).*",
|
2018-06-02 15:58:00 +03:00
|
|
|
SIZECHECKCMD="$SIZETOOL -A -d $SOURCES",
|
|
|
|
|
SIZEPRINTCMD="$SIZETOOL -B -d $SOURCES",
|
|
|
|
|
|
2018-11-24 15:29:21 +02:00
|
|
|
ERASEFLAGS=[
|
2020-05-11 21:17:48 +03:00
|
|
|
"--chip", mcu,
|
2018-11-24 15:29:21 +02:00
|
|
|
"--port", '"$UPLOAD_PORT"'
|
|
|
|
|
],
|
|
|
|
|
ERASECMD='"$PYTHONEXE" "$OBJCOPY" $ERASEFLAGS erase_flash',
|
|
|
|
|
|
2022-04-17 23:58:10 +03:00
|
|
|
# mkspiffs package contains two different binaries for IDF and Arduino
|
|
|
|
|
MKFSTOOL="mk%s" % filesystem
|
|
|
|
|
+ (
|
|
|
|
|
(
|
|
|
|
|
"_${PIOPLATFORM}_"
|
|
|
|
|
+ (
|
|
|
|
|
"espidf"
|
|
|
|
|
if "espidf" in env.subst("$PIOFRAMEWORK")
|
|
|
|
|
else "${PIOFRAMEWORK}"
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
if filesystem == "spiffs"
|
|
|
|
|
else ""
|
|
|
|
|
),
|
|
|
|
|
# Legacy `ESP32_SPIFFS_IMAGE_NAME` is used as the second fallback value for
|
|
|
|
|
# backward compatibility
|
|
|
|
|
ESP32_FS_IMAGE_NAME=env.get(
|
|
|
|
|
"ESP32_FS_IMAGE_NAME", env.get("ESP32_SPIFFS_IMAGE_NAME", filesystem)
|
|
|
|
|
),
|
2022-04-20 22:20:13 +03:00
|
|
|
|
|
|
|
|
ESP32_APP_OFFSET=board.get("upload.offset_address", "0x10000"),
|
2020-04-27 17:19:21 +03:00
|
|
|
|
2018-06-02 15:58:00 +03:00
|
|
|
PROGSUFFIX=".elf"
|
|
|
|
|
)
|
2016-10-24 20:23:25 +03:00
|
|
|
|
2018-01-03 18:23:00 +02:00
|
|
|
# Allow user to override via pre:script
|
|
|
|
|
if env.get("PROGNAME", "program") == "program":
|
|
|
|
|
env.Replace(PROGNAME="firmware")
|
|
|
|
|
|
2016-10-24 20:23:25 +03:00
|
|
|
env.Append(
|
|
|
|
|
BUILDERS=dict(
|
|
|
|
|
ElfToBin=Builder(
|
|
|
|
|
action=env.VerboseAction(" ".join([
|
2022-04-18 21:24:40 +03:00
|
|
|
'"$PYTHONEXE" "$OBJCOPY"',
|
2022-04-18 21:16:41 +03:00
|
|
|
"--chip", mcu, "elf2image",
|
2018-06-09 01:00:20 +03:00
|
|
|
"--flash_mode", "$BOARD_FLASH_MODE",
|
|
|
|
|
"--flash_freq", "${__get_board_f_flash(__env__)}",
|
2019-06-13 20:48:15 +03:00
|
|
|
"--flash_size", board.get("upload.flash_size", "detect"),
|
2018-06-09 01:00:20 +03:00
|
|
|
"-o", "$TARGET", "$SOURCES"
|
2016-10-24 20:23:25 +03:00
|
|
|
]), "Building $TARGET"),
|
2018-08-11 19:10:58 +03:00
|
|
|
suffix=".bin"
|
|
|
|
|
),
|
2018-05-11 02:16:58 +03:00
|
|
|
DataToBin=Builder(
|
2022-04-17 23:58:10 +03:00
|
|
|
action=env.VerboseAction(
|
|
|
|
|
" ".join(
|
|
|
|
|
['"$MKFSTOOL"', "-c", "$SOURCES", "-s", "$FS_SIZE"]
|
|
|
|
|
+ (
|
|
|
|
|
[
|
|
|
|
|
"-p",
|
|
|
|
|
"$FS_PAGE",
|
|
|
|
|
"-b",
|
|
|
|
|
"$FS_BLOCK",
|
|
|
|
|
]
|
|
|
|
|
if filesystem in ("spiffs", "littlefs")
|
|
|
|
|
else []
|
|
|
|
|
)
|
|
|
|
|
+ ["$TARGET"]
|
|
|
|
|
),
|
|
|
|
|
"Building FS image from '$SOURCES' directory to $TARGET",
|
|
|
|
|
),
|
|
|
|
|
emitter=__fetch_fs_size,
|
2018-05-11 02:16:58 +03:00
|
|
|
source_factory=env.Dir,
|
2022-04-17 23:58:10 +03:00
|
|
|
suffix=".bin",
|
|
|
|
|
),
|
2022-07-30 21:09:01 +03:00
|
|
|
MergeBin=Builder(
|
|
|
|
|
generator=merge_binaries,
|
|
|
|
|
suffix=".bin",
|
|
|
|
|
),
|
2018-08-11 19:10:58 +03:00
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
if not env.get("PIOFRAMEWORK"):
|
|
|
|
|
env.SConscript("frameworks/_bare.py", exports="env")
|
2017-04-28 11:51:04 +03:00
|
|
|
|
2016-10-24 20:23:25 +03:00
|
|
|
#
|
2022-04-17 23:58:10 +03:00
|
|
|
# Target: Build executable and linkable firmware or FS image
|
2016-10-24 20:23:25 +03:00
|
|
|
#
|
|
|
|
|
|
2020-06-01 17:29:48 +03:00
|
|
|
target_elf = None
|
2022-07-30 21:09:01 +03:00
|
|
|
target_firm_merged = None
|
2018-01-03 18:23:00 +02:00
|
|
|
if "nobuild" in COMMAND_LINE_TARGETS:
|
2019-06-12 23:09:40 +03:00
|
|
|
target_elf = join("$BUILD_DIR", "${PROGNAME}.elf")
|
2018-05-07 23:40:34 +03:00
|
|
|
if set(["uploadfs", "uploadfsota"]) & set(COMMAND_LINE_TARGETS):
|
2022-04-17 23:58:10 +03:00
|
|
|
fetch_fs_size(env)
|
|
|
|
|
target_firm = join("$BUILD_DIR", "${ESP32_FS_IMAGE_NAME}.bin")
|
2018-05-07 23:40:34 +03:00
|
|
|
else:
|
|
|
|
|
target_firm = join("$BUILD_DIR", "${PROGNAME}.bin")
|
2018-01-03 18:23:00 +02:00
|
|
|
else:
|
2020-06-01 17:29:48 +03:00
|
|
|
target_elf = env.BuildProgram()
|
2018-05-07 23:40:34 +03:00
|
|
|
if set(["buildfs", "uploadfs", "uploadfsota"]) & set(COMMAND_LINE_TARGETS):
|
|
|
|
|
target_firm = env.DataToBin(
|
2022-04-17 23:58:10 +03:00
|
|
|
join("$BUILD_DIR", "${ESP32_FS_IMAGE_NAME}"), "$PROJECT_DATA_DIR"
|
|
|
|
|
)
|
2020-09-07 12:56:44 +03:00
|
|
|
env.NoCache(target_firm)
|
2018-05-07 23:40:34 +03:00
|
|
|
AlwaysBuild(target_firm)
|
|
|
|
|
else:
|
2018-05-11 02:16:58 +03:00
|
|
|
target_firm = env.ElfToBin(
|
|
|
|
|
join("$BUILD_DIR", "${PROGNAME}"), target_elf)
|
2022-07-30 21:09:01 +03:00
|
|
|
if firmware_merge_required:
|
|
|
|
|
# Note: Default offset address must be set to 0x0 because debugging
|
|
|
|
|
# relies on OpenOCD that requires merged firmware
|
|
|
|
|
env["INTEGRATION_EXTRA_DATA"].update(
|
|
|
|
|
{"application_offset": "0x0", "merged_firmware": True}
|
|
|
|
|
)
|
|
|
|
|
target_firm_merged = env.MergeBin(join(
|
|
|
|
|
"$BUILD_DIR", "${PROGNAME}_merged"), target_firm)
|
2021-03-15 12:50:29 +02:00
|
|
|
env.Depends(target_firm, "checkprogsize")
|
2016-10-24 20:23:25 +03:00
|
|
|
|
2021-03-15 12:50:14 +02:00
|
|
|
env.AddPlatformTarget("buildfs", target_firm, target_firm, "Build Filesystem Image")
|
2018-01-03 18:23:00 +02:00
|
|
|
AlwaysBuild(env.Alias("nobuild", target_firm))
|
2016-11-13 21:42:12 +02:00
|
|
|
target_buildprog = env.Alias("buildprog", target_firm, target_firm)
|
2016-10-24 20:23:25 +03:00
|
|
|
|
2018-05-26 01:13:54 +03:00
|
|
|
# update max upload size based on CSV file
|
2018-06-04 14:10:58 +03:00
|
|
|
if env.get("PIOMAINPROG"):
|
|
|
|
|
env.AddPreAction(
|
|
|
|
|
"checkprogsize",
|
|
|
|
|
env.VerboseAction(
|
|
|
|
|
lambda source, target, env: _update_max_upload_size(env),
|
|
|
|
|
"Retrieving maximum program size $SOURCES"))
|
|
|
|
|
# remove after PIO Core 3.6 release
|
|
|
|
|
elif set(["checkprogsize", "upload"]) & set(COMMAND_LINE_TARGETS):
|
2018-05-26 01:13:54 +03:00
|
|
|
_update_max_upload_size(env)
|
|
|
|
|
|
2018-05-07 23:40:34 +03:00
|
|
|
#
|
2018-05-11 02:16:58 +03:00
|
|
|
# Target: Print binary size
|
2018-05-07 23:40:34 +03:00
|
|
|
#
|
|
|
|
|
|
2020-06-10 17:16:17 +03:00
|
|
|
target_size = env.AddPlatformTarget(
|
|
|
|
|
"size",
|
|
|
|
|
target_elf,
|
|
|
|
|
env.VerboseAction("$SIZEPRINTCMD", "Calculating size $SOURCE"),
|
|
|
|
|
"Program Size",
|
|
|
|
|
"Calculate program size",
|
|
|
|
|
)
|
2018-05-11 02:16:58 +03:00
|
|
|
|
|
|
|
|
#
|
2022-04-17 23:58:10 +03:00
|
|
|
# Target: Upload firmware or FS image
|
2018-05-11 02:16:58 +03:00
|
|
|
#
|
|
|
|
|
|
|
|
|
|
upload_protocol = env.subst("$UPLOAD_PROTOCOL")
|
2019-06-13 20:48:15 +03:00
|
|
|
debug_tools = board.get("debug.tools", {})
|
2018-05-11 02:16:58 +03:00
|
|
|
upload_actions = []
|
|
|
|
|
|
2019-05-11 22:13:26 +03:00
|
|
|
# Compatibility with old OTA configurations
|
|
|
|
|
if (upload_protocol != "espota"
|
|
|
|
|
and re.match(r"\"?((([0-9]{1,3}\.){3}[0-9]{1,3})|[^\\/]+\.local)\"?$",
|
|
|
|
|
env.get("UPLOAD_PORT", ""))):
|
|
|
|
|
upload_protocol = "espota"
|
|
|
|
|
sys.stderr.write(
|
|
|
|
|
"Warning! We have just detected `upload_port` as IP address or host "
|
|
|
|
|
"name of ESP device. `upload_protocol` is switched to `espota`.\n"
|
|
|
|
|
"Please specify `upload_protocol = espota` in `platformio.ini` "
|
|
|
|
|
"project configuration file.\n")
|
|
|
|
|
|
|
|
|
|
if upload_protocol == "espota":
|
|
|
|
|
if not env.subst("$UPLOAD_PORT"):
|
|
|
|
|
sys.stderr.write(
|
|
|
|
|
"Error: Please specify IP address or host name of ESP device "
|
|
|
|
|
"using `upload_port` for build environment or use "
|
|
|
|
|
"global `--upload-port` option.\n"
|
|
|
|
|
"See https://docs.platformio.org/page/platforms/"
|
|
|
|
|
"espressif32.html#over-the-air-ota-update\n")
|
2018-05-07 23:40:34 +03:00
|
|
|
env.Replace(
|
2018-05-11 02:16:58 +03:00
|
|
|
UPLOADER=join(
|
2019-05-14 00:23:48 +03:00
|
|
|
platform.get_package_dir("framework-arduinoespressif32") or "",
|
|
|
|
|
"tools", "espota.py"),
|
2019-05-11 22:13:26 +03:00
|
|
|
UPLOADERFLAGS=["--debug", "--progress", "-i", "$UPLOAD_PORT"],
|
|
|
|
|
UPLOADCMD='"$PYTHONEXE" "$UPLOADER" $UPLOADERFLAGS -f $SOURCE'
|
|
|
|
|
)
|
2021-02-03 16:10:34 +02:00
|
|
|
if set(["uploadfs", "uploadfsota"]) & set(COMMAND_LINE_TARGETS):
|
|
|
|
|
env.Append(UPLOADERFLAGS=["--spiffs"])
|
2019-05-11 22:13:26 +03:00
|
|
|
upload_actions = [env.VerboseAction("$UPLOADCMD", "Uploading $SOURCE")]
|
|
|
|
|
|
|
|
|
|
elif upload_protocol == "esptool":
|
|
|
|
|
env.Replace(
|
|
|
|
|
UPLOADER=join(
|
|
|
|
|
platform.get_package_dir("tool-esptoolpy") or "", "esptool.py"),
|
2018-05-07 23:40:34 +03:00
|
|
|
UPLOADERFLAGS=[
|
2020-05-11 21:17:48 +03:00
|
|
|
"--chip", mcu,
|
2018-06-09 01:00:20 +03:00
|
|
|
"--port", '"$UPLOAD_PORT"',
|
|
|
|
|
"--baud", "$UPLOAD_SPEED",
|
|
|
|
|
"--before", "default_reset",
|
|
|
|
|
"--after", "hard_reset",
|
|
|
|
|
"write_flash", "-z",
|
2021-11-05 14:48:05 +02:00
|
|
|
"--flash_mode", "${__get_board_flash_mode(__env__)}",
|
2018-06-09 01:00:20 +03:00
|
|
|
"--flash_freq", "${__get_board_f_flash(__env__)}",
|
2022-04-20 22:20:13 +03:00
|
|
|
"--flash_size", board.get("upload.flash_size", "detect")
|
2018-05-11 02:16:58 +03:00
|
|
|
],
|
2022-04-20 22:20:13 +03:00
|
|
|
UPLOADCMD='"$PYTHONEXE" "$UPLOADER" $UPLOADERFLAGS $ESP32_APP_OFFSET $SOURCE'
|
2018-05-07 23:40:34 +03:00
|
|
|
)
|
2018-05-15 17:35:22 -07:00
|
|
|
for image in env.get("FLASH_EXTRA_IMAGES", []):
|
2019-02-18 23:14:00 +02:00
|
|
|
env.Append(UPLOADERFLAGS=[image[0], env.subst(image[1])])
|
2018-05-07 23:40:34 +03:00
|
|
|
|
2018-05-11 02:16:58 +03:00
|
|
|
if "uploadfs" in COMMAND_LINE_TARGETS:
|
|
|
|
|
env.Replace(
|
|
|
|
|
UPLOADERFLAGS=[
|
2020-05-11 21:17:48 +03:00
|
|
|
"--chip", mcu,
|
2018-06-09 01:00:20 +03:00
|
|
|
"--port", '"$UPLOAD_PORT"',
|
|
|
|
|
"--baud", "$UPLOAD_SPEED",
|
|
|
|
|
"--before", "default_reset",
|
|
|
|
|
"--after", "hard_reset",
|
|
|
|
|
"write_flash", "-z",
|
|
|
|
|
"--flash_mode", "$BOARD_FLASH_MODE",
|
|
|
|
|
"--flash_size", "detect",
|
2022-04-18 21:16:41 +03:00
|
|
|
"$FS_START"
|
2018-05-21 22:08:26 +03:00
|
|
|
],
|
|
|
|
|
UPLOADCMD='"$PYTHONEXE" "$UPLOADER" $UPLOADERFLAGS $SOURCE',
|
2018-05-11 02:16:58 +03:00
|
|
|
)
|
2018-07-02 16:03:11 +03:00
|
|
|
|
2018-05-11 02:16:58 +03:00
|
|
|
upload_actions = [
|
2022-04-13 18:49:20 +03:00
|
|
|
env.VerboseAction(BeforeUpload, "Looking for upload port..."),
|
2018-05-11 02:16:58 +03:00
|
|
|
env.VerboseAction("$UPLOADCMD", "Uploading $SOURCE")
|
|
|
|
|
]
|
|
|
|
|
|
2020-03-17 10:51:38 +00:00
|
|
|
|
|
|
|
|
elif upload_protocol == "mbctool":
|
|
|
|
|
env.Replace(
|
|
|
|
|
UPLOADER=join(
|
|
|
|
|
platform.get_package_dir("tool-mbctool") or "", "bin", "mbctool"),
|
|
|
|
|
UPLOADERFLAGS=[
|
|
|
|
|
"--device", "esp",
|
2020-03-18 15:06:42 +02:00
|
|
|
"--speed", "$UPLOAD_SPEED",
|
|
|
|
|
"--port", '"$UPLOAD_PORT"',
|
2020-03-17 10:51:38 +00:00
|
|
|
"--upload",
|
|
|
|
|
"0x1000", join(
|
2020-04-27 17:19:21 +03:00
|
|
|
platform.get_package_dir("framework-arduino-mbcwb"),
|
2020-03-17 10:51:38 +00:00
|
|
|
"tools", "sdk", "bin", "bootloader_qio_80m.bin"),
|
|
|
|
|
"0x8000", join("$BUILD_DIR", "partitions.bin"),
|
|
|
|
|
"0xe000", join(
|
2020-04-27 17:19:21 +03:00
|
|
|
platform.get_package_dir("framework-arduino-mbcwb"),
|
2020-03-17 10:51:38 +00:00
|
|
|
"tools", "partitions", "boot_app0.bin"),
|
|
|
|
|
"0x10000", join("$BUILD_DIR", "${PROGNAME}.bin"),
|
|
|
|
|
],
|
2020-04-27 17:19:21 +03:00
|
|
|
UPLOADCMD='"$UPLOADER" $UPLOADERFLAGS'
|
2020-03-17 10:51:38 +00:00
|
|
|
)
|
|
|
|
|
upload_actions = [
|
|
|
|
|
env.VerboseAction(env.AutodetectUploadPort,
|
|
|
|
|
"Looking for upload port..."),
|
|
|
|
|
env.VerboseAction("$UPLOADCMD", "Uploading $SOURCE")
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
2018-05-11 02:16:58 +03:00
|
|
|
elif upload_protocol in debug_tools:
|
2022-07-30 21:09:01 +03:00
|
|
|
if firmware_merge_required:
|
|
|
|
|
# Only merged firmware with proper headers will work when uploading is done via
|
|
|
|
|
# debug probes. The firmware offset address must be adjusted to 0x0 accordingly.
|
|
|
|
|
target_firm = target_firm_merged
|
2019-06-13 20:48:15 +03:00
|
|
|
openocd_args = ["-d%d" % (2 if int(ARGUMENTS.get("PIOVERBOSE", 0)) else 1)]
|
|
|
|
|
openocd_args.extend(
|
2018-05-31 21:11:12 +03:00
|
|
|
debug_tools.get(upload_protocol).get("server").get("arguments", []))
|
2022-04-18 15:46:07 +03:00
|
|
|
openocd_args.extend(
|
|
|
|
|
[
|
2022-04-17 23:58:10 +03:00
|
|
|
"-c",
|
2022-04-18 15:46:07 +03:00
|
|
|
"adapter_khz %s" % env.GetProjectOption("debug_speed", "5000"),
|
|
|
|
|
"-c",
|
|
|
|
|
"program_esp {{$SOURCE}} %s verify"
|
|
|
|
|
% (
|
|
|
|
|
"$FS_START"
|
|
|
|
|
if "uploadfs" in COMMAND_LINE_TARGETS
|
2022-07-30 21:09:01 +03:00
|
|
|
else board.get(
|
|
|
|
|
"upload.offset_address",
|
|
|
|
|
"0x0" if firmware_merge_required else "$ESP32_APP_OFFSET"
|
|
|
|
|
)
|
2022-04-18 15:46:07 +03:00
|
|
|
),
|
|
|
|
|
]
|
|
|
|
|
)
|
2022-07-30 21:09:01 +03:00
|
|
|
if "uploadfs" not in COMMAND_LINE_TARGETS and not firmware_merge_required:
|
2022-04-18 15:46:07 +03:00
|
|
|
for image in env.get("FLASH_EXTRA_IMAGES", []):
|
|
|
|
|
openocd_args.extend(
|
|
|
|
|
[
|
|
|
|
|
"-c",
|
|
|
|
|
"program_esp {{%s}} %s verify"
|
|
|
|
|
% (_to_unix_slashes(image[1]), image[0]),
|
|
|
|
|
]
|
|
|
|
|
)
|
2019-06-13 20:48:15 +03:00
|
|
|
openocd_args.extend(["-c", "reset run; shutdown"])
|
|
|
|
|
openocd_args = [
|
|
|
|
|
f.replace(
|
|
|
|
|
"$PACKAGE_DIR",
|
|
|
|
|
_to_unix_slashes(
|
|
|
|
|
platform.get_package_dir("tool-openocd-esp32") or ""))
|
|
|
|
|
for f in openocd_args
|
|
|
|
|
]
|
2022-04-18 15:46:07 +03:00
|
|
|
env.Replace(
|
|
|
|
|
UPLOADER="openocd",
|
2022-04-17 23:58:10 +03:00
|
|
|
UPLOADERFLAGS=openocd_args,
|
2022-04-18 15:46:07 +03:00
|
|
|
UPLOADCMD="$UPLOADER $UPLOADERFLAGS",
|
|
|
|
|
)
|
2018-05-11 02:16:58 +03:00
|
|
|
upload_actions = [env.VerboseAction("$UPLOADCMD", "Uploading $SOURCE")]
|
2016-10-24 20:23:25 +03:00
|
|
|
|
2018-05-11 02:16:58 +03:00
|
|
|
# custom upload tool
|
2018-12-21 17:06:41 +02:00
|
|
|
elif upload_protocol == "custom":
|
2018-05-11 02:16:58 +03:00
|
|
|
upload_actions = [env.VerboseAction("$UPLOADCMD", "Uploading $SOURCE")]
|
2016-10-24 20:23:25 +03:00
|
|
|
|
2018-05-11 02:16:58 +03:00
|
|
|
else:
|
|
|
|
|
sys.stderr.write("Warning! Unknown upload protocol %s\n" % upload_protocol)
|
2016-10-24 20:23:25 +03:00
|
|
|
|
2020-06-10 17:16:17 +03:00
|
|
|
env.AddPlatformTarget("upload", target_firm, upload_actions, "Upload")
|
|
|
|
|
env.AddPlatformTarget("uploadfs", target_firm, upload_actions, "Upload Filesystem Image")
|
|
|
|
|
env.AddPlatformTarget(
|
|
|
|
|
"uploadfsota", target_firm, upload_actions, "Upload Filesystem Image OTA")
|
2016-10-24 20:23:25 +03:00
|
|
|
|
2018-11-24 15:29:21 +02:00
|
|
|
#
|
|
|
|
|
# Target: Erase Flash
|
|
|
|
|
#
|
|
|
|
|
|
2020-06-10 17:16:17 +03:00
|
|
|
env.AddPlatformTarget(
|
|
|
|
|
"erase",
|
|
|
|
|
None,
|
|
|
|
|
[
|
|
|
|
|
env.VerboseAction(env.AutodetectUploadPort, "Looking for serial port..."),
|
2019-05-11 22:13:26 +03:00
|
|
|
env.VerboseAction("$ERASECMD", "Erasing...")
|
2020-06-10 17:16:17 +03:00
|
|
|
],
|
|
|
|
|
"Erase Flash",
|
|
|
|
|
)
|
2018-11-24 15:29:21 +02:00
|
|
|
|
2020-01-29 15:38:58 +02:00
|
|
|
#
|
|
|
|
|
# Information about obsolete method of specifying linker scripts
|
|
|
|
|
#
|
|
|
|
|
|
|
|
|
|
if any("-Wl,-T" in f for f in env.get("LINKFLAGS", [])):
|
|
|
|
|
print("Warning! '-Wl,-T' option for specifying linker scripts is deprecated. "
|
|
|
|
|
"Please use 'board_build.ldscript' option in your 'platformio.ini' file.")
|
|
|
|
|
|
2022-07-29 17:53:19 +03:00
|
|
|
#
|
|
|
|
|
# A temporary workaround to propagate additional data to the debug configuration routine
|
|
|
|
|
#
|
|
|
|
|
|
|
|
|
|
Import("projenv")
|
|
|
|
|
projenv["INTEGRATION_EXTRA_DATA"] = env.get("INTEGRATION_EXTRA_DATA")
|
|
|
|
|
|
2016-10-24 20:23:25 +03:00
|
|
|
#
|
|
|
|
|
# Default targets
|
|
|
|
|
#
|
|
|
|
|
|
|
|
|
|
Default([target_buildprog, target_size])
|