Browse Source

🏗️ Refactor build encrypt / rename (#22124)

Scott Lahteine 4 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
 
8
 
9
 # Custom HEX from ELF
9
 # Custom HEX from ELF
10
 env.AddPostAction(
10
 env.AddPostAction(
11
-	join("$BUILD_DIR","${PROGNAME}.elf"),
11
+	join("$BUILD_DIR", "${PROGNAME}.elf"),
12
 	env.VerboseAction(" ".join([
12
 	env.VerboseAction(" ".join([
13
 		"$OBJCOPY", "-O ihex", "$TARGET", # TARGET=.pio/build/fysetc_STM32F1/firmware.elf
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
 	]), "Building $TARGET"))
15
 	]), "Building $TARGET"))
16
 
16
 
17
 # In-line command with arguments
17
 # In-line command with arguments

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

27
     output_file.write(input_file)
27
     output_file.write(input_file)
28
     return
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
 def encrypt(source, target, env):
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
     firmware = open(target[0].path, "rb")
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
     length = os.path.getsize(target[0].path)
36
     length = os.path.getsize(target[0].path)
36
 
37
 
37
     encrypt_file(firmware, renamed, length)
38
     encrypt_file(firmware, renamed, length)
39
     firmware.close()
40
     firmware.close()
40
     renamed.close()
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
 else:
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
 from SCons.Script import DefaultEnvironment
7
 from SCons.Script import DefaultEnvironment
8
 env = DefaultEnvironment()
8
 env = DefaultEnvironment()
9
 
9
 
10
+from os.path import join
11
+
10
 def copytree(src, dst, symlinks=False, ignore=None):
12
 def copytree(src, dst, symlinks=False, ignore=None):
11
    for item in os.listdir(src):
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
         if os.path.isdir(s):
16
         if os.path.isdir(s):
15
             shutil.copytree(s, d, symlinks, ignore)
17
             shutil.copytree(s, d, symlinks, ignore)
16
         else:
18
         else:
64
 		renamed.close()
66
 		renamed.close()
65
 
67
 
66
 def add_post_action(action):
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
 # Apply customizations for a MKS Robin
71
 # Apply customizations for a MKS Robin
70
 def prepare_robin(address, ldname, fwname):
72
 def prepare_robin(address, ldname, fwname):

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

3
 #
3
 #
4
 # Apply encryption and save as 'build.firmware' for these environments:
4
 # Apply encryption and save as 'build.firmware' for these environments:
5
 #  - env:mks_robin
5
 #  - env:mks_robin
6
+#  - env:mks_robin_e3
6
 #  - env:flsun_hispeedv1
7
 #  - env:flsun_hispeedv1
7
 #  - env:mks_robin_nano35
8
 #  - env:mks_robin_nano35
8
 #
9
 #
11
 from SCons.Script import DefaultEnvironment
12
 from SCons.Script import DefaultEnvironment
12
 board = DefaultEnvironment().BoardConfig()
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
 	import marlin
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
 	def encrypt(source, target, env):
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
 	marlin.add_post_action(encrypt);
23
 	marlin.add_post_action(encrypt);
23
 
24
 
24
 else:
25
 else:
25
 
26
 
26
 	import sys
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
 	env.Exit(1);
29
 	env.Exit(1);

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

6
 
6
 
7
 Import("env")
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
 #
1
 #
2
 # stm32_bootloader.py
2
 # stm32_bootloader.py
3
 #
3
 #
4
-import os,sys,shutil,marlin
4
+import os,sys,marlin
5
 Import("env")
5
 Import("env")
6
 
6
 
7
 from SCons.Script import DefaultEnvironment
7
 from SCons.Script import DefaultEnvironment
8
 board = DefaultEnvironment().BoardConfig()
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
 # For build.offset define LD_FLASH_OFFSET, used by ldscript.ld
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
 	LD_FLASH_OFFSET = board.get("build.offset")
16
 	LD_FLASH_OFFSET = board.get("build.offset")
22
 	marlin.relocate_vtab(LD_FLASH_OFFSET)
17
 	marlin.relocate_vtab(LD_FLASH_OFFSET)
23
 
18
 
35
 			env["LINKFLAGS"][i] = "-Wl,--defsym=LD_MAX_DATA_SIZE=" + str(maximum_ram_size - 40)
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
 extends              = common_STM32F103RC
84
 extends              = common_STM32F103RC
85
 build_flags          = ${common_stm32.build_flags} -DDEBUG_LEVEL=0 -DTIMER_SERVO=TIM5
85
 build_flags          = ${common_stm32.build_flags} -DDEBUG_LEVEL=0 -DTIMER_SERVO=TIM5
86
 board_build.offset   = 0x7000
86
 board_build.offset   = 0x7000
87
-board_build.encrypt  = No
88
-board_build.firmware = firmware.bin
89
 board_upload.offset_address = 0x08007000
87
 board_upload.offset_address = 0x08007000
90
 
88
 
91
 [env:STM32F103RC_btt_USB]
89
 [env:STM32F103RC_btt_USB]
113
 board_build.variant  = MARLIN_F103Zx
111
 board_build.variant  = MARLIN_F103Zx
114
 board_build.ldscript = ldscript.ld
112
 board_build.ldscript = ldscript.ld
115
 board_build.offset   = 0x7000
113
 board_build.offset   = 0x7000
116
-board_build.encrypt  = Yes
117
-board_build.firmware = Robin.bin
114
+board_build.encrypt  = Robin.bin
118
 build_flags          = ${common_stm32.build_flags}
115
 build_flags          = ${common_stm32.build_flags}
119
   -DENABLE_HWSERIAL3 -DTIMER_SERIAL=TIM5
116
   -DENABLE_HWSERIAL3 -DTIMER_SERIAL=TIM5
120
 build_unflags        = ${common_stm32.build_unflags}
117
 build_unflags        = ${common_stm32.build_unflags}
136
 build_unflags               = ${common_stm32.build_unflags} -DUSBCON -DUSBD_USE_CDC
133
 build_unflags               = ${common_stm32.build_unflags} -DUSBCON -DUSBD_USE_CDC
137
 monitor_speed               = 115200
134
 monitor_speed               = 115200
138
 board_build.offset          = 0x5000
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
 board_upload.offset_address = 0x08005000
137
 board_upload.offset_address = 0x08005000
142
 debug_tool                  = stlink
138
 debug_tool                  = stlink
143
 extra_scripts               = ${env:STM32F103RC.extra_scripts}
139
 extra_scripts               = ${env:STM32F103RC.extra_scripts}
215
 board_build.variant  = MARLIN_F103Vx
211
 board_build.variant  = MARLIN_F103Vx
216
 board_build.ldscript = ldscript.ld
212
 board_build.ldscript = ldscript.ld
217
 board_build.offset   = 0x7000
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
 board_upload.offset_address = 0x08007000
215
 board_upload.offset_address = 0x08007000
221
 build_unflags        = ${common_stm32.build_unflags} -DUSBCON -DUSBD_USE_CDC
216
 build_unflags        = ${common_stm32.build_unflags} -DUSBCON -DUSBD_USE_CDC
222
 extra_scripts        = ${common_stm32.extra_scripts}
217
 extra_scripts        = ${common_stm32.extra_scripts}
236
 board_build.variant  = MARLIN_F103Vx
231
 board_build.variant  = MARLIN_F103Vx
237
 board_build.ldscript = ldscript.ld
232
 board_build.ldscript = ldscript.ld
238
 board_build.offset   = 0x7000
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
 board_upload.offset_address = 0x08007000
235
 board_upload.offset_address = 0x08007000
242
 build_unflags        = ${common_stm32.build_unflags} -DUSBCON -DUSBD_USE_CDC
236
 build_unflags        = ${common_stm32.build_unflags} -DUSBCON -DUSBD_USE_CDC
243
 debug_tool           = jlink
237
 debug_tool           = jlink

+ 13
- 17
ini/stm32f4.ini View File

113
 board_build.core     = stm32
113
 board_build.core     = stm32
114
 board_build.variant  = MARLIN_F4x7Vx
114
 board_build.variant  = MARLIN_F4x7Vx
115
 board_build.ldscript = ldscript.ld
115
 board_build.ldscript = ldscript.ld
116
-board_build.firmware = firmware.srec
116
+board_build.encrypt  = firmware.srec
117
 # Just openblt.py (not stm32_bootloader.py) generates the file
117
 # Just openblt.py (not stm32_bootloader.py) generates the file
118
-board_build.encrypt  = Yes
119
 board_build.offset   = 0x10000
118
 board_build.offset   = 0x10000
120
 board_upload.offset_address = 0x08010000
119
 board_upload.offset_address = 0x08010000
121
 build_unflags        = ${common_stm32.build_unflags} -DUSBCON -DUSBD_USE_CDC -DUSBD_VID=0x0483
120
 build_unflags        = ${common_stm32.build_unflags} -DUSBCON -DUSBD_USE_CDC -DUSBD_VID=0x0483
265
 board               = marlin_STM32F407ZGT6
264
 board               = marlin_STM32F407ZGT6
266
 board_build.variant = MARLIN_LERDGE
265
 board_build.variant = MARLIN_LERDGE
267
 board_build.offset  = 0x10000
266
 board_build.offset  = 0x10000
268
-board_build.encrypt = Yes
267
+board_build.encrypt = firmware.bin
269
 extra_scripts       = ${common.extra_scripts}
268
 extra_scripts       = ${common.extra_scripts}
270
                       pre:buildroot/share/PlatformIO/scripts/generic_create_variant.py
269
                       pre:buildroot/share/PlatformIO/scripts/generic_create_variant.py
271
                       buildroot/share/PlatformIO/scripts/stm32_bootloader.py
270
                       buildroot/share/PlatformIO/scripts/stm32_bootloader.py
280
 # Lerdge X
279
 # Lerdge X
281
 #
280
 #
282
 [env:LERDGEX]
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
 # Lerdge X with USB Flash Drive Support
287
 # Lerdge X with USB Flash Drive Support
297
 # Lerdge S
296
 # Lerdge S
298
 #
297
 #
299
 [env:LERDGES]
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
 # Lerdge S with USB Flash Drive Support
304
 # Lerdge S with USB Flash Drive Support
314
 # Lerdge K
313
 # Lerdge K
315
 #
314
 #
316
 [env:LERDGEK]
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
 # Lerdge K with USB Flash Drive Support
322
 # Lerdge K with USB Flash Drive Support
347
 board_build.variant  = MARLIN_F446VE
346
 board_build.variant  = MARLIN_F446VE
348
 board_build.ldscript = ldscript.ld
347
 board_build.ldscript = ldscript.ld
349
 board_build.offset   = 0x0000
348
 board_build.offset   = 0x0000
350
-board_build.encrypt  = No
351
-board_build.firmware = firmware.bin
352
 extra_scripts        = ${common.extra_scripts}
349
 extra_scripts        = ${common.extra_scripts}
353
   pre:buildroot/share/PlatformIO/scripts/generic_create_variant.py
350
   pre:buildroot/share/PlatformIO/scripts/generic_create_variant.py
354
   buildroot/share/PlatformIO/scripts/stm32_bootloader.py
351
   buildroot/share/PlatformIO/scripts/stm32_bootloader.py
365
 board_build.core     = stm32
362
 board_build.core     = stm32
366
 board_build.variant  = MARLIN_F4x7Vx
363
 board_build.variant  = MARLIN_F4x7Vx
367
 board_build.ldscript = ldscript.ld
364
 board_build.ldscript = ldscript.ld
368
-board_build.firmware = firmware.bin
369
 board_build.offset   = 0x0000
365
 board_build.offset   = 0x0000
370
 board_upload.offset_address = 0x08000000
366
 board_upload.offset_address = 0x08000000
371
 build_unflags        = ${common_stm32.build_unflags} -DUSBCON -DUSBD_USE_CDC
367
 build_unflags        = ${common_stm32.build_unflags} -DUSBCON -DUSBD_USE_CDC
392
 board_build.core     = stm32
388
 board_build.core     = stm32
393
 board_build.variant  = MARLIN_F4x7Vx
389
 board_build.variant  = MARLIN_F4x7Vx
394
 board_build.ldscript = ldscript.ld
390
 board_build.ldscript = ldscript.ld
395
-board_build.firmware = Robin_nano_v3.bin
391
+board_build.rename   = Robin_nano_v3.bin
396
 board_build.offset   = 0xC000
392
 board_build.offset   = 0xC000
397
 board_upload.offset_address = 0x0800C000
393
 board_upload.offset_address = 0x0800C000
398
 build_unflags        = ${common_stm32.build_unflags}
394
 build_unflags        = ${common_stm32.build_unflags}

Loading…
Cancel
Save