Skip to content

Commit

Permalink
factory: add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
svenrademakers committed Jun 1, 2024
1 parent 7e6f45e commit e8fd871
Show file tree
Hide file tree
Showing 21 changed files with 401 additions and 78 deletions.
38 changes: 17 additions & 21 deletions tp2bmc/board/tp2bmc/factory_install.scr
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,27 @@

# read hardware version from EEPROM
tpi_info hw_version tpi_hw_version
ubi part ubi

if test -z "$tpi_crc_ok"; then
echo eeprom crc failure, rewrite version ${eeprom_ver}
run burn_eeprom
fi

linux_bootpart=2
if load ${devtype} ${devnum}:${linux_bootpart} ${loadaddr} /boot/turing-pi2.itb \
&& load ${devtype} ${devnum}:${distro_bootpart} ${ramdisk_addr_r} /boot/install.img
then
if ubi check rootfs
then
# if there is a rootfs partition on the ubi volume,
# We assume flashing is done.
echo turing-pi firmware already installed..
# boot "normally". let the boot.scr scan the rootfs partition on the
# SDcard and boot it. `boot_unlocked` signals that we want to release the write
# protection on the boot partition and eeprom.
env set boot_unlocked 0
else
# run installer
env set bootargs "loglevel=4 skip_confirm no_eject"
bootm ${loadaddr}#config-${tpi_hw_version:-v2.4.0} ${ramdisk_addr_r}
fi
install_magic=0x12341234
install_addr=0x0709010C
mw ${loadaddr} ${install_magic}

if cmp ${loadaddr} ${install_addr} 1; then
echo post firmware install, skipping factory boot
mw ${install_addr} 0x00000000
md ${install_addr}
ubi part ubi
env set devtype ubi
env set devnum 0
run bootcmd_ubi_primary
else
echo "Unable to load /boot/turing-pi2.itb or boot/install.img"
echo booting factory image
# let the boot.scr scan the rootfs partition on the
# SDcard and boot it. `boot_unlocked` signals that we want to release the write
# protection on the boot partition and eeprom.
env set boot_unlocked 0
fi
2 changes: 0 additions & 2 deletions tp2bmc/board/tp2bmc/factory_overlay/files_to_delete.txt
Original file line number Diff line number Diff line change
@@ -1,2 +0,0 @@
etc/init.d/S11bmc-otg
etc/init.d/S50sshd
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
#!/bin/bash

source helpers.sh
ASSERT_VERSION=4111
ASSERT_MODEL_NAME="Turing Pi 2 (v2.5.1)"

model=$(< /proc/device-tree/model tr -d '\0')

if [[ "$model" != "$ASSERT_MODEL_NAME" ]]; then
echo "Error: '$model' != 'Turing Pi 2 (v2.5.1)'"
exit 1
fi
source config.sh

eeprom=$(ls /sys/bus/i2c/devices/*/eeprom)
result=$(dd if="$eeprom" bs=1 skip=8 count=2 2>/dev/null | hexdump -e '1/1 "%02x"')
Expand All @@ -18,3 +9,10 @@ if [[ "$result" != "$ASSERT_VERSION" ]]; then
echo "Error: expected eeprom version '$ASSERT_VERSION' got '$result'"
exit 1
fi

model=$(< /proc/device-tree/model tr -d '\0')

if [[ "$model" != "$ASSERT_MODEL_NAME" ]]; then
echo "Error: got '$model', expected '$ASSERT_MODEL_NAME'"
exit 1
fi
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ set -e

# Check if /sys/class/rtc/rtc0 exists
if [ -d "/sys/class/rtc/rtc0" ]; then
echo "RTC Information:"
echo -e "\tRTC Information:"

# Read and print various RTC attributes
echo "Name: $(cat /sys/class/rtc/rtc0/name)"
echo -e "\tName: $(cat /sys/class/rtc/rtc0/name)"
#echo "Date and Time: $(cat /sys/class/rtc/rtc0/date) $(cat /sys/class/rtc/rtc0/time)"
#echo "Alarm: $(cat /sys/class/rtc/rtc0/wakealarm)"
#echo "Since Epoch: $(cat /sys/class/rtc/rtc0/since_epoch)"
echo "Max User Freq: $(cat /sys/class/rtc/rtc0/max_user_freq)"
echo -e "\tMax User Freq: $(cat /sys/class/rtc/rtc0/max_user_freq)"
else
echo "Error: /sys/class/rtc/rtc0 directory does not exist. No RTC information available."
exit 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ if [ -z "$gateway" ]; then
fi

mac=$(ifconfig eth0 | grep HWaddr | awk '{print $5}')
echo -e "interface:\t'eth0'"
echo -e "MAC: \t\t'${mac}'"
echo -e "\tinterface:\t'eth0'"
echo -e "\tMAC: \t\t'${mac}'"

ping -c 4 "${gateway}" > /dev/null

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
source helpers.sh

get_latest_device_sys() {
ls -lt /sys/class/block | grep -v 'total' | head -n 1 | awk '{print $9}'
ls -lt /sys/class/block | grep -v 'total' | head -n 1
}

verify_msd_connection() {
Expand All @@ -15,7 +15,7 @@ verify_msd_connection() {

if [ ! -f "$mount_point/$file1" ] && [ ! -f "$mount_point/$file2" ]; then
echo "Error: cannot find $file1 or $file2 on mount"
tpi power off > /dev/null
tpi power off > /dev/null
exit 1
fi

Expand All @@ -28,20 +28,25 @@ last_added_device=$(get_latest_device_sys)

for n in {1..4}
do
tpi advanced msd --node "${n}" > /dev/null
echo -en "\tNode $n"
res=$(tpi advanced msd --node "${n}")
exit_code=$?
sleep 2
sleep 3
new_block=$(get_latest_device_sys)
if [[ "$last_added_device" == "$new_block" ]]; then
echo "$res"
echo -e "\n$(uart_output_node "${n}")"
echo "Error: can not detect node $n over USB"
tpi power off > /dev/null
tpi power off > /dev/null
exit 1
fi

partition=$(echo "$new_block" | awk '{print $9}')
# start.elf should be present on the boot partition of the cm4 rpi
# boot.scr should be present on the RK1
verify_msd_connection "${new_block}1" "start.elf" "boot.scr"
# network-config should be present on the RK1
verify_msd_connection "${partition}1" "start.elf" "network-config"

tpi power off --node "${n}" > /dev/null
echo "Node $n ok"
echo " => OK"
done

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#!/bin/bash

source helpers.sh
source config.sh


retrieve_ip_from_uart() {
local n="$1"
local tty="/dev/ttyS${n}"

USERNAME="$RK1_USERNAME"
PASSWORD="$RK1_PASSWORD"

# login
sleep 2
echo "${USERNAME}" > "${tty}"
sleep 1
echo "${PASSWORD}" > "${tty}"
sleep 3
print_ipv4="ip -4 addr show | grep -oP '(?<=inet\\s)\\d+(\\.\\d+){3}'"
echo "$print_ipv4" > "/dev/ttyS${n}"
sleep 1
return_line=$(tpi uart --node "${n}" get | tail -n 2 | head -n 1)
echo "$return_line" | grep -oE '([0-9]{1,3}\.){3}[0-9]{1,3}'
}

get_ip_and_ping() {
local n="$1"
local ip

wait_until_booted $n
if [[ $? -ne 0 ]]; then
echo "$(uart_output_node "$n")"
echo "Error: Timeout occurred waiting for node ${n} to boot"
exit 1
fi

local node_ip_var="NODE${n}_IP"
local node_ip_value=$(eval echo \$$node_ip_var)

if [ -z "$node_ip_value" ]; then
echo -e "\tnode ${n}: getting ip from uart"
ip=$(retrieve_ip_from_uart "$n")
else
ip="$node_ip_value"
fi

# Ping the IP address
ping -c 4 "$ip" > /dev/null
if [ "$?" -ne 0 ]; then
echo "$(uart_output_node "$n")"
echo "Error: could not ping node $n"
exit 1
fi

echo -e "\tNode $n $ip => OK"
}

node1_test() {
get_ip_and_ping "1"
}

node2_test() {
get_ip_and_ping "2"
}

node3_test() {
get_ip_and_ping "3"
}

node4_test() {
get_ip_and_ping "4"
}

tpi power off > /dev/null
tpi power on > /dev/null

echo -e "\tWaiting for modules to boot, this can take up to a minute.."
sleep 15

node1_test
node2_test
node3_test
node4_test

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
#!/bin/bash

source helpers.sh
BMC_OTG="08DE:1234"
RK1_USB="2207:350b"

assert_pci_devices() {
local devices=$(get_pci_devices "$1" | grep -v '^$')
local count="$2"
line_count=$(echo "$devices" | wc -l)
# Exit with an error if there are fewer than 2 lines
if [ "$line_count" -lt "${count}" ]; then
echo "Error: Fewer than ${count} (got ${line_count}) PCI devices connected "
echo -e "\tFound:"
echo -e "\t${devices}"
echo "Error: Node ${n}: could not detect NVMe or MPCIE device"
exit 1
fi

}

print_usb_names() {
local usb_devices="$1"
# Loop through each line and print the name of the USB device
echo "$usb_devices" | while IFS= read -r line; do
# Extract and print the device name (fields starting from 7th position)
local dev=$(echo "$line" | awk '{for(i=7;i<=NF;i++) printf $i" "; print ""}')
echo -e "\t\t${dev}"
done
}

usb_dev_test() {
tpi advanced msd --node 4 >/dev/null
tpi usb device --node 4 > /dev/null
confirm "plug the USB cable from 'BMC_USB_OTG' to the 'USB_DEV' port"
devices=$(get_usb_devices "1")
if echo "$devices" | grep -q "ID ${RK1_USB}"; then
echo -e "\tUSB_DEV => OK"
else
echo "$devices"
echo "Error: Could not detect 'USB_DEV' port"
exit 1
fi
}

node1_tests() {
result=$(send_command "1" "lsusb -d ${BMC_OTG}")
if [[ $? -ne 0 ]]; then
echo "$result"
echo "Error: NODE1_USB_HOST or BMC_USB_OTG port not responding"
exit 1
fi
confirm "Do you see video output on the HDMI port?"
confirm "Do you see video output on the DSI port?"
assert_pci_devices "1" "2"
echo -e "\tNODE1 => OK"
}

node2_tests() {
assert_pci_devices "2" "2"
echo -e "\tNODE2 => OK"
}

node3_tests() {
assert_pci_devices "3" "1"
echo -e "\tNODE3 => OK"
}

node4_tests() {
usb_devices=$(get_usb_devices 4)
line_count=$(echo "$usb_devices" | wc -l)
# Exit with an error if there are fewer than 2 lines
if [ "$line_count" -lt 4 ]; then
echo "Error: Fewer than 4(${line_count}) USB devices connected to NODE4"
echo "got: ${usb_devices}"
exit 1
fi

echo -e "\tUSB3X2 NODE4"
print_usb_names "$usb_devices"
echo -e "\tUSB3X2 NODE4 => OK"
assert_pci_devices "4" "1"
echo -e "\tNODE4 => OK"

}

#node1_tests
#node2_tests
#node3_tests
#node4_tests
usb_dev_test
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash
source helpers.sh

confirm "Is the fan working?"
confirm "Switch the 'FAN VOL SWITCH'. Is the speed changing?"
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

set -e
source helpers.sh
tpi power on > /dev/null
question "Press 'Key1'. Do the red light go off?"
15 changes: 15 additions & 0 deletions tp2bmc/board/tp2bmc/factory_overlay/upper/factory/config.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash

ASSERT_VERSION=4111
ASSERT_MODEL_NAME="Turing Pi 2 (v2.5.1)"

# the amount allowed to wait for a module to boot (in secs)
WAITING_TIMEOUT=60
RK1_USERNAME=ubuntu
RK1_PASSWORD=Turingpi123
FINGERPRINT="ubuntu login:"

NODE1_IP=""
NODE2_IP=""
NODE3_IP=""
NODE4_IP=""
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

set -e
eeprom=$(ls /sys/bus/i2c/devices/*/eeprom)
dd if=/dev/zero bs=1 count=48 of="$eeprom"
dd if=/dev/zero bs=1 count=48 | tr '\0' '\377' > "$eeprom"
echo "EEPROM erased successfully"

Loading

0 comments on commit e8fd871

Please sign in to comment.