mirror of
https://github.com/Klipper3d/klipper.git
synced 2025-11-01 19:05:56 +01:00
spi_flash: add timestamp to firmware filenames on sdcard upload (#7063)
Some Creality bootloaders skip flashing if the firmware filename is unchanged. By appending a timestamp to the firmware filename during sdcard upload, each update generates a unique name, ensuring that the bootloader always accepts and flashes the new firmware. Signed-off-by: Sezgin AÇIKGÖZ <sezginacikgoz@mail.com>
This commit is contained in:
@@ -123,7 +123,8 @@ BOARD_DEFS = {
|
||||
'spi_bus': "swspi",
|
||||
'spi_pins': "PC8,PD2,PC12",
|
||||
'cs_pin': "PC11",
|
||||
'skip_verify': True
|
||||
'skip_verify': True,
|
||||
'requires_unique_fw_name': True
|
||||
},
|
||||
'monster8': {
|
||||
'mcu': "stm32f407xx",
|
||||
|
||||
@@ -1380,7 +1380,32 @@ class MCUConnection:
|
||||
input_sha = hashlib.sha1()
|
||||
sd_sha = hashlib.sha1()
|
||||
klipper_bin_path = self.board_config['klipper_bin_path']
|
||||
add_ts = self.board_config.get('requires_unique_fw_name', False)
|
||||
fw_path = self.board_config.get('firmware_path', "firmware.bin")
|
||||
if add_ts:
|
||||
fw_dir = os.path.dirname(fw_path)
|
||||
fw_name, fw_ext = os.path.splitext(os.path.basename(fw_path))
|
||||
ts = time.strftime("%Y%m%d%H%M%S")
|
||||
fw_name_ts = f"{ts}{fw_name}{fw_ext}"
|
||||
if fw_dir:
|
||||
fw_path = os.path.join(fw_dir, fw_name_ts)
|
||||
else:
|
||||
fw_path = fw_name_ts
|
||||
list_dir = fw_dir if fw_dir else ""
|
||||
try:
|
||||
output_line("\nSD Card FW Directory Contents:")
|
||||
for f in self.fatfs.list_sd_directory(list_dir):
|
||||
fname = f['name'].decode('utf-8')
|
||||
if fname.endswith(fw_ext):
|
||||
self.fatfs.remove_item(
|
||||
os.path.join(list_dir, fname)
|
||||
)
|
||||
output_line(
|
||||
"Old firmware file %s found and deleted"
|
||||
% (fname,)
|
||||
)
|
||||
except Exception:
|
||||
logging.exception("Error cleaning old firmware files")
|
||||
try:
|
||||
with open(klipper_bin_path, 'rb') as local_f:
|
||||
with self.fatfs.open_file(fw_path, "wb") as sd_f:
|
||||
|
||||
Reference in New Issue
Block a user