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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #
  2. # lerdge.py
  3. # Customizations for Lerdge build environments
  4. #
  5. import os,sys
  6. Import("env")
  7. from SCons.Script import DefaultEnvironment
  8. board = DefaultEnvironment().BoardConfig()
  9. custom_ld_script = os.path.abspath("buildroot/share/PlatformIO/ldscripts/lerdge.ld")
  10. for i, flag in enumerate(env["LINKFLAGS"]):
  11. if "-Wl,-T" in flag:
  12. env["LINKFLAGS"][i] = "-Wl,-T" + custom_ld_script
  13. elif flag == "-T":
  14. env["LINKFLAGS"][i + 1] = custom_ld_script
  15. def encryptByte(byte):
  16. byte = 0xFF & ((byte << 6) | (byte >> 2))
  17. i = 0x58 + byte
  18. j = 0x05 + byte + (i >> 8)
  19. byte = (0xF8 & i) | (0x07 & j)
  20. return byte
  21. def encrypt_file(input, output_file, file_length):
  22. input_file = bytearray(input.read())
  23. for i in range(len(input_file)):
  24. result = encryptByte(input_file[i])
  25. input_file[i] = result
  26. output_file.write(input_file)
  27. return
  28. # Encrypt ${PROGNAME}.bin and save it as build.firmware
  29. def encrypt(source, target, env):
  30. print("Encrypting to:", board.get("build.firmware"))
  31. firmware = open(target[0].path, "rb")
  32. result = open(target[0].dir.path + "/" + board.get("build.firmware"), "wb")
  33. length = os.path.getsize(target[0].path)
  34. encrypt_file(firmware, result, length)
  35. firmware.close()
  36. result.close()
  37. if 'firmware' in board.get("build").keys():
  38. env.AddPostAction("$BUILD_DIR/${PROGNAME}.bin", encrypt);
  39. else:
  40. print("You need to define output file via board_build.firmware = 'filename' parameter")
  41. exit(1);