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 d11c071
Show file tree
Hide file tree
Showing 12 changed files with 323 additions and 21 deletions.
2 changes: 2 additions & 0 deletions tp2bmc/board/tp2bmc/factory_overlay/files_to_delete.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
etc/init.d/S11bmc-otg
etc/init.d/S50sshd
63 changes: 63 additions & 0 deletions tp2bmc/board/tp2bmc/factory_overlay/upper/etc/inittab
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# /etc/inittab
#
# This inittab is a basic inittab sample for sysvinit, which mimics
# Buildroot's default inittab for BusyBox.
id:3:initdefault:

si0::sysinit:/bin/mount -t proc proc /proc
si1::sysinit:/bin/mount -o remount,rw /
si2::sysinit:/bin/mkdir -p /dev/pts /dev/shm
si3::sysinit:/bin/mount -a
si4::sysinit:/bin/mkdir -p /run/lock/subsys
si5::sysinit:/sbin/swapon -a
si6::sysinit:/bin/ln -sf /proc/self/fd /dev/fd 2>/dev/null
si7::sysinit:/bin/ln -sf /proc/self/fd/0 /dev/stdin 2>/dev/null
si8::sysinit:/bin/ln -sf /proc/self/fd/1 /dev/stdout 2>/dev/null
si9::sysinit:/bin/ln -sf /proc/self/fd/2 /dev/stderr 2>/dev/null
si10::sysinit:/bin/hostname -F /etc/hostname
rcS:12345:wait:/etc/init.d/rcS

S0::respawn:/sbin/getty -L ttyS0 115200 vt100 # GENERIC_SERIAL

# Stuff to do for the 3-finger salute
#ca::ctrlaltdel:/sbin/reboot

# cat /mnt/
overlay/ rom/ sdcard/
# cat /mnt/overlay/upper/
etc/ factory/ mnt/ root/ run/ var/
# cat /mnt/overlay/upper/etc/init
init.d/ inittab
# cat /mnt/overlay/upper/etc/inittab
# /etc/inittab
#
# This inittab is a basic inittab sample for sysvinit, which mimics
# Buildroot's default inittab for BusyBox.
id:3:initdefault:

si0::sysinit:/bin/mount -t proc proc /proc
si1::sysinit:/bin/mount -o remount,rw /
si2::sysinit:/bin/mkdir -p /dev/pts /dev/shm
si3::sysinit:/bin/mount -a
si4::sysinit:/bin/mkdir -p /run/lock/subsys
si5::sysinit:/sbin/swapon -a
si6::sysinit:/bin/ln -sf /proc/self/fd /dev/fd 2>/dev/null
si7::sysinit:/bin/ln -sf /proc/self/fd/0 /dev/stdin 2>/dev/null
si8::sysinit:/bin/ln -sf /proc/self/fd/1 /dev/stdout 2>/dev/null
si9::sysinit:/bin/ln -sf /proc/self/fd/2 /dev/stderr 2>/dev/null
si10::sysinit:/bin/hostname -F /etc/hostname
rcS:12345:wait:/etc/init.d/rcS

S0::respawn:/sbin/getty -L ttyS0 115200 vt100 # GENERIC_SERIAL

# Stuff to do for the 3-finger salute
#ca::ctrlaltdel:/sbin/reboot

# Stuff to do before rebooting
shd0:06:wait:/etc/init.d/rcK
shd1:06:wait:/sbin/swapoff -a
shd2:06:wait:/bin/umount -a -r

# The usual halt or reboot actions
hlt0:0:wait:/sbin/halt -dhp
reb0:6:wait:/sbin/reboot
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
-----BEGIN CERTIFICATE-----
MIIFITCCAwmgAwIBAgIUOjStH7igh+V9d4y830Nv9DcOeeYwDQYJKoZIhvcNAQEL
BQAwIDEeMBwGA1UEAwwVVHVyaW5nLVBpIHNlbGYgc2lnbmVkMB4XDTcwMDEwMTAw
MDExNFoXDTcwMDEzMTAwMDExNFowIDEeMBwGA1UEAwwVVHVyaW5nLVBpIHNlbGYg
c2lnbmVkMIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEApXbjlJXyaN7L
Bck+QCIuECOvKW44Va6lCYaNVFn4NGhZeIlALaoxmTk7zXYWn1PQqY3SM14DupFm
+sJG4bRYoVDQXjp+G9S/h03W5tu0mhh0QE4ZEIyQ9dDAfM2auYe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A5nIxGerTGCTxWkEK42aP4PRbbwjRZLDBEF8cy8eIfSU0I5esIA2Kub5
QnmCdbmzeaEPeMp++JbtjhKu5iPR3KPG7wuZ+nIJ+1UbC/XBNy/f086dPCJehVN0
pxuUMCH5g54Q5sC4Xg5KGLyHdxTI9dlbSfQCoPoIBn2L2uknSCNvh049+WWfNGS4
nPg0KZ9mDFjEp7qC/Jq3+mRlndjIBa1y2R+ZB+liqiQOrf+SHKJJYibIDhDseIKa
v0CpB4nFbhBqhaqIn4JWmiWntqNkA1jlN0qFcV+zpPX5YzD/9TaNfIKERxLHtoxH
21sArZK4Gl/crAxgh4OHAV3lW4IL
-----END CERTIFICATE-----
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
-----BEGIN PRIVATE KEY-----
MIIJQwIBADANBgkqhkiG9w0BAQEFAASCCS0wggkpAgEAAoICAQClduOUlfJo3ssF
yT5AIi4QI68pbjhVrqUJho1UWfg0aFl4iUAtqjGZOTvNdhafU9CpjdIzXgO6kWb6
wkbhtFihUNBeOn4b1L+HTdbm27SaGHRAThkQjJD10MB8zZq5h5fFvd28OuTYU0kr
YMbpc9BAlsirl9mGQ2dX/zf8iggtAy7njgFjeqBiAncPSzn/EQ/srRxF0VBWTtK1
GN/NXapb1/0boNk0Jebr5SV6boVIzOaGduutY0Bm9kLWTq7pvChDMTu4X92mX2dj
Wo+fYfCq325ml0Qx6QCVDM0xMNeObIGNc7jEtYJEShr56ikCTDKQ2vo1KbMDQvi3
u0ihlD5IZ/7kIU8BWOdCfj4TKM2VC9t8w6Y2ExtSiWdv3u40Y0bXicl4rhq7lHXH
3ifCrjrzigLguCOl7u8Qjp1YlC7X050anV+B8uNVWuqWWpU7pQt4NxIXOuvzuC8A
lRLXlewonVTN1U3x41BDJUlsVxteVdUfjm2z5VilONhBS/iA+CUfJ/XkP2RI5j4O
5BdFos2opS0toZI0GkC8mK21RJId8ALJknZpyC8nEu95AeAIqORjlmr193G9UHXH
QptFkI1cJJVL6CAZRguZig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GgwQ3HQyXVTgU5hRlbGhBpWhzH/ZG
h0A9AoIBADAT3SV1JmYmHaUoY8hoai8s+/MXHlKNw15qj7Qmo8aqHZlF+p6hkp25
ClkYqot/AFApNdfayZuiURU3BM88U+k4NwXufhPq/2fqxVH++kRv/Zljzg5W/zMQ
fIisII8yLSWehq5t04dSQhuIljPvB+TWYI6LZH2rifB1tfaGyYan/t5fRFOLQ+z7
EU5azAjsduCLFpKJ4tBRiUl8PGijmF4M8Q5ZjvUI08raeWUZHCL7L6/iV/v3ya+k
+O9mKwQn+Z6OlVTrf8zg/vfMxtjAaRUN4o8ZqqS0hHXxcFtlYHhQkJJgKMJlk9tB
37StHzHMK9rTgs9akfnlZcJsDfMo8X0=
-----END PRIVATE KEY-----
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}" > /dev/null

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 (1..4)
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

33 changes: 33 additions & 0 deletions tp2bmc/board/tp2bmc/factory_overlay/upper/factory/helpers.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/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
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
}
55 changes: 55 additions & 0 deletions tp2bmc/board/tp2bmc/factory_overlay/upper/factory/run_all_tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/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/factory_overlay/upper/root/.profile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/factory/run_all_tests.sh
13 changes: 13 additions & 0 deletions tp2bmc/board/tp2bmc/genimage.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,22 @@ image tp2-bmc-firmware-sdcard.img {
# Equivalent to 370 LEBs of NAND:
size = 45880K
}

partition overlay {
image = "factory_overlay.ext4"
}
}

image sdcard-bootpart.img {
vfat {}
size = 16M
}

image factory_overlay.ext4 {
ext4 {
label = "overlay"
features = "filetype"
}
srcpath = "factory_overlay"
size = 32M
}
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
12 changes: 12 additions & 0 deletions tp2bmc/board/tp2bmc/post_image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,18 @@ mkimage -A arm -T ramdisk -d installer.cpio.gz sdcard-bootpart/boot/install.img
cp -r $BOARD_DIR/sdcard_overlay/* sdcard-bootpart/
cp zImage *.dtb sdcard-bootpart/boot/

# prepare factory overlay partition
cp -r "$BOARD_DIR"/factory_overlay .
# Git doesnt support c nodes, manually create them from a .txt file
while IFS= read -r line
do
dest="factory_overlay/upper/${line}"
echo "deleting ${line} in overlay"
rm -f "$dest"
mknod "$dest" c 0 0
chmod 000 "$dest"
done < "factory_overlay/files_to_delete.txt"

# Generate the SD image
[ -d tmp/ ] && rm -fr tmp/
genimage --inputpath . --outputpath . --rootpath sdcard-bootpart \
Expand Down

0 comments on commit d11c071

Please sign in to comment.