Initial Commit
- initial default booting image
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
Recent Debian ncurses is built with NCURSES_OPAQUE_MENU, which means
|
||||
the menu item type can't be poked directly. Fix with accessors.
|
||||
|
||||
One wrinkle is the item name can't be modified, new_item has to be used.
|
||||
|
||||
Signed-off-by: Nicholas Piggin <npiggin at gmail.com>
|
||||
Upstream: https://github.com/open-power/petitboot/issues/106
|
||||
Signed-off-by: Nathaniel Roach <nroach44@nroach44.id.au>
|
||||
---
|
||||
ui/ncurses/nc-menu.c | 12 ++++++++----
|
||||
ui/ncurses/nc-menu.h | 4 ++--
|
||||
2 files changed, 10 insertions(+), 6 deletions(-)
|
||||
|
||||
diff --git a/ui/ncurses/nc-menu.c b/ui/ncurses/nc-menu.c
|
||||
index a90a02e..a1524b5 100644
|
||||
--- a/ui/ncurses/nc-menu.c
|
||||
+++ b/ui/ncurses/nc-menu.c
|
||||
@@ -141,9 +141,13 @@ int pmenu_item_update(struct pmenu_item *item, const char *name)
|
||||
if (!label)
|
||||
return -1;
|
||||
|
||||
- i = item->nci;
|
||||
- i->name.str = label;
|
||||
- i->name.length = strncols(label);
|
||||
+ i = new_item(label, NULL);
|
||||
+ if (!i) {
|
||||
+ talloc_free((char *)label);
|
||||
+ return -1;
|
||||
+ }
|
||||
+ free_item(item->nci);
|
||||
+ item->nci = i;
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -358,7 +362,7 @@ static int pmenu_item_get_index(const struct pmenu_item *item)
|
||||
return i;
|
||||
|
||||
pb_log_fn("not found: %p %s\n", item,
|
||||
- (item ? item->nci->name.str : "(null)"));
|
||||
+ (item ? item_name(item->nci) : "(null)"));
|
||||
return -1;
|
||||
}
|
||||
|
||||
diff --git a/ui/ncurses/nc-menu.h b/ui/ncurses/nc-menu.h
|
||||
index eb568c8..550c7e1 100644
|
||||
--- a/ui/ncurses/nc-menu.h
|
||||
+++ b/ui/ncurses/nc-menu.h
|
||||
@@ -126,7 +126,7 @@ static inline struct pmenu *pmenu_from_scr(struct nc_scr *scr)
|
||||
|
||||
static inline void pmenu_dump_item(const ITEM *item)
|
||||
{
|
||||
- pb_debug("%p %s\n", item, (item ? item->name.str : "(null)"));
|
||||
+ pb_debug("%p %s\n", item, (item ? item_name(item) : "(null)"));
|
||||
}
|
||||
|
||||
static inline void pmenu_dump_items(ITEM *const *items, unsigned int count)
|
||||
@@ -135,7 +135,7 @@ static inline void pmenu_dump_items(ITEM *const *items, unsigned int count)
|
||||
|
||||
for (i = 0; i < count; i++)
|
||||
pb_debug("%u: %p %s\n", i, items[i],
|
||||
- (items[i] ? items[i]->name.str : "(null)"));
|
||||
+ (items[i] ? item_name(items[i]) : "(null)"));
|
||||
}
|
||||
|
||||
#endif
|
||||
--
|
||||
2.42.0
|
||||
@@ -0,0 +1,54 @@
|
||||
When a menu item name is updated, the old label is not freed.
|
||||
|
||||
Signed-off-by: Nicholas Piggin <npiggin at gmail.com>
|
||||
Upstream: https://github.com/open-power/petitboot/issues/106
|
||||
Signed-off-by: Nathaniel Roach <nroach44@nroach44.id.au>
|
||||
---
|
||||
ui/ncurses/nc-menu.c | 4 ++++
|
||||
ui/ncurses/nc-menu.h | 1 +
|
||||
2 files changed, 5 insertions(+)
|
||||
|
||||
diff --git a/ui/ncurses/nc-menu.c b/ui/ncurses/nc-menu.c
|
||||
index a1524b5..70f2210 100644
|
||||
--- a/ui/ncurses/nc-menu.c
|
||||
+++ b/ui/ncurses/nc-menu.c
|
||||
@@ -82,6 +82,7 @@ static void pmenu_resize(struct nc_scr *scr)
|
||||
static int pmenu_item_destructor(void *arg)
|
||||
{
|
||||
struct pmenu_item *item = arg;
|
||||
+ talloc_free((char *)item->label);
|
||||
free_item(item->nci);
|
||||
return 0;
|
||||
}
|
||||
@@ -146,7 +147,9 @@ int pmenu_item_update(struct pmenu_item *item, const char *name)
|
||||
talloc_free((char *)label);
|
||||
return -1;
|
||||
}
|
||||
+ talloc_free((char *)item->label);
|
||||
free_item(item->nci);
|
||||
+ item->label = label;
|
||||
item->nci = i;
|
||||
|
||||
return 0;
|
||||
@@ -168,6 +171,7 @@ struct pmenu_item *pmenu_item_create(struct pmenu *menu, const char *name)
|
||||
|
||||
item->i_sig = pb_item_sig;
|
||||
item->pmenu = menu;
|
||||
+ item->label = label;
|
||||
item->nci = new_item(label, NULL);
|
||||
|
||||
if (!item->nci) {
|
||||
diff --git a/ui/ncurses/nc-menu.h b/ui/ncurses/nc-menu.h
|
||||
index 550c7e1..7ba45bf 100644
|
||||
--- a/ui/ncurses/nc-menu.h
|
||||
+++ b/ui/ncurses/nc-menu.h
|
||||
@@ -46,6 +46,7 @@ struct pmenu;
|
||||
|
||||
struct pmenu_item {
|
||||
enum pb_nc_sig i_sig;
|
||||
+ const char *label;
|
||||
ITEM *nci;
|
||||
struct pmenu *pmenu;
|
||||
void *data;
|
||||
--
|
||||
2.42.0
|
||||
50
package/petitboot/Config.in
Normal file
50
package/petitboot/Config.in
Normal file
@@ -0,0 +1,50 @@
|
||||
config BR2_PACKAGE_PETITBOOT
|
||||
bool "petitboot"
|
||||
depends on BR2_PACKAGE_KEXEC_ARCH_SUPPORTS || BR2_PACKAGE_KEXEC_LITE_ARCH_SUPPORTS
|
||||
depends on BR2_USE_MMU # lvm2, agetty
|
||||
depends on BR2_USE_WCHAR # elfutils, kexec-lite
|
||||
depends on !BR2_STATIC_LIBS # elfutils, kexec-lite, nvme
|
||||
depends on BR2_TOOLCHAIN_HAS_THREADS # elfutils, kexec-lite, lvm2
|
||||
depends on BR2_PACKAGE_HAS_UDEV
|
||||
depends on BR2_TOOLCHAIN_HEADERS_AT_LEAST_3_17 || !BR2_PACKAGE_KEXEC_ARCH_SUPPORTS # kexec
|
||||
select BR2_PACKAGE_ELFUTILS
|
||||
select BR2_PACKAGE_LVM2 # devmapper
|
||||
select BR2_PACKAGE_NCURSES
|
||||
select BR2_PACKAGE_NCURSES_WCHAR
|
||||
# run-time dependencies
|
||||
select BR2_PACKAGE_KEXEC if !BR2_PACKAGE_KEXEC_LITE_ARCH_SUPPORTS
|
||||
select BR2_PACKAGE_KEXEC_LITE if BR2_PACKAGE_KEXEC_LITE_ARCH_SUPPORTS && !BR2_PACKAGE_KEXEC
|
||||
select BR2_PACKAGE_LIBXCRYPT if BR2_TOOLCHAIN_USES_GLIBC
|
||||
select BR2_PACKAGE_NVME if ( BR2_powerpc || BR2_powerpc64 || BR2_powerpc64le )
|
||||
select BR2_PACKAGE_POWERPC_UTILS if ( BR2_powerpc || BR2_powerpc64 || BR2_powerpc64le )
|
||||
select BR2_PACKAGE_UTIL_LINUX
|
||||
select BR2_PACKAGE_UTIL_LINUX_AGETTY
|
||||
help
|
||||
Petitboot is a small kexec-based bootloader
|
||||
|
||||
NOTE: petitboot looks best in a UTF-8 locale; be sure there
|
||||
is one listed in BR2_GENERATE_LOCALE.
|
||||
|
||||
http://www.kernel.org/pub/linux/kernel/people/geoff/petitboot/petitboot.html
|
||||
|
||||
if BR2_PACKAGE_PETITBOOT
|
||||
|
||||
config BR2_PACKAGE_PETITBOOT_GETTY_PORT
|
||||
string "TTY port(s)"
|
||||
default "console"
|
||||
help
|
||||
Specify a space-separated list of ports to run the petitboot
|
||||
UI on. Wildcards are allowed. Example: "hvc* ttys0 ttyS*"
|
||||
|
||||
endif # BR2_PACKAGE_PETITBOOT
|
||||
|
||||
comment "petitboot needs a toolchain w/ wchar, dynamic library, threads, udev /dev management"
|
||||
depends on BR2_PACKAGE_KEXEC_ARCH_SUPPORTS
|
||||
depends on BR2_USE_MMU
|
||||
depends on !BR2_USE_WCHAR || BR2_STATIC_LIBS || \
|
||||
!BR2_TOOLCHAIN_HAS_THREADS || \
|
||||
!BR2_PACKAGE_HAS_UDEV
|
||||
|
||||
comment "petitboot w/ kexec needs a toolchain w/ headers >= 3.17"
|
||||
depends on BR2_PACKAGE_KEXEC_ARCH_SUPPORTS && !BR2_PACKAGE_KEXEC_LITE_ARCH_SUPPORTS
|
||||
depends on !BR2_TOOLCHAIN_HEADERS_AT_LEAST_3_17
|
||||
59
package/petitboot/S15pb-discover
Normal file
59
package/petitboot/S15pb-discover
Normal file
@@ -0,0 +1,59 @@
|
||||
#!/bin/sh
|
||||
|
||||
DAEMON="pb-discover"
|
||||
PIDFILE="/var/run/$DAEMON.pid"
|
||||
|
||||
# shellcheck source=/dev/null
|
||||
[ -r "/etc/default/petitboot" ] && . "/etc/default/petitboot"
|
||||
|
||||
if [ "$(pb-config debug)" = "enabled" ] ; then
|
||||
PB_DISCOVER_ARGS="$PB_DISCOVER_ARGS --verbose"
|
||||
fi
|
||||
|
||||
start() {
|
||||
printf 'Starting %s: ' "$DAEMON"
|
||||
# shellcheck disable=SC2174 # only apply -m to deepest dir
|
||||
mkdir -p -m 0775 /var/log/petitboot
|
||||
chown petituser:petitgroup /var/log/petitboot
|
||||
|
||||
# shellcheck disable=SC2086 # we need the word splitting
|
||||
start-stop-daemon -S -q -b -m -p "$PIDFILE" -x "/usr/sbin/$DAEMON" \
|
||||
-- $PB_DISCOVER_ARGS
|
||||
status=$?
|
||||
if [ "$status" -eq 0 ]; then
|
||||
echo "OK"
|
||||
else
|
||||
echo "FAIL"
|
||||
fi
|
||||
return "$status"
|
||||
}
|
||||
|
||||
stop() {
|
||||
printf 'Stopping %s: ' "$DAEMON"
|
||||
start-stop-daemon -K -q -p "$PIDFILE"
|
||||
status=$?
|
||||
if [ "$status" -eq 0 ]; then
|
||||
rm -f "$PIDFILE"
|
||||
echo "OK"
|
||||
else
|
||||
echo "FAIL"
|
||||
fi
|
||||
return "$status"
|
||||
}
|
||||
|
||||
restart() {
|
||||
stop
|
||||
sleep 1
|
||||
start
|
||||
}
|
||||
|
||||
case "$1" in
|
||||
start|stop|restart)
|
||||
"$1";;
|
||||
reload)
|
||||
restart;;
|
||||
*)
|
||||
echo "Usage: $0 {start|stop|restart|reload}"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
8
package/petitboot/kexec-restart.in
Normal file
8
package/petitboot/kexec-restart.in
Normal file
@@ -0,0 +1,8 @@
|
||||
#!/bin/sh
|
||||
|
||||
@KEXEC_COMMAND@
|
||||
|
||||
while :
|
||||
do
|
||||
sleep 1
|
||||
done
|
||||
38
package/petitboot/pb-console
Normal file
38
package/petitboot/pb-console
Normal file
@@ -0,0 +1,38 @@
|
||||
#!/bin/sh
|
||||
|
||||
DAEMON="pb-console"
|
||||
|
||||
PB_CONSOLE_PORT=${2:-"console"}
|
||||
PB_CONSOLE_ARGS="--getty=/sbin/agetty --detach -- -a petituser -n -i $PB_CONSOLE_PORT linux"
|
||||
|
||||
# shellcheck source=/dev/null
|
||||
[ -r "/etc/default/petitboot" ] && . "/etc/default/petitboot"
|
||||
|
||||
start() {
|
||||
printf 'Starting %s on %s: ' "$DAEMON" "$PB_CONSOLE_PORT"
|
||||
# shellcheck disable=SC2174 # only apply -m to deepest dir
|
||||
mkdir -p -m 0775 /var/log/petitboot
|
||||
chown petituser:petitgroup /var/log/petitboot
|
||||
|
||||
# shellcheck disable=SC2086 # we need the word splitting
|
||||
start-stop-daemon -S -q -x "/usr/libexec/petitboot/$DAEMON" \
|
||||
-- $PB_CONSOLE_ARGS
|
||||
status=$?
|
||||
if [ "$status" -eq 0 ]; then
|
||||
echo "OK"
|
||||
else
|
||||
echo "FAIL"
|
||||
fi
|
||||
return "$status"
|
||||
}
|
||||
|
||||
case "$1" in
|
||||
start)
|
||||
"$1";;
|
||||
stop|restart|reload)
|
||||
;;
|
||||
*)
|
||||
echo "Usage: $0 {start|stop|restart|reload} [port]"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
10
package/petitboot/pb-shell
Normal file
10
package/petitboot/pb-shell
Normal file
@@ -0,0 +1,10 @@
|
||||
#!/bin/sh
|
||||
|
||||
reset
|
||||
|
||||
cat <<EOM
|
||||
Exiting petitboot. Type 'exit' to return.
|
||||
You may run 'pb-sos' to gather diagnostic data.
|
||||
EOM
|
||||
|
||||
exec /bin/sh
|
||||
3
package/petitboot/petitboot.hash
Normal file
3
package/petitboot/petitboot.hash
Normal file
@@ -0,0 +1,3 @@
|
||||
# Locally computed
|
||||
sha256 eed29ec841c2bcd5ecc65347f5b95a0087a541bd9c04ca3c17c55d1f7357d189 petitboot-v1.15.tar.gz
|
||||
sha256 204d8eff92f95aac4df6c8122bc1505f468f3a901e5a4cc08940e0ede1938994 COPYING
|
||||
120
package/petitboot/petitboot.mk
Normal file
120
package/petitboot/petitboot.mk
Normal file
@@ -0,0 +1,120 @@
|
||||
################################################################################
|
||||
#
|
||||
# petitboot
|
||||
#
|
||||
################################################################################
|
||||
|
||||
PETITBOOT_VERSION = 1.15
|
||||
PETITBOOT_SOURCE = petitboot-v$(PETITBOOT_VERSION).tar.gz
|
||||
PETITBOOT_SITE = https://github.com/open-power/petitboot/releases/download/v$(PETITBOOT_VERSION)
|
||||
PETITBOOT_DEPENDENCIES = \
|
||||
elfutils \
|
||||
ncurses \
|
||||
udev \
|
||||
host-bison \
|
||||
host-flex \
|
||||
lvm2 \
|
||||
$(if $(BR2_PACKAGE_LIBXCRYPT),libxcrypt) \
|
||||
$(TARGET_NLS_DEPENDENCIES)
|
||||
PETITBOOT_LICENSE = GPL-2.0
|
||||
PETITBOOT_LICENSE_FILES = COPYING
|
||||
|
||||
PETITBOOT_CONF_ENV = LDFLAGS="$(TARGET_LDFLAGS) $(TARGET_NLS_LIBS)"
|
||||
PETITBOOT_CONF_OPTS = \
|
||||
--enable-crypt \
|
||||
--enable-platform-auto \
|
||||
--disable-mtd \
|
||||
--with-ncurses \
|
||||
--without-signed-boot \
|
||||
--without-twin-fbdev \
|
||||
--without-twin-x11 \
|
||||
$(if $(BR2_PACKAGE_BUSYBOX),--enable-busybox,--disable-busybox) \
|
||||
HOST_PROG_KEXEC=/usr/sbin/kexec \
|
||||
HOST_PROG_SH=/usr/libexec/petitboot/pb-shell \
|
||||
HOST_PROG_SHUTDOWN=/usr/libexec/petitboot/kexec-restart
|
||||
|
||||
# HPA and Busybox tftp are supported. HPA tftp is part of Buildroot's tftpd
|
||||
# package.
|
||||
ifeq ($(BR2_PACKAGE_TFTPD),y)
|
||||
PETITBOOT_CONF_OPTS += --with-tftp=hpa
|
||||
else ifeq ($(BR2_PACKAGE_BUSYBOX),y)
|
||||
PETITBOOT_CONF_OPTS += --with-tftp=busybox
|
||||
else
|
||||
# This actually means "autodetect", there's no way to really disable.
|
||||
PETITBOOT_CONF_OPTS += --without-tftp
|
||||
endif
|
||||
|
||||
ifeq ($(BR2_PACKAGE_DTC),y)
|
||||
PETITBOOT_DEPENDENCIES += dtc
|
||||
PETITBOOT_CONF_OPTS += --with-fdt
|
||||
define PETITBOOT_POST_INSTALL_DTB
|
||||
$(INSTALL) -D -m 0755 $(@D)/utils/hooks/30-dtb-updates \
|
||||
$(TARGET_DIR)/etc/petitboot/boot.d/30-dtb-updates
|
||||
endef
|
||||
PETITBOOT_POST_INSTALL_TARGET_HOOKS += PETITBOOT_POST_INSTALL_DTB
|
||||
else
|
||||
PETITBOOT_CONF_OPTS += --without-fdt
|
||||
endif
|
||||
|
||||
ifeq ($(BR2_INIT_BUSYBOX),y)
|
||||
# inittab "restart" runlevel entry runs kexec
|
||||
PETITBOOT_KEXEC_COMMAND = /bin/kill -QUIT 1
|
||||
define PETITBOOT_BUSYBOX_INITTAB
|
||||
grep -q kexec $(TARGET_DIR)/etc/inittab || \
|
||||
printf "\nnull::restart:/usr/sbin/kexec -f -e\n" >> $(TARGET_DIR)/etc/inittab
|
||||
endef
|
||||
PETITBOOT_TARGET_FINALIZE_HOOKS += PETITBOOT_BUSYBOX_INITTAB
|
||||
else ifeq ($(BR2_INIT_SYSV),y)
|
||||
# inittab runlevel 6 entry runs kexec
|
||||
PETITBOOT_KEXEC_COMMAND = /sbin/shutdown -r now
|
||||
define PETITBOOT_SYSV_INITTAB
|
||||
grep -q kexec $(TARGET_DIR)/etc/inittab || \
|
||||
$(SED) 's~^reb0:.*~reb0:6:wait:/usr/sbin/kexec -f -e~' $(TARGET_DIR)/etc/inittab
|
||||
endef
|
||||
PETITBOOT_TARGET_FINALIZE_HOOKS += PETITBOOT_SYSV_INITTAB
|
||||
else ifeq ($(BR2_INIT_OPENRC),y)
|
||||
PETITBOOT_KEXEC_COMMAND = /sbin/openrc-shutdown --kexec now
|
||||
else ifeq ($(BR2_INIT_SYSTEMD),y)
|
||||
PETITBOOT_KEXEC_COMMAND = /usr/bin/systemctl kexec
|
||||
else # BR2_INIT_NONE
|
||||
PETITBOOT_KEXEC_COMMAND = /usr/sbin/kexec -f -e
|
||||
endif
|
||||
|
||||
PETITBOOT_GETTY_PORT = $(patsubst %,'%',$(call qstrip,$(BR2_PACKAGE_PETITBOOT_GETTY_PORT)))
|
||||
|
||||
define PETITBOOT_POST_INSTALL
|
||||
$(INSTALL) -D -m 0755 $(PETITBOOT_PKGDIR)/kexec-restart.in \
|
||||
$(TARGET_DIR)/usr/libexec/petitboot/kexec-restart
|
||||
$(SED) 's~@KEXEC_COMMAND@~$(PETITBOOT_KEXEC_COMMAND)~' \
|
||||
$(TARGET_DIR)/usr/libexec/petitboot/kexec-restart
|
||||
$(INSTALL) -D -m 0755 $(@D)/utils/hooks/01-create-default-dtb \
|
||||
$(TARGET_DIR)/etc/petitboot/boot.d/01-create-default-dtb
|
||||
$(INSTALL) -D -m 0755 $(@D)/utils/hooks/90-sort-dtb \
|
||||
$(TARGET_DIR)/etc/petitboot/boot.d/90-sort-dtb
|
||||
$(INSTALL) -D -m 0755 $(PETITBOOT_PKGDIR)/S15pb-discover \
|
||||
$(TARGET_DIR)/etc/init.d/S15pb-discover
|
||||
$(INSTALL) -D -m 0755 $(PETITBOOT_PKGDIR)/pb-console \
|
||||
$(TARGET_DIR)/etc/init.d/pb-console
|
||||
$(INSTALL) -D -m 0755 $(PETITBOOT_PKGDIR)/pb-shell \
|
||||
$(TARGET_DIR)/usr/libexec/petitboot/pb-shell
|
||||
$(INSTALL) -D -m 0755 $(PETITBOOT_PKGDIR)/shell_profile \
|
||||
$(TARGET_DIR)/home/petituser/.profile
|
||||
|
||||
mkdir -p $(TARGET_DIR)/etc/udev/rules.d
|
||||
for port in $(PETITBOOT_GETTY_PORT); do \
|
||||
printf 'SUBSYSTEM=="tty", KERNEL=="%s", RUN+="/etc/init.d/pb-console start $$name"\n' "$$port"; \
|
||||
done > $(TARGET_DIR)/etc/udev/rules.d/petitboot-console-ui.rules
|
||||
|
||||
mkdir -p $(TARGET_DIR)/usr/share/udhcpc/default.script.d/
|
||||
ln -sf /usr/sbin/pb-udhcpc \
|
||||
$(TARGET_DIR)/usr/share/udhcpc/default.script.d/
|
||||
|
||||
endef
|
||||
|
||||
PETITBOOT_POST_INSTALL_TARGET_HOOKS += PETITBOOT_POST_INSTALL
|
||||
|
||||
define PETITBOOT_USERS
|
||||
petituser -1 petitgroup -1 * /home/petituser /bin/sh - petitboot user
|
||||
endef
|
||||
|
||||
$(eval $(autotools-package))
|
||||
3
package/petitboot/shell_profile
Normal file
3
package/petitboot/shell_profile
Normal file
@@ -0,0 +1,3 @@
|
||||
if [ "$PPID" = "1" ]; then
|
||||
exec /usr/libexec/petitboot/pb-console
|
||||
fi
|
||||
Reference in New Issue
Block a user