update code base to Marlin 2.0.9.2

This commit is contained in:
Stefan Kalscheuer
2021-10-03 18:57:12 +02:00
parent b9d7ba838e
commit 7077da3591
2617 changed files with 332093 additions and 103438 deletions

41
buildroot/share/PlatformIO/scripts/chitu_crypt.py Executable file → Normal file
View File

@@ -1,20 +1,11 @@
import os
import struct
Import("env")
#
# buildroot/share/PlatformIO/scripts/chitu_crypt.py
# Customizations for Chitu boards
#
import os,random,struct,uuid,marlin
# Relocate firmware from 0x08000000 to 0x08008800
for define in env['CPPDEFINES']:
if define[0] == "VECT_TAB_ADDR":
env['CPPDEFINES'].remove(define)
env['CPPDEFINES'].append(("VECT_TAB_ADDR", "0x8008800"))
custom_ld_script = os.path.abspath("buildroot/share/PlatformIO/ldscripts/chitu_f103.ld")
for i, flag in enumerate(env["LINKFLAGS"]):
if "-Wl,-T" in flag:
env["LINKFLAGS"][i] = "-Wl,-T" + custom_ld_script
elif flag == "-T":
env["LINKFLAGS"][i + 1] = custom_ld_script
marlin.relocate_firmware("0x08008800")
def calculate_crc(contents, seed):
accumulating_xor_value = seed;
@@ -32,7 +23,7 @@ def xor_block(r0, r1, block_number, block_size, file_key):
key_length = 0x18
# This is an initial seed
xor_seed = 0x4bad
xor_seed = 0x4BAD
# This is the block counter
block_number = xor_seed * block_number
@@ -42,7 +33,7 @@ def xor_block(r0, r1, block_number, block_size, file_key):
for loop_counter in range(0, block_size):
# meant to make sure different bits of the key are used.
xor_seed = int(loop_counter/key_length)
xor_seed = int(loop_counter / key_length)
# IP is a scratch register / R12
ip = loop_counter - (key_length * xor_seed)
@@ -68,14 +59,15 @@ def xor_block(r0, r1, block_number, block_size, file_key):
#increment the loop_counter
loop_counter = loop_counter + 1
def encrypt_file(input, output_file, file_length):
input_file = bytearray(input.read())
block_size = 0x800
key_length = 0x18
file_key = 0xDAB27F94
xor_crc = 0xef3d4323;
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
@@ -87,11 +79,11 @@ def encrypt_file(input, output_file, file_length):
# encrypt the contents using a known file header key
# write the file_key
output_file.write(struct.pack(">I", 0x947FB2DA))
output_file.write(struct.pack("<I", file_key))
#TODO - how to enforce that the firmware aligns to block boundaries?
block_count = int(len(input_file) / block_size)
print "Block Count is ", block_count
print ("Block Count is ", block_count)
for block_number in range(0, block_count):
block_offset = (block_number * block_size)
block_end = block_offset + block_size
@@ -110,11 +102,10 @@ def encrypt_file(input, output_file, file_length):
output_file.write(input_file)
return
# 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")
update = open(target[0].dir.path + '/update.cbd', "wb")
length = os.path.getsize(target[0].path)
encrypt_file(firmware, update, length)
@@ -122,4 +113,4 @@ def encrypt(source, target, env):
firmware.close()
update.close()
env.AddPostAction("$BUILD_DIR/${PROGNAME}.bin", encrypt);
marlin.add_post_action(encrypt);