2024-12-16 11:46:37 -05:00
|
|
|
#! /bin/bash
|
2023-03-13 12:26:41 -04:00
|
|
|
# Note this is used on legacy-flash boards that lack bash, it runs with busybox
|
|
|
|
# ash. Calls to bash scripts must be guarded by checking config.
|
|
|
|
|
2017-09-20 10:29:14 -04:00
|
|
|
mknod /dev/ttyprintk c 5 3
|
2024-12-16 13:28:34 -05:00
|
|
|
echo "hello world" >/dev/ttyprintk
|
2017-09-20 10:29:14 -04:00
|
|
|
|
|
|
|
# Setup our path
|
2018-02-02 15:50:17 -05:00
|
|
|
export PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin
|
2017-09-20 10:29:14 -04:00
|
|
|
|
2017-04-12 06:57:58 -04:00
|
|
|
# This is the very first script invoked by the Linux kernel and is
|
|
|
|
# running out of the ram disk. There are no fileysstems mounted.
|
|
|
|
# It is important to have a way to invoke a recovery shell in case
|
|
|
|
# the boot scripts are messed up, but also important to modify the
|
2024-03-27 10:04:10 -04:00
|
|
|
# PCRs if this happens to prevent the TPM Disk Unlock Keys from being revealed.
|
2017-04-12 06:57:58 -04:00
|
|
|
|
2016-07-31 22:39:07 -04:00
|
|
|
# First thing it is vital to mount the /dev and other system directories
|
2017-04-01 23:02:00 -04:00
|
|
|
mkdir /proc /sys /dev /tmp /boot /media 2>&- 1>&-
|
2017-09-20 10:29:14 -04:00
|
|
|
mount /dev 2>/dev/ttyprintk
|
|
|
|
mount /proc 2>/dev/ttyprintk
|
|
|
|
mount /sys 2>/dev/ttyprintk
|
2022-08-25 14:43:31 -04:00
|
|
|
|
2019-06-19 16:27:44 -05:00
|
|
|
if [ "$CONFIG_LINUXBOOT" = "y" ]; then
|
|
|
|
mount /sys/firmware/efi/efivars
|
|
|
|
fi
|
2017-09-20 10:29:14 -04:00
|
|
|
|
2024-04-01 15:20:49 -04:00
|
|
|
# Setup the pty pseudo filesystem
|
2017-09-20 10:29:14 -04:00
|
|
|
mkdir /dev/pts
|
|
|
|
mount /dev/pts 2>/dev/ttyprintk
|
|
|
|
|
|
|
|
if [ ! -r /dev/ptmx ]; then
|
|
|
|
ln -s /dev/pts/ptmx /dev/ptmx
|
|
|
|
fi
|
|
|
|
|
2022-08-25 14:43:31 -04:00
|
|
|
# Needed by bash
|
2023-03-13 12:52:06 -04:00
|
|
|
[ -e /dev/stdin ] || ln -s /proc/self/fd/0 /dev/stdin
|
|
|
|
[ -e /dev/stdout ] || ln -s /proc/self/fd/1 /dev/stdout
|
|
|
|
[ -e /dev/stderr ] || ln -s /proc/self/fd/2 /dev/stderr
|
|
|
|
[ -e /dev/fd ] || ln -s /proc/self/fd /dev/fd
|
2022-08-25 14:43:31 -04:00
|
|
|
|
2017-04-12 06:57:58 -04:00
|
|
|
# Recovery shells will erase anything from here
|
|
|
|
mkdir -p /tmp/secret
|
|
|
|
|
2016-07-31 22:39:07 -04:00
|
|
|
# Now it is safe to print a banner
|
2017-03-31 11:18:46 -04:00
|
|
|
if [ -r /etc/motd ]; then
|
2024-12-16 13:28:34 -05:00
|
|
|
cat /etc/motd >/dev/tty0
|
2017-03-31 11:18:46 -04:00
|
|
|
fi
|
2016-07-25 10:08:53 -04:00
|
|
|
|
2016-07-31 22:39:07 -04:00
|
|
|
# Load the date from the hardware clock, setting it in local time
|
|
|
|
hwclock -l -s
|
|
|
|
|
2024-02-02 13:24:34 -05:00
|
|
|
# When mounting a filesystem, try exFAT last, since it logs errors if the
|
|
|
|
# filesystem is not exFAT, and the errors go to the console. Those errors are
|
|
|
|
# spurious when the medium is iso9660. By default in our config, the only
|
|
|
|
# filesystem after exFAT is iso9660, move exFAT last.
|
|
|
|
(grep -v '^\texfat$' /proc/filesystems && echo -e '\texfat') >/etc/filesystems
|
|
|
|
|
2024-12-16 13:28:34 -05:00
|
|
|
# Read the system configuration parameters from build time board configuration
|
2017-04-12 06:57:58 -04:00
|
|
|
. /etc/config
|
2024-12-16 13:28:34 -05:00
|
|
|
# import global functions
|
|
|
|
. /etc/functions
|
2017-04-12 06:57:58 -04:00
|
|
|
|
2024-12-16 13:28:34 -05:00
|
|
|
# export user related content from cbfs
|
|
|
|
if [ "$CONFIG_COREBOOT" = "y" ]; then
|
|
|
|
/bin/cbfs-init
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Override CONFIG_USE_BLOB_JAIL if needed and persist via user config
|
|
|
|
if lspci -n | grep -E -q "8086:(2723|4df0)"; then
|
|
|
|
if ! cat /etc/config.user 2>/dev/null | grep -q "USE_BLOB_JAIL"; then
|
|
|
|
echo "CONFIG_USE_BLOB_JAIL=y" >>/etc/config.user
|
|
|
|
fi
|
2024-11-27 13:27:13 -05:00
|
|
|
fi
|
|
|
|
|
2024-12-16 13:28:34 -05:00
|
|
|
# Override CONFIG_TPM and CONFIG_TPM2_TOOLS from /etc/config with runtime value
|
|
|
|
# determined above.
|
|
|
|
#
|
|
|
|
# Values in user config have higher priority during combining thus effectively
|
|
|
|
# changing the value for the rest of the scripts which source /tmp/config.
|
|
|
|
|
|
|
|
#Only set CONFIG_TPM and CONFIG_TPM2_TOOLS if they are not already set in /etc/config.user
|
|
|
|
if ! grep -q 'CONFIG_TPM=' /etc/config.user 2>/dev/null; then
|
|
|
|
echo "export CONFIG_TPM=\"$CONFIG_TPM\"" >>/etc/config.user
|
|
|
|
fi
|
|
|
|
if ! grep -q 'CONFIG_TPM2_TOOLS=' /etc/config.user 2>/dev/null; then
|
|
|
|
echo "export CONFIG_TPM2_TOOLS=\"$CONFIG_TPM2_TOOLS\"" >>/etc/config.user
|
|
|
|
fi
|
|
|
|
|
|
|
|
# CONFIG_BASIC was previously CONFIG_PUREBOOT_BASIC in the PureBoot distribution.
|
|
|
|
# Substitute it in config.user if present for backward compatibility.
|
|
|
|
sed -i -e 's/^export CONFIG_PUREBOOT_BASIC=/export CONFIG_BASIC=/g' /etc/config.user
|
|
|
|
|
|
|
|
# Combine user configuration overrides from CBFS's /etc/config.user
|
|
|
|
combine_configs
|
|
|
|
# Load the user configuration parameters from combined config
|
|
|
|
. /tmp/config
|
|
|
|
|
|
|
|
# Enable maximum debug info from here if config.user extracted and combined from CBFS had CONFIG_DEBUG_OUTPUT=y
|
2023-10-10 12:28:52 -04:00
|
|
|
if [ "$CONFIG_DEBUG_OUTPUT" = "y" ]; then
|
2024-12-16 13:28:34 -05:00
|
|
|
#Output all kernel messages to console (8=debug)
|
|
|
|
#DEBUG and TRACE calls will be in dmesg and on console
|
2023-10-20 16:20:17 -04:00
|
|
|
# config.user extracted and combined from CBFS had CONFIG_DEBUG_OUTPUT=y
|
2024-12-16 16:39:12 -05:00
|
|
|
TRACE_FUNC
|
2024-12-16 13:28:34 -05:00
|
|
|
dmesg -n 8
|
2024-12-16 16:27:49 -05:00
|
|
|
DEBUG "Full debug output enabled from this point: output both in dmesg and on console (equivalent of passing debug to kernel cmdline)"
|
2024-12-16 13:28:34 -05:00
|
|
|
fi
|
|
|
|
|
|
|
|
# report if we are in quiet mode, tell user measurements logs available under /tmp/debug.log
|
|
|
|
if [ "$CONFIG_QUIET_MODE" = "y" ]; then
|
|
|
|
# check origin of quiet mode setting =y: if it is under /etc/config.user then early cbfs-init outputs are not suppressible
|
|
|
|
# if it is under /etc/config then early cbfs-init outputs are suppressible
|
|
|
|
if ! grep -q 'CONFIG_QUIET_MODE="y"' /etc/config.user 2>/dev/null; then
|
2024-12-17 13:40:44 -05:00
|
|
|
echo "Quiet mode enabled: refer to '/tmp/debug.log' for boot measurements traces" >/dev/tty0
|
2024-12-16 13:28:34 -05:00
|
|
|
else
|
2024-12-17 13:40:44 -05:00
|
|
|
echo "Runtime Quiet mode: refer to '/tmp/debug.log' for additional boot measurements traces past this point" >/dev/tty0
|
2024-12-16 13:28:34 -05:00
|
|
|
echo "To suppress earlier boot measurements traces, enable CONFIG_QUIET_MODE=y in your board configuration at build time." >/dev/tty0
|
|
|
|
fi
|
2023-10-10 12:28:52 -04:00
|
|
|
fi
|
|
|
|
|
2024-12-16 11:46:37 -05:00
|
|
|
TRACE_FUNC
|
2023-02-18 12:58:43 -05:00
|
|
|
|
2024-04-01 15:20:49 -04:00
|
|
|
# make sure we have sysctl requirements
|
|
|
|
if [ ! -d /proc/sys ]; then
|
|
|
|
warn "BUG!!! The following requirements to apply runtime kernel tweaks are missing:"
|
|
|
|
warn "CONFIG_SYSCTL=y"
|
|
|
|
warn "CONFIG_PROC_SYSCTL=y"
|
|
|
|
warn "Please open an issue"
|
|
|
|
fi
|
|
|
|
|
2024-12-16 13:28:34 -05:00
|
|
|
if [ ! -e /proc/sys/vm/panic_on_oom ]; then
|
|
|
|
warn "BUG!!! Requirements to setup Panic when under Out Of Memory situation through PROC_SYSCTL are missing (panic_on_oom was not enabled)"
|
2024-04-01 15:20:49 -04:00
|
|
|
warn "Please open an issue"
|
|
|
|
else
|
|
|
|
DEBUG "Applying panic_on_oom setting to sysctl"
|
2024-12-16 13:28:34 -05:00
|
|
|
echo 1 >/proc/sys/vm/panic_on_oom
|
2024-04-01 15:20:49 -04:00
|
|
|
fi
|
|
|
|
|
2024-12-16 16:39:12 -05:00
|
|
|
# set CONFIG_TPM dynamically off before init if no TPM device is present
|
2022-08-25 14:43:31 -04:00
|
|
|
if [ ! -e /dev/tpm0 ]; then
|
2022-08-20 00:21:39 +03:00
|
|
|
CONFIG_TPM='n'
|
2022-08-25 14:43:31 -04:00
|
|
|
CONFIG_TPM2_TOOLS='n'
|
2022-08-20 00:21:39 +03:00
|
|
|
fi
|
|
|
|
|
2021-10-29 13:29:31 -04:00
|
|
|
#Specify whiptail background colors cues under FBWhiptail only
|
2021-12-17 14:45:53 -05:00
|
|
|
if [ -x /bin/fbwhiptail ]; then
|
2021-10-29 13:29:31 -04:00
|
|
|
export BG_COLOR_WARNING="${CONFIG_WARNING_BG_COLOR:-"--background-gradient 0 0 0 150 125 0"}"
|
|
|
|
export BG_COLOR_ERROR="${CONFIG_ERROR_BG_COLOR:-"--background-gradient 0 0 0 150 0 0"}"
|
2024-09-07 16:19:17 -04:00
|
|
|
export BG_COLOR_MAIN_MENU="normal"
|
2021-12-17 14:45:53 -05:00
|
|
|
else
|
2024-06-06 22:59:13 +00:00
|
|
|
export TEXT_BG_COLOR_WARNING="${CONFIG_WARNING_TEXT_BG_COLOR:-"yellow"}"
|
|
|
|
export TEXT_BG_COLOR_ERROR="${CONFIG_ERROR_TEXT_BG_COLOR:-"red"}"
|
2024-09-07 16:19:17 -04:00
|
|
|
export BG_COLOR_MAIN_MENU="normal"
|
2021-10-29 13:29:31 -04:00
|
|
|
fi
|
|
|
|
|
2023-03-13 13:10:24 -04:00
|
|
|
if [ "$CONFIG_TPM" = "y" ]; then
|
2022-08-25 14:43:31 -04:00
|
|
|
# Initialize tpm2 encrypted sessions here
|
|
|
|
tpmr startsession
|
|
|
|
fi
|
|
|
|
|
2018-04-29 19:58:44 -07:00
|
|
|
if [ "$CONFIG_LINUXBOOT" = "y" ]; then
|
2024-12-16 16:39:12 -05:00
|
|
|
# Initialize the UEFI environment for linuxboot boards
|
2018-04-29 19:58:44 -07:00
|
|
|
/bin/uefi-init
|
|
|
|
fi
|
2018-12-01 08:37:34 -05:00
|
|
|
|
|
|
|
# Set GPG_TTY before calling gpg in key-init
|
2024-11-27 13:17:56 -05:00
|
|
|
#TODO: do better then this; on dual console gpg only interacts with main console (affects Talos-2 and all whiptail variants)
|
2020-01-25 20:45:03 -08:00
|
|
|
export GPG_TTY=/dev/console
|
2018-12-01 08:37:34 -05:00
|
|
|
|
2023-10-10 12:28:52 -04:00
|
|
|
# Initialize gpnupg with distro/user keys and setup the keyrings
|
2024-12-16 13:28:34 -05:00
|
|
|
/bin/key-init
|
2023-10-10 12:28:52 -04:00
|
|
|
|
2018-03-10 15:40:07 -08:00
|
|
|
# Setup recovery serial shell
|
|
|
|
if [ ! -z "$CONFIG_BOOT_RECOVERY_SERIAL" ]; then
|
|
|
|
stty -F "$CONFIG_BOOT_RECOVERY_SERIAL" 115200
|
2024-12-09 12:48:16 -05:00
|
|
|
pause_recovery 'Serial console recovery shell' \
|
2024-12-16 13:28:34 -05:00
|
|
|
<"$CONFIG_BOOT_RECOVERY_SERIAL" \
|
|
|
|
>"$CONFIG_BOOT_RECOVERY_SERIAL" 2>&1 &
|
2016-07-31 22:39:07 -04:00
|
|
|
fi
|
2017-03-27 18:03:09 -04:00
|
|
|
|
2020-02-19 11:40:34 -06:00
|
|
|
# load USB modules for boards using a USB keyboard
|
2024-01-09 09:43:28 -05:00
|
|
|
if [ "$CONFIG_USB_KEYBOARD_REQUIRED" = y ] || [ "$CONFIG_USER_USB_KEYBOARD" = "y" ]; then
|
2020-02-19 11:40:34 -06:00
|
|
|
enable_usb
|
|
|
|
fi
|
|
|
|
|
2017-07-18 13:44:02 -04:00
|
|
|
# If the user has been holding down r, enter a recovery shell
|
|
|
|
# otherwise immediately start the configured boot script.
|
|
|
|
# We don't print a prompt, since this is a near instant timeout.
|
2017-04-12 06:57:58 -04:00
|
|
|
read \
|
2017-07-18 13:44:02 -04:00
|
|
|
-t 0.1 \
|
2017-04-12 06:57:58 -04:00
|
|
|
-n 1 \
|
|
|
|
boot_option
|
|
|
|
echo
|
|
|
|
|
|
|
|
if [ "$boot_option" = "r" ]; then
|
|
|
|
# Start an interactive shell
|
|
|
|
recovery 'User requested recovery shell'
|
|
|
|
# just in case...
|
2018-03-10 15:40:07 -08:00
|
|
|
exit
|
2023-11-03 16:40:06 -04:00
|
|
|
elif [ "$boot_option" = "o" ]; then
|
2024-11-17 14:07:10 -05:00
|
|
|
# Launch OEM Factory Reset mode
|
2024-12-16 13:28:34 -05:00
|
|
|
echo -e "***** Entering OEM Factory Reset mode\n" >/dev/tty0
|
2024-11-17 14:07:10 -05:00
|
|
|
oem-factory-reset --mode oem
|
2023-11-03 16:40:06 -04:00
|
|
|
# just in case...
|
|
|
|
exit
|
2017-04-12 06:57:58 -04:00
|
|
|
fi
|
2017-03-31 11:18:46 -04:00
|
|
|
|
2023-06-21 14:36:28 -04:00
|
|
|
if [ "$CONFIG_BASIC" = "y" ]; then
|
2024-12-16 13:28:34 -05:00
|
|
|
echo -e "***** BASIC mode: tamper detection disabled\n" >/dev/tty0
|
2022-03-15 12:05:04 -05:00
|
|
|
fi
|
|
|
|
|
2020-06-25 09:58:01 +02:00
|
|
|
# export firmware version
|
2024-04-19 14:16:41 -04:00
|
|
|
export FW_VER=$(fw_version)
|
2020-06-25 09:58:01 +02:00
|
|
|
|
2018-12-06 16:34:47 -08:00
|
|
|
# Add our boot devices into the /etc/fstab, if they are defined
|
|
|
|
# in the configuration file.
|
|
|
|
if [ ! -z "$CONFIG_BOOT_DEV" ]; then
|
2024-12-16 13:28:34 -05:00
|
|
|
echo >>/etc/fstab "$CONFIG_BOOT_DEV /boot auto defaults,ro 0 0"
|
2018-12-06 16:34:47 -08:00
|
|
|
fi
|
|
|
|
|
2023-08-09 16:06:08 -04:00
|
|
|
# Set the console font if needed
|
2024-12-16 13:28:34 -05:00
|
|
|
setconsolefont.sh
|
2023-08-09 16:06:08 -04:00
|
|
|
|
2023-06-21 14:36:28 -04:00
|
|
|
if [ "$CONFIG_BASIC" = "y" ]; then
|
2022-03-15 12:05:04 -05:00
|
|
|
CONFIG_BOOTSCRIPT=/bin/gui-init-basic
|
|
|
|
export CONFIG_HOTPKEY=n
|
|
|
|
fi
|
|
|
|
|
2022-11-28 15:15:38 -05:00
|
|
|
# Perform board-specific init if present
|
|
|
|
if [ -x /bin/board-init.sh ]; then
|
|
|
|
/bin/board-init.sh
|
|
|
|
fi
|
|
|
|
|
2018-03-10 15:40:07 -08:00
|
|
|
if [ ! -x "$CONFIG_BOOTSCRIPT" -a ! -x "$CONFIG_BOOTSCRIPT_NETWORK" ]; then
|
|
|
|
recovery 'Boot script missing? Entering recovery shell'
|
|
|
|
else
|
|
|
|
if [ -x "$CONFIG_BOOTSCRIPT_NETWORK" ]; then
|
|
|
|
echo '***** Network Boot:' $CONFIG_BOOTSCRIPT_NETWORK
|
|
|
|
$CONFIG_BOOTSCRIPT_NETWORK
|
|
|
|
echo '***** Network Boot Completed:' $CONFIG_BOOTSCRIPT_NETWORK
|
|
|
|
# not blocking
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -x "$CONFIG_BOOTSCRIPT" ]; then
|
|
|
|
echo '***** Normal boot:' $CONFIG_BOOTSCRIPT
|
2022-07-22 20:27:28 +03:00
|
|
|
|
|
|
|
if [ -x /bin/setsid ] && [ -x /bin/agetty ]; then
|
|
|
|
for console in $CONFIG_BOOT_EXTRA_TTYS; do
|
|
|
|
setsid agetty -aroot -l"$CONFIG_BOOTSCRIPT" "$console" linux &
|
|
|
|
done
|
|
|
|
fi
|
2024-12-16 13:28:34 -05:00
|
|
|
|
2023-10-10 12:28:52 -04:00
|
|
|
#Setup a control tty so that all terminals outputs correct tty when tty is called
|
|
|
|
exec cttyhack "$CONFIG_BOOTSCRIPT"
|
2018-03-10 15:40:07 -08:00
|
|
|
else
|
|
|
|
# wait for boot via network to occur
|
|
|
|
pause_recovery 'Override network boot. Entering recovery shell'
|
|
|
|
fi
|
|
|
|
fi
|
2017-03-31 11:18:46 -04:00
|
|
|
|
2023-07-11 10:20:56 -04:00
|
|
|
# We should never reach here, but just in case...
|
|
|
|
recovery 'Boot script failure? Entering recovery shell'
|