aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCabia Rangris <me@cab404.ru>2020-08-30 18:59:28 +0200
committerGitHub <noreply@github.com>2020-08-30 12:59:28 -0400
commit15853da28c32543e40dd571a49fb7a819adbfc4f (patch)
tree33008444993f0ecc08fc6087cb8de5eeb82012a6
parenta7defdcad0306acb75c84f0d2ba65a726812dfd9 (diff)
downloadkutter-15853da28c32543e40dd571a49fb7a819adbfc4f.tar.gz
kutter-15853da28c32543e40dd571a49fb7a819adbfc4f.tar.xz
kutter-15853da28c32543e40dd571a49fb7a819adbfc4f.zip
config: Added TronXY X5SA support (#3265)
Added printer-tronxy-x5sa-v6 config. Added "chitu" bootloader option to stm32 Kconfig. Added chitu_crypt. Signed-off-by: Vladimir Serov <me@cab404.ru>
-rw-r--r--config/printer-tronxy-x5sa-v6-2019.cfg140
-rwxr-xr-xscripts/chitu_crypt.py130
-rw-r--r--src/stm32/Kconfig3
3 files changed, 273 insertions, 0 deletions
diff --git a/config/printer-tronxy-x5sa-v6-2019.cfg b/config/printer-tronxy-x5sa-v6-2019.cfg
new file mode 100644
index 00000000..698875ae
--- /dev/null
+++ b/config/printer-tronxy-x5sa-v6-2019.cfg
@@ -0,0 +1,140 @@
+# This is a Klipper configuration for TronXY X5SA, with
+# CXY-V6 motherboard.
+
+
+# === FLASHING WITH STOCK BOOTLOADER ===
+# You should make firmware for STM32F103 with bootloader offset
+# at 0x8008800 (Chitu v6 Bootloader). Uncheck USB, and leave default
+# serial settings.
+#
+# Use "./chitu_crypt.py out/klipper.bin" 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.
+
+[mcu]
+serial: /dev/serial/by-id/usb-1a86_USB_Serial-if00-port0
+restart_method: command
+
+[printer]
+kinematics: corexy
+max_velocity: 300
+max_accel: 7000
+max_accel_to_decel: 7000
+max_z_velocity: 25
+max_z_accel: 30
+
+[stepper_x]
+step_pin: PE5
+dir_pin: !PE6
+enable_pin: !PC13
+step_distance: .006275
+endstop_pin: !PG10
+position_endstop: -1
+position_min: -1
+position_max: 350
+homing_speed: 50
+homing_retract_dist: 10
+second_homing_speed: 10.0
+
+[stepper_y]
+step_pin: PE2
+dir_pin: !PE3
+enable_pin: !PE4
+step_distance: .006275
+endstop_pin: !PA12
+position_endstop: 0
+position_max: 330
+homing_retract_dist: 10
+homing_speed: 50.0
+second_homing_speed: 10.0
+
+[stepper_z]
+step_pin: PB9
+dir_pin: PE0
+enable_pin: !PE1
+step_distance: .00125
+endstop_pin: probe:z_virtual_endstop
+position_max: 400
+position_min: -2
+
+[extruder]
+step_pin: PB4
+dir_pin: PB5
+enable_pin: !PB8
+step_distance: 0.0111
+nozzle_diameter: 0.400
+filament_diameter: 1.750
+heater_pin: PG12
+sensor_type: ATC Semitec 104GT-2
+sensor_pin: PA1
+control: pid
+pid_Kp=18.831
+pid_Ki=0.821
+pid_Kd=108.044
+min_temp: 0
+max_temp: 250
+max_extrude_only_distance: 300
+pressure_advance: 0
+
+[heater_bed]
+heater_pin: PG11
+sensor_type: EPCOS 100K B57560G104F
+sensor_pin: PA0
+control: pid
+min_temp: 0
+max_temp: 130
+pid_Kp=73.932
+pid_Ki=1.521
+pid_Kd=898.279
+
+[heater_fan hotend_fan]
+pin: PG14
+heater: extruder
+heater_temp: 50
+fan_speed: 0.5
+
+[fan]
+pin: PG13
+max_power: 0.5
+
+[controller_fan drivers_fan]
+pin: PD6
+
+[filament_switch_sensor sentinel]
+pause_on_runout: True
+runout_gcode:
+ M25
+switch_pin: PA15
+
+[output_pin beeper]
+pin: PB0
+
+[safe_z_home]
+home_xy_position: 165,165
+speed: 50
+z_hop: 10
+z_hop_speed: 5
+
+[bed_screws]
+screw1: 5,5
+screw2: 165,5
+screw3: 325,5
+screw4: 5,325
+screw5: 165,325
+screw6: 325,325
+
+[bed_mesh]
+speed: 120
+probe_count: 5,5
+horizontal_move_z: 5
+algorithm: lagrange
+mesh_min : 20,20
+mesh_max : 310,310
+mesh_pps: 0
+
+[probe]
+x_offset: -40
+y_offset: 0
+pin: !PG9
+speed: 30
+z_offset: 2
diff --git a/scripts/chitu_crypt.py b/scripts/chitu_crypt.py
new file mode 100755
index 00000000..080b9f47
--- /dev/null
+++ b/scripts/chitu_crypt.py
@@ -0,0 +1,130 @@
+#!/usr/bin/env python2
+# Encrypts 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('<I', contents[ i : i + 4])[0]
+ accumulating_xor_value = accumulating_xor_value ^ value
+ return accumulating_xor_value
+
+def xor_block(r0, r1, block_number, block_size, file_key):
+ # This is the loop counter
+ loop_counter = 0x0
+
+ # This is the key length
+ key_length = 0x18
+
+ # This is an initial seed
+ xor_seed = 0x4bad
+
+ # This is the block counter
+ block_number = xor_seed * block_number
+
+ #load the xor key from the file
+ r7 = 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)
+
+ # IP is a scratch register / R12
+ ip = loop_counter - (key_length * xor_seed)
+
+ # xor_seed = (loop_counter * loop_counter) + block_number
+ xor_seed = (loop_counter * loop_counter) + block_number
+
+ # shift the xor_seed left by the bits in IP.
+ xor_seed = xor_seed >> 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 encrypt_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))
+ # encrypt the contents using a known file header key
+
+ # write the file_key
+ 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)
+ for block_number in range(0, block_count):
+ block_offset = (block_number * block_size)
+ block_end = block_offset + block_size
+ block_array = bytearray(input_file[block_offset: block_end])
+ xor_block(block_array, block_array, block_number, block_size, file_key)
+ for n in range (0, block_size):
+ input_file[block_offset + n] = block_array[n]
+
+ # update the expected CRC value.
+ xor_crc = calculate_crc(block_array, xor_crc)
+
+ # write CRC
+ output_file.write(struct.pack("<I", xor_crc))
+
+ # finally, append the encrypted results.
+ output_file.write(input_file)
+ return
+
+if len(sys.argv) == 1:
+ print("Usage: chitu_crypt [firmware.bin]")
+ exit(1)
+
+fw = sys.argv[-1]
+
+if not os.path.isfile(fw):
+ print("Usage: chitu_crypt [firmware.bin]")
+ print("Firmware file", fw, "does not exist")
+ exit(1)
+
+firmware = open(fw, "rb")
+update = open('./update.cbd', "wb")
+length = os.path.getsize(fw)
+
+encrypt_file(firmware, update, length)
+
+firmware.close()
+update.close()
+
+print("Encryption complete. Firmware is written to update.cbd.")
diff --git a/src/stm32/Kconfig b/src/stm32/Kconfig
index bd0388da..99a0e042 100644
--- a/src/stm32/Kconfig
+++ b/src/stm32/Kconfig
@@ -116,6 +116,8 @@ choice
bool "28KiB bootloader" if MACH_STM32F103
config STM32_FLASH_START_8000
bool "32KiB bootloader (SKR-PRO or TFT35-V3.0)" if MACH_STM32F207 || MACH_STM32F407
+ config STM32_FLASH_START_8800
+ bool "34KiB bootloader (Chitu v6 Bootloader)" if MACH_STM32F103
config STM32_FLASH_START_10000
bool "64KiB bootloader (Alfawise)" if MACH_STM32F103
config STM32_FLASH_START_0000
@@ -129,6 +131,7 @@ config FLASH_START
default 0x8005000 if STM32_FLASH_START_5000
default 0x8007000 if STM32_FLASH_START_7000
default 0x8008000 if STM32_FLASH_START_8000
+ default 0x8008800 if STM32_FLASH_START_8800
default 0x8010000 if STM32_FLASH_START_10000
default 0x8000000