[core] Support adding custom board JSON, pass it to ltchiptool
This commit is contained in:
@@ -535,7 +535,7 @@ image_app_rblh = "${BUILD_DIR}/image_${MCULC}_app.${FLASH_RBL_OFFSET}.rblh"
|
||||
image_ota_rbl = "${BUILD_DIR}/image_${MCULC}_app.ota.rbl"
|
||||
env.Replace(
|
||||
# linker command (encryption + packaging)
|
||||
LINK="${LTCHIPTOOL} link2bin ${VARIANT} '' ''",
|
||||
LINK="${LTCHIPTOOL} link2bin ${BOARD_JSON} '' ''",
|
||||
# UF2OTA input list
|
||||
UF2OTA=[
|
||||
# app binary image (enc+crc) for flasher
|
||||
|
||||
@@ -296,7 +296,7 @@ image_ota1 = "${BUILD_DIR}/image_ota1.${FLASH_OTA1_OFFSET}.bin"
|
||||
image_ota2 = "${BUILD_DIR}/image_ota2.${FLASH_OTA2_OFFSET}.bin"
|
||||
env.Replace(
|
||||
# linker command (dual .bin outputs)
|
||||
LINK="${LTCHIPTOOL} link2bin ${VARIANT} xip1 xip2",
|
||||
LINK="${LTCHIPTOOL} link2bin ${BOARD_JSON} xip1 xip2",
|
||||
# UF2OTA input list
|
||||
UF2OTA=[
|
||||
# same OTA images for flasher and device
|
||||
|
||||
@@ -14,10 +14,16 @@ board: PlatformBoardConfig = env.BoardConfig()
|
||||
platform: PlatformBase = env.PioPlatform()
|
||||
family: Family = env["FAMILY_OBJ"]
|
||||
|
||||
# Parse custom options
|
||||
env.ParseCustomOptions(platform)
|
||||
# Add flash layout C defines
|
||||
env.AddFlashLayout(board)
|
||||
# Write custom header options
|
||||
env.ApplyCustomOptions(platform)
|
||||
# Export board manifest for ltchiptool
|
||||
env.ExportBoardData(board)
|
||||
# Print information about versions and custom options
|
||||
env.PrintInfo(platform)
|
||||
# Apply custom header options
|
||||
env.ApplyCustomOptions(platform)
|
||||
|
||||
# TODO remove include path prepending ("!<...>")
|
||||
# Move common core sources (env.AddCoreSources()) and Arduino libs
|
||||
|
||||
@@ -49,10 +49,6 @@ env.Replace(
|
||||
|
||||
# Environment variables, include paths, etc.
|
||||
env.ConfigureEnvironment(platform, board)
|
||||
# Flash layout defines
|
||||
env.AddFlashLayout(board)
|
||||
# Parse custom options
|
||||
env.ParseCustomOptions(platform)
|
||||
|
||||
# Family builders details:
|
||||
# - call env.AddLibrary("lib name", "base dir", [sources]) to add lib sources
|
||||
@@ -72,7 +68,7 @@ env.ParseCustomOptions(platform)
|
||||
|
||||
# Framework builder (base.py/arduino.py) is executed in BuildProgram()
|
||||
# Force including the base framework in case no other is specified
|
||||
if not env.get("PIOFRAMEWORK"):
|
||||
if "nobuild" not in COMMAND_LINE_TARGETS and not env.get("PIOFRAMEWORK"):
|
||||
env.SConscript("frameworks/base.py")
|
||||
|
||||
#
|
||||
|
||||
@@ -96,7 +96,7 @@ def env_print_info(env: Environment, platform: PlatformBase):
|
||||
k = k.replace("#", ".")
|
||||
if isinstance(v, dict):
|
||||
print(f"{indent} - {k}:")
|
||||
for k, v in v.items():
|
||||
for k, v in sorted(v.items()):
|
||||
dump(k, v, indent + TAB)
|
||||
elif isinstance(v, list):
|
||||
print(f"{indent} - {k}:")
|
||||
@@ -112,7 +112,7 @@ def env_print_info(env: Environment, platform: PlatformBase):
|
||||
# Print custom platformio.ini options
|
||||
if platform.custom_opts:
|
||||
print("CUSTOM OPTIONS:")
|
||||
for k, v in platform.custom_opts.items():
|
||||
for k, v in sorted(platform.custom_opts.items()):
|
||||
dump(k, v)
|
||||
|
||||
|
||||
|
||||
@@ -17,10 +17,12 @@ def env_add_flash_layout(env: Environment, board):
|
||||
for name, layout in flash_layout.items():
|
||||
name = name.upper()
|
||||
(offset, _, length) = layout.partition("+")
|
||||
defines[f"FLASH_{name}_OFFSET"] = offset
|
||||
defines[f"FLASH_{name}_LENGTH"] = length
|
||||
offset = int(offset, 16)
|
||||
length = int(length, 16)
|
||||
defines[f"FLASH_{name}_OFFSET"] = f"0x{offset:06X}"
|
||||
defines[f"FLASH_{name}_LENGTH"] = f"0x{length:06X}"
|
||||
fal_items += f"FAL_PART_TABLE_ITEM({name.lower()},{name})"
|
||||
flash_size = max(flash_size, int(offset, 16) + int(length, 16))
|
||||
flash_size = max(flash_size, offset + length)
|
||||
defines["FLASH_LENGTH"] = f"0x{flash_size:06X}"
|
||||
# for "root" partition
|
||||
defines["FLASH_ROOT_OFFSET"] = "0x000000"
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
# Copyright (c) Kuba Szczodrzyński 2022-06-02.
|
||||
|
||||
import json
|
||||
from datetime import datetime
|
||||
from os.path import basename, join, normpath
|
||||
|
||||
from platformio.platform.base import PlatformBase
|
||||
from platformio.platform.board import PlatformBoardConfig
|
||||
from SCons.Script import Builder, DefaultEnvironment, Environment
|
||||
|
||||
env: Environment = DefaultEnvironment()
|
||||
@@ -43,13 +45,12 @@ def env_uf2ota(env: Environment, *args, **kwargs):
|
||||
cmd = [
|
||||
"@${LTCHIPTOOL} uf2 write",
|
||||
*output_opts,
|
||||
"--family ${FAMILY_SHORT_NAME}",
|
||||
"--board ${VARIANT}",
|
||||
"--board ${BOARD_JSON}",
|
||||
f"--lt-version {lt_version}",
|
||||
f'--fw "{project_name}:{project_version}"',
|
||||
f"--date {int(now.timestamp())}",
|
||||
"--legacy",
|
||||
*env["UF2OTA"],
|
||||
*(f'"{arg}"' for arg in env["UF2OTA"]),
|
||||
]
|
||||
|
||||
for output in outputs:
|
||||
@@ -72,6 +73,13 @@ def env_flash_write(env: Environment):
|
||||
return []
|
||||
|
||||
|
||||
def env_export_board_data(env: Environment, board: PlatformBoardConfig):
|
||||
output = join("${BUILD_DIR}", "board.json")
|
||||
with open(env.subst(output), "w") as f:
|
||||
json.dump(board.manifest, f, indent="\t")
|
||||
env["BOARD_JSON"] = output
|
||||
|
||||
|
||||
env.Append(
|
||||
BUILDERS=dict(
|
||||
BuildUF2OTA=Builder(
|
||||
@@ -80,3 +88,4 @@ env.Append(
|
||||
)
|
||||
)
|
||||
env.AddMethod(env_flash_write, "GetLtchiptoolWriteFlags")
|
||||
env.AddMethod(env_export_board_data, "ExportBoardData")
|
||||
|
||||
Reference in New Issue
Block a user