2021-02-27 23:38:57 -05:00
|
|
|
#
|
|
|
|
# stm32_bootloader.py
|
|
|
|
#
|
2021-04-27 05:49:21 -04:00
|
|
|
import os,sys,shutil,marlin
|
2020-07-06 18:08:52 -04:00
|
|
|
Import("env")
|
|
|
|
|
|
|
|
from SCons.Script import DefaultEnvironment
|
|
|
|
board = DefaultEnvironment().BoardConfig()
|
|
|
|
|
2021-03-23 00:58:03 -04:00
|
|
|
#
|
|
|
|
# Copy the firmware.bin file to build.firmware, no encryption
|
|
|
|
#
|
2020-07-06 18:08:52 -04:00
|
|
|
def noencrypt(source, target, env):
|
2021-04-27 05:49:21 -04:00
|
|
|
firmware = os.path.join(target[0].dir.path, board.get("build.firmware"))
|
|
|
|
shutil.copy(target[0].path, firmware)
|
2020-07-06 18:08:52 -04:00
|
|
|
|
2021-03-23 00:58:03 -04:00
|
|
|
#
|
|
|
|
# For build.offset define LD_FLASH_OFFSET, used by ldscript.ld
|
|
|
|
#
|
2020-07-06 18:08:52 -04:00
|
|
|
if 'offset' in board.get("build").keys():
|
2021-04-27 05:49:21 -04:00
|
|
|
LD_FLASH_OFFSET = board.get("build.offset")
|
|
|
|
marlin.relocate_vtab(LD_FLASH_OFFSET)
|
2021-03-23 00:58:03 -04:00
|
|
|
|
2021-05-11 11:44:54 -04: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 05:49:21 -04: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 18:08:52 -04:00
|
|
|
|
2021-04-27 05:49:21 -04: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 18:08:52 -04:00
|
|
|
|
2021-03-23 00:58:03 -04:00
|
|
|
#
|
|
|
|
# Only copy the file if there's no encrypt
|
|
|
|
#
|
2020-12-23 21:01:21 -05:00
|
|
|
board_keys = board.get("build").keys()
|
2021-05-11 11:44:54 -04:00
|
|
|
if 'firmware' in board_keys and ('encrypt' not in board_keys or board.get("build.encrypt") == 'No'):
|
2021-04-27 05:49:21 -04:00
|
|
|
import marlin
|
|
|
|
marlin.add_post_action(noencrypt)
|