1 | #!/bin/bash
|
---|
2 | # shellcheck disable=SC1091
|
---|
3 | # shellcheck disable=SC2034
|
---|
4 | # shellcheck disable=SC2059
|
---|
5 | # shellcheck disable=SC2086 # we want word splitting
|
---|
6 |
|
---|
7 | . "$SCRIPTS_DIR"/setup-test-env.sh
|
---|
8 |
|
---|
9 | # Boot script for devices attached to a PoE switch, using NFS for the root
|
---|
10 | # filesystem.
|
---|
11 |
|
---|
12 | # We're run from the root of the repo, make a helper var for our paths
|
---|
13 | BM=$CI_PROJECT_DIR/install/bare-metal
|
---|
14 | CI_COMMON=$CI_PROJECT_DIR/install/common
|
---|
15 | CI_INSTALL=$CI_PROJECT_DIR/install
|
---|
16 |
|
---|
17 | # Runner config checks
|
---|
18 | if [ -z "$BM_SERIAL" ]; then
|
---|
19 | echo "Must set BM_SERIAL in your gitlab-runner config.toml [[runners]] environment"
|
---|
20 | echo "This is the serial port to listen the device."
|
---|
21 | exit 1
|
---|
22 | fi
|
---|
23 |
|
---|
24 | if [ -z "$BM_POE_ADDRESS" ]; then
|
---|
25 | echo "Must set BM_POE_ADDRESS in your gitlab-runner config.toml [[runners]] environment"
|
---|
26 | echo "This is the PoE switch address to connect for powering up/down devices."
|
---|
27 | exit 1
|
---|
28 | fi
|
---|
29 |
|
---|
30 | if [ -z "$BM_POE_INTERFACE" ]; then
|
---|
31 | echo "Must set BM_POE_INTERFACE in your gitlab-runner config.toml [[runners]] environment"
|
---|
32 | echo "This is the PoE switch interface where the device is connected."
|
---|
33 | exit 1
|
---|
34 | fi
|
---|
35 |
|
---|
36 | if [ -z "$BM_POWERUP" ]; then
|
---|
37 | echo "Must set BM_POWERUP in your gitlab-runner config.toml [[runners]] environment"
|
---|
38 | echo "This is a shell script that should power up the device and begin its boot sequence."
|
---|
39 | exit 1
|
---|
40 | fi
|
---|
41 |
|
---|
42 | if [ -z "$BM_POWERDOWN" ]; then
|
---|
43 | echo "Must set BM_POWERDOWN in your gitlab-runner config.toml [[runners]] environment"
|
---|
44 | echo "This is a shell script that should power off the device."
|
---|
45 | exit 1
|
---|
46 | fi
|
---|
47 |
|
---|
48 | if [ ! -d /nfs ]; then
|
---|
49 | echo "NFS rootfs directory needs to be mounted at /nfs by the gitlab runner"
|
---|
50 | exit 1
|
---|
51 | fi
|
---|
52 |
|
---|
53 | if [ ! -d /tftp ]; then
|
---|
54 | echo "TFTP directory for this board needs to be mounted at /tftp by the gitlab runner"
|
---|
55 | exit 1
|
---|
56 | fi
|
---|
57 |
|
---|
58 | # job config checks
|
---|
59 | if [ -z "$BM_ROOTFS" ]; then
|
---|
60 | echo "Must set BM_ROOTFS to your board's rootfs directory in the job's variables"
|
---|
61 | exit 1
|
---|
62 | fi
|
---|
63 |
|
---|
64 | if [ -z "$BM_BOOTFS" ] && { [ -z "$BM_KERNEL" ] || [ -z "$BM_DTB" ]; } ; then
|
---|
65 | echo "Must set /boot files for the TFTP boot in the job's variables or set kernel and dtb"
|
---|
66 | exit 1
|
---|
67 | fi
|
---|
68 |
|
---|
69 | if [ -z "$BM_CMDLINE" ]; then
|
---|
70 | echo "Must set BM_CMDLINE to your board's kernel command line arguments"
|
---|
71 | exit 1
|
---|
72 | fi
|
---|
73 |
|
---|
74 | set -ex
|
---|
75 |
|
---|
76 | date +'%F %T'
|
---|
77 |
|
---|
78 | # Clear out any previous run's artifacts.
|
---|
79 | rm -rf results/
|
---|
80 | mkdir -p results
|
---|
81 |
|
---|
82 | # Create the rootfs in the NFS directory. rm to make sure it's in a pristine
|
---|
83 | # state, since it's volume-mounted on the host.
|
---|
84 | rsync -a --delete $BM_ROOTFS/ /nfs/
|
---|
85 |
|
---|
86 | date +'%F %T'
|
---|
87 |
|
---|
88 | # If BM_BOOTFS is an URL, download it
|
---|
89 | if echo $BM_BOOTFS | grep -q http; then
|
---|
90 | curl -L --retry 4 -f --retry-all-errors --retry-delay 60 \
|
---|
91 | "${FDO_HTTP_CACHE_URI:-}$BM_BOOTFS" -o /tmp/bootfs.tar
|
---|
92 | BM_BOOTFS=/tmp/bootfs.tar
|
---|
93 | fi
|
---|
94 |
|
---|
95 | date +'%F %T'
|
---|
96 |
|
---|
97 | # If BM_BOOTFS is a file, assume it is a tarball and uncompress it
|
---|
98 | if [ -f "${BM_BOOTFS}" ]; then
|
---|
99 | mkdir -p /tmp/bootfs
|
---|
100 | tar xf $BM_BOOTFS -C /tmp/bootfs
|
---|
101 | BM_BOOTFS=/tmp/bootfs
|
---|
102 | fi
|
---|
103 |
|
---|
104 | # If BM_KERNEL and BM_DTS is present
|
---|
105 | if [ -n "${FORCE_KERNEL_TAG}" ]; then
|
---|
106 | if [ -z "${BM_KERNEL}" ] || [ -z "${BM_DTB}" ]; then
|
---|
107 | echo "This machine cannot be tested with external kernel since BM_KERNEL or BM_DTB missing!"
|
---|
108 | exit 1
|
---|
109 | fi
|
---|
110 |
|
---|
111 | curl -L --retry 4 -f --retry-all-errors --retry-delay 60 \
|
---|
112 | "${FDO_HTTP_CACHE_URI:-}${KERNEL_IMAGE_BASE}/${DEBIAN_ARCH}/${BM_KERNEL}" -o "${BM_KERNEL}"
|
---|
113 | curl -L --retry 4 -f --retry-all-errors --retry-delay 60 \
|
---|
114 | "${FDO_HTTP_CACHE_URI:-}${KERNEL_IMAGE_BASE}/${DEBIAN_ARCH}/${BM_DTB}.dtb" -o "${BM_DTB}.dtb"
|
---|
115 | curl -L --retry 4 -f --retry-all-errors --retry-delay 60 \
|
---|
116 | "${FDO_HTTP_CACHE_URI:-}${KERNEL_IMAGE_BASE}/${DEBIAN_ARCH}/modules.tar.zst" -o modules.tar.zst
|
---|
117 | fi
|
---|
118 |
|
---|
119 | date +'%F %T'
|
---|
120 |
|
---|
121 | # Install kernel modules (it could be either in /lib/modules or
|
---|
122 | # /usr/lib/modules, but we want to install in the latter)
|
---|
123 | if [ -n "${FORCE_KERNEL_TAG}" ]; then
|
---|
124 | tar --keep-directory-symlink --zstd -xf modules.tar.zst -C /nfs/
|
---|
125 | rm modules.tar.zst &
|
---|
126 | elif [ -n "${BM_BOOTFS}" ]; then
|
---|
127 | [ -d $BM_BOOTFS/usr/lib/modules ] && rsync -a $BM_BOOTFS/usr/lib/modules/ /nfs/usr/lib/modules/
|
---|
128 | [ -d $BM_BOOTFS/lib/modules ] && rsync -a $BM_BOOTFS/lib/modules/ /nfs/lib/modules/
|
---|
129 | else
|
---|
130 | echo "No modules!"
|
---|
131 | fi
|
---|
132 |
|
---|
133 |
|
---|
134 | date +'%F %T'
|
---|
135 |
|
---|
136 | # Install kernel image + bootloader files
|
---|
137 | if [ -n "${FORCE_KERNEL_TAG}" ] || [ -z "$BM_BOOTFS" ]; then
|
---|
138 | mv "${BM_KERNEL}" "${BM_DTB}.dtb" /tftp/
|
---|
139 | else # BM_BOOTFS
|
---|
140 | rsync -aL --delete $BM_BOOTFS/boot/ /tftp/
|
---|
141 | fi
|
---|
142 |
|
---|
143 | date +'%F %T'
|
---|
144 |
|
---|
145 | # Set up the pxelinux config for Jetson Nano
|
---|
146 | mkdir -p /tftp/pxelinux.cfg
|
---|
147 | cat <<EOF >/tftp/pxelinux.cfg/default-arm-tegra210-p3450-0000
|
---|
148 | PROMPT 0
|
---|
149 | TIMEOUT 30
|
---|
150 | DEFAULT primary
|
---|
151 | MENU TITLE jetson nano boot options
|
---|
152 | LABEL primary
|
---|
153 | MENU LABEL CI kernel on TFTP
|
---|
154 | LINUX Image
|
---|
155 | FDT tegra210-p3450-0000.dtb
|
---|
156 | APPEND \${cbootargs} $BM_CMDLINE
|
---|
157 | EOF
|
---|
158 |
|
---|
159 | # Set up the pxelinux config for Jetson TK1
|
---|
160 | cat <<EOF >/tftp/pxelinux.cfg/default-arm-tegra124-jetson-tk1
|
---|
161 | PROMPT 0
|
---|
162 | TIMEOUT 30
|
---|
163 | DEFAULT primary
|
---|
164 | MENU TITLE jetson TK1 boot options
|
---|
165 | LABEL primary
|
---|
166 | MENU LABEL CI kernel on TFTP
|
---|
167 | LINUX zImage
|
---|
168 | FDT tegra124-jetson-tk1.dtb
|
---|
169 | APPEND \${cbootargs} $BM_CMDLINE
|
---|
170 | EOF
|
---|
171 |
|
---|
172 | # Create the rootfs in the NFS directory
|
---|
173 | . $BM/rootfs-setup.sh /nfs
|
---|
174 |
|
---|
175 | date +'%F %T'
|
---|
176 |
|
---|
177 | echo "$BM_CMDLINE" > /tftp/cmdline.txt
|
---|
178 |
|
---|
179 | # Add some options in config.txt, if defined
|
---|
180 | if [ -n "$BM_BOOTCONFIG" ]; then
|
---|
181 | printf "$BM_BOOTCONFIG" >> /tftp/config.txt
|
---|
182 | fi
|
---|
183 |
|
---|
184 | set +e
|
---|
185 | STRUCTURED_LOG_FILE=job_detail.json
|
---|
186 | python3 $CI_INSTALL/custom_logger.py ${STRUCTURED_LOG_FILE} --update dut_job_type "${DEVICE_TYPE}"
|
---|
187 | python3 $CI_INSTALL/custom_logger.py ${STRUCTURED_LOG_FILE} --update farm "${FARM}"
|
---|
188 | ATTEMPTS=3
|
---|
189 | first_attempt=True
|
---|
190 | while [ $((ATTEMPTS--)) -gt 0 ]; do
|
---|
191 | python3 $CI_INSTALL/custom_logger.py ${STRUCTURED_LOG_FILE} --create-dut-job dut_name "${CI_RUNNER_DESCRIPTION}"
|
---|
192 | # Update subtime time to CI_JOB_STARTED_AT only for the first run
|
---|
193 | if [ "$first_attempt" = "True" ]; then
|
---|
194 | python3 $CI_INSTALL/custom_logger.py ${STRUCTURED_LOG_FILE} --update-dut-time submit "${CI_JOB_STARTED_AT}"
|
---|
195 | else
|
---|
196 | python3 $CI_INSTALL/custom_logger.py ${STRUCTURED_LOG_FILE} --update-dut-time submit
|
---|
197 | fi
|
---|
198 | python3 $BM/poe_run.py \
|
---|
199 | --dev="$BM_SERIAL" \
|
---|
200 | --powerup="$BM_POWERUP" \
|
---|
201 | --powerdown="$BM_POWERDOWN" \
|
---|
202 | --test-timeout ${TEST_PHASE_TIMEOUT:-20}
|
---|
203 | ret=$?
|
---|
204 |
|
---|
205 | if [ $ret -eq 2 ]; then
|
---|
206 | echo "Did not detect boot sequence, retrying..."
|
---|
207 | python3 $CI_INSTALL/custom_logger.py ${STRUCTURED_LOG_FILE} --close-dut-job
|
---|
208 | first_attempt=False
|
---|
209 | else
|
---|
210 | ATTEMPTS=0
|
---|
211 | fi
|
---|
212 | done
|
---|
213 | python3 $CI_INSTALL/custom_logger.py ${STRUCTURED_LOG_FILE} --close-dut-job
|
---|
214 | python3 $CI_INSTALL/custom_logger.py ${STRUCTURED_LOG_FILE} --close
|
---|
215 | set -e
|
---|
216 |
|
---|
217 | date +'%F %T'
|
---|
218 |
|
---|
219 | # Bring artifacts back from the NFS dir to the build dir where gitlab-runner
|
---|
220 | # will look for them.
|
---|
221 | cp -Rp /nfs/results/. results/
|
---|
222 | if [ -f "${STRUCTURED_LOG_FILE}" ]; then
|
---|
223 | cp -p ${STRUCTURED_LOG_FILE} results/
|
---|
224 | echo "Structured log file is available at ${ARTIFACTS_BASE_URL}/results/${STRUCTURED_LOG_FILE}"
|
---|
225 | fi
|
---|
226 |
|
---|
227 | date +'%F %T'
|
---|
228 |
|
---|
229 | exit $ret
|
---|