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.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #
  2. # 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 pioutil
  9. if pioutil.is_pio_build():
  10. import os,marlin
  11. board = marlin.env.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. input_file[i] = encryptByte(input_file[i])
  22. output_file.write(input_file)
  23. # Encrypt ${PROGNAME}.bin and save it with the name given in build.crypt_lerdge
  24. def encrypt(source, target, env):
  25. fwpath = target[0].path
  26. enname = board.get("build.crypt_lerdge")
  27. print("Encrypting %s to %s" % (fwpath, enname))
  28. fwfile = open(fwpath, "rb")
  29. enfile = open(target[0].dir.path + "/" + enname, "wb")
  30. length = os.path.getsize(fwpath)
  31. encrypt_file(fwfile, enfile, length)
  32. fwfile.close()
  33. enfile.close()
  34. os.remove(fwpath)
  35. if 'crypt_lerdge' in board.get("build").keys():
  36. if board.get("build.crypt_lerdge") != "":
  37. marlin.add_post_action(encrypt)
  38. else:
  39. print("LERDGE builds require output file via board_build.crypt_lerdge = 'filename' parameter")
  40. exit(1)