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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #
  2. # marlin.py
  3. # Helper module with some commonly-used functions
  4. #
  5. import shutil
  6. from pathlib import Path
  7. from SCons.Script import DefaultEnvironment
  8. env = DefaultEnvironment()
  9. def copytree(src, dst, symlinks=False, ignore=None):
  10. for item in src.iterdir():
  11. if item.is_dir():
  12. shutil.copytree(item, dst / item.name, symlinks, ignore)
  13. else:
  14. shutil.copy2(item, dst / item.name)
  15. def replace_define(field, value):
  16. for define in env['CPPDEFINES']:
  17. if define[0] == field:
  18. env['CPPDEFINES'].remove(define)
  19. env['CPPDEFINES'].append((field, value))
  20. # Relocate the firmware to a new address, such as "0x08005000"
  21. def relocate_firmware(address):
  22. replace_define("VECT_TAB_ADDR", address)
  23. # Relocate the vector table with a new offset
  24. def relocate_vtab(address):
  25. replace_define("VECT_TAB_OFFSET", address)
  26. # Replace the existing -Wl,-T with the given ldscript path
  27. def custom_ld_script(ldname):
  28. apath = str(Path("buildroot/share/PlatformIO/ldscripts", ldname).resolve())
  29. for i, flag in enumerate(env["LINKFLAGS"]):
  30. if "-Wl,-T" in flag:
  31. env["LINKFLAGS"][i] = "-Wl,-T" + apath
  32. elif flag == "-T":
  33. env["LINKFLAGS"][i + 1] = apath
  34. # Encrypt ${PROGNAME}.bin and save it with a new name. This applies (mostly) to MKS boards
  35. # This PostAction is set up by offset_and_rename.py for envs with 'build.encrypt_mks'.
  36. def encrypt_mks(source, target, env, new_name):
  37. import sys
  38. key = [0xA3, 0xBD, 0xAD, 0x0D, 0x41, 0x11, 0xBB, 0x8D, 0xDC, 0x80, 0x2D, 0xD0, 0xD2, 0xC4, 0x9B, 0x1E, 0x26, 0xEB, 0xE3, 0x33, 0x4A, 0x15, 0xE4, 0x0A, 0xB3, 0xB1, 0x3C, 0x93, 0xBB, 0xAF, 0xF7, 0x3E]
  39. # If FIRMWARE_BIN is defined by config, override all
  40. mf = env["MARLIN_FEATURES"]
  41. if "FIRMWARE_BIN" in mf: new_name = mf["FIRMWARE_BIN"]
  42. fwpath = Path(target[0].path)
  43. fwfile = fwpath.open("rb")
  44. enfile = Path(target[0].dir.path, new_name).open("wb")
  45. length = fwpath.stat().st_size
  46. position = 0
  47. try:
  48. while position < length:
  49. byte = fwfile.read(1)
  50. if 320 <= position < 31040:
  51. byte = chr(ord(byte) ^ key[position & 31])
  52. if sys.version_info[0] > 2:
  53. byte = bytes(byte, 'latin1')
  54. enfile.write(byte)
  55. position += 1
  56. finally:
  57. fwfile.close()
  58. enfile.close()
  59. fwpath.unlink()
  60. def add_post_action(action):
  61. env.AddPostAction(str(Path("$BUILD_DIR", "${PROGNAME}.bin")), action);