Jump to content

Klipper automatic upgrade script


Recommended Posts

I have been working on a script to attempt to (mostly) automatically upgrade Klipper by running one command.  I am basing it off this code on the Klipper website.

 

I am currently running an Octopus 1.1 and a Huvud canbus.  I am currently having an issue with the transfer of the firmware file from my RasPi to my Octopus board.  Any thoughts?

 

sudo service klipper stop
cd ~/klipper
git pull

make clean KCONFIG_CONFIG=config.octopus
make menuconfig KCONFIG_CONFIG=config.octopus
make KCONFIG_CONFIG=config.octopus
read -p "Octopus firmware built, please check above for any errors. Press [Enter] to continue flashing, or [Ctrl+C] to abort"

~/klipper/scripts/flash-sdcard.sh /dev/ttyACM0 btt-octopus-f429-v1.1
read -p "Octopus firmware flashed, please check above for any errors. Press [Enter] to continue, or [Ctrl+C] to abort"

make clean KCONFIG_CONFIG=config.rpi
make menuconfig KCONFIG_CONFIG=config.rpi
make KCONFIG_CONFIG=config.rpi
read -p "RPi firmware built, please check above for any errors. Press [Enter] to continue flashing, or [Ctrl+C] to abort"
make flash KCONFIG_CONFIG=config.rpi

make clean KCONFIG_CONFIG=config.canhat
make menuconfig KCONFIG_CONFIG=config.canhat
make KCONFIG_CONFIG=config.canhat
read -p "Canhat firmware built.  Please check for errors.  Press [Enter] to continue flashing or [CTRL+C] to abort"
sudo service klipper stop
cd ~/klipper
git pull

make clean KCONFIG_CONFIG=config.octopus
make menuconfig KCONFIG_CONFIG=config.octopus
make KCONFIG_CONFIG=config.octopus
read -p "Octopus firmware built, please check above for any errors. Press [Enter] to continue flashing, or [Ctrl+C] to abort"

~/klipper/scripts/flash-sdcard.sh /dev/serial/by-id/usb-Klipper_stm32f429xx_23002E001151303439373431-if00 octopus
read -p "Octopus firmware flashed, please check above for any errors. Press [Enter] to continue, or [Ctrl+C] to abort"

make clean KCONFIG_CONFIG=config.rpi
make menuconfig KCONFIG_CONFIG=config.rpi
make KCONFIG_CONFIG=config.rpi
read -p "RPi firmware built, please check above for any errors. Press [Enter] to continue flashing, or [Ctrl+C] to abort"
make flash KCONFIG_CONFIG=config.rpi

make clean KCONFIG_CONFIG=config.canhat
make menuconfig KCONFIG_CONFIG=config.canhat
make KCONFIG_CONFIG=config.canhat
read -p "Canhat firmware built.  Please check for errors.  Press [Enter] to continue flashing or [CTRL+C] to abort"
python3 ~/klipper/lib/canboot/flash_can.py -i can0 ~/klipper/out/klipper.bin -u {uuid}

sudo service klipper start

sudo service klipper start

 

Link to comment
Share on other sites

Not related to the issue but to improve the "safety" you could add something like (after the compile statement):

if [ ! -f ~/klipper/out/klipper.bin ]
then 
  echo "ERROR: klipper.bin firmware missing"
  exit 1
fi

(NB: If you want to get a bit fancier you can vary the exit code so you know at which point the fail happen, assuming you use that exist point more than once in your script)

 

Back to your issue, what's the issue? I'm presuming it's the "~/klipper/scripts/flash-sdcard.sh /dev/ttyACM0 btt-octopus-f429-v1.1" statement that's failing? Is it producing some sort of error?

Link to comment
Share on other sites

I see in your commands you are using the path /dev/ttyACM0 for the Octopus. So that tells me you are connected via GPIO, correct? This is why I have held off on trying this myself. I've not seen any confirmation that this method works for GPIO-connected boards; I'm under the impression that this depends on the boards being connected via USB. I'll be interested to hear if you succeed with this.

Link to comment
Share on other sites

Flashing /home/pi/klipper/out/klipper.bin to /dev/ttyACM0
Checking FatFS CFFI Build...
Connecting to MCU...Connected
Checking Current MCU Configuration...Done
MCU needs restart: is_config=1, is_shutdown=1
Attempting MCU Reset...Done
Waiting for device to reconnect....Done
Connecting to MCU...Connected
Initializing SD Card and Mounting file system...

SD Card Information:
Version: 2.0
SDHC/SDXC: False
Write Protected: False
Sectors: 3985408
manufacturer_id: 2
oem_id: TM
product_name: SA02G
product_revision: 0.2
serial_number: 9C003160
manufacturing_date: 4/2008
capacity: 1946.0 MiB
fs_type: FAT32
volume_label: b''
volume_serial: 1488010087
Uploading Klipper Firmware to SD Card...
SD Card Flash Error: Error Uploading Firmware
Traceback (most recent call last):
  File "/home/pi/klipper/scripts/spi_flash/spi_flash.py", line 969, in sdcard_upload
    sd_f.write(buf)
  File "/home/pi/klipper/scripts/spi_flash/spi_flash.py", line 427, in __exit__
    self.close()
  File "/home/pi/klipper/scripts/spi_flash/spi_flash.py", line 420, in close
    % (self.path, FRESULT[ret]))
TypeError: %d format: a number is required, not str

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/pi/klipper/scripts/spi_flash/spi_flash.py", line 1237, in main
    spiflash.run()
  File "/home/pi/klipper/scripts/spi_flash/spi_flash.py", line 1177, in run
    self.run_reactor_task(self.run_sdcard_upload)
  File "/home/pi/klipper/scripts/spi_flash/spi_flash.py", line 1160, in run_reactor_task
    k_reactor.run()
  File "/home/pi/klipper/klippy/reactor.py", line 292, in run
    g_next.switch()
  File "/home/pi/klipper/klippy/reactor.py", line 340, in _dispatch_loop
    timeout = self._check_timers(eventtime, busy)
  File "/home/pi/klipper/klippy/reactor.py", line 158, in _check_timers
    t.waketime = waketime = t.callback(eventtime)
  File "/home/pi/klipper/klippy/reactor.py", line 48, in invoke
    res = self.callback(eventtime)
  File "/home/pi/klipper/scripts/spi_flash/spi_flash.py", line 1139, in run_sdcard_upload
    self.firmware_checksum = self.mcu_conn.sdcard_upload()
  File "/home/pi/klipper/scripts/spi_flash/spi_flash.py", line 972, in sdcard_upload
    raise SPIFlashError("Error Uploading Firmware")
SPIFlashError: Error Uploading Firmware

 

Link to comment
Share on other sites

I've got an octopus board somewhere I'll dig it out and see what it says to me, not knowing what the flash should look like doesn't help me. Although I'm intrigued in the bit in there about:

 

volume_label: b''

 

That doesn't look good as a volume label to me (when I start seeing spurious quotes being spat out by *nix [scripts] I'm suspcious,windows is a different matter.)

Looking at the section of code that spits out that error it basically opens the firmware file (klipper.bin) reads it in 4Kb chunks and just writes it out to the SD card file (firmware.bin). Nothing enormously fancy, but by that stage the spi_flash.py script has managed to mount the SD card, read details from the card (file system info) and create an empty firmware.bin file....so all good up to that point, it's the actual write command that's failing [sd_f.write(buf)].

Could the SD card be borked? I don't think it'll be something trivial as "write protect" as the card sits in the Octopus board and there's no real OS on that to write protect anything (it's just acting as a pass-thru), it's the actual write operation that's failing a bit odd. It might not tell a lot manually trying to copy firmware.bin to the SD-Card (guess it depends on how/where it's allocating "disk" blocks).

Link to comment
Share on other sites

  • 1 year later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...