runqemu-extract-sdk 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. #!/bin/bash
  2. #
  3. # This utility extracts an SDK image tarball using pseudo, and stores
  4. # the pseudo database in var/pseudo within the rootfs. If you want to
  5. # boot QEMU using an nfsroot, you *must* use this script to create the
  6. # rootfs to ensure it is done correctly with pseudo.
  7. #
  8. # Copyright (c) 2010 Intel Corp.
  9. #
  10. # This program is free software; you can redistribute it and/or modify
  11. # it under the terms of the GNU General Public License version 2 as
  12. # published by the Free Software Foundation.
  13. #
  14. # This program is distributed in the hope that it will be useful,
  15. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  17. # See the GNU General Public License for more details.
  18. #
  19. # You should have received a copy of the GNU General Public License
  20. # along with this program; if not, write to the Free Software
  21. # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  22. function usage() {
  23. echo "Usage: $0 <image-tarball> <extract-dir>"
  24. }
  25. if [ $# -ne 2 ]; then
  26. usage
  27. exit 1
  28. fi
  29. SYSROOT_SETUP_SCRIPT=`which oe-find-native-sysroot`
  30. if [ -z "$SYSROOT_SETUP_SCRIPT" ]; then
  31. echo "Error: Unable to find the oe-find-native-sysroot script"
  32. echo "Did you forget to source your build system environment setup script?"
  33. exit 1
  34. fi
  35. . $SYSROOT_SETUP_SCRIPT
  36. PSEUDO_OPTS="-P $OECORE_NATIVE_SYSROOT/usr"
  37. ROOTFS_TARBALL=$1
  38. SDK_ROOTFS_DIR=$2
  39. if [ ! -e "$ROOTFS_TARBALL" ]; then
  40. echo "Error: sdk tarball '$ROOTFS_TARBALL' does not exist"
  41. usage
  42. exit 1
  43. fi
  44. # Convert SDK_ROOTFS_DIR to a full pathname
  45. if [[ ${SDK_ROOTFS_DIR:0:1} != "/" ]]; then
  46. SDK_ROOTFS_DIR=$(pwd)/$SDK_ROOTFS_DIR
  47. fi
  48. TAR_OPTS=""
  49. if [[ "$ROOTFS_TARBALL" =~ tar\.bz2$ ]]; then
  50. TAR_OPTS="-xjf"
  51. fi
  52. if [[ "$ROOTFS_TARBALL" =~ tar\.gz$ ]]; then
  53. TAR_OPTS="-xzf"
  54. fi
  55. if [[ "$ROOTFS_TARBALL" =~ \.tar$ ]]; then
  56. TAR_OPTS="-xf"
  57. fi
  58. if [ -z "$TAR_OPTS" ]; then
  59. echo "Error: Unable to determine sdk tarball format"
  60. echo "Accepted types: .tar / .tar.gz / .tar.bz2"
  61. exit 1
  62. fi
  63. if [ ! -d "$SDK_ROOTFS_DIR" ]; then
  64. echo "Creating directory $SDK_ROOTFS_DIR"
  65. mkdir -p "$SDK_ROOTFS_DIR"
  66. fi
  67. if [ -e "$SDK_ROOTFS_DIR/var/pseudo" ]; then
  68. echo "Error: $SDK_ROOTFS_DIR/var/pseudo already exists!"
  69. echo "Please delete the entire rootfs tree manually if this is really what you want"
  70. exit 1
  71. fi
  72. mkdir -p "$SDK_ROOTFS_DIR/var/pseudo"
  73. touch "$SDK_ROOTFS_DIR/var/pseudo/pseudo.pid"
  74. PSEUDO_LOCALSTATEDIR="$SDK_ROOTFS_DIR/var/pseudo"
  75. export PSEUDO_LOCALSTATEDIR
  76. echo "Extracting rootfs tarball using pseudo..."
  77. echo "$PSEUDO $PSEUDO_OPTS tar -C \"$SDK_ROOTFS_DIR\" $TAR_OPTS \"$ROOTFS_TARBALL\""
  78. $PSEUDO $PSEUDO_OPTS tar -C "$SDK_ROOTFS_DIR" $TAR_OPTS "$ROOTFS_TARBALL"
  79. DIRCHECK=`ls -l "$SDK_ROOTFS_DIR" | wc -l`
  80. if [ "$DIRCHECK" -lt 5 ]; then
  81. echo "Warning: I don't see many files in $SDK_ROOTFS_DIR"
  82. echo "Please double-check the extraction worked as intended"
  83. exit 0
  84. fi
  85. echo "SDK image successfully extracted to $SDK_ROOTFS_DIR"
  86. exit 0