fix_framework_weakness.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334
  1. #
  2. # fix_framework_weakness.py
  3. #
  4. import pioutil
  5. if pioutil.is_pio_build():
  6. import shutil
  7. from os.path import join, isfile
  8. from pprint import pprint
  9. env = pioutil.env
  10. if env.MarlinHas("POSTMORTEM_DEBUGGING"):
  11. FRAMEWORK_DIR = env.PioPlatform().get_package_dir("framework-arduinoststm32-maple")
  12. patchflag_path = join(FRAMEWORK_DIR, ".exc-patching-done")
  13. # patch file only if we didn't do it before
  14. if not isfile(patchflag_path):
  15. print("Patching libmaple exception handlers")
  16. original_file = join(FRAMEWORK_DIR, "STM32F1", "cores", "maple", "libmaple", "exc.S")
  17. backup_file = join(FRAMEWORK_DIR, "STM32F1", "cores", "maple", "libmaple", "exc.S.bak")
  18. src_file = join("buildroot", "share", "PlatformIO", "scripts", "exc.S")
  19. assert isfile(original_file) and isfile(src_file)
  20. shutil.copyfile(original_file, backup_file)
  21. shutil.copyfile(src_file, original_file)
  22. def _touch(path):
  23. with open(path, "w") as fp:
  24. fp.write("")
  25. env.Execute(lambda *args, **kwargs: _touch(patchflag_path))
  26. print("Done patching exception handler")
  27. print("Libmaple modified and ready for post mortem debugging")