Browse Source

🏗️ Refactor build encrypt / rename (#22124)

Scott Lahteine 3 years ago
parent
commit
90dc41139f
No account linked to committer's email address

+ 2
- 2
buildroot/share/PlatformIO/scripts/STM32F103RC_fysetc.py View File

@@ -8,10 +8,10 @@ Import("env")
8 8
 
9 9
 # Custom HEX from ELF
10 10
 env.AddPostAction(
11
-	join("$BUILD_DIR","${PROGNAME}.elf"),
11
+	join("$BUILD_DIR", "${PROGNAME}.elf"),
12 12
 	env.VerboseAction(" ".join([
13 13
 		"$OBJCOPY", "-O ihex", "$TARGET", # TARGET=.pio/build/fysetc_STM32F1/firmware.elf
14
-		"\"" + join("$BUILD_DIR","${PROGNAME}.hex") + "\"", # Note: $BUILD_DIR is a full path
14
+		"\"" + join("$BUILD_DIR", "${PROGNAME}.hex") + "\"", # Note: $BUILD_DIR is a full path
15 15
 	]), "Building $TARGET"))
16 16
 
17 17
 # In-line command with arguments

+ 8
- 7
buildroot/share/PlatformIO/scripts/lerdge.py View File

@@ -27,11 +27,12 @@ def encrypt_file(input, output_file, file_length):
27 27
     output_file.write(input_file)
28 28
     return
29 29
 
30
-# Encrypt ${PROGNAME}.bin and save it as build.firmware
30
+# Encrypt ${PROGNAME}.bin and save it with the name given in build.encrypt
31 31
 def encrypt(source, target, env):
32
-    print("Encrypting to:", board.get("build.firmware"))
32
+    fwname = board.get("build.encrypt")
33
+    print("Encrypting %s to %s" % (target[0].path, fwname))
33 34
     firmware = open(target[0].path, "rb")
34
-    renamed = open(target[0].dir.path + "/" + board.get("build.firmware"), "wb")
35
+    renamed = open(target[0].dir.path + "/" + fwname, "wb")
35 36
     length = os.path.getsize(target[0].path)
36 37
 
37 38
     encrypt_file(firmware, renamed, length)
@@ -39,8 +40,8 @@ def encrypt(source, target, env):
39 40
     firmware.close()
40 41
     renamed.close()
41 42
 
42
-if 'firmware' in board.get("build").keys():
43
-  marlin.add_post_action(encrypt);
43
+if 'encrypt' in board.get("build").keys():
44
+    marlin.add_post_action(encrypt);
44 45
 else:
45
-  print("You need to define output file via board_build.firmware = 'filename' parameter")
46
-  exit(1);
46
+    print("LERDGE builds require output file via board_build.encrypt = 'filename' parameter")
47
+    exit(1);

+ 5
- 3
buildroot/share/PlatformIO/scripts/marlin.py View File

@@ -7,10 +7,12 @@ import os,shutil
7 7
 from SCons.Script import DefaultEnvironment
8 8
 env = DefaultEnvironment()
9 9
 
10
+from os.path import join
11
+
10 12
 def copytree(src, dst, symlinks=False, ignore=None):
11 13
    for item in os.listdir(src):
12
-        s = os.path.join(src, item)
13
-        d = os.path.join(dst, item)
14
+        s = join(src, item)
15
+        d = join(dst, item)
14 16
         if os.path.isdir(s):
15 17
             shutil.copytree(s, d, symlinks, ignore)
16 18
         else:
@@ -64,7 +66,7 @@ def encrypt_mks(source, target, env, new_name):
64 66
 		renamed.close()
65 67
 
66 68
 def add_post_action(action):
67
-	env.AddPostAction("$BUILD_DIR/${PROGNAME}.bin", action);
69
+	env.AddPostAction(join("$BUILD_DIR", "${PROGNAME}.bin"), action);
68 70
 
69 71
 # Apply customizations for a MKS Robin
70 72
 def prepare_robin(address, ldname, fwname):

+ 5
- 4
buildroot/share/PlatformIO/scripts/mks_encrypt.py View File

@@ -3,6 +3,7 @@
3 3
 #
4 4
 # Apply encryption and save as 'build.firmware' for these environments:
5 5
 #  - env:mks_robin
6
+#  - env:mks_robin_e3
6 7
 #  - env:flsun_hispeedv1
7 8
 #  - env:mks_robin_nano35
8 9
 #
@@ -11,18 +12,18 @@ Import("env")
11 12
 from SCons.Script import DefaultEnvironment
12 13
 board = DefaultEnvironment().BoardConfig()
13 14
 
14
-if 'firmware' in board.get("build").keys():
15
+if 'encrypt' in board.get("build").keys():
15 16
 
16 17
 	import marlin
17 18
 
18
-	# Encrypt ${PROGNAME}.bin and save it as build.firmware
19
+	# Encrypt ${PROGNAME}.bin and save it with the name given in build.encrypt
19 20
 	def encrypt(source, target, env):
20
-		marlin.encrypt_mks(source, target, env, board.get("build.firmware"))
21
+		marlin.encrypt_mks(source, target, env, board.get("build.encrypt"))
21 22
 
22 23
 	marlin.add_post_action(encrypt);
23 24
 
24 25
 else:
25 26
 
26 27
 	import sys
27
-	print("You need to define output file via board_build.firmware = 'filename' parameter", file=sys.stderr)
28
+	print("You need to define output file via board_build.encrypt = 'filename' parameter", file=sys.stderr)
28 29
 	env.Exit(1);

+ 10
- 7
buildroot/share/PlatformIO/scripts/openblt.py View File

@@ -6,10 +6,13 @@ from os.path import join
6 6
 
7 7
 Import("env")
8 8
 
9
-env.AddPostAction(
10
-    "$BUILD_DIR/${PROGNAME}.elf",
11
-    env.VerboseAction(" ".join([
12
-        "$OBJCOPY", "-O", "srec",
13
-        "\"$BUILD_DIR/${PROGNAME}.elf\"", "\"$BUILD_DIR/${PROGNAME}.srec\""
14
-    ]), "Building " + join("$BUILD_DIR", "${PROGNAME}.srec"))
15
-)
9
+board = env.BoardConfig()
10
+board_keys = board.get("build").keys()
11
+if 'encrypt' in board_keys:
12
+	env.AddPostAction(
13
+		join("$BUILD_DIR", "${PROGNAME}.bin"),
14
+		env.VerboseAction(" ".join([
15
+			"$OBJCOPY", "-O", "srec",
16
+			"\"$BUILD_DIR/${PROGNAME}.elf\"", "\"" + join("$BUILD_DIR", board.get("build.encrypt")) + "\""
17
+		]), "Building $TARGET")
18
+	)

+ 12
- 13
buildroot/share/PlatformIO/scripts/stm32_bootloader.py View File

@@ -1,23 +1,18 @@
1 1
 #
2 2
 # stm32_bootloader.py
3 3
 #
4
-import os,sys,shutil,marlin
4
+import os,sys,marlin
5 5
 Import("env")
6 6
 
7 7
 from SCons.Script import DefaultEnvironment
8 8
 board = DefaultEnvironment().BoardConfig()
9 9
 
10
-#
11
-# Copy the firmware.bin file to build.firmware, no encryption
12
-#
13
-def noencrypt(source, target, env):
14
-	firmware = os.path.join(target[0].dir.path, board.get("build.firmware"))
15
-	shutil.copy(target[0].path, firmware)
10
+board_keys = board.get("build").keys()
16 11
 
17 12
 #
18 13
 # For build.offset define LD_FLASH_OFFSET, used by ldscript.ld
19 14
 #
20
-if 'offset' in board.get("build").keys():
15
+if 'offset' in board_keys:
21 16
 	LD_FLASH_OFFSET = board.get("build.offset")
22 17
 	marlin.relocate_vtab(LD_FLASH_OFFSET)
23 18
 
@@ -35,9 +30,13 @@ if 'offset' in board.get("build").keys():
35 30
 			env["LINKFLAGS"][i] = "-Wl,--defsym=LD_MAX_DATA_SIZE=" + str(maximum_ram_size - 40)
36 31
 
37 32
 #
38
-# Only copy the file if there's no encrypt
33
+# For build.rename simply rename the firmware file.
39 34
 #
40
-board_keys = board.get("build").keys()
41
-if 'firmware' in board_keys and ('encrypt' not in board_keys or board.get("build.encrypt") == 'No'):
42
-	import marlin
43
-	marlin.add_post_action(noencrypt)
35
+if 'rename' in board_keys:
36
+
37
+	def rename_target(source, target, env):
38
+		firmware = os.path.join(target[0].dir.path, board.get("build.rename"))
39
+		import shutil
40
+		shutil.copy(target[0].path, firmware)
41
+
42
+	marlin.add_post_action(rename_target)

+ 4
- 10
ini/stm32f1.ini View File

@@ -84,8 +84,6 @@ platform             = ${common_stm32.platform}
84 84
 extends              = common_STM32F103RC
85 85
 build_flags          = ${common_stm32.build_flags} -DDEBUG_LEVEL=0 -DTIMER_SERVO=TIM5
86 86
 board_build.offset   = 0x7000
87
-board_build.encrypt  = No
88
-board_build.firmware = firmware.bin
89 87
 board_upload.offset_address = 0x08007000
90 88
 
91 89
 [env:STM32F103RC_btt_USB]
@@ -113,8 +111,7 @@ board_build.core     = stm32
113 111
 board_build.variant  = MARLIN_F103Zx
114 112
 board_build.ldscript = ldscript.ld
115 113
 board_build.offset   = 0x7000
116
-board_build.encrypt  = Yes
117
-board_build.firmware = Robin.bin
114
+board_build.encrypt  = Robin.bin
118 115
 build_flags          = ${common_stm32.build_flags}
119 116
   -DENABLE_HWSERIAL3 -DTIMER_SERIAL=TIM5
120 117
 build_unflags        = ${common_stm32.build_unflags}
@@ -136,8 +133,7 @@ build_flags                 = ${common_stm32.build_flags}
136 133
 build_unflags               = ${common_stm32.build_unflags} -DUSBCON -DUSBD_USE_CDC
137 134
 monitor_speed               = 115200
138 135
 board_build.offset          = 0x5000
139
-board_build.encrypt         = Yes
140
-board_build.firmware        = Robin_e3.bin
136
+board_build.encrypt         = Robin_e3.bin
141 137
 board_upload.offset_address = 0x08005000
142 138
 debug_tool                  = stlink
143 139
 extra_scripts               = ${env:STM32F103RC.extra_scripts}
@@ -215,8 +211,7 @@ board_build.core     = stm32
215 211
 board_build.variant  = MARLIN_F103Vx
216 212
 board_build.ldscript = ldscript.ld
217 213
 board_build.offset   = 0x7000
218
-board_build.firmware = Robin_mini.bin
219
-board_build.encrypt  = Yes
214
+board_build.encrypt  = Robin_mini.bin
220 215
 board_upload.offset_address = 0x08007000
221 216
 build_unflags        = ${common_stm32.build_unflags} -DUSBCON -DUSBD_USE_CDC
222 217
 extra_scripts        = ${common_stm32.extra_scripts}
@@ -236,8 +231,7 @@ board_build.core     = stm32
236 231
 board_build.variant  = MARLIN_F103Vx
237 232
 board_build.ldscript = ldscript.ld
238 233
 board_build.offset   = 0x7000
239
-board_build.encrypt  = Yes
240
-board_build.firmware = Robin_nano35.bin
234
+board_build.encrypt  = Robin_nano35.bin
241 235
 board_upload.offset_address = 0x08007000
242 236
 build_unflags        = ${common_stm32.build_unflags} -DUSBCON -DUSBD_USE_CDC
243 237
 debug_tool           = jlink

+ 13
- 17
ini/stm32f4.ini View File

@@ -113,9 +113,8 @@ board                = marlin_STM32F407VGT6_CCM
113 113
 board_build.core     = stm32
114 114
 board_build.variant  = MARLIN_F4x7Vx
115 115
 board_build.ldscript = ldscript.ld
116
-board_build.firmware = firmware.srec
116
+board_build.encrypt  = firmware.srec
117 117
 # Just openblt.py (not stm32_bootloader.py) generates the file
118
-board_build.encrypt  = Yes
119 118
 board_build.offset   = 0x10000
120 119
 board_upload.offset_address = 0x08010000
121 120
 build_unflags        = ${common_stm32.build_unflags} -DUSBCON -DUSBD_USE_CDC -DUSBD_VID=0x0483
@@ -265,7 +264,7 @@ extends             = common_stm32
265 264
 board               = marlin_STM32F407ZGT6
266 265
 board_build.variant = MARLIN_LERDGE
267 266
 board_build.offset  = 0x10000
268
-board_build.encrypt = Yes
267
+board_build.encrypt = firmware.bin
269 268
 extra_scripts       = ${common.extra_scripts}
270 269
                       pre:buildroot/share/PlatformIO/scripts/generic_create_variant.py
271 270
                       buildroot/share/PlatformIO/scripts/stm32_bootloader.py
@@ -280,9 +279,9 @@ build_unflags       = ${common_stm32.build_unflags} -DUSBCON -DUSBD_USE_CDC -DUS
280 279
 # Lerdge X
281 280
 #
282 281
 [env:LERDGEX]
283
-platform             = ${lerdge_common.platform}
284
-extends              = lerdge_common
285
-board_build.firmware = Lerdge_X_firmware_force.bin
282
+platform            = ${lerdge_common.platform}
283
+extends             = lerdge_common
284
+board_build.encrypt = Lerdge_X_firmware_force.bin
286 285
 
287 286
 #
288 287
 # Lerdge X with USB Flash Drive Support
@@ -297,9 +296,9 @@ build_flags       = ${stm_flash_drive.build_flags} ${lerdge_common.build_flags}
297 296
 # Lerdge S
298 297
 #
299 298
 [env:LERDGES]
300
-platform             = ${lerdge_common.platform}
301
-extends              = lerdge_common
302
-board_build.firmware = Lerdge_firmware_force.bin
299
+platform            = ${lerdge_common.platform}
300
+extends             = lerdge_common
301
+board_build.encrypt = Lerdge_firmware_force.bin
303 302
 
304 303
 #
305 304
 # Lerdge S with USB Flash Drive Support
@@ -314,10 +313,10 @@ build_flags       = ${stm_flash_drive.build_flags} ${lerdge_common.build_flags}
314 313
 # Lerdge K
315 314
 #
316 315
 [env:LERDGEK]
317
-platform             = ${lerdge_common.platform}
318
-extends              = lerdge_common
319
-board_build.firmware = Lerdge_K_firmware_force.bin
320
-build_flags          = ${lerdge_common.build_flags} -DLERDGEK
316
+platform            = ${lerdge_common.platform}
317
+extends             = lerdge_common
318
+board_build.encrypt = Lerdge_K_firmware_force.bin
319
+build_flags         = ${lerdge_common.build_flags} -DLERDGEK
321 320
 
322 321
 #
323 322
 # Lerdge K with USB Flash Drive Support
@@ -347,8 +346,6 @@ board_build.core     = stm32
347 346
 board_build.variant  = MARLIN_F446VE
348 347
 board_build.ldscript = ldscript.ld
349 348
 board_build.offset   = 0x0000
350
-board_build.encrypt  = No
351
-board_build.firmware = firmware.bin
352 349
 extra_scripts        = ${common.extra_scripts}
353 350
   pre:buildroot/share/PlatformIO/scripts/generic_create_variant.py
354 351
   buildroot/share/PlatformIO/scripts/stm32_bootloader.py
@@ -365,7 +362,6 @@ board                = genericSTM32F407VET6
365 362
 board_build.core     = stm32
366 363
 board_build.variant  = MARLIN_F4x7Vx
367 364
 board_build.ldscript = ldscript.ld
368
-board_build.firmware = firmware.bin
369 365
 board_build.offset   = 0x0000
370 366
 board_upload.offset_address = 0x08000000
371 367
 build_unflags        = ${common_stm32.build_unflags} -DUSBCON -DUSBD_USE_CDC
@@ -392,7 +388,7 @@ board                = marlin_STM32F407VGT6_CCM
392 388
 board_build.core     = stm32
393 389
 board_build.variant  = MARLIN_F4x7Vx
394 390
 board_build.ldscript = ldscript.ld
395
-board_build.firmware = Robin_nano_v3.bin
391
+board_build.rename   = Robin_nano_v3.bin
396 392
 board_build.offset   = 0xC000
397 393
 board_upload.offset_address = 0x0800C000
398 394
 build_unflags        = ${common_stm32.build_unflags}

Loading…
Cancel
Save