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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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 marlin
  14. env = marlin.env
  15. board = env.BoardConfig()
  16. board_keys = board.get("build").keys()
  17. #
  18. # For build.offset define LD_FLASH_OFFSET, used by ldscript.ld
  19. #
  20. if 'offset' in board_keys:
  21. LD_FLASH_OFFSET = board.get("build.offset")
  22. marlin.relocate_vtab(LD_FLASH_OFFSET)
  23. # Flash size
  24. maximum_flash_size = int(board.get("upload.maximum_size") / 1024)
  25. marlin.replace_define('STM32_FLASH_SIZE', maximum_flash_size)
  26. # Get upload.maximum_ram_size (defined by /buildroot/share/PlatformIO/boards/VARIOUS.json)
  27. maximum_ram_size = board.get("upload.maximum_ram_size")
  28. for i, flag in enumerate(env["LINKFLAGS"]):
  29. if "-Wl,--defsym=LD_FLASH_OFFSET" in flag:
  30. env["LINKFLAGS"][i] = "-Wl,--defsym=LD_FLASH_OFFSET=" + LD_FLASH_OFFSET
  31. if "-Wl,--defsym=LD_MAX_DATA_SIZE" in flag:
  32. env["LINKFLAGS"][i] = "-Wl,--defsym=LD_MAX_DATA_SIZE=" + str(maximum_ram_size - 40)
  33. #
  34. # For build.encrypt_mks rename and encode the firmware file.
  35. #
  36. if 'encrypt_mks' in board_keys:
  37. # Encrypt ${PROGNAME}.bin and save it with the name given in build.encrypt_mks
  38. def encrypt(source, target, env):
  39. marlin.encrypt_mks(source, target, env, board.get("build.encrypt_mks"))
  40. if board.get("build.encrypt_mks") != "":
  41. marlin.add_post_action(encrypt)
  42. #
  43. # For build.rename simply rename the firmware file.
  44. #
  45. if 'rename' in board_keys:
  46. # If FIRMWARE_BIN is defined by config, override all
  47. mf = env["MARLIN_FEATURES"]
  48. if "FIRMWARE_BIN" in mf: new_name = mf["FIRMWARE_BIN"]
  49. else: new_name = board.get("build.rename")
  50. def rename_target(source, target, env):
  51. from pathlib import Path
  52. Path(target[0].path).replace(Path(target[0].dir.path, new_name))
  53. marlin.add_post_action(rename_target)