|
4 | 4 | # |
5 | 5 | import pioutil |
6 | 6 | if pioutil.is_pio_build(): |
7 | | - import struct,uuid,marlin |
8 | | - |
9 | | - board = marlin.env.BoardConfig() |
| 7 | + import os,random,struct,uuid,marlin |
| 8 | + # Relocate firmware from 0x08000000 to 0x08008800 |
| 9 | + marlin.relocate_firmware("0x08008800") |
10 | 10 |
|
11 | 11 | def calculate_crc(contents, seed): |
12 | 12 | accumulating_xor_value = seed; |
@@ -105,22 +105,13 @@ def encrypt_file(input, output_file, file_length): |
105 | 105 |
|
106 | 106 | # Encrypt ${PROGNAME}.bin and save it as 'update.cbd' |
107 | 107 | def encrypt(source, target, env): |
108 | | - from pathlib import Path |
109 | | - |
110 | | - fwpath = Path(target[0].path) |
111 | | - fwsize = fwpath.stat().st_size |
| 108 | + firmware = open(target[0].path, "rb") |
| 109 | + update = open(target[0].dir.path + '/update.cbd', "wb") |
| 110 | + length = os.path.getsize(target[0].path) |
112 | 111 |
|
113 | | - enname = board.get("build.crypt_chitu") |
114 | | - enpath = Path(target[0].dir.path) |
| 112 | + encrypt_file(firmware, update, length) |
115 | 113 |
|
116 | | - fwfile = fwpath.open("rb") |
117 | | - enfile = (enpath / enname).open("wb") |
| 114 | + firmware.close() |
| 115 | + update.close() |
118 | 116 |
|
119 | | - print(f"Encrypting {fwpath} to {enname}") |
120 | | - encrypt_file(fwfile, enfile, fwsize) |
121 | | - fwfile.close() |
122 | | - enfile.close() |
123 | | - fwpath.unlink() |
124 | | - |
125 | | - marlin.relocate_firmware("0x08008800") |
126 | 117 | marlin.add_post_action(encrypt); |
0 commit comments