Signed-off-by: Jon Ringle <[email protected]>
---
generic/initramfs/conf/initramfs.conf | 54 ++++++
generic/initramfs/init | 180 +++++++++++++++++++
generic/initramfs/scripts/functions | 316 +++++++++++++++++++++++++++++++++
rules/initramfs-tools.in | 8 +
rules/initramfs-tools.make | 93 ++++++++++
5 files changed, 651 insertions(+), 0 deletions(-)
create mode 100644 generic/initramfs/conf/initramfs.conf
create mode 100755 generic/initramfs/init
create mode 100644 generic/initramfs/scripts/functions
create mode 100644 rules/initramfs-tools.in
create mode 100644 rules/initramfs-tools.make
diff --git a/generic/initramfs/conf/initramfs.conf
b/generic/initramfs/conf/initramfs.conf
new file mode 100644
index 0000000..1bb7c6d
--- /dev/null
+++ b/generic/initramfs/conf/initramfs.conf
@@ -0,0 +1,54 @@
+#
+# initramfs.conf
+# Configuration file for mkinitramfs(8). See initramfs.conf(5).
+#
+
+#
+# MODULES: [ most | netboot | dep | list ]
+#
+# most - Add all framebuffer, acpi, filesystem, and harddrive drivers.
+#
+# dep - Try and guess which modules to load.
+#
+# netboot - Add the base modules, network modules, but skip block devices.
+#
+# list - Only include modules from the 'additional modules' list
+#
+
+MODULES=most
+
+# BUSYBOX: [ y | n ]
+#
+# Use busybox if available.
+#
+
+BUSYBOX=n
+
+#
+# NFS Section of the config.
+#
+
+#
+# BOOT: [ local | nfs ]
+#
+# local - Boot off of local media (harddrive, USB stick).
+#
+# nfs - Boot using an NFS drive as the root of the drive.
+#
+
+BOOT=local
+
+#
+# DEVICE: ...
+#
+# Specify the network interface, like eth0
+#
+
+DEVICE=eth0
+
+#
+# NFSROOT: [ auto | HOST:MOUNT ]
+#
+
+NFSROOT=auto
+
diff --git a/generic/initramfs/init b/generic/initramfs/init
new file mode 100755
index 0000000..071c54e
--- /dev/null
+++ b/generic/initramfs/init
@@ -0,0 +1,180 @@
+#!/bin/sh
+
+echo "Loading, please wait..."
+
+[ -d /dev ] || mkdir -m 0755 /dev
+[ -d /root ] || mkdir -m 0700 /root
+[ -d /sys ] || mkdir /sys
+[ -d /proc ] || mkdir /proc
+[ -d /tmp ] || mkdir /tmp
+mkdir -p /var/lock
+mount -onodev,noexec,nosuid -t sysfs none /sys
+mount -onodev,noexec,nosuid -t proc none /proc
+
+# Note that this only becomes /dev on the real filesystem if udev's scripts
+# are used; which they will be, but it's worth pointing out
+mount -t tmpfs -o mode=0755 udev /dev
+[ -e /dev/console ] || mknod /dev/console c 5 1
+[ -e /dev/null ] || mknod /dev/null c 1 3
+> /dev/.initramfs-tools
+mkdir /dev/.initramfs
+
+# Export it for root hardcoding
+export ROOT=
+
+# Bring in the main config
+. /conf/initramfs.conf
+for i in conf/conf.d/*; do
+ [ -f ${i} ] && . ${i}
+done
+. /scripts/functions
+
+# Parse command line options
+export break=
+export init=/sbin/init
+export quiet=n
+export readonly=y
+export rootmnt=/root
+export debug=
+export cryptopts=${CRYPTOPTS}
+export panic
+
+for x in $(cat /proc/cmdline); do
+ case $x in
+ init=*)
+ init=${x#init=}
+ ;;
+ root=*)
+ ROOT=${x#root=}
+ case $ROOT in
+ LABEL=*)
+ ROOT="/dev/disk/by-label/${ROOT#LABEL=}"
+ ;;
+ UUID=*)
+ ROOT="/dev/disk/by-uuid/${ROOT#UUID=}"
+ ;;
+ /dev/nfs)
+ BOOT=nfs
+ ;;
+ esac
+ ;;
+ rootflags=*)
+ ROOTFLAGS="-o ${x#rootflags=}"
+ ;;
+ rootfstype=*)
+ ROOTFSTYPE="${x#rootfstype=}"
+ ;;
+ rootdelay=*)
+ ROOTDELAY="${x#rootdelay=}"
+ ;;
+ resumedelay=*)
+ RESUMEDELAY="${x#resumedelay=}"
+ ;;
+ loop=*)
+ LOOP="${x#loop=}"
+ ;;
+ loopflags=*)
+ LOOPFLAGS="-o ${x#loopflags=}"
+ ;;
+ loopfstype=*)
+ LOOPFSTYPE="${x#loopfstype=}"
+ ;;
+ cryptopts=*)
+ cryptopts="${x#cryptopts=}"
+ ;;
+ nfsroot=*)
+ NFSROOT="${x#nfsroot=}"
+ ;;
+ netboot=*)
+ NETBOOT="${x#netboot=}"
+ ;;
+ ip=*)
+ IPOPTS="${x#ip=}"
+ ;;
+ boot=*)
+ BOOT=${x#boot=}
+ ;;
+ resume=*)
+ RESUME="${x#resume=}"
+ ;;
+ noresume)
+ NORESUME=y
+ ;;
+ panic=*)
+ panic="${x#panic=}"
+ ;;
+ quiet)
+ quiet=y
+ ;;
+ ro)
+ readonly=y
+ ;;
+ rw)
+ readonly=n
+ ;;
+ debug)
+ debug=y
+ exec >/tmp/initramfs.debug 2>&1
+ set -x
+ ;;
+ debug=*)
+ debug=y
+ set -x
+ ;;
+ break=*)
+ break=${x#break=}
+ ;;
+ break)
+ break=premount
+ ;;
+ esac
+done
+
+if [ -z "${NORESUME}" ]; then
+ export resume=${RESUME}
+fi
+
+[ -x /sbin/depmod ] && depmod -a
+maybe_break top
+
+# Don't do log messages here to avoid confusing usplash
+run_scripts /scripts/init-top
+
+maybe_break modules
+log_begin_msg "Loading essential drivers..."
+load_modules
+log_end_msg
+
+maybe_break premount
+[ "$quiet" != "y" ] && log_begin_msg "Running /scripts/init-premount"
+run_scripts /scripts/init-premount
+[ "$quiet" != "y" ] && log_end_msg
+
+maybe_break mount
+log_begin_msg "Mounting root file system..."
+. /scripts/${BOOT}
+parse_numeric ${ROOT}
+mountroot
+log_end_msg
+
+maybe_break bottom
+[ "$quiet" != "y" ] && log_begin_msg "Running /scripts/init-bottom"
+run_scripts /scripts/init-bottom
+[ "$quiet" != "y" ] && log_end_msg
+
+# Move virtual filesystems over to the real filesystem
+mount -n -o move /sys ${rootmnt}/sys
+mount -n -o move /proc ${rootmnt}/proc
+
+while [ ! -x ${rootmnt}${init} ]; do
+ panic "Target filesystem doesn't have ${init}"
+done
+
+# Confuses /etc/init.d/rc
+if [ -n ${debug} ]; then
+ unset debug
+fi
+
+# Chain to real filesystem
+maybe_break init
+exec run-init ${rootmnt} ${init} "$@" <${rootmnt}/dev/console
>${rootmnt}/dev/console 2>&1
diff --git a/generic/initramfs/scripts/functions
b/generic/initramfs/scripts/functions
new file mode 100644
index 0000000..206b3e9
--- /dev/null
+++ b/generic/initramfs/scripts/functions
@@ -0,0 +1,316 @@
+# -*- shell-script -*-
+
+_log_msg()
+{
+ if [ "$quiet" = "y" ]; then return; fi
+ echo "initramfs: $@"
+}
+
+log_msg()
+{
+ _log_msg "$@"
+}
+
+log_success_msg()
+{
+ _log_msg "Success: $@"
+}
+
+log_failure_msg()
+{
+ _log_msg "Failure: $@"
+}
+
+log_warning_msg()
+{
+ _log_msg "Warning: $@"
+}
+
+log_begin_msg()
+{
+ if [ -x /sbin/usplash_write ]; then
+ /sbin/usplash_write "TEXT $@"
+ fi
+ _log_msg "Begin: $@ ..."
+}
+
+log_end_msg()
+{
+ if [ -x /sbin/usplash_write ]; then
+ /sbin/usplash_write "SUCCESS ok"
+ fi
+ _log_msg "Done."
+}
+
+reboot()
+{
+ echo "Rebooting..."
+ echo b > /proc/sysrq-trigger
+}
+
+panic()
+{
+ if [ -x /sbin/usplash_write ]; then
+ /sbin/usplash_write "QUIT"
+ fi
+ # Disallow console access
+ if [ "${panic}" = 0 ]; then
+ reboot
+ fi
+
+ # Call mountroot failure hooks if requested.
+ if [ "${1}" = "-r" ]; then
+ shift 1
+
+ if [ -r "/tmp/mountroot-fail.hooks" ]; then
+ mountroot_fail_hooks=$(cat /tmp/mountroot-fail.hooks)
+ for mr_fh in ${mountroot_fail_hooks}; do
+ ${mr_fh} mountfail
+ done
+ fi
+ fi
+
+ echo $@
+ PS1='(initramfs) ' /bin/sh -i </dev/console >/dev/console 2>&1
+}
+
+maybe_break()
+{
+ if [ x$1 = x${break} ]; then
+ panic "Spawning shell within the initramfs"
+ fi
+}
+
+render()
+{
+ eval "echo -n \...@}"
+}
+
+set_initlist()
+{
+ unset initlist
+ for si_x in ${initdir}/*; do
+ if [ ! -x ${si_x} ]; then
+ continue
+ fi
+ initlist="${initlist} ${si_x#${initdir}/}"
+ done
+}
+
+reduce_satisfied()
+{
+ deplist="$(render array_${1})"
+ unset tmpdeplist
+ for rs_y in ${deplist}; do
+ case $rs_y in
+ *\|*)
+ OLD_IFS="$IFS"
+ IFS='|'
+ for rs_z in $rs_y; do
+ IFS="$OLD_IFS"
+ if [ ! -f ${initdir}/${rs_z} ]; then
+ IFS='|'
+ continue
+ fi
+ tmpdeplist="${tmpdeplist} ${rs_z}"
+ break
+ done
+ IFS="$OLD_IFS"
+ ;;
+ *)
+ if [ ! -f ${initdir}/${rs_y} ]; then
+ continue
+ fi
+ tmpdeplist="${tmpdeplist} ${rs_y}"
+ ;;
+ esac
+ done
+ deplist=${tmpdeplist}
+ for rs_x in ${runlist}; do
+ pop_list_item ${rs_x} ${deplist}
+ deplist=${tmppop}
+ done
+ eval array_${1}=\"${deplist}\"
+}
+
+get_prereqs()
+{
+ set_initlist
+ for gp_x in ${initlist}; do
+ tmp=$(${initdir}/${gp_x} prereqs)
+ eval array_${gp_x}=\"${tmp}\"
+ done
+}
+
+count_unsatisfied()
+{
+ set -- $...@}
+ return ${#}
+}
+
+# Removes $1 from initlist
+pop_list_item()
+{
+ item=${1}
+ shift
+ set -- $...@}
+ unset tmppop
+ # Iterate
+ for pop in $...@}; do
+ if [ ${pop} = ${item} ]; then
+ continue
+ fi
+ tmppop="${tmppop} ${pop}"
+ done
+
+}
+
+# This function generates the runlist, so we clear it first.
+reduce_prereqs()
+{
+ unset runlist
+ set_initlist
+ set -- ${initlist}
+ i=$#
+ # Loop until there's no more in the queue to loop through
+ while [ ${i} -ne 0 ]; do
+ oldi=${i}
+ for rp_x in ${initlist}; do
+ reduce_satisfied ${rp_x}
+ count_unsatisfied $(render array_${rp_x})
+ cnt=${?}
+ if [ ${cnt} -eq 0 ]; then
+ runlist="${runlist} ${rp_x}"
+ pop_list_item ${rp_x} ${initlist}
+ initlist=${tmppop}
+ i=$((${i} - 1))
+ fi
+ done
+ if [ ${i} -eq ${oldi} ]; then
+ panic "PANIC: Circular dependancy. Exiting."
+ fi
+ done
+}
+
+call_scripts()
+{
+ for cs_x in ${runlist}; do
+ # mkinitramfs verbose output
+ if [ "${verbose}" = "y" ]; then
+ echo "Calling hook ${cs_x}"
+ fi
+ ${initdir}/${cs_x}
+ # allow boot scripts to modify exported boot paramaters
+ if [ -e /conf/param.conf ]; then
+ . /conf/param.conf
+ fi
+ done
+}
+
+run_scripts()
+{
+ initdir=${1}
+ get_prereqs
+ reduce_prereqs
+ call_scripts
+}
+
+# Load custom modules first
+load_modules()
+{
+ if [ -e /conf/modules ]; then
+ cat /conf/modules | while read m; do
+ # Skip empty lines
+ if [ -z "$m" ]; then
+ continue
+ fi
+ # Skip comments - d?ash removes whitespace prefix
+ com=$(printf "%.1s" "${m}")
+ if [ "$com" = "#" ]; then
+ continue
+ fi
+ modprobe -Qb $m
+ done
+ fi
+}
+
+# lilo compatibility
+parse_numeric() {
+ case $1 in
+ "")
+ return
+ ;;
+ /*)
+ return
+ ;;
+ *:*)
+ minor=${1#*:}
+ major=${1%:*}
+ ;;
+ *)
+ value=$(( 0x${1} ))
+ minor=$(( ${value} % 256 ))
+ major=$(( ${value} / 256 ))
+ ;;
+ esac
+
+ mknod /dev/root b ${major} ${minor}
+ ROOT=/dev/root
+}
+
+add_mountroot_fail_hook()
+{
+ echo "$0" >> /tmp/mountroot-fail.hooks
+}
+
+# Add a ".d"-stype failure hook; backported from Intrepid to Hardy
+add_mountroot_fail_hook_d()
+{
+ mkdir -p /tmp/mountroot-fail-hooks.d
+ ln -s "$0" /tmp/mountroot-fail-hooks.d/"$1"
+}
+
+# Run failure hooks.
+# When a failure hook exits "1", it has not done anything to correct the
+# system. Exiting "0" means that something has been attempted to resolve
+# the lack of a root filesystem.
+# Hooks are run in lexigraphical order, and are responsible for removing
+# themselves if they should not re-run in a later cycle. When one exits
+# "0", the stack is stopped, so the caller can return to the main rootfs
+# wait loop.
+try_failure_hooks()
+{
+ local hook
+
+ # Disable usplash so text from hooks can be seen
+ if [ -x /sbin/usplash_write ]; then
+ /sbin/usplash_write "QUIT"
+ fi
+ chvt 1
+
+ if [ ! -d "/tmp/mountroot-fail-hooks.d" ]; then
+ return 1
+ fi
+
+ for hook in /tmp/mountroot-fail-hooks.d/*; do
+ if [ -x ${hook} ] && ${hook} mountfail; then
+ return 0
+ fi
+ done
+ return 1
+}
+
+mtdparse ()
+{
+ {
+ OLDIFS=${IFS}
+ IFS=" :\""
+ while read d s e n; do
+ read n1 n2 <<-EOF
+ ${n}
+ EOF
+ [ -z ${n2} ] && [ ${1}x = ${n1}x ] && export
${1}fs_root=mtdblock${d#mtd}
+ done
+ } < /proc/mtd
+ IFS=${OLDIFS}
+}
diff --git a/rules/initramfs-tools.in b/rules/initramfs-tools.in
new file mode 100644
index 0000000..4f6e71e
--- /dev/null
+++ b/rules/initramfs-tools.in
@@ -0,0 +1,8 @@
+## SECTION=initramfs
+
+config INITRAMFS_TOOLS
+ tristate
+ select KLIBC
+ prompt "initramfs-tools"
+ help
+ Install initramfs skeleton framework
diff --git a/rules/initramfs-tools.make b/rules/initramfs-tools.make
new file mode 100644
index 0000000..6f7d4a2
--- /dev/null
+++ b/rules/initramfs-tools.make
@@ -0,0 +1,93 @@
+# -*-makefile-*-
+# $Id$
+#
+# Copyright (C) 2009 by Jon Ringle
+#
+# See CREDITS for details about who has contributed to this project.
+#
+# For further information about the PTXdist project and license conditions
+# see the README file.
+#
+
+#
+# We provide this package
+#
+PACKAGES-$(PTXCONF_INITRAMFS_TOOLS) += initramfs-tools
+
+# Dummy to make ipkg happy
+INITRAMFS_TOOLS_VERSION := 1.0
+INITRAMFS_TOOLS_DIR := $(KLIBC_BUILDDIR)/$(INITRAMFS_TOOLS)
+
+ifdef PTXCONF_INITRAMFS_TOOLS
+$(STATEDIR)/kernel.compile: $(STATEDIR)/initramfs-tools.install
+endif
+
+# ----------------------------------------------------------------------------
+# Get
+# ----------------------------------------------------------------------------
+
+$(STATEDIR)/initramfs-tools.get:
+ @$(call targetinfo)
+ @$(call touch)
+
+# ----------------------------------------------------------------------------
+# Extract
+# ----------------------------------------------------------------------------
+
+$(STATEDIR)/initramfs-tools.extract:
+ @$(call targetinfo)
+ @$(call touch)
+
+# ----------------------------------------------------------------------------
+# Prepare
+# ----------------------------------------------------------------------------
+
+$(STATEDIR)/initramfs-tools.prepare:
+ @$(call targetinfo)
+ @$(call touch)
+
+# ----------------------------------------------------------------------------
+# Compile
+# ----------------------------------------------------------------------------
+
+$(STATEDIR)/initramfs-tools.compile:
+ @$(call targetinfo)
+ @$(call touch)
+
+# ----------------------------------------------------------------------------
+# Install
+# ----------------------------------------------------------------------------
+ifdef PTXCONF_INITRAMFS_TOOLS
+$(STATEDIR)/klibc-user-spec.compile: $(STATEDIR)/initramfs-tools.install
+endif
+
+$(STATEDIR)/initramfs-tools.install:
+ @$(call targetinfo)
+ @$(call install_alt_initramfs, initramfs-tools, 0, 0, 0755, /init)
+ @$(call install_initramfs, initramfs-tools, 0, 0, 0755, /conf)
+ @$(call install_alt_initramfs, initramfs-tools, 0, 0, 0755,
/conf/initramfs.conf)
+ @$(call install_initramfs, initramfs-tools, 0, 0, 0755, /conf/conf.d)
+ @$(call install_initramfs, initramfs-tools, 0, 0, 0755, /scripts)
+ @$(call install_initramfs, initramfs-tools, 0, 0, 0755,
/scripts/init-top)
+ @$(call install_initramfs, initramfs-tools, 0, 0, 0755,
/scripts/init-premount)
+ @$(call install_initramfs, initramfs-tools, 0, 0, 0755,
/scripts/init-bottom)
+ @$(call install_alt_initramfs, initramfs-tools, 0, 0, 0755,
/scripts/functions)
+ @$(call touch)
+
+# ----------------------------------------------------------------------------
+# Target-Install
+# ----------------------------------------------------------------------------
+
+$(STATEDIR)/initramfs-tools.targetinstall:
+ @$(call targetinfo)
+ @$(call touch)
+
+# ----------------------------------------------------------------------------
+# Clean
+# ----------------------------------------------------------------------------
+
+initramfs-tools_clean:
+ rm -rf $(STATEDIR)/initramfs-tools.*
+ rm -rf $(PKGDIR)/initramfs-tools_*
+
+# vim: syntax=make
--
1.6.3.3.334.g916e1
--
ptxdist mailing list
[email protected]