From patchwork Tue Jun 17 05:21:47 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeremy Kerr X-Patchwork-Id: 360314 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from hemlock.osuosl.org (hemlock.osuosl.org [140.211.166.133]) by ozlabs.org (Postfix) with ESMTP id 877C1140099 for ; Tue, 17 Jun 2014 15:22:11 +1000 (EST) Received: from localhost (localhost [127.0.0.1]) by hemlock.osuosl.org (Postfix) with ESMTP id C9B6389991; Tue, 17 Jun 2014 05:22:09 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from hemlock.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id knx1LSarFXN4; Tue, 17 Jun 2014 05:22:08 +0000 (UTC) Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by hemlock.osuosl.org (Postfix) with ESMTP id 859C08A705; Tue, 17 Jun 2014 05:22:08 +0000 (UTC) X-Original-To: buildroot@lists.busybox.net Delivered-To: buildroot@osuosl.org Received: from whitealder.osuosl.org (whitealder.osuosl.org [140.211.166.138]) by ash.osuosl.org (Postfix) with ESMTP id 120021BF96A for ; Tue, 17 Jun 2014 05:22:03 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by whitealder.osuosl.org (Postfix) with ESMTP id 0BADC8AD2D for ; Tue, 17 Jun 2014 05:22:03 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from whitealder.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id cfut3Yc-UV8K for ; Tue, 17 Jun 2014 05:22:02 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from ozlabs.org (ozlabs.org [103.22.144.67]) by whitealder.osuosl.org (Postfix) with ESMTPS id 05C508AD5B for ; Tue, 17 Jun 2014 05:22:01 +0000 (UTC) Received: by ozlabs.org (Postfix, from userid 1023) id E9D9514009C; Tue, 17 Jun 2014 15:21:58 +1000 (EST) MIME-Version: 1.0 Message-Id: <1402982507.185942.882894195923.6.gpush@pablo> In-Reply-To: <1402982507.183937.570365596242.0.gpush@pablo> To: buildroot@busybox.net From: Jeremy Kerr Date: Tue, 17 Jun 2014 13:21:47 +0800 Subject: [Buildroot] [PATCH 6/7 v3] package/petitboot: Add petitboot, the userspace bootloader X-BeenThere: buildroot@busybox.net X-Mailman-Version: 2.1.14 Precedence: list List-Id: Discussion and development of buildroot List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: buildroot-bounces@busybox.net Sender: buildroot-bounces@busybox.net This change adds the petitboot package, a bootloader that exists in userspace, and uses the kexec facility to boot into a new kernel. We add a little extra infrastructure to get things integrated into a buildroot environment: - scripts to make kexec work with busybox init, for a clean shutdown - udev rules to get removable event notifications, and start the petitboot UI processes - startup scripts for the device-discovery process Signed-off-by: Jeremy Kerr --- package/Config.in | 1 package/petitboot/Config.in | 21 +++++++ package/petitboot/S14silence-console | 9 +++ package/petitboot/S15pb-discover | 23 +++++++ package/petitboot/kexec-restart | 8 ++ package/petitboot/petitboot-console-ui.rules | 5 + package/petitboot/petitboot.mk | 57 +++++++++++++++++++ package/petitboot/removable-event-poll.rules | 4 + 8 files changed, 128 insertions(+) diff --git a/package/Config.in b/package/Config.in index b0d4d47..a769d33 100644 --- a/package/Config.in +++ b/package/Config.in @@ -1116,6 +1116,7 @@ endif source "package/ncdu/Config.in" source "package/numactl/Config.in" source "package/nut/Config.in" + source "package/petitboot/Config.in" source "package/powerpc-utils/Config.in" source "package/polkit/Config.in" if BR2_PACKAGE_BUSYBOX_SHOW_OTHERS diff --git a/package/petitboot/Config.in b/package/petitboot/Config.in new file mode 100644 index 0000000..d1e1783 --- /dev/null +++ b/package/petitboot/Config.in @@ -0,0 +1,21 @@ +config BR2_PACKAGE_PETITBOOT + bool "petitboot" + # petitboot needs udev /dev management + depends on BR2_PACKAGE_HAS_UDEV + select BR2_PACKAGE_NCURSES + select BR2_PACKAGE_NCURSES_TARGET_PANEL + select BR2_PACKAGE_NCURSES_TARGET_FORM + select BR2_PACKAGE_NCURSES_TARGET_MENU + # run-time dependency only + select BR2_PACKAGE_KEXEC_LITE if !BR2_PACKAGE_KEXEC + # run-time dependency only + select BR2_PACKAGE_POWERPC_UTILS if BR2_powerpc || BR2_powerpc64 + # run-time dependency only + select BR2_PACKAGE_IPRUTILS if BR2_powerpc || BR2_powerpc64 + help + Petitboot is a small kexec-based bootloader + + http://www.kernel.org/pub/linux/kernel/people/geoff/petitboot/petitboot.html + +comment "petitboot requires udev to be enabled" + depends on !BR2_PACKAGE_HAS_UDEV diff --git a/package/petitboot/S14silence-console b/package/petitboot/S14silence-console new file mode 100755 index 0000000..6570200 --- /dev/null +++ b/package/petitboot/S14silence-console @@ -0,0 +1,9 @@ +#!/bin/sh + +case "$1" in + start) + echo 0 0 7 0 > /proc/sys/kernel/printk + ;; +esac + +exit 0 diff --git a/package/petitboot/S15pb-discover b/package/petitboot/S15pb-discover new file mode 100755 index 0000000..ebdf944 --- /dev/null +++ b/package/petitboot/S15pb-discover @@ -0,0 +1,23 @@ +#!/bin/sh + +LOGFILE=/var/log/petitboot/pb-discover.log +PIDFILE=/var/run/petitboot.pid + +case "$1" in + start) + ulimit -c unlimited + mkdir -p $(dirname $LOGFILE) + PATH=/usr/bin:/usr/sbin:/bin:/sbin pb-discover -l $LOGFILE & + echo $! > $PIDFILE + ;; + stop) + pid=$(cat $PIDFILE) + [ -n "$pid" ] && kill -TERM $pid + ;; + *) + echo "Usage: $0 {start|stop}" + exit 1 + ;; +esac + +exit 0 diff --git a/package/petitboot/kexec-restart b/package/petitboot/kexec-restart new file mode 100755 index 0000000..0175e76 --- /dev/null +++ b/package/petitboot/kexec-restart @@ -0,0 +1,8 @@ +#!/bin/sh + +/usr/sbin/kexec -f -e + +while : +do + sleep 1 +done diff --git a/package/petitboot/petitboot-console-ui.rules b/package/petitboot/petitboot-console-ui.rules new file mode 100644 index 0000000..7464856 --- /dev/null +++ b/package/petitboot/petitboot-console-ui.rules @@ -0,0 +1,5 @@ + +# spawn a petitboot UI on common user-visible interface devices +SUBSYSTEM=="tty", KERNEL=="hvc*", RUN+="/usr/libexec/petitboot/pb-console --getty --detach -- -n -i 0 $name vt100" +SUBSYSTEM=="tty", KERNEL=="tty0", RUN+="/usr/libexec/petitboot/pb-console --getty --detach -- -n -i 0 $name vt100" +SUBSYSTEM=="tty", KERNEL=="ttyS*", RUN+="/usr/libexec/petitboot/pb-console --getty --detach -- -n -i 0 $name vt100" diff --git a/package/petitboot/petitboot.mk b/package/petitboot/petitboot.mk new file mode 100644 index 0000000..1bbf522 --- /dev/null +++ b/package/petitboot/petitboot.mk @@ -0,0 +1,57 @@ +################################################################################ +# +# petitboot +# +################################################################################ + +PETITBOOT_VERSION = 509fca5ca2733a741521ae4332400d54d95ee073 +PETITBOOT_SITE = git://ozlabs.org/~jk/petitboot +PETITBOOT_DEPENDENCIES = ncurses udev host-bison host-flex +PETITBOOT_LICENSE = GPLv2 +PETITBOOT_LICENSE_FILES = COPYING + +PETITBOOT_AUTORECONF = YES +PETITBOOT_AUTORECONF_OPT = -i +PETITBOOT_CONF_OPT += --with-ncurses --without-twin-x11 --without-twin-fbdev \ + --localstatedir=/var \ + HOST_PROG_KEXEC=/usr/sbin/kexec \ + HOST_PROG_SHUTDOWN=/usr/libexec/petitboot/bb-kexec-reboot \ + $(if $(BR2_PACKAGE_BUSYBOX),--with-tftp=busybox) + +ifdef PETITBOOT_DEBUG +PETITBOOT_CONF_OPT += --enable-debug +endif + +ifeq ($(BR2_PACKAGE_NCURSES_WCHAR),y) +PETITBOOT_CONF_OPT += --with-ncursesw MENU_LIB=-lmenuw FORM_LIB=-lformw +endif + +PETITBOOT_PRE_CONFIGURE_HOOKS += PETITBOOT_PRE_CONFIGURE_BOOTSTRAP + +define PETITBOOT_POST_INSTALL + $(INSTALL) -D -m 0755 $(@D)/utils/bb-kexec-reboot \ + $(TARGET_DIR)/usr/libexec/petitboot + $(INSTALL) -d -m 0755 $(TARGET_DIR)/etc/petitboot/boot.d + $(INSTALL) -D -m 0755 $(@D)/utils/hooks/01-create-default-dtb \ + $(TARGET_DIR)/etc/petitboot/boot.d/ + $(INSTALL) -D -m 0755 $(@D)/utils/hooks/20-set-stdout \ + $(TARGET_DIR)/etc/petitboot/boot.d/ + + $(INSTALL) -D -m 0755 package/petitboot/S14silence-console \ + $(TARGET_DIR)/etc/init.d/ + $(INSTALL) -D -m 0755 package/petitboot/S15pb-discover \ + $(TARGET_DIR)/etc/init.d/ + $(INSTALL) -D -m 0755 package/petitboot/kexec-restart \ + $(TARGET_DIR)/usr/sbin/ + $(INSTALL) -D -m 0755 package/petitboot/petitboot-console-ui.rules \ + $(TARGET_DIR)/etc/udev/rules.d/ + $(INSTALL) -D -m 0755 package/petitboot/removable-event-poll.rules \ + $(TARGET_DIR)/etc/udev/rules.d/ + + ln -sf /usr/sbin/pb-udhcpc \ + $(TARGET_DIR)/usr/share/udhcpc/default.script.d/ +endef + +PETITBOOT_POST_INSTALL_TARGET_HOOKS += PETITBOOT_POST_INSTALL + +$(eval $(autotools-package)) diff --git a/package/petitboot/removable-event-poll.rules b/package/petitboot/removable-event-poll.rules new file mode 100644 index 0000000..b736aef --- /dev/null +++ b/package/petitboot/removable-event-poll.rules @@ -0,0 +1,4 @@ + +# petitboot needs notification for media change events on removable devices, +# which we only get if we've set the poll_msecs sysfs attribute. +ACTION!="remove", ATTR{removable}=="1", ATTR{events_poll_msecs}="2000"