runqemu-export-rootfs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. #!/bin/bash
  2. #
  3. # Copyright (c) 2005-2009 Wind River Systems, Inc.
  4. #
  5. # SPDX-License-Identifier: GPL-2.0-only
  6. #
  7. usage() {
  8. echo "Usage: $0 {start|stop|restart} <nfs-export-dir>"
  9. }
  10. if [ $# != 2 ]; then
  11. usage
  12. exit 1
  13. fi
  14. if [[ "$1" != "start" && "$1" != "stop" && "$1" != "restart" ]]; then
  15. echo "Unknown command '$1'"
  16. usage
  17. exit 1
  18. fi
  19. if [ ! -d "$2" ]; then
  20. echo "Error: '$2' does not exist"
  21. usage
  22. exit 1
  23. fi
  24. # Ensure the nfs-export-dir is an absolute path
  25. NFS_EXPORT_DIR=$(cd "$2" && pwd)
  26. SYSROOT_SETUP_SCRIPT=`which oe-find-native-sysroot 2> /dev/null`
  27. if [ -z "$SYSROOT_SETUP_SCRIPT" ]; then
  28. echo "Error: Unable to find the oe-find-native-sysroot script"
  29. echo "Did you forget to source your build environment setup script?"
  30. exit 1
  31. fi
  32. . $SYSROOT_SETUP_SCRIPT meta-ide-support
  33. if [ ! -e "$OECORE_NATIVE_SYSROOT/usr/bin/unfsd" ]; then
  34. echo "Error: Unable to find unfsd binary in $OECORE_NATIVE_SYSROOT/usr/bin/"
  35. if [ "x$OECORE_DISTRO_VERSION" = "x" ]; then
  36. echo "Have you run 'bitbake meta-ide-support'?"
  37. else
  38. echo "This shouldn't happen - something is missing from your toolchain installation"
  39. fi
  40. exit 1
  41. fi
  42. if [ ! -d ~/.runqemu-sdk ]; then
  43. mkdir -p ~/.runqemu-sdk
  44. fi
  45. NFS_INSTANCE=${NFS_INSTANCE:=0}
  46. EXPORTS=~/.runqemu-sdk/exports$NFS_INSTANCE
  47. RMTAB=~/.runqemu-sdk/rmtab$NFS_INSTANCE
  48. NFSPID=~/.runqemu-sdk/nfs$NFS_INSTANCE.pid
  49. MOUNTPID=~/.runqemu-sdk/mount$NFS_INSTANCE.pid
  50. PSEUDO_OPTS="-P $OECORE_NATIVE_SYSROOT/usr"
  51. PSEUDO_LOCALSTATEDIR="$NFS_EXPORT_DIR/../$(basename $NFS_EXPORT_DIR).pseudo_state"
  52. export PSEUDO_LOCALSTATEDIR
  53. if [ ! -d "$PSEUDO_LOCALSTATEDIR" ]; then
  54. echo "Error: $PSEUDO_LOCALSTATEDIR does not exist."
  55. echo "Did you create the export directory using runqemu-extract-sdk?"
  56. exit 1
  57. fi
  58. # NFS server port number
  59. NFSD_PORT=${NFSD_PORT:=$[ 3049 + 2 * $NFS_INSTANCE ]}
  60. # mountd port number
  61. MOUNTD_PORT=${MOUNTD_PORT:=$[ 3048 + 2 * $NFS_INSTANCE ]}
  62. ## For debugging you would additionally add
  63. ## --debug all
  64. UNFSD_OPTS="-p -i $NFSPID -e $EXPORTS -n $NFSD_PORT -m $MOUNTD_PORT"
  65. # See how we were called.
  66. case "$1" in
  67. start)
  68. echo "Creating exports file..."
  69. echo "$NFS_EXPORT_DIR (rw,no_root_squash,no_all_squash,insecure)" > $EXPORTS
  70. echo "Starting User Mode nfsd"
  71. echo " $PSEUDO $PSEUDO_OPTS $OECORE_NATIVE_SYSROOT/usr/bin/unfsd $UNFSD_OPTS"
  72. $PSEUDO $PSEUDO_OPTS $OECORE_NATIVE_SYSROOT/usr/bin/unfsd $UNFSD_OPTS
  73. if [ ! $? = 0 ]; then
  74. echo "Error starting nfsd"
  75. exit 1
  76. fi
  77. # Check to make sure everything started ok.
  78. if [ ! -f $NFSPID ]; then
  79. echo "rpc.nfsd did not start correctly"
  80. exit 1
  81. fi
  82. ps -fp `cat $NFSPID` > /dev/null 2> /dev/null
  83. if [ ! $? = 0 ]; then
  84. echo "rpc.nfsd did not start correctly"
  85. exit 1
  86. fi
  87. echo " "
  88. echo "On your target please remember to add the following options for NFS"
  89. echo "nfsroot=IP_ADDRESS:$NFS_EXPORT_DIR,nfsvers=3,port=$NFSD_PORT,udp,mountport=$MOUNTD_PORT"
  90. ;;
  91. stop)
  92. if [ -f "$NFSPID" ]; then
  93. echo "Stopping rpc.nfsd"
  94. kill `cat $NFSPID`
  95. rm -f $NFSPID
  96. else
  97. echo "No PID file, not stopping rpc.nfsd"
  98. fi
  99. if [ -f "$EXPORTS" ]; then
  100. echo "Removing exports file"
  101. rm -f $EXPORTS
  102. fi
  103. ;;
  104. restart)
  105. $0 stop $NFS_EXPORT_DIR
  106. $0 start $NFS_EXPORT_DIR
  107. if [ ! $? = 0 ]; then
  108. exit 1
  109. fi
  110. ;;
  111. *)
  112. echo "$0 {start|stop|restart} <nfs-export-dir>"
  113. ;;
  114. esac
  115. exit 0