fwupdate 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. #!/bin/sh
  2. # This file is part of the OpenADK project.
  3. # Do update.
  4. GRUB=$(which grub-reboot)
  5. if [ "${GRUB}" = "/usr/sbin/grub-reboot" ]; then
  6. REVERSE=0
  7. else
  8. REVERSE=1
  9. fi
  10. DISK=@@DISK@@
  11. if [ $REVERSE -eq 1 ]; then
  12. PART0="/dev/${DISK}p1"
  13. PART1="/dev/${DISK}p2"
  14. else
  15. PART0="/dev/${DISK}2"
  16. PART1="/dev/${DISK}3"
  17. fi
  18. # Name of the archive, which is the firmware. For this file is the checksum calculated and
  19. # checked against the one from the tar archive.
  20. FW_NAME="openadk.tar.xz"
  21. CHECK_SUM_FILE="sha256.txt"
  22. TMP_MOUNT="/mnt"
  23. if [ -z $1 ]; then
  24. echo "Usage: $0 <full path to update filename>"
  25. exit 1
  26. fi
  27. if [ ! -f $1 ]; then
  28. echo "File $1 not found"
  29. exit 1
  30. fi
  31. FIRMWARE=$1
  32. echo "Validate new firmware $FIRMWARE"
  33. echo "Extract checksum file ..."
  34. cmd="tar -xf $FIRMWARE $CHECK_SUM_FILE"
  35. $cmd
  36. if [ ! -f $CHECK_SUM_FILE ];then
  37. echo "No checksum file found! $CHECK_SUM_FILE"
  38. exit 3
  39. fi
  40. if [ $(wc -m $CHECK_SUM_FILE | cut -d\ -f1) -eq 65 ];then
  41. echo "Found a checksum in file $CHECK_SUM_FILE"
  42. else
  43. echo "No checksum found in archive! $(wc -m $CHECK_SUM_FILE | cut -d\ -f1)"
  44. exit 4
  45. fi
  46. CHECK_SUM_UPDATE_FILE="$(cat $CHECK_SUM_FILE)"
  47. echo "Calculate the checksum of the new firmware ..."
  48. CHECK_SUM_NEW_SYSTEM=$(tar -xf $FIRMWARE $FW_NAME -O | sha256sum - |cut -d\ -f1)
  49. echo "Compare the checksums ..."
  50. if [ "X$CHECK_SUM_NEW_SYSTEM" = "X$CHECK_SUM_UPDATE_FILE" ]; then
  51. echo "Checksum verified (they match) ..."
  52. else
  53. echo "Checksum does not match!"
  54. echo "${CHECK_SUM_UPDATE_FILE} "
  55. echo "${CHECK_SUM_NEW_SYSTEM}"
  56. fi
  57. echo "First unmount $TMP_MOUNT the spare partition just in case ..."
  58. umount $TMP_MOUNT 2>/dev/null
  59. # create the mkfs options depending on which is the active partition
  60. CURRENT_SYS="$(rdev /|awk '{ print $1 }')"
  61. case "$CURRENT_SYS" in
  62. "$PART0")
  63. MOUNTPART="$PART1"
  64. PARTNUM=2
  65. OS=OpenADK2
  66. ;;
  67. "$PART1")
  68. MOUNTPART="$PART0"
  69. PARTNUM=1
  70. OS=OpenADK1
  71. ;;
  72. *)
  73. echo "Current partition $CURRENT_SYS not recognized"
  74. exit 5
  75. ;;
  76. esac
  77. echo "Currently the system is running on $CURRENT_SYS"
  78. # Create filesystem on inactive partition
  79. echo "The partition $MOUNTPART is going to be prepared for the new system."
  80. echo "Creating the filesystem ..."
  81. mkfs.ext2 -j -q -F $MOUNTPART
  82. if [ $? -ne 0 ];then
  83. echo "It was not possible to create the new filesystem on $MOUNTPART"
  84. exit 6
  85. fi
  86. echo "Mount the new partition $MOUNTPART ..."
  87. mount -t ext4 $MOUNTPART $TMP_MOUNT
  88. if [ $? -ne 0 ];then
  89. echo "It was not possible to mount the partition for the new system!"
  90. echo "Please reboot the system and try to update again."
  91. exit 7
  92. fi
  93. cd $TMP_MOUNT
  94. echo "The new system is going to be extracted into the partition $MOUNTPART ..."
  95. tar -xf $FIRMWARE $FW_NAME -O|tar -xJf -
  96. if [ $? -ne 0 ]; then
  97. echo "The extraction of the new system failed!"
  98. echo "Please reboot the system and try to update again."
  99. cd /
  100. umount $MOUNTPART
  101. exit 8
  102. fi
  103. echo "Checking the new system on next boot"
  104. touch $TMP_MOUNT/firmware_check
  105. if [ $? -ne 0 ]; then
  106. echo "General ERROR"
  107. echo "Please reboot the system and try to update again."
  108. cd /
  109. umount $MOUNTPART
  110. exit 9
  111. fi
  112. # echo "DD.MM.YYYY hh:mm:hh\n$(date '+%d.%m.%Y %H:%M:%S')" > install_date.txt
  113. date '+%d.%B.%Y %H:%M:%S' > $TMP_MOUNT/installation_date.txt
  114. if [ $? -ne 0 ]; then
  115. echo "General ERROR"
  116. echo "Please reboot the system and try to update again."
  117. cd /
  118. umount $MOUNTPART
  119. exit 9
  120. fi
  121. echo "$CHECK_SUM_NEW_FW" >> $TMP_MOUNT/installation_date.txt
  122. if [ $? -ne 0 ]; then
  123. echo "General ERROR"
  124. echo "Please reboot the system and try to update again."
  125. cd /
  126. umount $MOUNTPART
  127. exit 9
  128. fi
  129. cd /
  130. umount $MOUNTPART
  131. if [ $REVERSE -eq 1 ]; then
  132. echo "Switch bootable partition to new system"
  133. sfdisk -A /dev/$DISK $PARTNUM >/dev/null 2>&1
  134. else
  135. grep /boot /proc/mounts 2>/dev/null
  136. if [ $? -eq 0 ]; then
  137. mount -o remount,rw /boot
  138. else
  139. mount /dev/sda1 /boot
  140. fi
  141. grub-reboot $OS
  142. grep /boot /proc/mounts 2>/dev/null
  143. if [ $? -eq 0 ]; then
  144. mount -o remount,ro /boot
  145. else
  146. umount /boot
  147. fi
  148. fi
  149. sync
  150. echo "Reboot now to the updated system $OS"