update-gateware.sh 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #!/bin/sh
  2. if [ ! -e "$1"/mpfs_bitstream.spi ]; then
  3. echo "No gateware file found."
  4. exit 1
  5. fi
  6. if [ ! -d /lib/firmware ]
  7. then
  8. mkdir /lib/firmware
  9. fi
  10. cp "$1"/mpfs_dtbo.spi /lib/firmware/mpfs_dtbo.spi
  11. cp "$1"/mpfs_bitstream.spi /lib/firmware/mpfs_bitstream.spi
  12. # Trash existing device tree overlay in case the rest of the process fails:
  13. flash_erase /dev/mtd0 0 16
  14. # Initiate FPGA update for dtbo
  15. echo 1 > /sys/class/firmware/mpfs-auto-update/loading
  16. # Write device tree overlay
  17. cat /lib/firmware/mpfs_dtbo.spi > /sys/class/firmware/mpfs-auto-update/data
  18. # Signal completion for dtbo load
  19. echo 0 > /sys/class/firmware/mpfs-auto-update/loading
  20. while [ "$(cat /sys/class/firmware/mpfs-auto-update/status)" != "idle" ]; do
  21. # Do nothing, just keep checking
  22. sleep 1
  23. done
  24. # Fake the presence of a golden image for now.
  25. dd if=/dev/zero of=/dev/mtd0 count=1 bs=4
  26. # Initiate FPGA update for bitstream
  27. echo 1 > /sys/class/firmware/mpfs-auto-update/loading
  28. # Write the firmware image to the data sysfs file
  29. cat /lib/firmware/mpfs_bitstream.spi > /sys/class/firmware/mpfs-auto-update/data
  30. # Signal completion for bitstream load
  31. echo 0 > /sys/class/firmware/mpfs-auto-update/loading
  32. while [ "$(cat /sys/class/firmware/mpfs-auto-update/status)" != "idle" ]; do
  33. # Do nothing, just keep checking
  34. sleep 1
  35. done
  36. # When the status is 'idle' and no error has occured, reboot the system for
  37. # the gateware update to take effect. FPGA reprogramming takes places between
  38. # Linux shut-down and HSS restarting the board.
  39. if [ "$(cat /sys/class/firmware/mpfs-auto-update/error)" = "" ]; then
  40. echo "FPGA update ready. Rebooting."
  41. reboot
  42. else
  43. echo "FPGA update failed with status: $(cat /sys/class/firmware/mpfs-auto-update/error)"
  44. exit 1
  45. fi