Marlin_Firmware/buildroot/share/PlatformIO/scripts/mks_robin.py
jmz52 33abb86b7e Add support for MKS Robin board (#12650)
Implement initial support for MKS Robin (STM32F103ZET6) board.
Custom build script is used to generate encrypted firmware compatible with original MSK Robin bootloader (i.e. safe firmware update from SD card and possibility to go back to original close-source firmware).
2018-12-20 17:23:27 -06:00

29 lines
1.1 KiB
Python

Import("env")
# Relocate firmware from 0x08000000 to 0x08007000
env['CPPDEFINES'].remove(("VECT_TAB_ADDR", 134217728))
env['CPPDEFINES'].append(("VECT_TAB_ADDR", "0x08007000"))
env.Replace(LDSCRIPT_PATH="buildroot/share/PlatformIO/ldscripts/mks_robin.ld")
# Encrypt ${PROGNAME}.bin and save it as 'Robin.bin'
def encrypt(source, target, env):
import os
key = [0xA3, 0xBD, 0xAD, 0x0D, 0x41, 0x11, 0xBB, 0x8D, 0xDC, 0x80, 0x2D, 0xD0, 0xD2, 0xC4, 0x9B, 0x1E, 0x26, 0xEB, 0xE3, 0x33, 0x4A, 0x15, 0xE4, 0x0A, 0xB3, 0xB1, 0x3C, 0x93, 0xBB, 0xAF, 0xF7, 0x3E]
firmware = open(target[0].path, "rb")
robin = open(target[0].dir.path +'/Robin.bin', "wb")
length = os.path.getsize(target[0].path)
position = 0
try:
while position < length:
byte = firmware.read(1)
if position >= 320 and position < 31040:
byte = chr(ord(byte) ^ key[position & 31])
robin.write(byte)
position += 1
finally:
firmware.close()
robin.close()
env.AddPostAction("$BUILD_DIR/${PROGNAME}.bin", encrypt);