changeset 572:1277d5ae4507

Move bin/qemu-setup.sh to sbin/init.sh and do more work on initramfs packaging. (Doesn't work yet.)
author Rob Landley <rob@landley.net>
date Thu, 08 Jan 2009 00:13:50 -0600
parents f07d714321fe
children de6725a2fdad
files mini-native.sh package-mini-native.sh sources/native/bin/chroot-setup.sh sources/native/bin/qemu-setup.sh sources/native/sbin/init.sh sources/toys/gen_initramfs_list.sh
diffstat 6 files changed, 142 insertions(+), 94 deletions(-) [+]
line wrap: on
line diff
--- a/mini-native.sh	Thu Jan 08 00:05:53 2009 -0600
+++ b/mini-native.sh	Thu Jan 08 00:13:50 2009 -0600
@@ -103,7 +103,7 @@
 
 if [ -z "${NATIVE_TOOLSDIR}" ]
 then
-  sed -i -e 's@/tools/@/usr/@g' "${TOOLS}/bin/qemu-setup.sh" || dienow
+  sed -i -e 's@/tools/@/usr/@g' "${TOOLS}/sbin/init.sh" || dienow
 fi
 
 if [ -z "$NATIVE_TOOLCHAIN" ]
--- a/package-mini-native.sh	Thu Jan 08 00:05:53 2009 -0600
+++ b/package-mini-native.sh	Thu Jan 08 00:13:50 2009 -0600
@@ -10,6 +10,9 @@
 SYSIMAGE="${BUILD}/system-image-${ARCH}"
 IMAGE="${SYSIMAGE}/image-${ARCH}.ext2"
 
+TOOLSDIR=tools
+[ -z "$NATIVE_TOOLSDIR" ] && TOOLSDIR=usr
+
 # Flush old system-image directory
 
 rm -rf "${SYSIMAGE}"
@@ -18,20 +21,45 @@
 # 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?
+make ARCH="${KARCH}" KCONFIG_ALLCONFIG="$(getconfig linux)" \
+  allnoconfig > /dev/null || dienow
 
 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
+  echo "Generating initramfs (in background)"
+  (
+    $CC usr/gen_init_cpio.c -o my_gen_init_cpio || dienow
+    (./my_gen_init_cpio <(
+        [ ! -d "$NATIVE"/dev ] && echo "dir /dev 755 0 0"
+        [ ! -e "$NATIVE"/init ] &&
+          echo "slink /init $NATIVE/$TOOLSDIR/sbin/init.sh 755 0 0"
+
+        "$SOURCES"/toys/gen_initramfs_list.sh "$NATIVE" &&
+        echo "nod /dev/console 640 0 0 c 5 1" >> initramfs.txt || dienow
+      ) || dienow
+    ) | gzip -9 > initramfs_data.cpio.gz || dienow
+    echo Initramfs generated.
+  ) &
+fi
 
-  make ARCH="${KARCH}" CROSS_COMPILE="${ARCH}-" \
-    CONFIG_INITRAMFS_SOURCE=initramfs.txt || dienow
+# Build a kernel.
+
+make -j $CPUS ARCH="${KARCH}" CROSS_COMPILE="${ARCH}-" || dienow
+wait4background 0
+
+# Embed an initramfs image in the kernel?
+
+if [ ! -z "USE_INITRAMFS" ]
+then
+  # This is a repeat of an earlier make invocation, but if we try to
+  # consolidate them the dependencies build unnecessary prereqisites
+  # and then decide that they're newer than the cpio.gz we supplied,
+  # and thus overwrite it with a default (emptyish) one.
+
+  [ -f initramfs_data.cpio.gz ] &&
+  touch initramfs_data.cpio.gz &&
+  mv initramfs_data.cpio.gz usr &&
+  make -j $CPUS ARCH="${KARCH}" CROSS_COMPILE="${ARCH}-" || dienow
 fi
 
 # Install kernel
@@ -64,8 +92,8 @@
   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"'
+       "rw init=/$TOOLSDIR/sbin/init.sh panic=1" \
+       'PATH=$DISTCC_PATH_PREFIX/$TOOLSDIR/bin $KERNEL_EXTRA"'
 }
 
 # Write out a script to call the appropriate emulator.  We split out the
@@ -77,13 +105,6 @@
 
 [ $? -ne 0 ] && dienow
 
-# Adjust things before creating tarball.
-
-if [ -z "$NATIVE_TOOLSDIR" ]
-then
-  sed -i 's@/tools/@/usr/@g' "$SYSIMAGE/run-emulator.sh" || dienow
-fi
-
 if [ "$ARCH" == powerpc ]
 then
   cp "$SOURCES"/toys/ppc_rom.bin "$SYSIMAGE" || dienow
--- a/sources/native/bin/chroot-setup.sh	Thu Jan 08 00:05:53 2009 -0600
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-qemu-setup.sh
\ No newline at end of file
--- a/sources/native/bin/qemu-setup.sh	Thu Jan 08 00:05:53 2009 -0600
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,73 +0,0 @@
-#!/tools/bin/sh
-
-# If you're doing a Linux From Scratch build, the /tools directory is
-# sufficient.  (Start by installing kernel headers and building a C library.)
-
-# Otherwise, building source packages wants things like /bin/bash and
-# running the results wants /lib/ld-uClibc.so.0, so set up some directories
-# and symlinks to let you easily compile source packages.
-
-# Add /tools to $PATH if it's not there
-
-if [ -d tools/bin ] && [ -z "$(echo :$PATH | tools/bin/grep :/tools/bin)" ]
-then
-  [ -z "$PATH" ] && PATH=/tools/bin || PATH="$PATH":/tools/bin
-  export PATH
-fi
-export HOME=/home
-
-# Create some temporary directories at the root level
-mkdir -p {proc,sys,dev,etc,tmp,home}
-[ ! -e bin ] && ln -s tools/bin bin
-[ ! -e lib ] && ln -s tools/lib lib
-[ ! -e usr ] && ln -s tools usr
-
-# Populate /dev
-mountpoint -q sys || mount -t sysfs sys sys
-mountpoint -q dev || mount -t tmpfs dev dev
-mdev -s
-
-# Mount /proc is there
-mountpoint -q proc || mount -t proc proc proc
-
-# If we're running under qemu, do some more setup
-if [ $$ -eq 1 ]
-then
-
-  # Note that 10.0.2.2 forwards to 127.0.0.1 on the host.
-
-  # Setup networking for QEMU (needs /proc)
-  echo "nameserver 10.0.2.3" > /etc/resolv.conf
-  ifconfig eth0 10.0.2.15
-  route add default gw 10.0.2.2
-
-  # If we have no RTC, try rdate instead:
-  [ `date +%s` -lt 1000 ] && rdate 10.0.2.2 # or time-b.nist.gov
-
-  # If there's a /dev/hdb or /dev/sdb, mount it on home
-
-  [ -b /dev/hdb ] && HOMEDEV=/dev/hdb
-  [ -b /dev/sdb ] && HOMEDEV=/dev/sdb
-  if [ ! -z "$HOMEDEV" ]
-  then
-    mount $HOMEDEV /home
-  fi
-
-  echo Type exit when done.
-  exec /tools/bin/oneit -c /dev/"$(dmesg | sed -n '/^Kernel command line:/s@.* console=\(/dev/\)*\([^ ]*\).*@\2@p')" /tools/bin/ash
-
-# If we're not PID 1, it's probably a chroot.
-else
-  echo "nameserver 4.2.2.1" > /etc/resolv.conf
-
-  # Switch to a shell with command history.
-
-  echo Type exit when done.
-  /tools/bin/ash
-  cd /
-  umount ./dev
-  umount ./home
-  umount ./sys
-  umount ./proc
-  sync
-fi
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sources/native/sbin/init.sh	Thu Jan 08 00:13:50 2009 -0600
@@ -0,0 +1,73 @@
+#!/tools/bin/sh
+
+# If you're doing a Linux From Scratch build, the /tools directory is
+# sufficient.  (Start by installing kernel headers and building a C library.)
+
+# Otherwise, building source packages wants things like /bin/bash and
+# running the results wants /lib/ld-uClibc.so.0, so set up some directories
+# and symlinks to let you easily compile source packages.
+
+# Add /tools to $PATH if it's not there
+
+if [ -d tools/bin ] && [ -z "$(echo :$PATH | tools/bin/grep :/tools/bin)" ]
+then
+  [ -z "$PATH" ] && PATH=/tools/bin || PATH="$PATH":/tools/bin
+  export PATH
+fi
+export HOME=/home
+
+# Create some temporary directories at the root level
+mkdir -p {proc,sys,dev,etc,tmp,home}
+[ ! -e bin ] && ln -s tools/bin bin
+[ ! -e lib ] && ln -s tools/lib lib
+[ ! -e usr ] && ln -s tools usr
+
+# Populate /dev
+mountpoint -q sys || mount -t sysfs sys sys
+mountpoint -q dev || mount -t tmpfs dev dev
+mdev -s
+
+# Mount /proc is there
+mountpoint -q proc || mount -t proc proc proc
+
+# If we're running under qemu, do some more setup
+if [ $$ -eq 1 ]
+then
+
+  # Note that 10.0.2.2 forwards to 127.0.0.1 on the host.
+
+  # Setup networking for QEMU (needs /proc)
+  echo "nameserver 10.0.2.3" > /etc/resolv.conf
+  ifconfig eth0 10.0.2.15
+  route add default gw 10.0.2.2
+
+  # If we have no RTC, try rdate instead:
+  [ `date +%s` -lt 1000 ] && rdate 10.0.2.2 # or time-b.nist.gov
+
+  # If there's a /dev/hdb or /dev/sdb, mount it on home
+
+  [ -b /dev/hdb ] && HOMEDEV=/dev/hdb
+  [ -b /dev/sdb ] && HOMEDEV=/dev/sdb
+  if [ ! -z "$HOMEDEV" ]
+  then
+    mount $HOMEDEV /home
+  fi
+
+  echo Type exit when done.
+  exec /tools/bin/oneit -c /dev/"$(dmesg | sed -n '/^Kernel command line:/s@.* console=\(/dev/\)*\([^ ]*\).*@\2@p')" /tools/bin/ash
+
+# If we're not PID 1, it's probably a chroot.
+else
+  echo "nameserver 4.2.2.1" > /etc/resolv.conf
+
+  # Switch to a shell with command history.
+
+  echo Type exit when done.
+  /tools/bin/ash
+  cd /
+  umount ./dev
+  umount ./home
+  umount ./sys
+  umount ./proc
+  sync
+fi
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sources/toys/gen_initramfs_list.sh	Thu Jan 08 00:13:50 2009 -0600
@@ -0,0 +1,28 @@
+#!/bin/bash
+
+if [ ! -d "$1" ]
+then
+  echo "usage: gen_initramfs_list.sh dirname" >&2
+  exit 1
+fi
+
+LEN=$(echo $1 | wc -c)
+
+find "$1" | while read i
+do
+  PERM=$(stat -c %a "$i")
+  NAME="$(echo $i | cut -b ${LEN}-)"
+
+  [ -z "$NAME" ] && continue
+
+  if [ -L "$i" ]
+  then
+      echo "slink $NAME $(readlink "$i") $PERM 0 0"
+  elif [ -f "$i" ]
+  then
+      echo "file $NAME $i $PERM 0 0"
+  elif [ -d "$i" ]
+  then
+      echo "dir $NAME $PERM 0 0"
+  fi
+done