STM32F103VE_longer.py 976 B

1234567891011121314151617181920212223242526272829
  1. import os, marlin
  2. Import("env")
  3. # Relocate firmware from 0x08000000 to 0x08010000
  4. marlin.relocate_firmware("0x08010000")
  5. custom_ld_script = os.path.abspath("buildroot/share/PlatformIO/ldscripts/STM32F103VE_longer.ld")
  6. for i, flag in enumerate(env["LINKFLAGS"]):
  7. if "-Wl,-T" in flag:
  8. env["LINKFLAGS"][i] = "-Wl,-T" + custom_ld_script
  9. elif flag == "-T":
  10. env["LINKFLAGS"][i + 1] = custom_ld_script
  11. # Rename ${PROGNAME}.bin and save it as 'project.bin' (No encryption on the Longer3D)
  12. def encrypt(source, target, env):
  13. firmware = open(target[0].path, "rb")
  14. marlin_alfa = open(target[0].dir.path +'/project.bin', "wb")
  15. length = os.path.getsize(target[0].path)
  16. position = 0
  17. try:
  18. while position < length:
  19. byte = firmware.read(1)
  20. marlin_alfa.write(byte)
  21. position += 1
  22. finally:
  23. firmware.close()
  24. marlin_alfa.close()
  25. env.AddPostAction("$BUILD_DIR/${PROGNAME}.bin", encrypt);