fel-load.sh 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. #!/bin/bash
  2. #
  3. # Copyright (c) 2015 Igor Pecovnik, igor.pecovnik@gma**.com
  4. #
  5. # This file is licensed under the terms of the GNU General Public
  6. # License version 2. This program is licensed "as is" without any
  7. # warranty of any kind, whether express or implied.
  8. # FEL_ROOTFS should be set to path to debootstrapped root filesystem
  9. # unless you want to kill your /etc/fstab and share your rootfs on NFS
  10. # without any access control
  11. fel_prepare_host()
  12. {
  13. # Start rpcbind for NFS if inside docker container
  14. [ "$(systemd-detect-virt)" == 'docker' ] && service rpcbind start
  15. # remove and re-add NFS share
  16. rm -f /etc/exports.d/orangepi.exports
  17. mkdir -p /etc/exports.d
  18. echo "$FEL_ROOTFS *(rw,async,no_subtree_check,no_root_squash,fsid=root)" > /etc/exports.d/orangepi.exports
  19. # Start NFS server if inside docker container
  20. [ "$(systemd-detect-virt)" == 'docker' ] && service nfs-kernel-server start
  21. exportfs -ra
  22. }
  23. fel_prepare_target()
  24. {
  25. if [[ -f $USERPATCHES_PATH/fel-boot.cmd ]]; then
  26. display_alert "Using custom boot script" "userpatches/fel-boot.cmd" "info"
  27. cp "$USERPATCHES_PATH"/fel-boot.cmd "${FEL_ROOTFS}"/boot/boot.cmd
  28. else
  29. cp "${EXTER}"/config/templates/fel-boot.cmd.template "${FEL_ROOTFS}"/boot/boot.cmd
  30. fi
  31. if [[ -z $FEL_LOCAL_IP ]]; then
  32. FEL_LOCAL_IP=$(ifconfig "${NET_IFNAME}" | sed -En 's/127.0.0.1//;s/.*inet (addr:)?(([0-9]*\.){3}[0-9]*).*/\2/p')
  33. fi
  34. sed -i "s#BRANCH#$BRANCH#" "${FEL_ROOTFS}"/boot/boot.cmd
  35. sed -i "s#FEL_LOCAL_IP#$FEL_LOCAL_IP#" "${FEL_ROOTFS}"/boot/boot.cmd
  36. sed -i "s#FEL_ROOTFS#$FEL_ROOTFS#" "${FEL_ROOTFS}"/boot/boot.cmd
  37. mkimage -C none -A arm -T script -d "${FEL_ROOTFS}"/boot/boot.cmd "${FEL_ROOTFS}"/boot/boot.scr > /dev/null
  38. # kill /etc/fstab on target
  39. echo > "${FEL_ROOTFS}"/etc/fstab
  40. echo "/dev/nfs / nfs defaults 0 0" >> "${FEL_ROOTFS}"/etc/fstab
  41. echo "tmpfs /tmp tmpfs defaults,nosuid 0 0" >> "${FEL_ROOTFS}"/etc/fstab
  42. }
  43. fel_load()
  44. {
  45. # update each time in case boot/script.bin link was changed in multi-board images
  46. local dtb_file
  47. if [[ -n $FEL_DTB_FILE ]]; then
  48. dtb_file=$FEL_DTB_FILE
  49. else
  50. if [[ $BRANCH == legacy ]]; then
  51. # script.bin is either regular file or absolute symlink
  52. if [[ -L $FEL_ROOTFS/boot/script.bin ]]; then
  53. dtb_file=boot/bin/$(basename "$(readlink "${FEL_ROOTFS}"/boot/script.bin)")
  54. else
  55. dtb_file=boot/script.bin
  56. fi
  57. else
  58. dtb_file=boot/dtb/$(grep CONFIG_DEFAULT_DEVICE_TREE "${FEL_ROOTFS}/usr/lib/u-boot/${BOOTCONFIG}" | cut -d '"' -f2).dtb
  59. fi
  60. fi
  61. [[ $(type -t fel_pre_load) == function ]] && fel_pre_load
  62. display_alert "Loading files via" "FEL USB" "info"
  63. sunxi-fel "${FEL_EXTRA_ARGS}" -p uboot "${FEL_ROOTFS}/usr/lib/${CHOSEN_UBOOT}_${REVISION}_armhf/u-boot-sunxi-with-spl.bin" \
  64. write 0x42000000 "${FEL_ROOTFS}"/boot/zImage \
  65. write 0x43000000 "${FEL_ROOTFS}/${dtb_file}" \
  66. write 0x43300000 "${FEL_ROOTFS}"/boot/uInitrd \
  67. write 0x43100000 "${FEL_ROOTFS}"/boot/boot.scr
  68. }
  69. if [[ -f $USERPATCHES_PATH/fel-hooks.sh ]]; then
  70. display_alert "Using additional FEL hooks in" "external/userpatches/fel-hooks.sh" "info"
  71. # shellcheck source=/dev/null
  72. source "$USERPATCHES_PATH"/fel-hooks.sh
  73. fi
  74. # basic sanity check
  75. if [[ -n $FEL_ROOTFS ]]; then
  76. fel_prepare_host
  77. fel_prepare_target
  78. [[ $(type -t fel_post_prepare) == function ]] && fel_post_prepare
  79. RES=b
  80. while [[ $RES != q ]]; do
  81. if [[ $FEL_AUTO != yes ]]; then
  82. display_alert "Connect device in FEL mode and press" "<Enter>" "info"
  83. read -r
  84. fi
  85. fel_load
  86. display_alert "Press any key to boot again, <q> to finish" "FEL" "info"
  87. read -r -n 1 RES
  88. echo
  89. done
  90. service nfs-kernel-server restart
  91. fi