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