diff options
author | Tudor Florea <tudor.florea@enea.com> | 2015-10-09 22:59:03 +0200 |
---|---|---|
committer | Tudor Florea <tudor.florea@enea.com> | 2015-10-09 22:59:03 +0200 |
commit | 972dcfcdbfe75dcfeb777150c136576cf1a71e99 (patch) | |
tree | 97a61cd7e293d7ae9d56ef7ed0f81253365bb026 /meta/recipes-core/initrdscripts/initramfs-framework/init | |
download | poky-972dcfcdbfe75dcfeb777150c136576cf1a71e99.tar.gz |
initial commit for Enea Linux 5.0 arm
Signed-off-by: Tudor Florea <tudor.florea@enea.com>
Diffstat (limited to 'meta/recipes-core/initrdscripts/initramfs-framework/init')
-rwxr-xr-x | meta/recipes-core/initrdscripts/initramfs-framework/init | 140 |
1 files changed, 140 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..95fa9fb1a0 --- /dev/null +++ b/meta/recipes-core/initrdscripts/initramfs-framework/init | |||
@@ -0,0 +1,140 @@ | |||
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 | # make mount stop complaining about missing /etc/fstab | ||
72 | touch /etc/fstab | ||
73 | |||
74 | # initialize /proc, /sys and /var/lock | ||
75 | mkdir -p /proc /sys /var/lock | ||
76 | mount -t proc proc /proc | ||
77 | mount -t sysfs sysfs /sys | ||
78 | |||
79 | # populate bootparam environment | ||
80 | for p in `cat /proc/cmdline`; do | ||
81 | opt=`echo $p | cut -d'=' -f1` | ||
82 | opt=`echo $opt | sed -e 's/-/_/'` | ||
83 | if [ "`echo $p | cut -d'=' -f1`" = "$p" ]; then | ||
84 | eval "bootparam_${opt}=true" | ||
85 | else | ||
86 | value="`echo $p | cut -d'=' -f2-`" | ||
87 | eval "bootparam_${opt}=\"${value}\"" | ||
88 | fi | ||
89 | done | ||
90 | |||
91 | # use /dev with devtmpfs | ||
92 | if grep -q devtmpfs /proc/filesystems; then | ||
93 | mkdir -p /dev | ||
94 | mount -t devtmpfs devtmpfs /dev | ||
95 | else | ||
96 | if [ ! -d /dev ]; then | ||
97 | fatal "ERROR: /dev doesn't exist and kernel doesn't has devtmpfs enabled." | ||
98 | fi | ||
99 | fi | ||
100 | |||
101 | mkdir $ROOTFS_DIR | ||
102 | |||
103 | # Load and run modules | ||
104 | for m in $MODULES_DIR/*; do | ||
105 | # Skip backup files | ||
106 | if [ "`echo $m | sed -e 's/\~$//'`" != "$m" ]; then | ||
107 | continue | ||
108 | fi | ||
109 | |||
110 | module=`basename $m | cut -d'-' -f 2` | ||
111 | debug "Loading module $module" | ||
112 | |||
113 | # pre hooks | ||
114 | for h in $MODULE_PRE_HOOKS; do | ||
115 | debug "Calling module hook (pre): $h" | ||
116 | eval "$h pre $module" | ||
117 | debug "Finished module hook (pre): $h" | ||
118 | done | ||
119 | |||
120 | # process module | ||
121 | . $m | ||
122 | |||
123 | if ! eval "${module}_enabled"; then | ||
124 | debug "Skipping module $module" | ||
125 | continue | ||
126 | fi | ||
127 | |||
128 | debug "Running ${module}_run" | ||
129 | eval "${module}_run" | ||
130 | |||
131 | # post hooks | ||
132 | for h in $MODULE_POST_HOOKS; do | ||
133 | debug "Calling module hook (post): $h" | ||
134 | eval "$h post $module" | ||
135 | debug "Finished module hook (post): $h" | ||
136 | done | ||
137 | done | ||
138 | |||
139 | # Catch all | ||
140 | fatal "ERROR: Initramfs failed to initialize the system." | ||