aboutsummaryrefslogtreecommitdiff
path: root/buildroot/share/PlatformIO/scripts/stm32_bootloader.py
diff options
context:
space:
mode:
authorGeorgiy Bondarenko <69736697+nehilo@users.noreply.github.com>2021-03-04 20:54:23 +0300
committerGeorgiy Bondarenko <69736697+nehilo@users.noreply.github.com>2021-03-04 20:54:23 +0300
commite8701195e66f2d27ffe17fb514eae8173795aaf7 (patch)
tree9f519c4abf6556b9ae7190a6210d87ead1dfadde /buildroot/share/PlatformIO/scripts/stm32_bootloader.py
downloadkp3s-lgvl-e8701195e66f2d27ffe17fb514eae8173795aaf7.tar.xz
kp3s-lgvl-e8701195e66f2d27ffe17fb514eae8173795aaf7.zip
Initial commit
Diffstat (limited to 'buildroot/share/PlatformIO/scripts/stm32_bootloader.py')
-rw-r--r--buildroot/share/PlatformIO/scripts/stm32_bootloader.py30
1 files changed, 30 insertions, 0 deletions
diff --git a/buildroot/share/PlatformIO/scripts/stm32_bootloader.py b/buildroot/share/PlatformIO/scripts/stm32_bootloader.py
new file mode 100644
index 0000000..7f49ea0
--- /dev/null
+++ b/buildroot/share/PlatformIO/scripts/stm32_bootloader.py
@@ -0,0 +1,30 @@
+import os,sys,shutil
+Import("env")
+
+from SCons.Script import DefaultEnvironment
+board = DefaultEnvironment().BoardConfig()
+
+def noencrypt(source, target, env):
+ firmware = os.path.join(target[0].dir.path, board.get("build.firmware"))
+ shutil.copy(target[0].path, firmware)
+
+if 'offset' in board.get("build").keys():
+ LD_FLASH_OFFSET = board.get("build.offset")
+
+ for define in env['CPPDEFINES']:
+ if define[0] == "VECT_TAB_OFFSET":
+ env['CPPDEFINES'].remove(define)
+ env['CPPDEFINES'].append(("VECT_TAB_OFFSET", LD_FLASH_OFFSET))
+
+ maximum_ram_size = board.get("upload.maximum_ram_size")
+
+ for i, flag in enumerate(env["LINKFLAGS"]):
+ if "-Wl,--defsym=LD_FLASH_OFFSET" in flag:
+ env["LINKFLAGS"][i] = "-Wl,--defsym=LD_FLASH_OFFSET=" + LD_FLASH_OFFSET
+ if "-Wl,--defsym=LD_MAX_DATA_SIZE" in flag:
+ env["LINKFLAGS"][i] = "-Wl,--defsym=LD_MAX_DATA_SIZE=" + str(maximum_ram_size - 40)
+
+board_keys = board.get("build").keys()
+# Only copy file if there's no encryptation
+if 'firmware' in board_keys and not 'encrypt' in board_keys:
+ env.AddPostAction("$BUILD_DIR/${PROGNAME}.bin", noencrypt)