changeset 553:80f3356577fc

Move kernel building from mini-native to package-mini-native in preparation for initramfs packaging option.
author Rob Landley <rob@landley.net>
date Sat, 27 Dec 2008 06:21:42 -0600
parents a0a26ea9299d
children 52248870bdb0
files mini-native.sh package-mini-native.sh sources/include.sh
diffstat 3 files changed, 51 insertions(+), 31 deletions(-) [+]
line wrap: on
line diff
--- a/mini-native.sh	Sat Dec 27 05:56:01 2008 -0600
+++ b/mini-native.sh	Sat Dec 27 06:21:42 2008 -0600
@@ -12,7 +12,6 @@
 
 if [ ! -z "${NATIVE_TOOLSDIR}" ]
 then
-  TOOLS="${NATIVE}/tools"
   mkdir -p "${TOOLS}/bin" || dienow
 
   # Tell the wrapper script where to find the dynamic linker.
@@ -21,7 +20,6 @@
   UCLIBC_DLPREFIX="/tools"
 else
   mkdir -p "${NATIVE}"/{tmp,proc,sys,dev,etc} || dienow
-  TOOLS="${NATIVE}/usr"
   UCLIBC_TOPDIR="${TOOLS}"
   for i in bin sbin lib
   do
@@ -34,18 +32,13 @@
 
 cp -r "${SOURCES}/native/." "${TOOLS}/" || dienow
 
-# Build and install Linux kernel.
+# Install Linux kernel headers.
 
 setupfor linux
 # Install Linux kernel headers (for use by uClibc).
 make headers_install -j "$CPUS" ARCH="${KARCH}" INSTALL_HDR_PATH="${TOOLS}" &&
 # This makes some very old package builds happy.
 ln -s ../sys/user.h "${TOOLS}/include/asm/page.h" &&
-# build bootable kernel for target
-make ARCH="${KARCH}" KCONFIG_ALLCONFIG="$(getconfig linux)" allnoconfig &&
-cp .config "${TOOLS}"/src/config-linux &&
-make -j $CPUS ARCH="${KARCH}" CROSS_COMPILE="${ARCH}-" &&
-cp "${KERNEL_PATH}" "${NATIVE}/zImage-${ARCH}" &&
 cd ..
 
 cleanup linux
--- a/package-mini-native.sh	Sat Dec 27 05:56:01 2008 -0600
+++ b/package-mini-native.sh	Sat Dec 27 06:21:42 2008 -0600
@@ -13,34 +13,57 @@
 # Flush old system-image directory
 
 rm -rf "${SYSIMAGE}"
-mkdir -p "${SYSIMAGE}" &&
+mkdir -p "${SYSIMAGE}" || dienow
+
+# Build a linux kernel for the target
+
+setupfor linux
+make ARCH="${KARCH}" KCONFIG_ALLCONFIG="$(getconfig linux)" allnoconfig &&
+make -j $CPUS ARCH="${KARCH}" CROSS_COMPILE="${ARCH}-" || dienow
+
+# Embed an initramfs image?
+
+if [ ! -z "USE_INITRAMFS" ]
+then
+  /bin/bash scripts/gen_initramfs_list.sh -u $(id -u) -g $(id -g) \
+    "$NATIVE" > initramfs.txt
+  [ ! -d "$NATIVE"/dir ] && echo "dir /dev 0755 0 0" >> initramfs.txt
+  echo "nod /dev/console 0640 0 0 c 5 1" >> initramfs.txt
 
-# Generate a 64 megabyte filesystem image from the $NATIVE directory, with a
-# temporary file defining the /dev nodes for the new ext2 filesystem.
+  make ARCH="${KARCH}" CROSS_COMPILE="${ARCH}-" \
+    CONFIG_INITRAMFS_SOURCE=initramfs.txt || dienow
+fi
+
+# Install kernel
 
-cat > "$WORK/devlist" << EOF &&
+[ -d "${TOOLS}/src" ] && cp .config "${TOOLS}"/src/config-linux
+cp "${KERNEL_PATH}" "${SYSIMAGE}/zImage-${ARCH}" &&
+cd ..
+
+cleanup linux
+
+if [ -z "$USE_INITRAMFS" ]
+then
+  # Generate a 64 megabyte ext2 filesystem image from the $NATIVE directory,
+  # with a temporary file defining the /dev nodes for the new filesystem.
+
+  cat > "$WORK/devlist" << EOF &&
 /dev d 755 0 0 - - - - -
 /dev/console c 640 0 0 5 1 0 0 -
 EOF
-mv "$NATIVE/zImage-$ARCH" "$SYSIMAGE" || dienow
-genext2fs -z -D "$WORK/devlist" -d "${NATIVE}" -i 1024 -b $[64*1024] "$IMAGE"
-
-# This little dance is because genext2fs hasn't got --exclude so we have to
-# move the kernel out of the directory, then hardlink it back.
-TEMP=$?
-ln "$SYSIMAGE/zImage-$ARCH" "$NATIVE" || dienow
-rm "$WORK/devlist" || dienow
-
-[ "$TEMP" -ne 0 ] && dienow
+  genext2fs -z -D "$WORK/devlist" -d "${NATIVE}" -i 1024 -b $[64*1024] \
+    "$IMAGE" &&
+  rm "$WORK/devlist" || dienow
+fi
 
 # Provide qemu's common command line options between architectures.  The lack
 # of ending quotes on -append is intentional, callers append more kernel
 # command line arguments and provide their own ending quote.
 function qemu_defaults()
 {
-  echo "-nographic -no-reboot \$WITH_HDB" \
-       "-hda \"$1\" -kernel \"$2\"" \
-       "-append \"root=/dev/$ROOT console=$CONSOLE" \
+  echo -n "-nographic -no-reboot \$WITH_HDB"
+  [ -z "$USE_INITRAMFS" ] && echo -n " -hda \"$1\""
+  echo " -kernel \"$2\" -append \"root=/dev/$ROOT console=$CONSOLE" \
        "rw init=/tools/bin/qemu-setup.sh panic=1" \
        'PATH=$DISTCC_PATH_PREFIX/tools/bin $KERNEL_EXTRA"'
 }
--- a/sources/include.sh	Sat Dec 27 05:56:01 2008 -0600
+++ b/sources/include.sh	Sat Dec 27 06:21:42 2008 -0600
@@ -13,7 +13,7 @@
 
 if [ -z "$CPUS" ]
 then
-  export CPUS=$[$(echo /sys/devices/system/cpu/cpu[0-9]* | wc -w)+0]
+  export CPUS=$(echo /sys/devices/system/cpu/cpu[0-9]* | wc -w)
   [ "$CPUS" -lt 1 ] && CPUS=1
 fi
 
@@ -51,7 +51,7 @@
   PATH="$BUILD/wrapdir"
 fi
 
-mkdir -p "${SRCDIR}"
+mkdir -p "${SRCDIR}" || dienow
 
 # Tell bash not to cache the $PATH because we modify it.  Without this, bash
 # won't find new executables added after startup.
@@ -79,7 +79,7 @@
 
   export WORK="${BUILD}/temp-$ARCH"
   rm -rf "${WORK}"
-  mkdir -p "${WORK}"
+  mkdir -p "${WORK}" || dienow
 
   # Say "unknown" in two different ways so it doesn't assume we're NOT
   # cross compiling when the host and target are the same processor.  (If host
@@ -97,8 +97,12 @@
 else
   ARCH_NAME=host
   export WORK="${BUILD}/host-temp"
-  mkdir -p "${WORK}"
+  mkdir -p "${WORK}" || dienow
 fi
 
-[ $? -ne 0 ] && dienow
-
+if [ ! -z "${NATIVE_TOOLSDIR}" ]
+then
+  TOOLS="${NATIVE}/tools"
+else
+  TOOLS="${NATIVE}/usr"
+fi