Skip to content

Commit

Permalink
Use older chitu_crypt.py
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkyhead committed Jul 4, 2023
1 parent 5ac0c72 commit 44d2368
Showing 1 changed file with 9 additions and 18 deletions.
27 changes: 9 additions & 18 deletions buildroot/share/PlatformIO/scripts/chitu_crypt.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
#
import pioutil
if pioutil.is_pio_build():
import struct,uuid,marlin

board = marlin.env.BoardConfig()
import os,random,struct,uuid,marlin
# Relocate firmware from 0x08000000 to 0x08008800
marlin.relocate_firmware("0x08008800")

def calculate_crc(contents, seed):
accumulating_xor_value = seed;
Expand Down Expand Up @@ -105,22 +105,13 @@ def encrypt_file(input, output_file, file_length):

# Encrypt ${PROGNAME}.bin and save it as 'update.cbd'
def encrypt(source, target, env):
from pathlib import Path

fwpath = Path(target[0].path)
fwsize = fwpath.stat().st_size
firmware = open(target[0].path, "rb")
update = open(target[0].dir.path + '/update.cbd', "wb")
length = os.path.getsize(target[0].path)

enname = board.get("build.crypt_chitu")
enpath = Path(target[0].dir.path)
encrypt_file(firmware, update, length)

fwfile = fwpath.open("rb")
enfile = (enpath / enname).open("wb")
firmware.close()
update.close()

print(f"Encrypting {fwpath} to {enname}")
encrypt_file(fwfile, enfile, fwsize)
fwfile.close()
enfile.close()
fwpath.unlink()

marlin.relocate_firmware("0x08008800")
marlin.add_post_action(encrypt);

0 comments on commit 44d2368

Please sign in to comment.