My Marlin configs for Fabrikator Mini and CTC i3 Pro B
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.

lerdge.py 1.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #
  2. # buildroot/share/PlatformIO/scripts/lerdge.py
  3. # Customizations for Lerdge build environments:
  4. # env:LERDGEX env:LERDGEX_usb_flash_drive
  5. # env:LERDGES env:LERDGES_usb_flash_drive
  6. # env:LERDGEK env:LERDGEK_usb_flash_drive
  7. #
  8. import os,marlin
  9. Import("env")
  10. from SCons.Script import DefaultEnvironment
  11. board = DefaultEnvironment().BoardConfig()
  12. def encryptByte(byte):
  13. byte = 0xFF & ((byte << 6) | (byte >> 2))
  14. i = 0x58 + byte
  15. j = 0x05 + byte + (i >> 8)
  16. byte = (0xF8 & i) | (0x07 & j)
  17. return byte
  18. def encrypt_file(input, output_file, file_length):
  19. input_file = bytearray(input.read())
  20. for i in range(len(input_file)):
  21. result = encryptByte(input_file[i])
  22. input_file[i] = result
  23. output_file.write(input_file)
  24. return
  25. # Encrypt ${PROGNAME}.bin and save it with the name given in build.encrypt
  26. def encrypt(source, target, env):
  27. fwname = board.get("build.encrypt")
  28. print("Encrypting %s to %s" % (target[0].path, fwname))
  29. firmware = open(target[0].path, "rb")
  30. renamed = open(target[0].dir.path + "/" + fwname, "wb")
  31. length = os.path.getsize(target[0].path)
  32. encrypt_file(firmware, renamed, length)
  33. firmware.close()
  34. renamed.close()
  35. if 'encrypt' in board.get("build").keys():
  36. if board.get("build.encrypt") != "":
  37. marlin.add_post_action(encrypt)
  38. else:
  39. print("LERDGE builds require output file via board_build.encrypt = 'filename' parameter")
  40. exit(1)