1
0
mirror of https://github.com/MarlinFirmware/Marlin.git synced 2024-12-18 16:27:17 +00:00
MarlinFirmware/buildroot/share/PlatformIO/scripts/stm32_bootloader.py

46 lines
1.4 KiB
Python
Raw Normal View History

2021-02-28 04:38:57 +00:00
#
# stm32_bootloader.py
#
2020-07-06 22:08:52 +00:00
import os,sys,shutil
Import("env")
from SCons.Script import DefaultEnvironment
board = DefaultEnvironment().BoardConfig()
#
# Copy the firmware.bin file to build.firmware, no encryption
#
2020-07-06 22:08:52 +00:00
def noencrypt(source, target, env):
firmware = os.path.join(target[0].dir.path, board.get("build.firmware"))
2020-12-24 02:01:21 +00:00
shutil.copy(target[0].path, firmware)
2020-07-06 22:08:52 +00:00
#
# For build.offset define LD_FLASH_OFFSET, used by ldscript.ld
#
2020-07-06 22:08:52 +00:00
if 'offset' in board.get("build").keys():
LD_FLASH_OFFSET = board.get("build.offset")
# Remove an existing VECT_TAB_OFFSET from CPPDEFINES
2020-07-06 22:08:52 +00:00
for define in env['CPPDEFINES']:
if define[0] == "VECT_TAB_OFFSET":
env['CPPDEFINES'].remove(define)
# Replace VECT_TAB_OFFSET with our LD_FLASH_OFFSET
2020-07-06 22:08:52 +00:00
env['CPPDEFINES'].append(("VECT_TAB_OFFSET", LD_FLASH_OFFSET))
# Get upload.maximum_ram_size (defined by /buildroot/share/PlatformIO/boards/VARIOUS.json)
2020-07-06 22:08:52 +00:00
maximum_ram_size = board.get("upload.maximum_ram_size")
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)
#
# Only copy the file if there's no encrypt
#
2020-12-24 02:01:21 +00:00
board_keys = board.get("build").keys()
if 'firmware' in board_keys and not 'encrypt' in board_keys:
env.AddPostAction("$BUILD_DIR/${PROGNAME}.bin", noencrypt)