Skip to content

Commit

Permalink
factory sdcard image:
Browse files Browse the repository at this point in the history
* burns eeprom if contents is empty
* flashes firmware if to flash if empty
* starts test runner on login
* test runner executes certain scripts prefixed with 000-
* added first couple of tests
  • Loading branch information
svenrademakers committed May 23, 2024
1 parent 04acfc8 commit bddf4df
Show file tree
Hide file tree
Showing 9 changed files with 164 additions and 88 deletions.
35 changes: 14 additions & 21 deletions tp2bmc/board/tp2bmc/install.scr
Original file line number Diff line number Diff line change
@@ -1,29 +1,22 @@
# SPDX-License-Identifier: GPL-2.0+
# Copyright (C) 2023 Sam Edwards <CFSworks@gmail.com>
# Copyright (C) 2024 Sven Rademakers <sven.rademakers@gmail.com>

installer_marker=/install.txt
# load EEPROM data
tpi_info

# The installer doesn't have any concept of "safe mode," so if this is
# requested, the user is most likely trying to say that the installer should
# NOT run. Perhaps the user is trying to get into safe mode to erase the
# installer microSD card because it's too inconvenient to remove?
if test "${bootmode}" != "safemode"; then
echo Checking ${installer_marker}...
if test -e ${devtype} ${devnum}:${distro_bootpart} ${installer_marker}; then
echo ...exists: entering installer
if test -z "${tpi_crc_ok}"; then
echo new eeprom detected, burning default..
run burn_eeprom

# read hardware version from EEPROM
tpi_info hw_version tpi_hw_version
linux_bootpart=2
linux_bootpart=2

# Load image, initramfs, and FDT
if load ${devtype} ${devnum}:${linux_bootpart} ${loadaddr} /boot/turing-pi2.itb \
&& load ${devtype} ${devnum}:${distro_bootpart} ${ramdisk_addr_r} /boot/install.img
then
env set bootargs loglevel=4
bootm ${loadaddr}#config-${tpi_hw_version:-v2.4.0} ${ramdisk_addr_r}
fi
else
echo ...does not exist: proceeding with normal boot
# Load image, initramfs, and FDT
if load ${devtype} ${devnum}:${linux_bootpart} ${loadaddr} /boot/turing-pi3.itb && \
load ${devtype} ${devnum}:${distro_bootpart} ${ramdisk_addr_r} /boot/install.img; then
env set bootargs loglevel=4 skip_confirm
bootm ${loadaddr}#config-${tpi_hw_version} ${ramdisk_addr_r}
fi
else
echo firmware already burned, continuing with boot..
fi
65 changes: 0 additions & 65 deletions tp2bmc/board/tp2bmc/overlay/etc/init.d/S11bmc-otg

This file was deleted.

11 changes: 11 additions & 0 deletions tp2bmc/board/tp2bmc/overlay/factory/001-hello_world.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash

# Prompt the user for input
echo "Please enter some text:"

# Read the user input
read user_input

# Echo the input back to the user
echo "You entered: $user_input"

20 changes: 20 additions & 0 deletions tp2bmc/board/tp2bmc/overlay/factory/002-bmc_ethernet.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash

set -e

# Extract the gateway address for the eth0 interface
gateway=$(ip route show dev eth0 | grep default | awk '{print $3}')

# Check if the gateway was found
if [ -z "$gateway" ]; then
echo "No gateway found for eth0"
exit 1
fi

ping -c 4 "${gateway}"

tpi power on

echo "go to your router and verify all 4 nodes are present in the DHCP client list"
echo "Press Enter to continue..."
read -r
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash

source helpers.sh

for n in (0..3)
do
tpi advanced msd --node "${n}"
exit_code=$?
sleep 3
echo "Node ${n} is exposed as a mass storage device. Go to your computer and verify you can connect to the drive."

if [[ $exit_code -ne 0 ]]; then
if try_again; then
tpi advanced msd --node "${n}"
sleep 8
else
tpi advanced normal --node "${n}"
exit 1
fi
else
if ! confirm; then
tpi advanced normal --node "${n}"
exit 1
fi
fi
tpi advanced normal --node "${n}"
done

35 changes: 35 additions & 0 deletions tp2bmc/board/tp2bmc/overlay/factory/helpers.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/bash
#
try_again() {
while true; do
read -p "Do you want to try again? [Y/n]: " -r REPLY
# If the user presses Enter or types 'y'/'Y'
if [[ -z "$REPLY" || "$REPLY" =~ ^[Yy]$ ]]; then
return 0
# If the user types 'n'/'N'
elif [[ "$REPLY" =~ ^[Nn]$ ]]; then
return 1
else
# Prompt the user to try again for invalid input
echo "Invalid input, please try again."
fi
done
}

confirm() {
while true; do
read -p "Do you want to continue? [Y/n]: " -r REPLY
# If the user presses Enter or types 'y'/'Y'
if [[ -z "$REPLY" || "$REPLY" =~ ^[Yy]$ ]]; then
echo "Confirmed"
return 0
# If the user types 'n'/'N'
elif [[ "$REPLY" =~ ^[Nn]$ ]]; then
echo "Cancelled"
return 1
else
# Prompt the user to try again for invalid input
echo "Invalid input, please try again."
fi
done
}
54 changes: 54 additions & 0 deletions tp2bmc/board/tp2bmc/overlay/factory/run_all_tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/bin/bash
# Define color codes
RED='\033[0;31m'
YELLOW='\033[0;33m'
GREEN='\033[0;32m'
NC='\033[0m' # No Color

# Define the directory to search
TEST_DIR="/factory"
NON_EXECUTABLE_FILES=()
EXIT_CODE=0

nr_of_executed_tests=0
# Iterate over files in the test directory that are prefixed with 3 numbers
# followed by a dash. e.g. "999-"
for FILE in "$TEST_DIR"/[0-9][0-9][0-9]-*; do
# Check if the file exists and is executable
if [[ -x "$FILE" ]]; then
FILENAME=$(basename "$FILE")
test_id="${FILENAME:0:3}"
test_name="${FILENAME:4}"
test_name="${test_name%%.*}"
test_name="${test_name//_/ }"

echo -e " [${test_id}] Running ${test_name}...\t"
"$FILE"
EXIT_CODE=$?

# Increment the counter
((nr_of_executed_tests++))
echo -ne " [${test_id}] ${test_name} => "
if [[ $EXIT_CODE -ne 0 ]]; then
echo -e "${RED}FAIL:${NC} exited with code $EXIT_CODE"
break
else
echo -e "${GREEN}OK${NC}"
fi
else
NON_EXECUTABLE_FILES+=("$FILE")
fi
done

if [[ ${#NON_EXECUTABLE_FILES[@]} -ne 0 ]]; then
echo -e "${YELLOW}Warning: skipped the following files as they are not executable or do not exist:${NC}"
for NON_EXECUTABLE_FILE in "${NON_EXECUTABLE_FILES[@]}"; do
echo -e "\t$NON_EXECUTABLE_FILE"
done
fi

if [[ $EXIT_CODE -eq 0 ]]; then
echo -e "${GREEN}${nr_of_executed_tests} tests executed successfully.${NC}"
fi
exit $EXIT_CODE

1 change: 1 addition & 0 deletions tp2bmc/board/tp2bmc/overlay/root/.profile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/factory/run_all_tests.sh
3 changes: 1 addition & 2 deletions tp2bmc/board/tp2bmc/uboot.env
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ setexpr _hdr_offset ${tempaddr_r} + ${_hdr_offset};\
mw ${_hw_offset} ${eeprom_ver} 1;\
crc32 ${_hdr_offset} ${_crc_len} ${_crc_offset};\
i2c write ${tempaddr_r} 0x50 0 ${_board_info_len};\
env delete _crc_offset _hdr_offset _hw_offset _board_info_len _crc_len;\
reset
env delete _crc_offset _hdr_offset _hw_offset _board_info_len _crc_len

###############################################################################
############################### ETHERNET SWITCH ###############################
Expand Down

0 comments on commit bddf4df

Please sign in to comment.