dualboot_datachk.sh 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. # The U-Boot loader with the datachk patchset for dualbooting requires image
  2. # sizes and checksums to be provided in the U-Boot environment.
  3. # The devices come with 2 main partitions - while one is active
  4. # sysupgrade will flash the other. The boot order is changed to boot the
  5. # newly flashed partition. If the new partition can't be booted due to
  6. # upgrade failures the previously used partition is loaded.
  7. platform_do_upgrade_dualboot_datachk() {
  8. local next_boot_part=1
  9. local tar_file="$1"
  10. local bootseq
  11. local setenv_script="/tmp/fw_env_upgrade"
  12. if [ "$(grep 'ubi.mtd=firmware1' /proc/cmdline)" ]; then
  13. next_boot_part=2
  14. bootseq="2,1"
  15. else
  16. next_boot_part=1
  17. bootseq="1,2"
  18. fi
  19. local board_dir="$(tar tf "${tar_file}" | grep -m 1 '^sysupgrade-.*/$')"
  20. board_dir="${board_dir%/}"
  21. local kernel_length="$(tar xf "${tar_file}" "${board_dir}/kernel" -O | wc -c)"
  22. local rootfs_length="$(tar xf "${tar_file}" "${board_dir}/root" -O | wc -c)"
  23. local kernel_md5="$(tar xf "${tar_file}" "${board_dir}/kernel" -O | md5sum)"
  24. kernel_md5="${kernel_md5%% *}"
  25. local rootfs_md5="$(tar xf "${tar_file}" "${board_dir}/root" -O | md5sum)"
  26. rootfs_md5="${rootfs_md5%% *}"
  27. CI_UBIPART="firmware${next_boot_part}"
  28. CI_KERNPART="kernel"
  29. CI_ROOTPART="rootfs"
  30. nand_upgrade_prepare_ubi "${rootfs_length}" "squashfs" "$kernel_length" "0"
  31. local ubidev="$(nand_find_ubi "${CI_UBIPART}")"
  32. local kern_ubivol="$(nand_find_volume "${ubidev}" "${CI_KERNPART}")"
  33. tar xf "${tar_file}" "${board_dir}/kernel" -O | \
  34. ubiupdatevol "/dev/${kern_ubivol}" -s "${kernel_length}" -
  35. local root_ubivol="$(nand_find_volume "${ubidev}" "${CI_ROOTPART}")"
  36. tar xf "${tar_file}" "${board_dir}/root" -O | \
  37. ubiupdatevol "/dev/${root_ubivol}" -s "${rootfs_length}" -
  38. [ -f "${UPGRADE_BACKUP}" ] && nand_restore_config "${UPGRADE_BACKUP}"
  39. # write new new uboot-env
  40. printf "bootseq ${bootseq}\n" > "${setenv_script}"
  41. printf "kernel_%i_size 0x%08x\n" "${next_boot_part}" "${kernel_length}" >> "${setenv_script}"
  42. printf "kernel_%i_checksum %s\n" "${next_boot_part}" "${kernel_md5}" >> "${setenv_script}"
  43. printf "rootfs_%i_size 0x%08x\n" "${next_boot_part}" "${rootfs_length}" >> "${setenv_script}"
  44. printf "rootfs_%i_checksum %s\n" "${next_boot_part}" "${rootfs_md5}" >> "${setenv_script}"
  45. mkdir -p /var/lock
  46. fw_setenv -s "${setenv_script}" || {
  47. echo "failed to update U-Boot environment"
  48. return 1
  49. }
  50. }