runqemu-extract-sdk 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. # SPDX-License-Identifier: GPL-2.0-only
  11. #
  12. function usage() {
  13. echo "Usage: $0 <image-tarball> <extract-dir>"
  14. }
  15. if [ $# -ne 2 ]; then
  16. usage
  17. exit 1
  18. fi
  19. SYSROOT_SETUP_SCRIPT=`which oe-find-native-sysroot 2> /dev/null`
  20. if [ -z "$SYSROOT_SETUP_SCRIPT" ]; then
  21. echo "Error: Unable to find the oe-find-native-sysroot script"
  22. echo "Did you forget to source your build system environment setup script?"
  23. exit 1
  24. fi
  25. . $SYSROOT_SETUP_SCRIPT meta-ide-support
  26. PSEUDO_OPTS="-P $OECORE_NATIVE_SYSROOT/usr"
  27. ROOTFS_TARBALL=$1
  28. SDK_ROOTFS_DIR=$2
  29. if [ ! -e "$ROOTFS_TARBALL" ]; then
  30. echo "Error: sdk tarball '$ROOTFS_TARBALL' does not exist"
  31. usage
  32. exit 1
  33. fi
  34. # Convert SDK_ROOTFS_DIR to a full pathname
  35. if [[ ${SDK_ROOTFS_DIR:0:1} != "/" ]]; then
  36. SDK_ROOTFS_DIR=$(readlink -f $(pwd)/$SDK_ROOTFS_DIR)
  37. fi
  38. TAR_OPTS=""
  39. if [[ "$ROOTFS_TARBALL" =~ tar\.xz$ ]]; then
  40. TAR_OPTS="--numeric-owner -xJf"
  41. fi
  42. if [[ "$ROOTFS_TARBALL" =~ tar\.bz2$ ]]; then
  43. TAR_OPTS="--numeric-owner -xjf"
  44. fi
  45. if [[ "$ROOTFS_TARBALL" =~ tar\.gz$ ]]; then
  46. TAR_OPTS="--numeric-owner -xzf"
  47. fi
  48. if [[ "$ROOTFS_TARBALL" =~ \.tar$ ]]; then
  49. TAR_OPTS="--numeric-owner -xf"
  50. fi
  51. if [ -z "$TAR_OPTS" ]; then
  52. echo "Error: Unable to determine sdk tarball format"
  53. echo "Accepted types: .tar / .tar.gz / .tar.bz2 / .tar.xz"
  54. exit 1
  55. fi
  56. if [ ! -d "$SDK_ROOTFS_DIR" ]; then
  57. echo "Creating directory $SDK_ROOTFS_DIR"
  58. mkdir -p "$SDK_ROOTFS_DIR"
  59. fi
  60. pseudo_state_dir="$SDK_ROOTFS_DIR/../$(basename "$SDK_ROOTFS_DIR").pseudo_state"
  61. pseudo_state_dir="$(readlink -f $pseudo_state_dir)"
  62. debug_image="`echo $ROOTFS_TARBALL | grep '\-dbg\.rootfs\.tar'`"
  63. if [ -e "$pseudo_state_dir" -a -z "$debug_image" ]; then
  64. echo "Error: $pseudo_state_dir already exists!"
  65. echo "Please delete the rootfs tree and pseudo directory manually"
  66. echo "if this is really what you want."
  67. exit 1
  68. fi
  69. mkdir -p "$pseudo_state_dir"
  70. touch "$pseudo_state_dir/pseudo.pid"
  71. PSEUDO_LOCALSTATEDIR="$pseudo_state_dir"
  72. export PSEUDO_LOCALSTATEDIR
  73. echo "Extracting rootfs tarball using pseudo..."
  74. echo "$PSEUDO $PSEUDO_OPTS tar -C \"$SDK_ROOTFS_DIR\" $TAR_OPTS \"$ROOTFS_TARBALL\""
  75. $PSEUDO $PSEUDO_OPTS tar -C "$SDK_ROOTFS_DIR" $TAR_OPTS "$ROOTFS_TARBALL"
  76. DIRCHECK=`ls -l "$SDK_ROOTFS_DIR" | wc -l`
  77. if [ "$DIRCHECK" -lt 5 ]; then
  78. echo "Warning: I don't see many files in $SDK_ROOTFS_DIR"
  79. echo "Please double-check the extraction worked as intended"
  80. exit 0
  81. fi
  82. echo "SDK image successfully extracted to $SDK_ROOTFS_DIR"
  83. exit 0