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