2021-02-27 22:38:57 -06:00
|
|
|
#
|
2021-07-14 19:44:51 -05:00
|
|
|
# offset_and_rename.py
|
2021-02-27 22:38:57 -06:00
|
|
|
#
|
2021-06-29 16:25:37 -05:00
|
|
|
# - If 'build.offset' is provided, either by JSON or by the environment...
|
|
|
|
# - Set linker flag LD_FLASH_OFFSET and relocate the VTAB based on 'build.offset'.
|
|
|
|
# - Set linker flag LD_MAX_DATA_SIZE based on 'build.maximum_ram_size'.
|
|
|
|
# - Define STM32_FLASH_SIZE from 'upload.maximum_size' for use by Flash-based EEPROM emulation.
|
|
|
|
#
|
|
|
|
# - For 'board_build.rename' add a post-action to rename the firmware file.
|
|
|
|
#
|
2021-06-13 15:43:33 -05:00
|
|
|
import os,sys,marlin
|
2020-07-06 17:08:52 -05:00
|
|
|
Import("env")
|
|
|
|
|
|
|
|
from SCons.Script import DefaultEnvironment
|
|
|
|
board = DefaultEnvironment().BoardConfig()
|
|
|
|
|
2021-06-13 15:43:33 -05:00
|
|
|
board_keys = board.get("build").keys()
|
2020-07-06 17:08:52 -05:00
|
|
|
|
2021-03-22 23:58:03 -05:00
|
|
|
#
|
|
|
|
# For build.offset define LD_FLASH_OFFSET, used by ldscript.ld
|
|
|
|
#
|
2021-06-13 15:43:33 -05:00
|
|
|
if 'offset' in board_keys:
|
2021-04-27 04:49:21 -05:00
|
|
|
LD_FLASH_OFFSET = board.get("build.offset")
|
|
|
|
marlin.relocate_vtab(LD_FLASH_OFFSET)
|
2021-03-22 23:58:03 -05:00
|
|
|
|
2021-05-11 10:44:54 -05:00
|
|
|
# Flash size
|
|
|
|
maximum_flash_size = int(board.get("upload.maximum_size") / 1024)
|
|
|
|
marlin.replace_define('STM32_FLASH_SIZE', maximum_flash_size)
|
|
|
|
|
2021-04-27 04:49:21 -05:00
|
|
|
# Get upload.maximum_ram_size (defined by /buildroot/share/PlatformIO/boards/VARIOUS.json)
|
|
|
|
maximum_ram_size = board.get("upload.maximum_ram_size")
|
2020-07-06 17:08:52 -05:00
|
|
|
|
2021-04-27 04:49:21 -05:00
|
|
|
for i, flag in enumerate(env["LINKFLAGS"]):
|
|
|
|
if "-Wl,--defsym=LD_FLASH_OFFSET" in flag:
|
|
|
|
env["LINKFLAGS"][i] = "-Wl,--defsym=LD_FLASH_OFFSET=" + LD_FLASH_OFFSET
|
|
|
|
if "-Wl,--defsym=LD_MAX_DATA_SIZE" in flag:
|
|
|
|
env["LINKFLAGS"][i] = "-Wl,--defsym=LD_MAX_DATA_SIZE=" + str(maximum_ram_size - 40)
|
2020-07-06 17:08:52 -05:00
|
|
|
|
2021-07-14 19:44:51 -05:00
|
|
|
#
|
|
|
|
# For build.encrypt rename and encode the firmware file.
|
|
|
|
#
|
|
|
|
if 'encrypt' in board_keys:
|
|
|
|
|
|
|
|
# Encrypt ${PROGNAME}.bin and save it with the name given in build.encrypt
|
|
|
|
def encrypt(source, target, env):
|
|
|
|
marlin.encrypt_mks(source, target, env, board.get("build.encrypt"))
|
|
|
|
|
2021-09-01 18:55:36 -05:00
|
|
|
if board.get("build.encrypt") != "":
|
|
|
|
marlin.add_post_action(encrypt)
|
2021-07-14 19:44:51 -05:00
|
|
|
|
2021-03-22 23:58:03 -05:00
|
|
|
#
|
2021-06-13 15:43:33 -05:00
|
|
|
# For build.rename simply rename the firmware file.
|
2021-03-22 23:58:03 -05:00
|
|
|
#
|
2021-06-13 15:43:33 -05:00
|
|
|
if 'rename' in board_keys:
|
|
|
|
|
|
|
|
def rename_target(source, target, env):
|
|
|
|
firmware = os.path.join(target[0].dir.path, board.get("build.rename"))
|
|
|
|
import shutil
|
|
|
|
shutil.copy(target[0].path, firmware)
|
|
|
|
|
|
|
|
marlin.add_post_action(rename_target)
|