2021-02-28 04:38:57 +00:00
|
|
|
#
|
|
|
|
# fix_framework_weakness.py
|
|
|
|
#
|
2021-11-04 10:28:42 +00:00
|
|
|
import pioutil
|
|
|
|
if pioutil.is_pio_build():
|
2021-02-21 02:22:20 +00:00
|
|
|
|
2022-08-19 16:00:52 +00:00
|
|
|
import shutil
|
|
|
|
from os.path import join, isfile
|
|
|
|
from pprint import pprint
|
2021-02-21 02:22:20 +00:00
|
|
|
|
2024-06-14 21:01:34 +00:00
|
|
|
env = pioutil.env
|
2022-08-19 16:00:52 +00:00
|
|
|
if env.MarlinHas("POSTMORTEM_DEBUGGING"):
|
|
|
|
FRAMEWORK_DIR = env.PioPlatform().get_package_dir("framework-arduinoststm32-maple")
|
|
|
|
patchflag_path = join(FRAMEWORK_DIR, ".exc-patching-done")
|
2021-02-21 02:22:20 +00:00
|
|
|
|
2022-08-19 16:00:52 +00:00
|
|
|
# patch file only if we didn't do it before
|
|
|
|
if not isfile(patchflag_path):
|
|
|
|
print("Patching libmaple exception handlers")
|
|
|
|
original_file = join(FRAMEWORK_DIR, "STM32F1", "cores", "maple", "libmaple", "exc.S")
|
|
|
|
backup_file = join(FRAMEWORK_DIR, "STM32F1", "cores", "maple", "libmaple", "exc.S.bak")
|
|
|
|
src_file = join("buildroot", "share", "PlatformIO", "scripts", "exc.S")
|
2021-02-21 02:22:20 +00:00
|
|
|
|
2022-08-19 16:00:52 +00:00
|
|
|
assert isfile(original_file) and isfile(src_file)
|
|
|
|
shutil.copyfile(original_file, backup_file)
|
2023-11-14 05:48:01 +00:00
|
|
|
shutil.copyfile(src_file, original_file)
|
2021-02-21 02:22:20 +00:00
|
|
|
|
2022-08-19 16:00:52 +00:00
|
|
|
def _touch(path):
|
|
|
|
with open(path, "w") as fp:
|
|
|
|
fp.write("")
|
2021-02-21 02:22:20 +00:00
|
|
|
|
2022-08-19 16:00:52 +00:00
|
|
|
env.Execute(lambda *args, **kwargs: _touch(patchflag_path))
|
|
|
|
print("Done patching exception handler")
|
2021-11-04 10:28:42 +00:00
|
|
|
|
2022-08-19 16:00:52 +00:00
|
|
|
print("Libmaple modified and ready for post mortem debugging")
|