Marlin 2.0 for Flying Bear 4S/5
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

48 lines
1.4 KiB

#
4 years ago
# buildroot/share/PlatformIO/scripts/lerdge.py
# Customizations for Lerdge build environments:
# env:LERDGEX env:LERDGEX_usb_flash_drive
# env:LERDGES env:LERDGES_usb_flash_drive
# env:LERDGEK env:LERDGEK_usb_flash_drive
#
4 years ago
import os,marlin
4 years ago
Import("env")
from SCons.Script import DefaultEnvironment
board = DefaultEnvironment().BoardConfig()
def encryptByte(byte):
byte = 0xFF & ((byte << 6) | (byte >> 2))
i = 0x58 + byte
j = 0x05 + byte + (i >> 8)
byte = (0xF8 & i) | (0x07 & j)
return byte
def encrypt_file(input, output_file, file_length):
input_file = bytearray(input.read())
for i in range(len(input_file)):
result = encryptByte(input_file[i])
input_file[i] = result
output_file.write(input_file)
return
3 years ago
# Encrypt ${PROGNAME}.bin and save it with the name given in build.encrypt
4 years ago
def encrypt(source, target, env):
3 years ago
fwname = board.get("build.encrypt")
print("Encrypting %s to %s" % (target[0].path, fwname))
4 years ago
firmware = open(target[0].path, "rb")
3 years ago
renamed = open(target[0].dir.path + "/" + fwname, "wb")
4 years ago
length = os.path.getsize(target[0].path)
4 years ago
encrypt_file(firmware, renamed, length)
4 years ago
firmware.close()
4 years ago
renamed.close()
4 years ago
3 years ago
if 'encrypt' in board.get("build").keys():
marlin.add_post_action(encrypt);
4 years ago
else:
3 years ago
print("LERDGE builds require output file via board_build.encrypt = 'filename' parameter")
exit(1);