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