bmc-debug-tools/boot_and_check.sh

121 lines
2.4 KiB
Bash
Executable File

#!/usr/bin/env bash
#
# KGPE-D16 firmware boot process debugging tools via BMC
#
# Copyright (C) 2024 Adrien 'neox' Bourmault <neox@gnu.org>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
source power.inc
source logs.inc
buffer=$(mktemp)
greyblue='\033[38;5;245m'
color_reset='\033[0m'
CRIT=$(mktemp)
ERR=$(mktemp)
WARN=$(mktemp)
INFO=$(mktemp)
echo 0 > $CRIT
echo 0 > $ERR
echo 0 > $WARN
echo 0 > $INFO
new_critical()
{
local crit=$(cat $CRIT)
echo $((crit+1)) > $CRIT
echo Stopping logs...
stop_logs
echo Halting...
halt
pkill -P $$
exit 0
}
new_error()
{
local err=$(cat $ERR)
echo $((err+1)) > $ERR
}
new_warning()
{
local warn=$(cat $WARN)
echo $((warn+1)) > $WARN
}
new_info()
{
local info=$(cat $INFO)
echo $((info+1)) > $INFO
}
## Main program ---------------------------------------------------------------
echo 'Welcome to the KGPE-D16 debugging tools'
echo 'Copyright (C) 2024 Adrien "neox" Bourmault <neox@gnu.org>'
echo " "
echo Log file at ${buffer}
echo " "
check_logs_still_on
react_to_info $buffer new_info 'starting' &
react_to_info $buffer new_info 'payload' &
react_to_warn $buffer new_warning 'Warning' &
react_to_warn $buffer new_warning 'AMD_CB_EventNotify' &
react_to_warn $buffer new_warning 'amd_ht_fixup' &
react_to_err $buffer new_error 'Error' &
react_to_critical $buffer new_critical 'fatal' &
react_to_critical $buffer new_critical 'FAULT' &
echo Starting logs...
start_logs $buffer
echo Booting up...
boot
wait_for $buffer 'Debian GNU/Linux 9'
echo Criticals: $(cat $CRIT)
echo Errors: $(cat $ERR)
echo Warnings: $(cat $WARN)
if [ "$(cat $CRIT)" -le 0 ]; then
echo System successfully booted!
else
echo Summary: fail to boot.
pkill -P $$
exit 0
fi
wait_for $buffer 'link becomes ready'
echo Network ready
wait_for $buffer 'tty'
echo Login should be ready
echo Shutting down
shutdown
echo Successful power cycle!
pkill -P $$
exit 0