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.

marlin.py 2.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #
  2. # 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. from os.path import join
  9. def copytree(src, dst, symlinks=False, ignore=None):
  10. for item in os.listdir(src):
  11. s = join(src, item)
  12. d = join(dst, item)
  13. if os.path.isdir(s):
  14. shutil.copytree(s, d, symlinks, ignore)
  15. else:
  16. shutil.copy2(s, d)
  17. def replace_define(field, value):
  18. for define in env['CPPDEFINES']:
  19. if define[0] == field:
  20. env['CPPDEFINES'].remove(define)
  21. env['CPPDEFINES'].append((field, value))
  22. # Relocate the firmware to a new address, such as "0x08005000"
  23. def relocate_firmware(address):
  24. replace_define("VECT_TAB_ADDR", address)
  25. # Relocate the vector table with a new offset
  26. def relocate_vtab(address):
  27. replace_define("VECT_TAB_OFFSET", address)
  28. # Replace the existing -Wl,-T with the given ldscript path
  29. def custom_ld_script(ldname):
  30. apath = os.path.abspath("buildroot/share/PlatformIO/ldscripts/" + ldname)
  31. for i, flag in enumerate(env["LINKFLAGS"]):
  32. if "-Wl,-T" in flag:
  33. env["LINKFLAGS"][i] = "-Wl,-T" + apath
  34. elif flag == "-T":
  35. env["LINKFLAGS"][i + 1] = apath
  36. # Encrypt ${PROGNAME}.bin and save it with a new name
  37. # Called by specific encrypt() functions, mostly for MKS boards
  38. def encrypt_mks(source, target, env, new_name):
  39. import sys
  40. 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]
  41. # If FIRMWARE_BIN is defined by config, override all
  42. import re
  43. patt = re.compile("^\\s*#define\\s+FIRMWARE_BIN\\s+\"?(.+)\"?")
  44. with open(join("Marlin", "Configuration.h"), encoding="utf-8") as f:
  45. for line in f:
  46. m = patt.search(line)
  47. if m != None:
  48. new_name = m.group(1)
  49. fwpath = target[0].path
  50. fwfile = open(fwpath, "rb")
  51. enfile = open(target[0].dir.path + "/" + new_name, "wb")
  52. length = os.path.getsize(fwpath)
  53. position = 0
  54. try:
  55. while position < length:
  56. byte = fwfile.read(1)
  57. if position >= 320 and position < 31040:
  58. byte = chr(ord(byte) ^ key[position & 31])
  59. if sys.version_info[0] > 2:
  60. byte = bytes(byte, 'latin1')
  61. enfile.write(byte)
  62. position += 1
  63. finally:
  64. fwfile.close()
  65. enfile.close()
  66. os.remove(fwpath)
  67. def add_post_action(action):
  68. env.AddPostAction(join("$BUILD_DIR", "${PROGNAME}.bin"), action);