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.

offset_and_rename.py 2.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #
  2. # offset_and_rename.py
  3. #
  4. # - If 'build.offset' is provided, either by JSON or by the environment...
  5. # - Set linker flag LD_FLASH_OFFSET and relocate the VTAB based on 'build.offset'.
  6. # - Set linker flag LD_MAX_DATA_SIZE based on 'build.maximum_ram_size'.
  7. # - Define STM32_FLASH_SIZE from 'upload.maximum_size' for use by Flash-based EEPROM emulation.
  8. #
  9. # - For 'board_build.rename' add a post-action to rename the firmware file.
  10. #
  11. import pioutil
  12. if pioutil.is_pio_build():
  13. import os,sys,marlin
  14. Import("env")
  15. from SCons.Script import DefaultEnvironment
  16. board = DefaultEnvironment().BoardConfig()
  17. board_keys = board.get("build").keys()
  18. #
  19. # For build.offset define LD_FLASH_OFFSET, used by ldscript.ld
  20. #
  21. if 'offset' in board_keys:
  22. LD_FLASH_OFFSET = board.get("build.offset")
  23. marlin.relocate_vtab(LD_FLASH_OFFSET)
  24. # Flash size
  25. maximum_flash_size = int(board.get("upload.maximum_size") / 1024)
  26. marlin.replace_define('STM32_FLASH_SIZE', maximum_flash_size)
  27. # Get upload.maximum_ram_size (defined by /buildroot/share/PlatformIO/boards/VARIOUS.json)
  28. maximum_ram_size = board.get("upload.maximum_ram_size")
  29. for i, flag in enumerate(env["LINKFLAGS"]):
  30. if "-Wl,--defsym=LD_FLASH_OFFSET" in flag:
  31. env["LINKFLAGS"][i] = "-Wl,--defsym=LD_FLASH_OFFSET=" + LD_FLASH_OFFSET
  32. if "-Wl,--defsym=LD_MAX_DATA_SIZE" in flag:
  33. env["LINKFLAGS"][i] = "-Wl,--defsym=LD_MAX_DATA_SIZE=" + str(maximum_ram_size - 40)
  34. #
  35. # For build.encrypt rename and encode the firmware file.
  36. #
  37. if 'encrypt' in board_keys:
  38. # Encrypt ${PROGNAME}.bin and save it with the name given in build.encrypt
  39. def encrypt(source, target, env):
  40. marlin.encrypt_mks(source, target, env, board.get("build.encrypt"))
  41. if board.get("build.encrypt") != "":
  42. marlin.add_post_action(encrypt)
  43. #
  44. # For build.rename simply rename the firmware file.
  45. #
  46. if 'rename' in board_keys:
  47. def rename_target(source, target, env):
  48. firmware = os.path.join(target[0].dir.path, board.get("build.rename"))
  49. os.replace(target[0].path, firmware)
  50. marlin.add_post_action(rename_target)