mirror of
https://github.com/MarlinFirmware/Marlin.git
synced 2024-11-26 21:36:21 +00:00
🏗️ Refactor build encrypt / rename (#22124)
This commit is contained in:
parent
14ffc66c45
commit
2aa35577f2
@ -27,11 +27,12 @@ def encrypt_file(input, output_file, file_length):
|
||||
output_file.write(input_file)
|
||||
return
|
||||
|
||||
# Encrypt ${PROGNAME}.bin and save it as build.firmware
|
||||
# Encrypt ${PROGNAME}.bin and save it with the name given in build.encrypt
|
||||
def encrypt(source, target, env):
|
||||
print("Encrypting to:", board.get("build.firmware"))
|
||||
fwname = board.get("build.encrypt")
|
||||
print("Encrypting %s to %s" % (target[0].path, fwname))
|
||||
firmware = open(target[0].path, "rb")
|
||||
renamed = open(target[0].dir.path + "/" + board.get("build.firmware"), "wb")
|
||||
renamed = open(target[0].dir.path + "/" + fwname, "wb")
|
||||
length = os.path.getsize(target[0].path)
|
||||
|
||||
encrypt_file(firmware, renamed, length)
|
||||
@ -39,8 +40,8 @@ def encrypt(source, target, env):
|
||||
firmware.close()
|
||||
renamed.close()
|
||||
|
||||
if 'firmware' in board.get("build").keys():
|
||||
if 'encrypt' in board.get("build").keys():
|
||||
marlin.add_post_action(encrypt);
|
||||
else:
|
||||
print("You need to define output file via board_build.firmware = 'filename' parameter")
|
||||
print("LERDGE builds require output file via board_build.encrypt = 'filename' parameter")
|
||||
exit(1);
|
||||
|
@ -7,10 +7,12 @@ import os,shutil
|
||||
from SCons.Script import DefaultEnvironment
|
||||
env = DefaultEnvironment()
|
||||
|
||||
from os.path import join
|
||||
|
||||
def copytree(src, dst, symlinks=False, ignore=None):
|
||||
for item in os.listdir(src):
|
||||
s = os.path.join(src, item)
|
||||
d = os.path.join(dst, item)
|
||||
s = join(src, item)
|
||||
d = join(dst, item)
|
||||
if os.path.isdir(s):
|
||||
shutil.copytree(s, d, symlinks, ignore)
|
||||
else:
|
||||
@ -64,7 +66,7 @@ def encrypt_mks(source, target, env, new_name):
|
||||
renamed.close()
|
||||
|
||||
def add_post_action(action):
|
||||
env.AddPostAction("$BUILD_DIR/${PROGNAME}.bin", action);
|
||||
env.AddPostAction(join("$BUILD_DIR", "${PROGNAME}.bin"), action);
|
||||
|
||||
# Apply customizations for a MKS Robin
|
||||
def prepare_robin(address, ldname, fwname):
|
||||
|
@ -3,6 +3,7 @@
|
||||
#
|
||||
# Apply encryption and save as 'build.firmware' for these environments:
|
||||
# - env:mks_robin
|
||||
# - env:mks_robin_e3
|
||||
# - env:flsun_hispeedv1
|
||||
# - env:mks_robin_nano35
|
||||
#
|
||||
@ -11,18 +12,18 @@ Import("env")
|
||||
from SCons.Script import DefaultEnvironment
|
||||
board = DefaultEnvironment().BoardConfig()
|
||||
|
||||
if 'firmware' in board.get("build").keys():
|
||||
if 'encrypt' in board.get("build").keys():
|
||||
|
||||
import marlin
|
||||
|
||||
# Encrypt ${PROGNAME}.bin and save it as build.firmware
|
||||
# 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.firmware"))
|
||||
marlin.encrypt_mks(source, target, env, board.get("build.encrypt"))
|
||||
|
||||
marlin.add_post_action(encrypt);
|
||||
|
||||
else:
|
||||
|
||||
import sys
|
||||
print("You need to define output file via board_build.firmware = 'filename' parameter", file=sys.stderr)
|
||||
print("You need to define output file via board_build.encrypt = 'filename' parameter", file=sys.stderr)
|
||||
env.Exit(1);
|
||||
|
@ -6,10 +6,13 @@ from os.path import join
|
||||
|
||||
Import("env")
|
||||
|
||||
board = env.BoardConfig()
|
||||
board_keys = board.get("build").keys()
|
||||
if 'encrypt' in board_keys:
|
||||
env.AddPostAction(
|
||||
"$BUILD_DIR/${PROGNAME}.elf",
|
||||
join("$BUILD_DIR", "${PROGNAME}.bin"),
|
||||
env.VerboseAction(" ".join([
|
||||
"$OBJCOPY", "-O", "srec",
|
||||
"\"$BUILD_DIR/${PROGNAME}.elf\"", "\"$BUILD_DIR/${PROGNAME}.srec\""
|
||||
]), "Building " + join("$BUILD_DIR", "${PROGNAME}.srec"))
|
||||
"\"$BUILD_DIR/${PROGNAME}.elf\"", "\"" + join("$BUILD_DIR", board.get("build.encrypt")) + "\""
|
||||
]), "Building $TARGET")
|
||||
)
|
||||
|
@ -1,23 +1,18 @@
|
||||
#
|
||||
# stm32_bootloader.py
|
||||
#
|
||||
import os,sys,shutil,marlin
|
||||
import os,sys,marlin
|
||||
Import("env")
|
||||
|
||||
from SCons.Script import DefaultEnvironment
|
||||
board = DefaultEnvironment().BoardConfig()
|
||||
|
||||
#
|
||||
# Copy the firmware.bin file to build.firmware, no encryption
|
||||
#
|
||||
def noencrypt(source, target, env):
|
||||
firmware = os.path.join(target[0].dir.path, board.get("build.firmware"))
|
||||
shutil.copy(target[0].path, firmware)
|
||||
board_keys = board.get("build").keys()
|
||||
|
||||
#
|
||||
# For build.offset define LD_FLASH_OFFSET, used by ldscript.ld
|
||||
#
|
||||
if 'offset' in board.get("build").keys():
|
||||
if 'offset' in board_keys:
|
||||
LD_FLASH_OFFSET = board.get("build.offset")
|
||||
marlin.relocate_vtab(LD_FLASH_OFFSET)
|
||||
|
||||
@ -35,9 +30,13 @@ if 'offset' in board.get("build").keys():
|
||||
env["LINKFLAGS"][i] = "-Wl,--defsym=LD_MAX_DATA_SIZE=" + str(maximum_ram_size - 40)
|
||||
|
||||
#
|
||||
# Only copy the file if there's no encrypt
|
||||
# For build.rename simply rename the firmware file.
|
||||
#
|
||||
board_keys = board.get("build").keys()
|
||||
if 'firmware' in board_keys and ('encrypt' not in board_keys or board.get("build.encrypt") == 'No'):
|
||||
import marlin
|
||||
marlin.add_post_action(noencrypt)
|
||||
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)
|
||||
|
@ -84,8 +84,6 @@ platform = ${common_stm32.platform}
|
||||
extends = common_STM32F103RC
|
||||
build_flags = ${common_stm32.build_flags} -DDEBUG_LEVEL=0 -DTIMER_SERVO=TIM5
|
||||
board_build.offset = 0x7000
|
||||
board_build.encrypt = No
|
||||
board_build.firmware = firmware.bin
|
||||
board_upload.offset_address = 0x08007000
|
||||
|
||||
[env:STM32F103RC_btt_USB]
|
||||
@ -113,8 +111,7 @@ board_build.core = stm32
|
||||
board_build.variant = MARLIN_F103Zx
|
||||
board_build.ldscript = ldscript.ld
|
||||
board_build.offset = 0x7000
|
||||
board_build.encrypt = Yes
|
||||
board_build.firmware = Robin.bin
|
||||
board_build.encrypt = Robin.bin
|
||||
build_flags = ${common_stm32.build_flags}
|
||||
-DENABLE_HWSERIAL3 -DTIMER_SERIAL=TIM5
|
||||
build_unflags = ${common_stm32.build_unflags}
|
||||
@ -136,8 +133,7 @@ build_flags = ${common_stm32.build_flags}
|
||||
build_unflags = ${common_stm32.build_unflags} -DUSBCON -DUSBD_USE_CDC
|
||||
monitor_speed = 115200
|
||||
board_build.offset = 0x5000
|
||||
board_build.encrypt = Yes
|
||||
board_build.firmware = Robin_e3.bin
|
||||
board_build.encrypt = Robin_e3.bin
|
||||
board_upload.offset_address = 0x08005000
|
||||
debug_tool = stlink
|
||||
extra_scripts = ${env:STM32F103RC.extra_scripts}
|
||||
@ -215,8 +211,7 @@ board_build.core = stm32
|
||||
board_build.variant = MARLIN_F103Vx
|
||||
board_build.ldscript = ldscript.ld
|
||||
board_build.offset = 0x7000
|
||||
board_build.firmware = Robin_mini.bin
|
||||
board_build.encrypt = Yes
|
||||
board_build.encrypt = Robin_mini.bin
|
||||
board_upload.offset_address = 0x08007000
|
||||
build_unflags = ${common_stm32.build_unflags} -DUSBCON -DUSBD_USE_CDC
|
||||
extra_scripts = ${common_stm32.extra_scripts}
|
||||
@ -236,8 +231,7 @@ board_build.core = stm32
|
||||
board_build.variant = MARLIN_F103Vx
|
||||
board_build.ldscript = ldscript.ld
|
||||
board_build.offset = 0x7000
|
||||
board_build.encrypt = Yes
|
||||
board_build.firmware = Robin_nano35.bin
|
||||
board_build.encrypt = Robin_nano35.bin
|
||||
board_upload.offset_address = 0x08007000
|
||||
build_unflags = ${common_stm32.build_unflags} -DUSBCON -DUSBD_USE_CDC
|
||||
debug_tool = jlink
|
||||
|
@ -113,9 +113,8 @@ board = marlin_STM32F407VGT6_CCM
|
||||
board_build.core = stm32
|
||||
board_build.variant = MARLIN_F4x7Vx
|
||||
board_build.ldscript = ldscript.ld
|
||||
board_build.firmware = firmware.srec
|
||||
board_build.encrypt = firmware.srec
|
||||
# Just openblt.py (not stm32_bootloader.py) generates the file
|
||||
board_build.encrypt = Yes
|
||||
board_build.offset = 0x10000
|
||||
board_upload.offset_address = 0x08010000
|
||||
build_unflags = ${common_stm32.build_unflags} -DUSBCON -DUSBD_USE_CDC -DUSBD_VID=0x0483
|
||||
@ -265,7 +264,7 @@ extends = common_stm32
|
||||
board = marlin_STM32F407ZGT6
|
||||
board_build.variant = MARLIN_LERDGE
|
||||
board_build.offset = 0x10000
|
||||
board_build.encrypt = Yes
|
||||
board_build.encrypt = firmware.bin
|
||||
extra_scripts = ${common.extra_scripts}
|
||||
pre:buildroot/share/PlatformIO/scripts/generic_create_variant.py
|
||||
buildroot/share/PlatformIO/scripts/stm32_bootloader.py
|
||||
@ -282,7 +281,7 @@ build_unflags = ${common_stm32.build_unflags} -DUSBCON -DUSBD_USE_CDC -DUS
|
||||
[env:LERDGEX]
|
||||
platform = ${lerdge_common.platform}
|
||||
extends = lerdge_common
|
||||
board_build.firmware = Lerdge_X_firmware_force.bin
|
||||
board_build.encrypt = Lerdge_X_firmware_force.bin
|
||||
|
||||
#
|
||||
# Lerdge X with USB Flash Drive Support
|
||||
@ -299,7 +298,7 @@ build_flags = ${stm_flash_drive.build_flags} ${lerdge_common.build_flags}
|
||||
[env:LERDGES]
|
||||
platform = ${lerdge_common.platform}
|
||||
extends = lerdge_common
|
||||
board_build.firmware = Lerdge_firmware_force.bin
|
||||
board_build.encrypt = Lerdge_firmware_force.bin
|
||||
|
||||
#
|
||||
# Lerdge S with USB Flash Drive Support
|
||||
@ -316,7 +315,7 @@ build_flags = ${stm_flash_drive.build_flags} ${lerdge_common.build_flags}
|
||||
[env:LERDGEK]
|
||||
platform = ${lerdge_common.platform}
|
||||
extends = lerdge_common
|
||||
board_build.firmware = Lerdge_K_firmware_force.bin
|
||||
board_build.encrypt = Lerdge_K_firmware_force.bin
|
||||
build_flags = ${lerdge_common.build_flags} -DLERDGEK
|
||||
|
||||
#
|
||||
@ -347,8 +346,6 @@ board_build.core = stm32
|
||||
board_build.variant = MARLIN_F446VE
|
||||
board_build.ldscript = ldscript.ld
|
||||
board_build.offset = 0x0000
|
||||
board_build.encrypt = No
|
||||
board_build.firmware = firmware.bin
|
||||
extra_scripts = ${common.extra_scripts}
|
||||
pre:buildroot/share/PlatformIO/scripts/generic_create_variant.py
|
||||
buildroot/share/PlatformIO/scripts/stm32_bootloader.py
|
||||
@ -365,7 +362,6 @@ board = genericSTM32F407VET6
|
||||
board_build.core = stm32
|
||||
board_build.variant = MARLIN_F4x7Vx
|
||||
board_build.ldscript = ldscript.ld
|
||||
board_build.firmware = firmware.bin
|
||||
board_build.offset = 0x0000
|
||||
board_upload.offset_address = 0x08000000
|
||||
build_unflags = ${common_stm32.build_unflags} -DUSBCON -DUSBD_USE_CDC
|
||||
@ -392,7 +388,7 @@ board = marlin_STM32F407VGT6_CCM
|
||||
board_build.core = stm32
|
||||
board_build.variant = MARLIN_F4x7Vx
|
||||
board_build.ldscript = ldscript.ld
|
||||
board_build.firmware = Robin_nano_v3.bin
|
||||
board_build.rename = Robin_nano_v3.bin
|
||||
board_build.offset = 0xC000
|
||||
board_upload.offset_address = 0x0800C000
|
||||
build_unflags = ${common_stm32.build_unflags}
|
||||
|
Loading…
Reference in New Issue
Block a user