~mmach/netext73/mesa-haswell

« back to all changes in this revision

Viewing changes to .gitlab-ci/bare-metal/poe-powered.sh

  • Committer: mmach
  • Date: 2022-09-22 19:56:13 UTC
  • Revision ID: netbit73@gmail.com-20220922195613-wtik9mmy20tmor0i
2022-09-22 21:17:09

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/bin/bash
2
 
 
3
 
# Boot script for devices attached to a PoE switch, using NFS for the root
4
 
# filesystem.
5
 
 
6
 
# We're run from the root of the repo, make a helper var for our paths
7
 
BM=$CI_PROJECT_DIR/install/bare-metal
8
 
CI_COMMON=$CI_PROJECT_DIR/install/common
9
 
 
10
 
# Runner config checks
11
 
if [ -z "$BM_SERIAL" ]; then
12
 
  echo "Must set BM_SERIAL in your gitlab-runner config.toml [[runners]] environment"
13
 
  echo "This is the serial port to listen the device."
14
 
  exit 1
15
 
fi
16
 
 
17
 
if [ -z "$BM_POE_ADDRESS" ]; then
18
 
  echo "Must set BM_POE_ADDRESS in your gitlab-runner config.toml [[runners]] environment"
19
 
  echo "This is the PoE switch address to connect for powering up/down devices."
20
 
  exit 1
21
 
fi
22
 
 
23
 
if [ -z "$BM_POE_INTERFACE" ]; then
24
 
  echo "Must set BM_POE_INTERFACE in your gitlab-runner config.toml [[runners]] environment"
25
 
  echo "This is the PoE switch interface where the device is connected."
26
 
  exit 1
27
 
fi
28
 
 
29
 
if [ -z "$BM_POWERUP" ]; then
30
 
  echo "Must set BM_POWERUP in your gitlab-runner config.toml [[runners]] environment"
31
 
  echo "This is a shell script that should power up the device and begin its boot sequence."
32
 
  exit 1
33
 
fi
34
 
 
35
 
if [ -z "$BM_POWERDOWN" ]; then
36
 
  echo "Must set BM_POWERDOWN in your gitlab-runner config.toml [[runners]] environment"
37
 
  echo "This is a shell script that should power off the device."
38
 
  exit 1
39
 
fi
40
 
 
41
 
if [ ! -d /nfs ]; then
42
 
  echo "NFS rootfs directory needs to be mounted at /nfs by the gitlab runner"
43
 
  exit 1
44
 
fi
45
 
 
46
 
if [ ! -d /tftp ]; then
47
 
  echo "TFTP directory for this board needs to be mounted at /tftp by the gitlab runner"
48
 
  exit 1
49
 
fi
50
 
 
51
 
# job config checks
52
 
if [ -z "$BM_ROOTFS" ]; then
53
 
  echo "Must set BM_ROOTFS to your board's rootfs directory in the job's variables"
54
 
  exit 1
55
 
fi
56
 
 
57
 
if [ -z "$BM_BOOTFS" ]; then
58
 
  echo "Must set /boot files for the TFTP boot in the job's variables"
59
 
  exit 1
60
 
fi
61
 
 
62
 
if [ -z "$BM_CMDLINE" ]; then
63
 
  echo "Must set BM_CMDLINE to your board's kernel command line arguments"
64
 
  exit 1
65
 
fi
66
 
 
67
 
if [ -z "$BM_BOOTCONFIG" ]; then
68
 
  echo "Must set BM_BOOTCONFIG to your board's required boot configuration arguments"
69
 
  exit 1
70
 
fi
71
 
 
72
 
set -ex
73
 
 
74
 
# Clear out any previous run's artifacts.
75
 
rm -rf results/
76
 
mkdir -p results
77
 
 
78
 
# Create the rootfs in the NFS directory.  rm to make sure it's in a pristine
79
 
# state, since it's volume-mounted on the host.
80
 
rsync -a --delete $BM_ROOTFS/ /nfs/
81
 
 
82
 
# If BM_BOOTFS is an URL, download it
83
 
if echo $BM_BOOTFS | grep -q http; then
84
 
  apt install -y wget
85
 
  wget ${FDO_HTTP_CACHE_URI:-}$BM_BOOTFS -O /tmp/bootfs.tar
86
 
  BM_BOOTFS=/tmp/bootfs.tar
87
 
fi
88
 
 
89
 
# If BM_BOOTFS is a file, assume it is a tarball and uncompress it
90
 
if [ -f $BM_BOOTFS ]; then
91
 
  mkdir -p /tmp/bootfs
92
 
  tar xf $BM_BOOTFS -C /tmp/bootfs
93
 
  BM_BOOTFS=/tmp/bootfs
94
 
fi
95
 
 
96
 
# Install kernel modules (it could be either in /lib/modules or
97
 
# /usr/lib/modules, but we want to install in the latter)
98
 
[ -d $BM_BOOTFS/usr/lib/modules ] && rsync -a $BM_BOOTFS/usr/lib/modules/ /nfs/usr/lib/modules/
99
 
[ -d $BM_BOOTFS/lib/modules ] && rsync -a $BM_BOOTFS/lib/modules/ /nfs/lib/modules/
100
 
 
101
 
# Install kernel image + bootloader files
102
 
rsync -aL --delete $BM_BOOTFS/boot/ /tftp/
103
 
 
104
 
# Set up the pxelinux config for Jetson Nano
105
 
mkdir -p /tftp/pxelinux.cfg
106
 
cat <<EOF >/tftp/pxelinux.cfg/default-arm-tegra210-p3450-0000
107
 
PROMPT 0
108
 
TIMEOUT 30
109
 
DEFAULT primary
110
 
MENU TITLE jetson nano boot options
111
 
LABEL primary
112
 
      MENU LABEL CI kernel on TFTP
113
 
      LINUX Image
114
 
      FDT tegra210-p3450-0000.dtb
115
 
      APPEND \${cbootargs} $BM_CMDLINE
116
 
EOF
117
 
 
118
 
# Create the rootfs in the NFS directory
119
 
mkdir -p /nfs/results
120
 
. $BM/rootfs-setup.sh /nfs
121
 
 
122
 
echo "$BM_CMDLINE" > /tftp/cmdline.txt
123
 
 
124
 
# Add some required options in config.txt
125
 
printf "$BM_BOOTCONFIG" >> /tftp/config.txt
126
 
 
127
 
set +e
128
 
ATTEMPTS=10
129
 
while [ $((ATTEMPTS--)) -gt 0 ]; do
130
 
  python3 $BM/poe_run.py \
131
 
          --dev="$BM_SERIAL" \
132
 
          --powerup="$BM_POWERUP" \
133
 
          --powerdown="$BM_POWERDOWN" \
134
 
          --timeout="${BM_POE_TIMEOUT:-60}"
135
 
  ret=$?
136
 
 
137
 
  if [ $ret -eq 2 ]; then
138
 
    echo "Did not detect boot sequence, retrying..."
139
 
  else
140
 
    ATTEMPTS=0
141
 
  fi
142
 
done
143
 
set -e
144
 
 
145
 
# Bring artifacts back from the NFS dir to the build dir where gitlab-runner
146
 
# will look for them.
147
 
cp -Rp /nfs/results/. results/
148
 
 
149
 
exit $ret