From 19f592c3a16ce40450d16cd8ef3794fc857b6f9d Mon Sep 17 00:00:00 2001 From: Qiyang Sun <qs2g22@soton.ac.uk> Date: Fri, 2 Aug 2024 00:52:06 +0100 Subject: [PATCH] Add fastinit to replace sysvinit --- recipes-core/fastinit/fastinit.bb | 14 +++++ recipes-core/fastinit/files/fastinit.sh | 73 ++++++++++++++++++++++++ recipes-core/images/mar-image-minimal.bb | 6 +- 3 files changed, 88 insertions(+), 5 deletions(-) create mode 100644 recipes-core/fastinit/fastinit.bb create mode 100755 recipes-core/fastinit/files/fastinit.sh diff --git a/recipes-core/fastinit/fastinit.bb b/recipes-core/fastinit/fastinit.bb new file mode 100644 index 0000000..1d97a8d --- /dev/null +++ b/recipes-core/fastinit/fastinit.bb @@ -0,0 +1,14 @@ +SUMMARY = "Installs fast init script to replace SysVinit" +LICENSE = "CLOSED" + +SRC_URI = "file://fastinit.sh" + +S = "${WORKDIR}" + +do_install() { + install -d ${D}/usr/sbin + install -m 0755 ${WORKDIR}/fastinit.sh ${D}/usr/sbin/ +} + +FILES:${PN} = "/usr/sbin/fastinit.sh" + diff --git a/recipes-core/fastinit/files/fastinit.sh b/recipes-core/fastinit/files/fastinit.sh new file mode 100755 index 0000000..059a909 --- /dev/null +++ b/recipes-core/fastinit/files/fastinit.sh @@ -0,0 +1,73 @@ +#!/bin/sh + +trap 'exec /sbin/poweroff -f' TERM +trap 'exec /sbin/reboot -f' INT HUP + +log_to_kernel() { + echo "<4>fastinit: $1" > /dev/kmsg +} + +warn_to_kernel() { + echo "<2>fastinit: $1" > /dev/kmsg +} + +crit_to_kernel() { + echo "<1>fastinit: $1" > /dev/kmsg +} + +level_zero() { + exec /sbin/poweroff -f +} + +level_one() { + log_to_kernel "mounting filesystems" + mount -t proc proc /proc + mount -t sysfs sysfs /sys + mount -o ro /dev/mmcblk0p1 /boot + + log_to_kernel "getting teletypes on ttyS0" + /sbin/getty -L 115200 ttyS0 vt100 +} + +level_five() { + exec /sbin/init 5 +} + +level_six() { + exec /sbin/reboot -f +} + +runlevel=$1 + +if [ -z "$runlevel" ]; then + warn_to_kernel "cannot read runlevel from argument" + warn_to_kernel "please edit cmdline.txt in bootfs" + warn_to_kernel "usage: init=/usr/sbin/fastinit RUNLEVEL" +else + case $runlevel in + 0) + log_to_kernel "entering runlevel 0 (halt)" + level_zero + ;; + 1) + log_to_kernel "entering runlevel 1 (minimal)" + level_one + ;; + 5) + log_to_kernel "entering runlevel 5 (sysvinit)" + level_five + ;; + 6) + log_to_kernel "entering runlevel 6 (reboot)" + level_six + ;; + *) + warn_to_kernel "Runlevel $runlevel not implemented" + warn_to_kernel "usage: /usr/sbin/fastinit RUNLEVEL" + ;; + esac +fi + +crit_to_kernel "host is up and ready" + +exit 0 diff --git a/recipes-core/images/mar-image-minimal.bb b/recipes-core/images/mar-image-minimal.bb index 84a3d9b..30a2700 100644 --- a/recipes-core/images/mar-image-minimal.bb +++ b/recipes-core/images/mar-image-minimal.bb @@ -2,15 +2,11 @@ SUMMARY = "A small image just capable of allowing a device to boot." IMAGE_INSTALL = "packagegroup-core-boot \ packagegroup-base-extended \ - zeromq \ python3 \ - python3-pyzmq \ python3-pyserial \ - connman \ - connman-client \ screen \ - serial-usb \ usb-modeswitch \ + fastinit \ serial-usb \ ${CORE_IMAGE_EXTRA_INSTALL}" -- GitLab