platform.sh 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. #
  2. # Copyright 2015-2019 Traverse Technologies
  3. # Copyright 2020 NXP
  4. #
  5. RAMFS_COPY_BIN=""
  6. RAMFS_COPY_DATA=""
  7. REQUIRE_IMAGE_METADATA=1
  8. platform_do_upgrade_sdboot() {
  9. local diskdev partdev parttype=ext4
  10. local tar_file="$1"
  11. local board_dir=$(tar tf $tar_file | grep -m 1 '^sysupgrade-.*/$')
  12. board_dir=${board_dir%/}
  13. export_bootdevice && export_partdevice diskdev 0 || {
  14. echo "Unable to determine upgrade device"
  15. return 1
  16. }
  17. if export_partdevice partdev 1; then
  18. mount -t $parttype -o rw,noatime "/dev/$partdev" /mnt 2>&1
  19. echo "Writing kernel..."
  20. tar xf $tar_file ${board_dir}/kernel -O > /mnt/fitImage
  21. umount /mnt
  22. fi
  23. echo "Erasing rootfs..."
  24. dd if=/dev/zero of=/dev/mmcblk0p2 bs=1M > /dev/null 2>&1
  25. echo "Writing rootfs..."
  26. tar xf $tar_file ${board_dir}/root -O | dd of=/dev/mmcblk0p2 bs=512k > /dev/null 2>&1
  27. }
  28. platform_do_upgrade_traverse_slotubi() {
  29. part="$(awk -F 'ubi.mtd=' '{printf $2}' /proc/cmdline | sed -e 's/ .*$//')"
  30. echo "Active boot slot: ${part}"
  31. new_active_sys="b"
  32. if [ ! -z "${part}" ]; then
  33. if [ "${part}" = "ubia" ]; then
  34. CI_UBIPART="ubib"
  35. else
  36. CI_UBIPART="ubia"
  37. new_active_sys="a"
  38. fi
  39. fi
  40. echo "Updating UBI part ${CI_UBIPART}"
  41. fw_setenv "openwrt_active_sys" "${new_active_sys}"
  42. nand_do_upgrade "$1"
  43. return $?
  44. }
  45. platform_copy_config_sdboot() {
  46. local diskdev partdev parttype=ext4
  47. export_bootdevice && export_partdevice diskdev 0 || {
  48. echo "Unable to determine upgrade device"
  49. return 1
  50. }
  51. if export_partdevice partdev 1; then
  52. mount -t $parttype -o rw,noatime "/dev/$partdev" /mnt 2>&1
  53. echo "Saving config backup..."
  54. cp -af "$UPGRADE_BACKUP" "/mnt/$BACKUP_FILE"
  55. umount /mnt
  56. fi
  57. }
  58. platform_copy_config() {
  59. local board=$(board_name)
  60. case "$board" in
  61. fsl,ls1012a-frwy-sdboot | \
  62. fsl,ls1021a-iot-sdboot | \
  63. fsl,ls1021a-twr-sdboot | \
  64. fsl,ls1028a-rdb-sdboot | \
  65. fsl,ls1043a-rdb-sdboot | \
  66. fsl,ls1046a-frwy-sdboot | \
  67. fsl,ls1046a-rdb-sdboot | \
  68. fsl,ls1088a-rdb-sdboot | \
  69. fsl,lx2160a-rdb-sdboot)
  70. platform_copy_config_sdboot
  71. ;;
  72. esac
  73. }
  74. platform_check_image() {
  75. local board=$(board_name)
  76. case "$board" in
  77. traverse,ten64)
  78. nand_do_platform_check "ten64-mtd" $1
  79. return $?
  80. ;;
  81. fsl,ls1012a-frdm | \
  82. fsl,ls1012a-frwy-sdboot | \
  83. fsl,ls1012a-rdb | \
  84. fsl,ls1021a-iot-sdboot | \
  85. fsl,ls1021a-twr | \
  86. fsl,ls1021a-twr-sdboot | \
  87. fsl,ls1028a-rdb | \
  88. fsl,ls1028a-rdb-sdboot | \
  89. fsl,ls1043a-rdb | \
  90. fsl,ls1043a-rdb-sdboot | \
  91. fsl,ls1046a-frwy | \
  92. fsl,ls1046a-frwy-sdboot | \
  93. fsl,ls1046a-rdb | \
  94. fsl,ls1046a-rdb-sdboot | \
  95. fsl,ls1088a-rdb | \
  96. fsl,ls1088a-rdb-sdboot | \
  97. fsl,ls2088a-rdb | \
  98. fsl,lx2160a-rdb | \
  99. fsl,lx2160a-rdb-sdboot)
  100. return 0
  101. ;;
  102. *)
  103. echo "Sysupgrade is not currently supported on $board"
  104. ;;
  105. esac
  106. return 1
  107. }
  108. platform_do_upgrade() {
  109. local board=$(board_name)
  110. # Force the creation of fw_printenv.lock
  111. mkdir -p /var/lock
  112. touch /var/lock/fw_printenv.lock
  113. case "$board" in
  114. traverse,ten64)
  115. platform_do_upgrade_traverse_slotubi "${1}"
  116. ;;
  117. fsl,ls1012a-frdm | \
  118. fsl,ls1012a-rdb | \
  119. fsl,ls1021a-twr | \
  120. fsl,ls1028a-rdb | \
  121. fsl,ls1043a-rdb | \
  122. fsl,ls1046a-frwy | \
  123. fsl,ls1046a-rdb | \
  124. fsl,ls1088a-rdb | \
  125. fsl,ls2088a-rdb | \
  126. fsl,lx2160a-rdb)
  127. PART_NAME=firmware
  128. default_do_upgrade "$1"
  129. ;;
  130. fsl,ls1012a-frwy-sdboot | \
  131. fsl,ls1021a-iot-sdboot | \
  132. fsl,ls1021a-twr-sdboot | \
  133. fsl,ls1028a-rdb-sdboot | \
  134. fsl,ls1043a-rdb-sdboot | \
  135. fsl,ls1046a-frwy-sdboot | \
  136. fsl,ls1046a-rdb-sdboot | \
  137. fsl,ls1088a-rdb-sdboot | \
  138. fsl,lx2160a-rdb-sdboot)
  139. platform_do_upgrade_sdboot "$1"
  140. return 0
  141. ;;
  142. *)
  143. echo "Sysupgrade is not currently supported on $board"
  144. ;;
  145. esac
  146. }