Browse Source

🔨 Delete after encrypt. Lerdge encrypt only once

Scott Lahteine 2 years ago
parent
commit
6cf6c4cd85

+ 23
- 24
buildroot/share/PlatformIO/scripts/lerdge.py View File

@@ -12,37 +12,36 @@ from SCons.Script import DefaultEnvironment
12 12
 board = DefaultEnvironment().BoardConfig()
13 13
 
14 14
 def encryptByte(byte):
15
-    byte = 0xFF & ((byte << 6) | (byte >> 2))
16
-    i = 0x58 + byte
17
-    j = 0x05 + byte + (i >> 8)
18
-    byte = (0xF8 & i) | (0x07 & j)
19
-    return byte
15
+	byte = 0xFF & ((byte << 6) | (byte >> 2))
16
+	i = 0x58 + byte
17
+	j = 0x05 + byte + (i >> 8)
18
+	byte = (0xF8 & i) | (0x07 & j)
19
+	return byte
20 20
 
21 21
 def encrypt_file(input, output_file, file_length):
22
-    input_file = bytearray(input.read())
23
-    for i in range(len(input_file)):
24
-        result = encryptByte(input_file[i])
25
-        input_file[i] = result
26
-
27
-    output_file.write(input_file)
28
-    return
22
+	input_file = bytearray(input.read())
23
+	for i in range(len(input_file)):
24
+		input_file[i] = encryptByte(input_file[i])
25
+	output_file.write(input_file)
29 26
 
30 27
 # Encrypt ${PROGNAME}.bin and save it with the name given in build.encrypt
31 28
 def encrypt(source, target, env):
32
-    fwname = board.get("build.encrypt")
33
-    print("Encrypting %s to %s" % (target[0].path, fwname))
34
-    firmware = open(target[0].path, "rb")
35
-    renamed = open(target[0].dir.path + "/" + fwname, "wb")
36
-    length = os.path.getsize(target[0].path)
29
+	fwpath = target[0].path
30
+	enname = board.get("build.encrypt")
31
+	print("Encrypting %s to %s" % (fwpath, enname))
32
+	fwfile = open(fwpath, "rb")
33
+	enfile = open(target[0].dir.path + "/" + enname, "wb")
34
+	length = os.path.getsize(fwpath)
37 35
 
38
-    encrypt_file(firmware, renamed, length)
36
+	encrypt_file(fwfile, enfile, length)
39 37
 
40
-    firmware.close()
41
-    renamed.close()
38
+	fwfile.close()
39
+	enfile.close()
40
+	os.remove(fwpath)
42 41
 
43 42
 if 'encrypt' in board.get("build").keys():
44
-    if board.get("build.encrypt") != "":
45
-        marlin.add_post_action(encrypt)
43
+	if board.get("build.encrypt") != "":
44
+		marlin.add_post_action(encrypt)
46 45
 else:
47
-    print("LERDGE builds require output file via board_build.encrypt = 'filename' parameter")
48
-    exit(1)
46
+	print("LERDGE builds require output file via board_build.encrypt = 'filename' parameter")
47
+	exit(1)

+ 9
- 7
buildroot/share/PlatformIO/scripts/marlin.py View File

@@ -48,22 +48,24 @@ def encrypt_mks(source, target, env, new_name):
48 48
 
49 49
 	key = [0xA3, 0xBD, 0xAD, 0x0D, 0x41, 0x11, 0xBB, 0x8D, 0xDC, 0x80, 0x2D, 0xD0, 0xD2, 0xC4, 0x9B, 0x1E, 0x26, 0xEB, 0xE3, 0x33, 0x4A, 0x15, 0xE4, 0x0A, 0xB3, 0xB1, 0x3C, 0x93, 0xBB, 0xAF, 0xF7, 0x3E]
50 50
 
51
-	firmware = open(target[0].path, "rb")
52
-	renamed = open(target[0].dir.path + "/" + new_name, "wb")
53
-	length = os.path.getsize(target[0].path)
51
+	fwpath = target[0].path
52
+	fwfile = open(fwpath, "rb")
53
+	enfile = open(target[0].dir.path + "/" + new_name, "wb")
54
+	length = os.path.getsize(fwpath)
54 55
 	position = 0
55 56
 	try:
56 57
 		while position < length:
57
-			byte = firmware.read(1)
58
+			byte = fwfile.read(1)
58 59
 			if position >= 320 and position < 31040:
59 60
 				byte = chr(ord(byte) ^ key[position & 31])
60 61
 				if sys.version_info[0] > 2:
61 62
 					byte = bytes(byte, 'latin1')
62
-			renamed.write(byte)
63
+			enfile.write(byte)
63 64
 			position += 1
64 65
 	finally:
65
-		firmware.close()
66
-		renamed.close()
66
+		fwfile.close()
67
+		enfile.close()
68
+		os.remove(fwpath)
67 69
 
68 70
 def add_post_action(action):
69 71
 	env.AddPostAction(join("$BUILD_DIR", "${PROGNAME}.bin"), action);

+ 2
- 2
ini/stm32f4.ini View File

@@ -263,13 +263,13 @@ platform            = ${common_stm32.platform}
263 263
 extends             = stm32_variant
264 264
 board               = marlin_STM32F407ZGT6
265 265
 board_build.variant = MARLIN_LERDGE
266
-board_build.encrypt = firmware.bin
267 266
 board_build.offset  = 0x10000
268 267
 build_flags         = ${stm32_variant.build_flags}
269 268
                       -DSTM32F4 -DSTM32F4xx -DTARGET_STM32F4
270 269
                       -DDISABLE_GENERIC_SERIALUSB -DARDUINO_ARCH_STM32 -DLERDGE_TFT35
271 270
 build_unflags       = ${stm32_variant.build_unflags} -DUSBCON -DUSBD_USE_CDC -DUSBD_VID=0x0483
272
-extra_scripts       = ${stm32_variant.extra_scripts}
271
+extra_scripts       = ${common_stm32.extra_scripts}
272
+                      pre:buildroot/share/PlatformIO/scripts/generic_create_variant.py
273 273
                       buildroot/share/PlatformIO/scripts/lerdge.py
274 274
 
275 275
 #

Loading…
Cancel
Save