From 12529ef6cda3c2e8835a630b465e2b1025569bcf Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Sun, 30 Aug 2020 13:11:34 -0400 Subject: update_chitu: Rename script and minor changes Signed-off-by: Kevin O'Connor --- scripts/update_chitu.py | 134 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 134 insertions(+) create mode 100755 scripts/update_chitu.py (limited to 'scripts/update_chitu.py') diff --git a/scripts/update_chitu.py b/scripts/update_chitu.py new file mode 100755 index 00000000..2da78276 --- /dev/null +++ b/scripts/update_chitu.py @@ -0,0 +1,134 @@ +#!/usr/bin/env python2 +# Encodes STM32 firmwares to be flashable from SD card by Chitu motherboards. +# Relocate firmware to 0x08008800! + +# Copied from Marlin and modified. +# Licensed under GPL-3.0 + +import os +import random +import struct +import uuid +import sys + +def calculate_crc(contents, seed): + accumulating_xor_value = seed; + + for i in range(0, len(contents), 4): + value = struct.unpack('> ip + + # load a byte into IP + ip = r0[loop_counter] + + # XOR the seed with r7 + xor_seed = xor_seed ^ r7 + + # and then with IP + xor_seed = xor_seed ^ ip + + #Now store the byte back + r1[loop_counter] = xor_seed & 0xFF + + #increment the loop_counter + loop_counter = loop_counter + 1 + + +def encode_file(input, output_file, file_length): + input_file = bytearray(input.read()) + block_size = 0x800 + key_length = 0x18 + + uid_value = uuid.uuid4() + file_key = int(uid_value.hex[0:8], 16) + + xor_crc = 0xef3d4323; + + # the input file is exepcted to be in chunks of 0x800 + # so round the size + while len(input_file) % block_size != 0: + input_file.extend(b'0x0') + + # write the file header + output_file.write(struct.pack(">I", 0x443D2D3F)) + # encode the contents using a known file header key + + # write the file_key + output_file.write(struct.pack(" ") + exit(1) + + fw, output = sys.argv[1:] + + if not os.path.isfile(fw): + print("Usage: update_chitu ") + print("Firmware file", fw, "does not exist") + exit(1) + + firmware = open(fw, "rb") + update = open(output, "wb") + length = os.path.getsize(fw) + + encode_file(firmware, update, length) + + firmware.close() + update.close() + + print("Encoding complete.") + +if __name__ == '__main__': + main() -- cgit v1.2.3-70-g09d2