update_chitu: Rename script and minor changes

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2020-08-30 13:11:34 -04:00
parent 1d201c3592
commit 12529ef6cd
2 changed files with 24 additions and 20 deletions

View File

@ -7,7 +7,7 @@
# at 0x8008800 (Chitu v6 Bootloader). Uncheck USB, and leave default
# serial settings.
#
# Use "./chitu_crypt.py out/klipper.bin" to generate update.cbz.
# Use "./update_chitu.py out/klipper.bin update.cbz" to generate update.cbz.
# Put `update.cbz` onto SD card, and reboot the printer.
# It will be automatically installed, and you will be able to update it this way.

View File

@ -1,5 +1,5 @@
#!/usr/bin/env python2
# Encrypts STM32 firmwares to be flashable from SD card by Chitu motherboards.
# Encodes STM32 firmwares to be flashable from SD card by Chitu motherboards.
# Relocate firmware to 0x08008800!
# Copied from Marlin and modified.
@ -64,7 +64,7 @@ def xor_block(r0, r1, block_number, block_size, file_key):
loop_counter = loop_counter + 1
def encrypt_file(input, output_file, file_length):
def encode_file(input, output_file, file_length):
input_file = bytearray(input.read())
block_size = 0x800
key_length = 0x18
@ -81,7 +81,7 @@ def encrypt_file(input, output_file, file_length):
# write the file header
output_file.write(struct.pack(">I", 0x443D2D3F))
# encrypt the contents using a known file header key
# encode the contents using a known file header key
# write the file_key
output_file.write(struct.pack("<I", file_key))
@ -103,28 +103,32 @@ def encrypt_file(input, output_file, file_length):
# write CRC
output_file.write(struct.pack("<I", xor_crc))
# finally, append the encrypted results.
# finally, append the encoded results.
output_file.write(input_file)
return
if len(sys.argv) == 1:
print("Usage: chitu_crypt [firmware.bin]")
def main():
if len(sys.argv) != 3:
print("Usage: update_chitu <input_file> <output_file>")
exit(1)
fw = sys.argv[-1]
fw, output = sys.argv[1:]
if not os.path.isfile(fw):
print("Usage: chitu_crypt [firmware.bin]")
if not os.path.isfile(fw):
print("Usage: update_chitu <input_file> <output_file>")
print("Firmware file", fw, "does not exist")
exit(1)
firmware = open(fw, "rb")
update = open('./update.cbd', "wb")
length = os.path.getsize(fw)
firmware = open(fw, "rb")
update = open(output, "wb")
length = os.path.getsize(fw)
encrypt_file(firmware, update, length)
encode_file(firmware, update, length)
firmware.close()
update.close()
firmware.close()
update.close()
print("Encryption complete. Firmware is written to update.cbd.")
print("Encoding complete.")
if __name__ == '__main__':
main()