🔨 Simplify scripts with pathlib (#24574)

This commit is contained in:
Scott Lahteine
2022-08-01 01:14:58 -05:00
parent c3f2586445
commit 3b30951e83
14 changed files with 182 additions and 196 deletions

View File

@ -4,9 +4,7 @@
#
import pioutil
if pioutil.is_pio_build():
import os,random,struct,uuid,marlin
# Relocate firmware from 0x08000000 to 0x08008800
marlin.relocate_firmware("0x08008800")
import struct,uuid
def calculate_crc(contents, seed):
accumulating_xor_value = seed;
@ -105,13 +103,13 @@ if pioutil.is_pio_build():
# Encrypt ${PROGNAME}.bin and save it as 'update.cbd'
def encrypt(source, target, env):
firmware = open(target[0].path, "rb")
update = open(target[0].dir.path + '/update.cbd', "wb")
length = os.path.getsize(target[0].path)
encrypt_file(firmware, update, length)
firmware.close()
update.close()
from pathlib import Path
fwpath = Path(target[0].path)
fwsize = fwpath.stat().st_size
fwfile = fwpath.open("rb")
upfile = Path(target[0].dir.path, 'update.cbd').open("wb")
encrypt_file(fwfile, upfile, fwsize)
import marlin
marlin.relocate_firmware("0x08008800")
marlin.add_post_action(encrypt);