|
@@ -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)
|