Mercurial > hg > aboriginal
changeset 1350:7eabfa815c90
Split up system-image.sh into root-image.sh, linux-kernel.sh, and system-image.sh. Rename CROSS_HOST_ARCH to CROSS_COMPILER_HOST.
author | Rob Landley <rob@landley.net> |
---|---|
date | Mon, 18 Apr 2011 18:41:04 -0500 |
parents | 37ba3859ea14 |
children | c41de203f9b8 |
files | build.sh config cross-compiler.sh linux-kernel.sh more/buildall.sh more/cronjob.sh root-image.sh system-image.sh |
diffstat | 8 files changed, 172 insertions(+), 132 deletions(-) [+] |
line wrap: on
line diff
--- a/build.sh Mon Apr 18 08:04:46 2011 -0500 +++ b/build.sh Mon Apr 18 18:41:04 2011 -0500 @@ -25,7 +25,7 @@ # that can be used to cross compile more stuff (if you're into that sort of # thing). To enable that: -# CROSS_HOST_ARCH=i686 ./build.sh $TARGET +# CROSS_COMPILER_HOST=i686 ./build.sh $TARGET # Where "i686" is whichever target you want the new cross compiler to run on. @@ -70,6 +70,14 @@ return 0 } +zap() +{ + for i in "$@" + do + rm -f "$BUILD/$i-$ARCH.tar.bz2" + done +} + # The first two stages (download.sh and host-tools.sh) are architecture # independent. In order to allow multiple builds in parallel, re-running # them after they've already completed must be a safe NOP. @@ -92,7 +100,7 @@ then # If we need to build cross compiler, assume root filesystem is stale. - rm -rf "$BUILD/simple-root-filesystem-$ARCH.tar.bz2" + zap simple-root-filesystem linux-kernel time ./simple-cross-compiler.sh "$ARCH" || exit 1 fi @@ -101,15 +109,15 @@ # canadian cross. (It's more powerful than we need here, but if you're going # to use the cross compiler in other contexts this is probably what you want.) -if [ ! -z "$CROSS_HOST_ARCH" ] && not_already cross-compiler +if [ ! -z "$CROSS_COMPILER_HOST" ] && not_already cross-compiler then - rm -rf "$BUILD/simple-root-filesystem-$ARCH.tar.bz2" + zap simple-root-filesystem linux-kernel # Build the host compiler if necessary - if ARCH="$CROSS_HOST_ARCH" not_already simple-cross-compiler + if ARCH="$CROSS_COMPILER_HOST" not_already simple-cross-compiler then - time ./simple-cross-compiler.sh "$CROSS_HOST_ARCH" || exit 1 + time ./simple-cross-compiler.sh "$CROSS_COMPILER_HOST" || exit 1 fi time ./cross-compiler.sh "$ARCH" || exit 1 @@ -120,10 +128,9 @@ if not_already simple-root-filesystem then # If we need to build root filesystem, assume root-filesystem and - # system-image are stale. + # root-image are stale. - rm -rf "$BUILD/root-filesystem-$ARCH.tar.bz2" - rm -rf "$BUILD/system-image-$ARCH.tar.bz2" + zap root-filesystem root-image time ./simple-root-filesystem.sh "$ARCH" || exit 1 @@ -134,7 +141,7 @@ if not_already native-compiler && [ -z "$NO_NATIVE_COMPILER" ] then - rm -rf "$BUILD/root-filesystem-$ARCH.tar.bz2" + zap root-filesystem root-image time ./native-compiler.sh "$ARCH" || exit 1 fi @@ -143,12 +150,30 @@ if not_already root-filesystem && [ -z "$NO_NATIVE_COMPILER" ] then - rm -rf "$BUILD/system-image-$ARCH.tar.bz2" + zap root-image time ./root-filesystem.sh "$ARCH" || exit 1 fi -# Package it up into something qemu can boot. +# Create filesystem image from [simple-]root-filesystem directory + +if not_already root-image +then + zap system-image + + time ./root-image.sh "$ARCH" || exit 1 +fi + +# Build a kernel. (Possibly includes cpio file for initramfs image type.) + +if not_already linux-kernel +then + zap system-image + + time ./linux-kernel.sh "$ARCH" || exit 1 +fi + +# Package it all up into something qemu can boot. if not_already system-image then
--- a/config Mon Apr 18 08:04:46 2011 -0500 +++ b/config Mon Apr 18 18:41:04 2011 -0500 @@ -42,7 +42,7 @@ # Note that most x86_64 systems can run a statically linked i686 binary even # if they don't have the 32-bit libraries installed, so that's a good default. -# export CROSS_HOST_ARCH=i686 +# export CROSS_COMPILER_HOST=i686 # If this is set, only build a C compiler and not C++
--- a/cross-compiler.sh Mon Apr 18 08:04:46 2011 -0500 +++ b/cross-compiler.sh Mon Apr 18 18:41:04 2011 -0500 @@ -18,7 +18,7 @@ # should run on an x86-64 host just fine, even if it hasn't got 32-bit # libraries installed). -BUILD_STATIC=${BUILD_STATIC:-all} HOST_ARCH="${CROSS_HOST_ARCH:-i686}" \ +BUILD_STATIC=${BUILD_STATIC:-all} HOST_ARCH="${CROSS_COMPILER_HOST:-i686}" \ TOOLCHAIN_PREFIX="${1}-" STAGE_NAME=cross-compiler \ ./native-compiler.sh "$1" || exit 1
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/linux-kernel.sh Mon Apr 18 18:41:04 2011 -0500 @@ -0,0 +1,26 @@ +#!/bin/bash + +# Package a root filesystem directory into a filesystem image file + +source sources/include.sh || exit 1 + +# Parse the sources/targets/$1 directory + +read_arch_dir "$1" + +# =================== build kernel ======================== + +[ -e "$BUILD/root-image-$ARCH/initramfs_data.cpio" ] && + MORE_KERNEL_CONFIG="CONFIG_BLK_DEV_INITRD=y\nCONFIG_INITRAMFS_SOURCE=\"$BUILD/root-image-$ARCH/initramfs_data.cpio\"\nCONFIG_INITRAMFS_COMPRESSION_GZIP=y" + +# Build linux kernel for the target + +setupfor linux +[ -z "$BOOT_KARCH" ] && BOOT_KARCH=$KARCH +make ARCH=$BOOT_KARCH $LINUX_FLAGS KCONFIG_ALLCONFIG=<(getconfig linux && echo -e "$MORE_KERNEL_CONFIG") allnoconfig >/dev/null && +make -j $CPUS ARCH=$BOOT_KARCH $DO_CROSS $LINUX_FLAGS $VERBOSITY && +cp "$KERNEL_PATH" "$STAGE_DIR" + +cleanup + +create_stage_tarball
--- a/more/buildall.sh Mon Apr 18 08:04:46 2011 -0500 +++ b/more/buildall.sh Mon Apr 18 18:41:04 2011 -0500 @@ -5,7 +5,7 @@ . sources/utility_functions.sh || exit 1 -[ -z "$CROSS_HOST_ARCH" ] && export CROSS_HOST_ARCH=i686 +[ -z "$CROSS_COMPILER_HOST" ] && export CROSS_COMPILER_HOST=i686 trap "killtree $$" EXIT @@ -25,7 +25,7 @@ mkdir -p build/logs && (EXTRACT_ALL=1 ./download.sh 2>&1 && ./host-tools.sh 2>&1 && - ./simple-cross-compiler.sh 2>&1 "$CROSS_HOST_ARCH" || + ./simple-cross-compiler.sh 2>&1 "$CROSS_COMPILER_HOST" || dienow) | tee build/logs/build-host-cc.txt | maybe_quiet cp packages/MANIFEST build || dienow
--- a/more/cronjob.sh Mon Apr 18 08:04:46 2011 -0500 +++ b/more/cronjob.sh Mon Apr 18 18:41:04 2011 -0500 @@ -40,7 +40,7 @@ # build base repo export FORK=1 -export CROSS_HOST_ARCH=i686 +export CROSS_COMPILER_HOST=i686 hg pull -u build_snapshot()
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/root-image.sh Mon Apr 18 18:41:04 2011 -0500 @@ -0,0 +1,94 @@ +#!/bin/bash + +# Package a root filesystem directory into a filesystem image file + +source sources/include.sh || exit 1 + +# Parse the sources/targets/$1 directory + +read_arch_dir "$1" + +# Which directory do we package up? + +if [ -z "$NATIVE_ROOT" ] +then + [ -z "$NO_NATIVE_COMPILER" ] && + NATIVE_ROOT="$BUILD/root-filesystem-$ARCH" + + [ -e "$NATIVE_ROOT" ] || + NATIVE_ROOT="$BUILD/simple-root-filesystem-$ARCH" +fi + +if [ ! -d "$NATIVE_ROOT" ] +then + [ -z "$FAIL_QUIET" ] && echo No "$NATIVE_ROOT" >&2 + exit 1 +fi + +[ -z "$SYSIMAGE_TYPE" ] && SYSIMAGE_TYPE=squashfs + +echo "Generating $SYSIMAGE_TYPE root filesystem from $NATIVE_ROOT." + +# Embed an initramfs image in the kernel? + +if [ "$SYSIMAGE_TYPE" == "initramfs" ] +then + $CC "$SOURCES/toys/gen_init_cpio.c" -o my_gen_init_cpio || dienow + ./my_gen_init_cpio <( + "$SOURCES"/toys/gen_initramfs_list.sh "$NATIVE_ROOT" || dienow + [ ! -e "$NATIVE_ROOT"/init ] && + echo "slink /init /sbin/init.sh 755 0 0" + [ ! -d "$NATIVE_ROOT"/dev ] && echo "dir /dev 755 0 0" + echo "nod /dev/console 660 0 0 c 5 1" + ) > "$STAGE_DIR/initramfs_data.cpio" || dienow + echo Initramfs generated. + +elif [ "$SYSIMAGE_TYPE" == "ext2" ] +then + # Generate a 64 megabyte ext2 filesystem image from the $NATIVE_ROOT + # directory, with a temporary file defining the /dev nodes for the new + # filesystem. + + [ -z "$SYSIMAGE_HDA_MEGS" ] && SYSIMAGE_HDA_MEGS=64 + + echo "/dev d 755 0 0 - - - - -" > "$WORK/devs" && + echo "/dev/console c 640 0 0 5 1 0 0 -" >> "$WORK/devs" && + + # Produce a filesystem with the currently used space plus 20% for filesystem + # overhead, which should always be big enough. + + BLOCKS=$[1024*(($(du -m -s "$NATIVE_ROOT" | awk '{print $1}')*12)/10)] + [ $BLOCKS -lt 4096 ] && BLOCKS=4096 + + genext2fs -z -D "$WORK/devs" -d "$NATIVE_ROOT" -b $BLOCKS -i 1024 \ + "$STAGE_DIR/hda.ext2" && + rm "$WORK/devs" || dienow + + # Extend image size to HDA_MEGS if necessary, keeping it sparse. (Feeding + # a larger -b size to genext2fs is insanely slow, and not particularly + # sparse.) + + echo "$(stat -c %s "$STAGE_DIR/$IMAGE") -lt $SYSIMAGE_HDA_MEGS" + + if [ ! -z "$SYSIMAGE_HDA_MEGS" ] && + [ $((`stat -c %s "$STAGE_DIR/$IMAGE"` / (1024*1024) )) -lt "$SYSIMAGE_HDA_MEGS" ] + then + echo resizing image to $SYSIMAGE_HDA_MEGS + dd if=/dev/zero of="$STAGE_DIR/$IMAGE" bs=1k count=1 seek=$[1024*1024-1] && + resize2fs "$STAGE_DIR/$IMAGE" ${SYSIMAGE_HDA_MEGS}M || dienow + echo resize complete + fi + +elif [ "$SYSIMAGE_TYPE" == "squashfs" ] +then + mksquashfs "${NATIVE_ROOT}" "$STAGE_DIR/hda.sqf" -noappend -all-root \ + ${FORK:+-no-progress} -p "/dev d 755 0 0" \ + -p "/dev/console c 666 0 0 5 1" || dienow +else + echo "Unknown image type $SYSIMAGE_TYPE" >&2 + dienow +fi + +create_stage_tarball + +echo Image generation complete.
--- a/system-image.sh Mon Apr 18 08:04:46 2011 -0500 +++ b/system-image.sh Mon Apr 18 18:41:04 2011 -0500 @@ -1,7 +1,6 @@ #!/bin/bash -# Package a root filesystem directory into a filesystem image, with -# associated bootable kernel binary and launch scripts. +# Combine a filesystem image and kernel with emulator launch scripts. source sources/include.sh || exit 1 @@ -9,116 +8,12 @@ read_arch_dir "$1" -# Do we have our prerequisites? - -if [ -z "$NATIVE_ROOT" ] -then - [ -z "$NO_NATIVE_COMPILER" ] && - NATIVE_ROOT="$BUILD/root-filesystem-$ARCH" - - [ -e "$NATIVE_ROOT" ] || - NATIVE_ROOT="$BUILD/simple-root-filesystem-$ARCH" -fi - -if [ ! -d "$NATIVE_ROOT" ] -then - [ -z "$FAIL_QUIET" ] && echo No "$NATIVE_ROOT" >&2 - exit 1 -fi - -# Announce start of stage. (Down here after the recursive call above so -# it doesn't get announced twice.) - -echo "=== Packaging system image from root-filesystem" - -# The initramfs packaging uses the kernels build infrastructure, so extract -# it now. - -setupfor linux - -[ -z "$SYSIMAGE_TYPE" ] && SYSIMAGE_TYPE=squashfs -echo "Generating $SYSIMAGE_TYPE root filesystem from $NATIVE_ROOT." - -# Embed an initramfs image in the kernel? - -if [ "$SYSIMAGE_TYPE" == "initramfs" ] -then - $CC usr/gen_init_cpio.c -o my_gen_init_cpio || dienow - ./my_gen_init_cpio <( - "$SOURCES"/toys/gen_initramfs_list.sh "$NATIVE_ROOT" || dienow - [ ! -e "$NATIVE_ROOT"/init ] && - echo "slink /init /sbin/init.sh 755 0 0" - [ ! -d "$NATIVE_ROOT"/dev ] && echo "dir /dev 755 0 0" - echo "nod /dev/console 660 0 0 c 5 1" - ) > initramfs_data.cpio || dienow - echo Initramfs generated. - - # No need to supply an hda image to the emulator. - - IMAGE= - - MORE_KERNEL_CONFIG='CONFIG_BLK_DEV_INITRD=y\nCONFIG_INITRAMFS_SOURCE="initramfs_data.cpio"\nCONFIG_INITRAMFS_COMPRESSION_GZIP=y' - -elif [ "$SYSIMAGE_TYPE" == "ext2" ] -then - # Generate a 64 megabyte ext2 filesystem image from the $NATIVE_ROOT - # directory, with a temporary file defining the /dev nodes for the new - # filesystem. - - [ -z "$SYSIMAGE_HDA_MEGS" ] && SYSIMAGE_HDA_MEGS=64 - - IMAGE="image-${ARCH}.ext2" - DEVLIST="$WORK"/devlist - - echo "/dev d 755 0 0 - - - - -" > "$DEVLIST" && - echo "/dev/console c 640 0 0 5 1 0 0 -" >> "$DEVLIST" && - - # Produce a filesystem with the currently used space plus 20% for filesystem - # overhead, which should always be big enough. - - BLOCKS=$[1024*(($(du -m -s "$NATIVE_ROOT" | awk '{print $1}')*12)/10)] - [ $BLOCKS -lt 4096 ] && BLOCKS=4096 - - genext2fs -z -D "$DEVLIST" -d "$NATIVE_ROOT" -b $BLOCKS -i 1024 \ - "$STAGE_DIR/$IMAGE" && - rm "$DEVLIST" || dienow - - # Extend image size to HDA_MEGS if necessary, keeping it sparse. (Feeding - # a larger -b size to genext2fs is insanely slow, and not particularly - # sparse.) - - echo "$(stat -c %s "$STAGE_DIR/$IMAGE") -lt $SYSIMAGE_HDA_MEGS" - - if [ ! -z "$SYSIMAGE_HDA_MEGS" ] && - [ $((`stat -c %s "$STAGE_DIR/$IMAGE"` / (1024*1024) )) -lt "$SYSIMAGE_HDA_MEGS" ] - then - echo resizing image to $SYSIMAGE_HDA_MEGS - dd if=/dev/zero of="$STAGE_DIR/$IMAGE" bs=1k count=1 seek=$[1024*1024-1] && - resize2fs "$STAGE_DIR/$IMAGE" ${SYSIMAGE_HDA_MEGS}M || dienow - echo resize complete - fi - -elif [ "$SYSIMAGE_TYPE" == "squashfs" ] -then - IMAGE="image-${ARCH}.sqf" - mksquashfs "${NATIVE_ROOT}" "$STAGE_DIR/$IMAGE" -noappend -all-root \ - ${FORK:+-no-progress} -p "/dev d 755 0 0" \ - -p "/dev/console c 666 0 0 5 1" || dienow -else - echo "Unknown image type." >&2 - dienow -fi - -echo Image generation complete. - -# Build linux kernel for the target - -[ -z "$BOOT_KARCH" ] && BOOT_KARCH=$KARCH -make ARCH=$BOOT_KARCH $LINUX_FLAGS KCONFIG_ALLCONFIG=<(getconfig linux && echo -e "$MORE_KERNEL_CONFIG") allnoconfig >/dev/null && -make -j $CPUS ARCH=$BOOT_KARCH $DO_CROSS $LINUX_FLAGS $VERBOSITY && -cp "$KERNEL_PATH" "$STAGE_DIR/zImage-$ARCH" - -cleanup +cd "$BUILD/linux-kernel-$ARCH_NAME" && +KERNEL="$(ls)" && +ln "$KERNEL" "$STAGE_DIR" && +cd "$BUILD/root-image-$ARCH" && +IMAGE="$(ls)" && +ln "$IMAGE" "$STAGE_DIR" || dienow # Provide qemu's common command line options between architectures. @@ -133,8 +28,8 @@ qemu_defaults() { - echo -n "-nographic -no-reboot -kernel \"$2\" \$WITH_HDC \$WITH_HDB" - [ "$SYSIMAGE_TYPE" != "initramfs" ] && echo -n " -hda \"$1\"" + echo -n "-nographic -no-reboot -kernel $KERNEL \$WITH_HDC \$WITH_HDB" + [ "$SYSIMAGE_TYPE" != "initramfs" ] && echo -n " -hda $IMAGE" echo -n " -append \"$(kernel_cmdline)\" \$QEMU_EXTRA" } @@ -147,7 +42,7 @@ run_emulator() { [ ! -z "\$DEBUG" ] && set -x - $(emulator_command "$IMAGE" zImage-$ARCH) + $(emulator_command) } if [ "\$1" != "--norun" ]