summaryrefslogtreecommitdiffstats
path: root/meta/recipes-core/initrdscripts
diff options
context:
space:
mode:
authorOtavio Salvador <otavio@ossystems.com.br>2011-12-07 21:23:00 +0000
committerRichard Purdie <richard.purdie@linuxfoundation.org>2011-12-08 15:24:28 +0000
commited2ac23c5b47c1aa2d5371f2b4c29f471501928a (patch)
tree5bebed84cb2a46f84134e301365a3a3713258b85 /meta/recipes-core/initrdscripts
parent1e459c83e5092b6e1e7d73dce22b29c9e3138607 (diff)
downloadpoky-ed2ac23c5b47c1aa2d5371f2b4c29f471501928a.tar.gz
initramfs-framework: provides a modular initramfs
Provides the API and modules for a modular initramfs. The currently included modules are: * initramfs-module-debug adds support to dynamic debugging of initramfs using bootparams * initramfs-module-udev: enables udev usage * initramfs-module-mdev: enables mdev usage * initramfs-module-e2fs: adds support for ext4, ext3 and ext2 filesystems (From OE-Core rev: 7b69ad2167a1f0e57db82817b98a0cbcb70a0dd3) Signed-off-by: Otavio Salvador <otavio@ossystems.com.br> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/recipes-core/initrdscripts')
-rw-r--r--meta/recipes-core/initrdscripts/initramfs-framework/debug82
-rwxr-xr-xmeta/recipes-core/initrdscripts/initramfs-framework/e2fs28
-rwxr-xr-xmeta/recipes-core/initrdscripts/initramfs-framework/finish46
-rwxr-xr-xmeta/recipes-core/initrdscripts/initramfs-framework/init136
-rw-r--r--meta/recipes-core/initrdscripts/initramfs-framework/mdev30
-rw-r--r--meta/recipes-core/initrdscripts/initramfs-framework/udev22
-rw-r--r--meta/recipes-core/initrdscripts/initramfs-framework_1.0.bb57
7 files changed, 401 insertions, 0 deletions
diff --git a/meta/recipes-core/initrdscripts/initramfs-framework/debug b/meta/recipes-core/initrdscripts/initramfs-framework/debug
new file mode 100644
index 0000000000..00bfd7d3f5
--- /dev/null
+++ b/meta/recipes-core/initrdscripts/initramfs-framework/debug
@@ -0,0 +1,82 @@
1#!/bin/sh
2# Copyright (C) 2011 O.S. Systems Software LTDA.
3# Licensed on MIT
4
5# Adds support to dynamic debugging of initramfs using bootparam in
6# following format:
7# shell : starts a shell before and after each module
8# shell=before:<module> : starts a shell before <module> is loaded and run
9# shell=after:<module> : starts a shell after <module> is loaded and run
10#
11# shell-debug : run set -x as soon as possible
12# shell-debug=before:<module> : run set -x before <module> is loaded and run
13# shell-debug=after:<module> : run set -x after <module> is loaded and run
14
15DEBUG_SHELL="false"
16
17debug_hook_handler() {
18 status=$1
19 module=$2
20
21 if [ -n "$bootparam_shell" ] && [ "$bootparam_shell" != "true" ]; then
22 shell_wanted_status=`expr $bootparam_shell : '\(.*\):.*'`
23 shell_wanted_module=`expr $bootparam_shell : '.*:\(.*\)'`
24
25 if [ "$shell_wanted_status" = "before" ]; then
26 shell_wanted_status=pre
27 else
28 shell_wanted_status=post
29 fi
30 fi
31
32 if [ "$bootparam_shell" = "true" ] ||
33 ( [ "$status" = "$shell_wanted_status" ] &&
34 [ "$module" = "$shell_wanted_module" ] ); then
35 if [ "$status" = "pre" ]; then
36 status_msg="before"
37 else
38 status_msg="after"
39 fi
40
41 msg "Starting shell $status_msg $module..."
42 sh
43 fi
44
45 if [ -n "$bootparam_shell_debug" ] && [ "$bootparam_shell_debug" != "true" ]; then
46 shell_debug_wanted_status=`expr $bootparam_shell_debug : '\(.*\):.*'`
47 shell_debug_wanted_module=`expr $bootparam_shell_debug : '.*:\(.*\)'`
48
49 if [ "$shell_debug_wanted_status" = "before" ]; then
50 shell_debug_wanted_status=pre
51 else
52 shell_debug_wanted_status=post
53 fi
54 fi
55
56 if [ "$bootparam_shell_debug" = "true" ] ||
57 ( [ "$status" = "$shell_debug_wanted_status" ] &&
58 [ "$module" = "$shell_debug_wanted_module" ] ); then
59 if [ "$DEBUG_SHELL" = "true" ]; then
60 return 0
61 fi
62
63 if [ "$status" = "pre" ]; then
64 status_msg="before"
65 else
66 status_msg="after"
67 fi
68
69 msg "Starting shell debugging $status_msg $module..."
70 DEBUG_SHELL="true"
71 set -x
72 fi
73}
74
75debug_enabled() {
76 return 0
77}
78
79debug_run() {
80 add_module_pre_hook "debug_hook_handler"
81 add_module_post_hook "debug_hook_handler"
82}
diff --git a/meta/recipes-core/initrdscripts/initramfs-framework/e2fs b/meta/recipes-core/initrdscripts/initramfs-framework/e2fs
new file mode 100755
index 0000000000..29f801a7bd
--- /dev/null
+++ b/meta/recipes-core/initrdscripts/initramfs-framework/e2fs
@@ -0,0 +1,28 @@
1#!/bin/sh
2# Copyright (C) 2011 O.S. Systems Software LTDA.
3# Licensed on MIT
4
5e2fs_enabled() {
6 return 0
7}
8
9e2fs_run() {
10 filesystems="ext4 ext3 ext2"
11
12 # load modules
13 for fs in $filesystems; do
14 load_kernel_module $fs
15 done
16
17 for fs in $filesystems; do
18 eval "fs_options=\$bootparam_${fs}"
19 if [ -n "$fs_options" ]; then
20 dev=`expr "$fs_options" : '\([^:]*\).*'`
21 path=`expr "$fs_options" : '[^:]*:\([^:]*\).*'`
22
23 info "Mounting $dev as $fs on $path as $fs..."
24 mkdir -p $path
25 mount -t $fs $dev $path
26 fi
27 done
28}
diff --git a/meta/recipes-core/initrdscripts/initramfs-framework/finish b/meta/recipes-core/initrdscripts/initramfs-framework/finish
new file mode 100755
index 0000000000..bedd803f10
--- /dev/null
+++ b/meta/recipes-core/initrdscripts/initramfs-framework/finish
@@ -0,0 +1,46 @@
1#!/bin/sh
2# Copyright (C) 2011 O.S. Systems Software LTDA.
3# Licensed on MIT
4
5finish_enabled() {
6 return 0
7}
8
9finish_run() {
10 if [ -n "$ROOTFS_DIR" ]; then
11 if [ -n "$bootparam_rootdelay" ]; then
12 debug "Sleeping for $rootdelay second(s) to wait root to settle..."
13 sleep $bootparam_rootdelay
14 fi
15
16 if [ -n "$bootparam_root" ]; then
17 debug "No e2fs compatible filesystem has been mounted, mounting $bootparam_root..."
18
19 if [ "${bootparam_root:0:5}" = "UUID=" ]; then
20 bootparam_root="/dev/disk/by-uuid/${bootparam_root/UUID=/}"
21 fi
22
23 if [ -e "$bootparam_root" ]; then
24 mount $bootparam_root $ROOTFS_DIR
25 else
26 debug "root '$bootparam_root' doesn't exist."
27 fi
28 fi
29
30 if [ ! -d $ROOTFS_DIR/dev ]; then
31 fatal "ERROR: There's no '/dev' on rootfs."
32 fi
33
34 info "Switching root to '$ROOTFS_DIR'..."
35
36 debug "Moving /dev, /proc and /sys onto rootfs..."
37 mount --move /dev $ROOTFS_DIR/dev
38 mount --move /proc $ROOTFS_DIR/proc
39 mount --move /sys $ROOTFS_DIR/sys
40
41 cd $ROOTFS_DIR
42 exec switch_root -c /dev/console $ROOTFS_DIR /sbin/init
43 else
44 debug "No rootfs has been set"
45 fi
46}
diff --git a/meta/recipes-core/initrdscripts/initramfs-framework/init b/meta/recipes-core/initrdscripts/initramfs-framework/init
new file mode 100755
index 0000000000..fc4b0db4b4
--- /dev/null
+++ b/meta/recipes-core/initrdscripts/initramfs-framework/init
@@ -0,0 +1,136 @@
1#!/bin/sh
2# Copyright (C) 2011 O.S. Systems Software LTDA.
3# Licensed on MIT
4#
5# Provides the API to be used by the initramfs modules
6#
7# Modules need to provide the following functions:
8#
9# <module>_enabled : check if the module ought to run (return 1 to skip)
10# <module>_run : do what is need
11#
12# Boot parameters are available on environment in the as:
13#
14# 'foo=value' as 'bootparam_foo=value'
15# 'foo' as 'bootparam_foo=true'
16
17# Register a function to be called before running a module
18# The hook is called as:
19# <function> pre <module>
20add_module_pre_hook() {
21 MODULE_PRE_HOOKS="$MODULE_PRE_HOOKS $1"
22}
23
24# Register a function to be called after running a module
25# The hook is called as:
26# <function> post <module>
27add_module_post_hook() {
28 MODULE_POST_HOOKS="$MODULE_POST_HOOKS $1"
29}
30
31# Load kernel module
32load_kernel_module() {
33 if modprobe $1 >/dev/null 2>&1; then
34 info "Loaded module $1"
35 else
36 debug "Failed to load module $1"
37 fi
38}
39
40# Prints information
41msg() {
42 echo "$@" >/dev/console
43}
44
45# Prints information if verbose bootparam is used
46info() {
47 [ -n "$bootparam_verbose" ] && echo "$@" >/dev/console
48}
49
50# Prints information if debug bootparam is used
51debug() {
52 [ -n "$bootparam_debug" ] && echo "DEBUG: $@" >/dev/console
53}
54
55# Prints a message and start a endless loop
56fatal() {
57 echo $1 >/dev/console
58 echo >/dev/console
59
60 while [ "true" ]; do
61 sleep 3600
62 done
63}
64
65# Variables shared amoung modules
66ROOTFS_DIR="/rootfs" # where to do the switch root
67MODULE_PRE_HOOKS="" # functions to call before running each module
68MODULE_POST_HOOKS="" # functions to call after running each module
69MODULES_DIR=/init.d # place to look for modules
70
71# initialize /proc and /sys
72mkdir -p /proc /sys
73mount -t proc proc /proc
74mount -t sysfs sysfs /sys
75
76# populate bootparam environment
77for p in `cat /proc/cmdline`; do
78 opt="${p%%=*}"
79 opt=${opt/-/_}
80 if [ "${p/=/}" = "$p" ]; then
81 eval "bootparam_${opt}=true"
82 else
83 eval "bootparam_${opt}=\"${p#*=}\""
84 fi
85done
86
87# use /dev with devtmpfs
88if grep -q devtmpfs /proc/filesystems; then
89 mkdir -p /dev
90 mount -t devtmpfs devtmpfs /dev
91else
92 if [ ! -d /dev ]; then
93 fatal "ERROR: /dev doesn't exist and kernel doesn't has devtmpfs enabled."
94 fi
95fi
96
97mkdir $ROOTFS_DIR
98
99# Load and run modules
100for m in $MODULES_DIR/*; do
101 # Skip backup files
102 if [ "${m/\~/}" != "$m" ]; then
103 continue
104 fi
105
106 module=`basename $m | cut -d'-' -f 2`
107 debug "Loading module $module"
108
109 # pre hooks
110 for h in $MODULE_PRE_HOOKS; do
111 debug "Calling module hook (pre): $h"
112 eval "$h pre $module"
113 debug "Finished module hook (pre): $h"
114 done
115
116 # process module
117 source $m
118
119 if ! eval "${module}_enabled"; then
120 debug "Skipping module $module"
121 continue
122 fi
123
124 debug "Running ${module}_run"
125 eval "${module}_run"
126
127 # post hooks
128 for h in $MODULE_POST_HOOKS; do
129 debug "Calling module hook (post): $h"
130 eval "$h post $module"
131 debug "Finished module hook (post): $h"
132 done
133done
134
135# Catch all
136fatal "ERROR: Initramfs failed to initialize the system."
diff --git a/meta/recipes-core/initrdscripts/initramfs-framework/mdev b/meta/recipes-core/initrdscripts/initramfs-framework/mdev
new file mode 100644
index 0000000000..a5df1d717a
--- /dev/null
+++ b/meta/recipes-core/initrdscripts/initramfs-framework/mdev
@@ -0,0 +1,30 @@
1#!/bin/sh
2# Copyright (C) 2011 O.S. Systems Software LTDA.
3# Licensed on MIT
4
5mdev_enabled() {
6 if [ ! -e /sbin/mdev ]; then
7 debug "/sbin/mdev doesn't exist"
8 return 1
9 fi
10
11 return 0
12}
13
14mdev_run() {
15 # setup the environment
16 mount -t tmpfs tmpfs /dev
17
18 mkdir -m 1777 /dev/shm
19
20 mkdir -m 0755 /dev/pts
21 mount -t devpts devpts /dev/pts
22
23 echo /sbin/mdev > /proc/sys/kernel/hotplug
24 mdev -s
25
26 # load modules for devices
27 find /sys -name modalias | while read m; do
28 load_kernel_module $(cat $m)
29 done
30}
diff --git a/meta/recipes-core/initrdscripts/initramfs-framework/udev b/meta/recipes-core/initrdscripts/initramfs-framework/udev
new file mode 100644
index 0000000000..9ea8aa3641
--- /dev/null
+++ b/meta/recipes-core/initrdscripts/initramfs-framework/udev
@@ -0,0 +1,22 @@
1#!/bin/sh
2# Copyright (C) 2011 O.S. Systems Software LTDA.
3# Licensed on MIT
4
5udev_enabled() {
6 if [ ! -e /sbin/udevd ]; then
7 debug "/sbin/udev doesn't exist"
8 return 1
9 fi
10
11 return 0
12}
13
14udev_run() {
15 mkdir -p /run
16
17 udevd --daemon > /dev/null
18 udevadm trigger --action=add
19 udevadm settle
20
21 killall udevd 2>/dev/null
22}
diff --git a/meta/recipes-core/initrdscripts/initramfs-framework_1.0.bb b/meta/recipes-core/initrdscripts/initramfs-framework_1.0.bb
new file mode 100644
index 0000000000..58e41d4d4c
--- /dev/null
+++ b/meta/recipes-core/initrdscripts/initramfs-framework_1.0.bb
@@ -0,0 +1,57 @@
1DESCRIPTION = "initramfs modular system"
2LICENSE = "MIT"
3LIC_FILES_CHKSUM = "file://${COREBASE}/meta/COPYING.MIT;md5=3da9cfbcb788c80a0384361b4de20420"
4RDEPENDS = "busybox"
5
6inherit allarch
7
8SRC_URI = "file://init \
9 file://finish \
10 file://mdev \
11 file://udev \
12 file://e2fs \
13 file://debug"
14
15do_install() {
16 install -d ${D}/init.d
17
18 # base
19 install -m 0755 ${WORKDIR}/init ${D}/init
20 install -m 0755 ${WORKDIR}/finish ${D}/init.d/99-finish
21
22 # mdev
23 install -m 0755 ${WORKDIR}/mdev ${D}/init.d/01-mdev
24
25 # udev
26 install -m 0755 ${WORKDIR}/udev ${D}/init.d/01-udev
27
28 # e2fs
29 install -m 0755 ${WORKDIR}/e2fs ${D}/init.d/10-e2fs
30
31 # debug
32 install -m 0755 ${WORKDIR}/debug ${D}/init.d/00-debug
33}
34
35PACKAGES = "${PN}-base \
36 initramfs-module-mdev \
37 initramfs-module-udev \
38 initramfs-module-e2fs \
39 initramfs-module-debug"
40
41FILES_${PN}-base = "/init /init.d/99-finish"
42
43DESCRIPTION_initramfs-module-mdev = "initramfs support for mdev"
44RDEPENDS_initramfs-module-mdev = "${PN}-base"
45FILES_initramfs-module-mdev = "/init.d/01-mdev"
46
47DESCRIPTION_initramfs-module-udev = "initramfs support for udev"
48RDEPENDS_initramfs-module-udev = "${PN}-base udev udev-utils"
49FILES_initramfs-module-udev = "/init.d/01-udev"
50
51DESCRIPTION_initramfs-module-e2fs = "initramfs support for ext4/ext3/ext2 filesystems"
52RDEPENDS_initramfs-module-e2fs = "${PN}-base"
53FILES_initramfs-module-e2fs = "/init.d/10-e2fs"
54
55DESCRIPTION_initramfs-module-debug = "initramfs dynamic debug support"
56RDEPENDS_initramfs-module-debug = "${PN}-base"
57FILES_initramfs-module-debug = "/init.d/00-debug"