update-gateware.sh 2.0 KB

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