From 51c1b427ec838530a695495bd62e2b196d36cb33 Mon Sep 17 00:00:00 2001 From: Jan Luebbe Date: Wed, 27 May 2015 22:53:00 +0200 Subject: [PATCH] initramfs-framework: override init file to reboot on error The initramfs-framework from oe-core performs an endless loop of "sleep 3600" when fatal() is called. We need to reboot instead. Signed-off-by: Jan Luebbe --- .../initrdscripts/initramfs-framework/init | 139 ++++++++++++++++++ .../initramfs-framework_sysmocom.inc | 4 + yocto-shared/initramfs-framework_1.0.bbappend | 1 + 3 files changed, 144 insertions(+) create mode 100755 recipes-core/initrdscripts/initramfs-framework/init create mode 100644 recipes-core/initrdscripts/initramfs-framework_sysmocom.inc create mode 100644 yocto-shared/initramfs-framework_1.0.bbappend diff --git a/recipes-core/initrdscripts/initramfs-framework/init b/recipes-core/initrdscripts/initramfs-framework/init new file mode 100755 index 0000000..fc12991 --- /dev/null +++ b/recipes-core/initrdscripts/initramfs-framework/init @@ -0,0 +1,139 @@ +#!/bin/sh +# Copyright (C) 2011 O.S. Systems Software LTDA. +# Licensed on MIT +# +# Provides the API to be used by the initramfs modules +# +# Modules need to provide the following functions: +# +# _enabled : check if the module ought to run (return 1 to skip) +# _run : do what is need +# +# Boot parameters are available on environment in the as: +# +# 'foo=value' as 'bootparam_foo=value' +# 'foo' as 'bootparam_foo=true' + +# Register a function to be called before running a module +# The hook is called as: +# pre +add_module_pre_hook() { + MODULE_PRE_HOOKS="$MODULE_PRE_HOOKS $1" +} + +# Register a function to be called after running a module +# The hook is called as: +# post +add_module_post_hook() { + MODULE_POST_HOOKS="$MODULE_POST_HOOKS $1" +} + +# Load kernel module +load_kernel_module() { + if modprobe $1 >/dev/null 2>&1; then + info "Loaded module $1" + else + debug "Failed to load module $1" + fi +} + +# Prints information +msg() { + echo "$@" >/dev/console +} + +# Prints information if verbose bootparam is used +info() { + [ -n "$bootparam_verbose" ] && echo "$@" >/dev/console +} + +# Prints information if debug bootparam is used +debug() { + [ -n "$bootparam_debug" ] && echo "DEBUG: $@" >/dev/console +} + +# Prints a message and exit (resulting in a panic) +fatal() { + echo $1 >/dev/console + echo >/dev/console + + msg "fatal error: rebooting" + reboot -f +} + +# Variables shared amoung modules +ROOTFS_DIR="/rootfs" # where to do the switch root +MODULE_PRE_HOOKS="" # functions to call before running each module +MODULE_POST_HOOKS="" # functions to call after running each module +MODULES_DIR=/init.d # place to look for modules + +# make mount stop complaining about missing /etc/fstab +touch /etc/fstab + +# initialize /proc, /sys and /var/lock +mkdir -p /proc /sys /var/lock +mount -t proc proc /proc +mount -t sysfs sysfs /sys + +# populate bootparam environment +for p in `cat /proc/cmdline`; do + opt=`echo $p | cut -d'=' -f1` + opt=`echo $opt | sed -e 's/-/_/'` + if [ "`echo $p | cut -d'=' -f1`" = "$p" ]; then + eval "bootparam_${opt}=true" + else + value="`echo $p | cut -d'=' -f2-`" + eval "bootparam_${opt}=\"${value}\"" + fi +done + +# use /dev with devtmpfs +if grep -q devtmpfs /proc/filesystems; then + mkdir -p /dev + mount -t devtmpfs devtmpfs /dev +else + if [ ! -d /dev ]; then + fatal "ERROR: /dev doesn't exist and kernel doesn't has devtmpfs enabled." + fi +fi + +mkdir $ROOTFS_DIR + +# Load and run modules +for m in $MODULES_DIR/*; do + # Skip backup files + if [ "`echo $m | sed -e 's/\~$//'`" != "$m" ]; then + continue + fi + + module=`basename $m | cut -d'-' -f 2` + debug "Loading module $module" + + # pre hooks + for h in $MODULE_PRE_HOOKS; do + debug "Calling module hook (pre): $h" + eval "$h pre $module" + debug "Finished module hook (pre): $h" + done + + # process module + . $m + + if ! eval "${module}_enabled"; then + debug "Skipping module $module" + continue + fi + + debug "Running ${module}_run" + eval "${module}_run" + + # post hooks + for h in $MODULE_POST_HOOKS; do + debug "Calling module hook (post): $h" + eval "$h post $module" + debug "Finished module hook (post): $h" + done +done + +# Catch all +fatal "ERROR: Initramfs failed to initialize the system." diff --git a/recipes-core/initrdscripts/initramfs-framework_sysmocom.inc b/recipes-core/initrdscripts/initramfs-framework_sysmocom.inc new file mode 100644 index 0000000..2d0b9ee --- /dev/null +++ b/recipes-core/initrdscripts/initramfs-framework_sysmocom.inc @@ -0,0 +1,4 @@ +THISDIR := "${@os.path.dirname(bb.data.getVar('FILE', d, True))}" +FILESPATH =. "${@base_set_filespath(["${THISDIR}/${PN}"], d)}:" + +PRINC="4" diff --git a/yocto-shared/initramfs-framework_1.0.bbappend b/yocto-shared/initramfs-framework_1.0.bbappend new file mode 100644 index 0000000..69d3d84 --- /dev/null +++ b/yocto-shared/initramfs-framework_1.0.bbappend @@ -0,0 +1 @@ +require recipes-core/initrdscripts/${PN}_sysmocom.inc