My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

marlin.py 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #
  2. # buildroot/share/PlatformIO/scripts/marlin.py
  3. # Helper module with some commonly-used functions
  4. #
  5. import os,shutil
  6. from SCons.Script import DefaultEnvironment
  7. env = DefaultEnvironment()
  8. def copytree(src, dst, symlinks=False, ignore=None):
  9. for item in os.listdir(src):
  10. s = os.path.join(src, item)
  11. d = os.path.join(dst, item)
  12. if os.path.isdir(s):
  13. shutil.copytree(s, d, symlinks, ignore)
  14. else:
  15. shutil.copy2(s, d)
  16. def replace_define(field, value):
  17. for define in env['CPPDEFINES']:
  18. if define[0] == field:
  19. env['CPPDEFINES'].remove(define)
  20. env['CPPDEFINES'].append((field, value))
  21. # Relocate the firmware to a new address, such as "0x08005000"
  22. def relocate_firmware(address):
  23. replace_define("VECT_TAB_ADDR", address)
  24. # Relocate the vector table with a new offset
  25. def relocate_vtab(address):
  26. replace_define("VECT_TAB_OFFSET", address)
  27. # Replace the existing -Wl,-T with the given ldscript path
  28. def custom_ld_script(ldname):
  29. apath = os.path.abspath("buildroot/share/PlatformIO/ldscripts/" + ldname)
  30. for i, flag in enumerate(env["LINKFLAGS"]):
  31. if "-Wl,-T" in flag:
  32. env["LINKFLAGS"][i] = "-Wl,-T" + apath
  33. elif flag == "-T":
  34. env["LINKFLAGS"][i + 1] = apath
  35. # Encrypt ${PROGNAME}.bin and save it with a new name
  36. # Called by specific encrypt() functions, mostly for MKS boards
  37. def encrypt_mks(source, target, env, new_name):
  38. import sys
  39. 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]
  40. firmware = open(target[0].path, "rb")
  41. renamed = open(target[0].dir.path + "/" + new_name, "wb")
  42. length = os.path.getsize(target[0].path)
  43. position = 0
  44. try:
  45. while position < length:
  46. byte = firmware.read(1)
  47. if position >= 320 and position < 31040:
  48. byte = chr(ord(byte) ^ key[position & 31])
  49. if sys.version_info[0] > 2:
  50. byte = bytes(byte, 'latin1')
  51. renamed.write(byte)
  52. position += 1
  53. finally:
  54. firmware.close()
  55. renamed.close()
  56. def add_post_action(action):
  57. env.AddPostAction("$BUILD_DIR/${PROGNAME}.bin", action);
  58. # Apply customizations for a MKS Robin
  59. def prepare_robin(address, ldname, fwname):
  60. def encrypt(source, target, env):
  61. encrypt_mks(source, target, env, fwname)
  62. relocate_firmware(address)
  63. custom_ld_script(ldname)
  64. add_post_action(encrypt);