diff options
author | Otavio Salvador <otavio@ossystems.com.br> | 2011-12-07 21:23:00 +0000 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2011-12-08 15:24:28 +0000 |
commit | ed2ac23c5b47c1aa2d5371f2b4c29f471501928a (patch) | |
tree | 5bebed84cb2a46f84134e301365a3a3713258b85 /meta/recipes-core/initrdscripts/initramfs-framework/init | |
parent | 1e459c83e5092b6e1e7d73dce22b29c9e3138607 (diff) | |
download | poky-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/initramfs-framework/init')
-rwxr-xr-x | meta/recipes-core/initrdscripts/initramfs-framework/init | 136 |
1 files changed, 136 insertions, 0 deletions
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> | ||
20 | add_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> | ||
27 | add_module_post_hook() { | ||
28 | MODULE_POST_HOOKS="$MODULE_POST_HOOKS $1" | ||
29 | } | ||
30 | |||
31 | # Load kernel module | ||
32 | load_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 | ||
41 | msg() { | ||
42 | echo "$@" >/dev/console | ||
43 | } | ||
44 | |||
45 | # Prints information if verbose bootparam is used | ||
46 | info() { | ||
47 | [ -n "$bootparam_verbose" ] && echo "$@" >/dev/console | ||
48 | } | ||
49 | |||
50 | # Prints information if debug bootparam is used | ||
51 | debug() { | ||
52 | [ -n "$bootparam_debug" ] && echo "DEBUG: $@" >/dev/console | ||
53 | } | ||
54 | |||
55 | # Prints a message and start a endless loop | ||
56 | fatal() { | ||
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 | ||
66 | ROOTFS_DIR="/rootfs" # where to do the switch root | ||
67 | MODULE_PRE_HOOKS="" # functions to call before running each module | ||
68 | MODULE_POST_HOOKS="" # functions to call after running each module | ||
69 | MODULES_DIR=/init.d # place to look for modules | ||
70 | |||
71 | # initialize /proc and /sys | ||
72 | mkdir -p /proc /sys | ||
73 | mount -t proc proc /proc | ||
74 | mount -t sysfs sysfs /sys | ||
75 | |||
76 | # populate bootparam environment | ||
77 | for 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 | ||
85 | done | ||
86 | |||
87 | # use /dev with devtmpfs | ||
88 | if grep -q devtmpfs /proc/filesystems; then | ||
89 | mkdir -p /dev | ||
90 | mount -t devtmpfs devtmpfs /dev | ||
91 | else | ||
92 | if [ ! -d /dev ]; then | ||
93 | fatal "ERROR: /dev doesn't exist and kernel doesn't has devtmpfs enabled." | ||
94 | fi | ||
95 | fi | ||
96 | |||
97 | mkdir $ROOTFS_DIR | ||
98 | |||
99 | # Load and run modules | ||
100 | for 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 | ||
133 | done | ||
134 | |||
135 | # Catch all | ||
136 | fatal "ERROR: Initramfs failed to initialize the system." | ||