Mercurial > hg > aboriginal
changeset 499:9d5fd8e1467b
Merge run-*.sh so run-emulator.sh takes command line arguments. Rename emulator-build.sh to be more clear what it does.
author | Rob Landley <rob@landley.net> |
---|---|
date | Fri, 28 Nov 2008 14:58:08 -0600 |
parents | e4f6da942dbf |
children | 63e8b28ea07f |
files | emulator-build.sh package-mini-native.sh run-from-build.sh sources/toys/run-emulator.sh sources/toys/run-with-distcc.sh sources/toys/run-with-home.sh |
diffstat | 6 files changed, 117 insertions(+), 103 deletions(-) [+] |
line wrap: on
line diff
--- a/emulator-build.sh Fri Nov 28 14:55:26 2008 -0600 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,14 +0,0 @@ -#!/bin/bash - -SAVEPATH="$PATH" -source include.sh -PATH="$SAVEPATH" - -cd "${BUILD}/system-image-$ARCH" || exit 1 - -# A little paranoia. -fsck.ext2 -y "image-${ARCH}.ext2" </dev/null - -# And run it, using the distccd we built (if necessary) and the cross-compiler. - -PATH="$HOSTTOOLS:$PATH" ./run-with-distcc.sh "$CROSS"
--- a/package-mini-native.sh Fri Nov 28 14:55:26 2008 -0600 +++ b/package-mini-native.sh Fri Nov 28 14:58:08 2008 -0600 @@ -57,10 +57,9 @@ # filesystem, kernel, and base kernel command line arguments in case you want # to use an emulator other than qemu, but put the default case in qemu_defaults -emulator_command image-$ARCH.ext2 zImage-$ARCH > "$SYSIMAGE/run-emulator.sh" && -chmod +x "$SYSIMAGE/run-emulator.sh" && -ln "$WORK/zImage-$ARCH" "$SYSIMAGE" && -cp "$SOURCES"/toys/run-with-{distcc,home}.sh "$SYSIMAGE" +cp "$SOURCES/toys/run-emulator.sh" "$SYSIMAGE/run-emulator.sh" && +emulator_command image-$ARCH.ext2 zImage-$ARCH >> "$SYSIMAGE/run-emulator.sh" && +ln "$WORK/zImage-$ARCH" "$SYSIMAGE" [ $? -ne 0 ] && dienow @@ -68,7 +67,7 @@ if [ -z "$NATIVE_TOOLSDIR" ] then - sed -i 's@/tools/@/usr/@g' "$SYSIMAGE"/*.sh || dienow + sed -i 's@/tools/@/usr/@g' "$SYSIMAGE/run-emulator.sh" || dienow fi if [ "$ARCH" == powerpc ]
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/run-from-build.sh Fri Nov 28 14:58:08 2008 -0600 @@ -0,0 +1,14 @@ +#!/bin/bash + +SAVEPATH="$PATH" +source include.sh +PATH="$SAVEPATH" + +cd "${BUILD}/system-image-$ARCH" || exit 1 + +# A little paranoia. +fsck.ext2 -y "image-${ARCH}.ext2" </dev/null + +# And run it, using the distccd we built (if necessary) and the cross-compiler. + +PATH="$HOSTTOOLS:$PATH" ./run-emulator.sh --make-hdb 2048 --with-distcc "$CROSS"
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/sources/toys/run-emulator.sh Fri Nov 28 14:58:08 2008 -0600 @@ -0,0 +1,99 @@ +#!/bin/bash + +# Parse command line arguments + +while [ ! -z "$1" ] +do + if [ "$1" == "--make-hdb" ] + then + shift + HDBMEGS="$1" + elif [ "$1" == "--with-hdb" ] + then + shift + HDB="$1" + elif [ "$1" == "--with-distcc" ] + then + DCC="$(which distccd)" + if [ -z "$DCC" ] + then + echo 'No distccd in $PATH' >&2 + exit 1 + fi + + shift + DISTCC_PATH="$1" + else + echo "unknown argument $1" + echo 'Usage: run-emulator.sh [--make-hdb $MEGS] [--with-hdb $FILE] [$CROSS_COMPILER_PATH]' >&2 + exit 1 + fi + + shift +done + +if [ ! -z "$DISTCC_PATH" ] +then + + # Try to find a unique port number for each running instance of the program. + + # To reduce the chance of the port already being in use by another program, + # we use a range either before or after that used by normal programs, but + # beyond that allocated to most persistent demons. There's a small chance + # even these ports are already in use, but this at least prevents + # simultaneous run-emulator instances for different targets from + # trivially interfering with each other. + + START=8192 + RANGE=$[$(awk '{print $1}' /proc/sys/net/ipv4/ip_local_port_range)-$START] + if [ $RANGE -lt 1 ] + then + START=$[$(awk '{print $2}' /proc/sys/net/ipv4/ip_local_port_range)] + RANGE=$[65535-$START] + fi + PORT=$[($$%$RANGE)+$START] + + # Run the distcc daemon on the host system with $PATH restricted to the + # cross compiler binaries. + + # Note that we tell it --no-detach and background it oursleves so jobs -p can + # find it later to kill it after the emulator exits. + + PATH="$(readlink -f "$1"/*-unknown-linux/bin)" "$DCC" --listen 127.0.0.1 \ + --no-detach --log-file distccd.log --log-level warning --daemon \ + -a 127.0.0.1 -p $PORT & + # Cleanup afterwards: Kill child processes we started (I.E. distccd). + trap "kill $(jobs -p)" EXIT + + # Prepare some environment variables for run-qemu.sh + + DISTCC_PATH_PREFIX=/tools/distcc: + CPUS=$[$(echo /sys/devices/system/cpu/cpu[0-9]* | wc -w)*2] + KERNEL_EXTRA="DISTCC_HOSTS=10.0.2.2:$PORT CPUS=$CPUS $KERNEL_EXTRA" +fi + +# Should we set up an ext3 image as a second virtual hard drive for /home? + +# Default to image "hdb.img" +[ -z "$HDB" ] && HDB="hdb.img" + +if [ ! -e "$HDB" ] +then + + # If we don't already have an hdb image, should we set up a sparse file and + # format it ext3? + + if [ ! -z "$HDBMEGS" ] + then + dd if=/dev/zero of="$HDB" bs=1024 seek=$[$HDBMEGS*1024-1] count=1 && + mke2fs -b 1024 -F "$HDB" && + tune2fs -j -c 0 -i 0 "$HDB" + + [ $? -ne 0 ] && exit 1 + fi +fi + +[ -e "$HDB" ] && WITH_HDB="-hdb $HDB" + +# The actual emulator invocation command gets appended here +
--- a/sources/toys/run-with-distcc.sh Fri Nov 28 14:55:26 2008 -0600 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,54 +0,0 @@ -#!/bin/bash - -# Wrapper script that sets up distcc on the host and tells the native build -# where to find it, then hands off to run-with-home.sh - -if [ ! -f "$1"/*-unknown-linux/bin/gcc ] -then - echo "Usage: $0 cross-compiler-path" >&2 - exit 1 -fi - -# Run the distcc daemon on the host system with $PATH restricted to the -# cross compiler's symlinks. - -# Note that we tell it --no-detach and background it oursleves so jobs -p can -# find it later to kill it after the emulator exits. - -DCC="$(which distccd)" -if [ -z "$DCC" ] -then - echo 'No distccd in $PATH' - exit 1 -fi - -function portno() -{ - START=8192 - RANGE=$[$(awk '{print $1}' /proc/sys/net/ipv4/ip_local_port_range)-$START] - if [ $RANGE -lt 1 ] - then - START=$[$(awk '{print $2}' /proc/sys/net/ipv4/ip_local_port_range)] - RANGE=$[65535-$PORT] - fi - echo $[($$%$RANGE)+$START] -} - -PORT=$(portno) -PATH="$(readlink -f "$1"/*-unknown-linux/bin)" "$DCC" --listen 127.0.0.1 \ - --no-detach --log-file distccd.log --log-level warning --daemon \ - -a 127.0.0.1 -p $PORT & -# Cleanup afterwards: Kill child processes we started (I.E. distccd). -trap "kill $(jobs -p)" EXIT - -# Prepare some environment variables for run-qemu.sh - -export DISTCC_PATH_PREFIX=/tools/distcc: -CPUS=$[$(echo /sys/devices/system/cpu/cpu[0-9]* | wc -w)*2] -export KERNEL_EXTRA="DISTCC_HOSTS=10.0.2.2:$PORT CPUS=$CPUS $KERNEL_EXTRA" - -# Hand off to run-with-home.sh in the directory this script's running from. - -"$(readlink -f "$(which $0)" | sed -e 's@\(.*/\).*@\1@')"run-with-home.sh - -echo
--- a/sources/toys/run-with-home.sh Fri Nov 28 14:55:26 2008 -0600 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,30 +0,0 @@ -#!/bin/bash - -# Wrapper around run-qemu.sh that sets up an ext3 image as a second virtual -# hard drive, then calls run-qemu.sh - -# Default to image "hdb.img" - -HDB="$1" -[ -z "$HDB" ] && HDB="hdb.img" - -# Default size to create 2 gigabytes - -HDBSIZE="$2" -[ -z "$HDBSIZE" ] && HDBSIZE=2048 - - -# If we don't already have an hdb image, set up a 2 gigabyte sparse file and -# format it ext3. - -if [ ! -e "$HDB" ] -then - dd if=/dev/zero of="$HDB" bs=1024 seek=$[$HDBSIZE*1024-1] count=1 - mke2fs -b 1024 -F "$HDB" - tune2fs -j -c 0 -i 0 "$HDB" -fi - -export WITH_HDB="-hdb $HDB" - -# Find the directory this script's running out of and call next script -"$(readlink -f "$(which $0)" | sed -e 's@\(.*/\).*@\1@')"run-emulator.sh