blob: dca9ef3027b7e079496e4705ca803fe34e13278d [file] [log] [blame]
Pali Rohár56847f32020-10-31 17:32:48 +01001#!/bin/bash -e
Pali Rohár6cfd09d2020-05-17 14:38:22 +02002# SPDX-License-Identifier: GPL-2.0+
3# (C) 2020 Pali Rohár <pali@kernel.org>
4
5# External tools needed for this test:
6echo '
7 wget
8 git
9 truncate
10 tar
11 dpkg
12 dd
13 make
14 gcc
15 arm-linux-gnueabi-gcc
16 fakeroot (homepage http://fakeroot-ng.lingnu.com/)
17 mcopy (from mtools, homepage http://www.gnu.org/software/mtools/)
18 mformat (from mtools, homepage http://www.gnu.org/software/mtools/)
19 /usr/sbin/mkfs.ubifs (from mtd-utils, homepage http://www.linux-mtd.infradead.org/)
20 /usr/sbin/ubinize (from mtd-utils, homepage http://www.linux-mtd.infradead.org/)
Pali Rohár65298232021-06-18 15:31:08 +020021 /lib/ld-linux.so.2 (32-bit x86 version of LD loader, needed for qflasher)
Pali Rohár6cfd09d2020-05-17 14:38:22 +020022' | while read tool info; do
23 if test -z "$tool"; then continue; fi
24 if ! which $tool 1>/dev/null 2>&1; then
25 echo "Tool $tool was not found and is required to run this test"
26 echo "First install $tool $info"
27 exit 1
28 fi
29done || exit 1
30
31echo
32echo "============================================================"
33echo "========== Compiling U-Boot for Nokia RX-51 board =========="
34echo "============================================================"
35echo
36
Pali Rohár43f7b812022-09-15 20:59:48 +020037# First compile u-boot-ubifs.bin binary with UBI/UBIFS support for Nokia RX-51 board according to doc/board/nokia/rx51.rst
38make nokia_rx51_config
39cat >> .config << EOF
40CONFIG_CMD_UBI=y
41CONFIG_CMD_UBIFS=y
42CONFIG_MTD_UBI_BEB_LIMIT=10
43EOF
44make olddefconfig
45make -j4 u-boot.bin CROSS_COMPILE=arm-linux-gnueabi-
46mv u-boot.bin u-boot-ubifs.bin
47
48# Then compile standard u-boot.bin binary for Nokia RX-51 board
Pali Rohár6cfd09d2020-05-17 14:38:22 +020049make nokia_rx51_config
Pali Rohár92e08722022-09-04 03:29:04 +020050make -j4 u-boot.bin CROSS_COMPILE=arm-linux-gnueabi-
Pali Rohár6cfd09d2020-05-17 14:38:22 +020051
52# And then do all stuff in temporary directory
53mkdir -p nokia_rx51_tmp
54cd nokia_rx51_tmp
55
56test -f mkimage || ln -s ../tools/mkimage .
57test -f u-boot.bin || ln -s ../u-boot.bin .
Pali Rohár43f7b812022-09-15 20:59:48 +020058test -f u-boot-ubifs.bin || ln -s ../u-boot-ubifs.bin .
Pali Rohár6cfd09d2020-05-17 14:38:22 +020059
60echo
61echo "=========================================================================="
62echo "========== Downloading and compiling qemu from qemu-linaro fork =========="
63echo "=========================================================================="
64echo
65
66# Download and compile linaro version qemu which has support for n900 machine
67# Last working commit is 8f8d8e0796efe1a6f34cdd83fb798f3c41217ec1
68if ! test -f qemu-system-arm; then
69 test -d qemu-linaro || git clone https://git.linaro.org/qemu/qemu-linaro.git
70 cd qemu-linaro
71 git checkout 8f8d8e0796efe1a6f34cdd83fb798f3c41217ec1
Tom Rinib1c21022021-06-10 10:57:36 -040072 ./configure --enable-system --target-list=arm-softmmu --python=/usr/bin/python2.7 --disable-sdl --disable-gtk --disable-curses --audio-drv-list= --audio-card-list= --disable-werror --disable-xen --disable-xen-pci-passthrough --disable-brlapi --disable-vnc --disable-curl --disable-slirp --disable-kvm --disable-user --disable-linux-user --disable-bsd-user --disable-guest-base --disable-uuid --disable-vde --disable-linux-aio --disable-cap-ng --disable-attr --disable-blobs --disable-docs --disable-spice --disable-libiscsi --disable-smartcard-nss --disable-usb-redir --disable-guest-agent --disable-seccomp --disable-glusterfs --disable-nptl --disable-fdt
Pali Rohár6cfd09d2020-05-17 14:38:22 +020073 make -j4
74 cd ..
75 ln -s qemu-linaro/arm-softmmu/qemu-system-arm .
76fi
77
78echo
79echo "==================================================="
80echo "========== Downloading external binaries =========="
81echo "==================================================="
82echo
83
84# Download qflasher and nolo images
85# This is proprietary qemu flasher tool with first stage images, but license allows non-commercial redistribution
Pali Rohárce0f7452023-02-21 11:22:29 -050086if ! test -f qflasher || ! test -f xloader-qemu.bin || ! test -f secondary-qemu.bin; then
87 test -f qemu-n900.tar.gz || wget -c http://repository.maemo.org/qemu-n900/qemu-n900.tar.gz
88 tar -xf qemu-n900.tar.gz
89fi
Pali Rohár6cfd09d2020-05-17 14:38:22 +020090
91# Download Maemo script u-boot-gen-combined
92if ! test -f u-boot-gen-combined; then
93 test -d u-boot-maemo || git clone https://github.com/pali/u-boot-maemo.git
94 chmod +x u-boot-maemo/debian/u-boot-gen-combined
95 ln -s u-boot-maemo/debian/u-boot-gen-combined .
96fi
97
98# Download Maemo fiasco kernel
Pali Rohárce0f7452023-02-21 11:22:29 -050099if ! test -d kernel_2.6.28; then
100 test -f kernel_2.6.28-20103103+0m5_armel.deb || wget -c http://repository.maemo.org/pool/maemo5.0/free/k/kernel/kernel_2.6.28-20103103+0m5_armel.deb
101 dpkg -x kernel_2.6.28-20103103+0m5_armel.deb kernel_2.6.28
102fi
Pali Rohár6cfd09d2020-05-17 14:38:22 +0200103
104# Download Maemo libc
Pali Rohárce0f7452023-02-21 11:22:29 -0500105if ! test -d libc6_2.5.1; then
106 test -f libc6_2.5.1-1eglibc27+0m5_armel.deb || wget -c http://repository.maemo.org/pool/maemo5.0/free/g/glibc/libc6_2.5.1-1eglibc27+0m5_armel.deb
107 dpkg -x libc6_2.5.1-1eglibc27+0m5_armel.deb libc6_2.5.1
108fi
Pali Rohár6cfd09d2020-05-17 14:38:22 +0200109
110# Download Maemo busybox
Pali Rohárce0f7452023-02-21 11:22:29 -0500111if ! test -d busybox_1.10.2; then
112 test -f busybox_1.10.2.legal-1osso30+0m5_armel.deb || wget -c http://repository.maemo.org/pool/maemo5.0/free/b/busybox/busybox_1.10.2.legal-1osso30+0m5_armel.deb
113 dpkg -x busybox_1.10.2.legal-1osso30+0m5_armel.deb busybox_1.10.2
114fi
Pali Rohár6cfd09d2020-05-17 14:38:22 +0200115
116echo
117echo "======================================="
118echo "========== Generating images =========="
119echo "======================================="
120echo
121
Pali Rohár43f7b812022-09-15 20:59:48 +0200122# Generate kernel image in zImage and uImage format from FIASCO format
123dd if=kernel_2.6.28/boot/zImage-2.6.28-20103103+0m5.fiasco of=zImage-2.6.28-omap1 skip=95 bs=1
124./mkimage -A arm -O linux -T kernel -C none -a 80008000 -e 80008000 -n zImage-2.6.28-omap1 -d zImage-2.6.28-omap1 uImage-2.6.28-omap1
125
Pali Rohár6cfd09d2020-05-17 14:38:22 +0200126# Generate rootfs directory
127mkdir -p rootfs
128mkdir -p rootfs/dev/
129mkdir -p rootfs/bin/
130mkdir -p rootfs/sbin/
131mkdir -p rootfs/lib/
132cp -a busybox_1.10.2/bin/busybox rootfs/bin/
133cp -a libc6_2.5.1/lib/ld-linux.so.3 rootfs/lib/
134cp -a libc6_2.5.1/lib/ld-2.5.so rootfs/lib/
135cp -a libc6_2.5.1/lib/libc.so.6 rootfs/lib/
136cp -a libc6_2.5.1/lib/libc-2.5.so rootfs/lib/
137cp -a libc6_2.5.1/lib/libcrypt.so.1 rootfs/lib/
138cp -a libc6_2.5.1/lib/libcrypt-2.5.so rootfs/lib/
139test -f rootfs/bin/sh || ln -sf busybox rootfs/bin/sh
140test -f rootfs/sbin/poweroff || ln -sf ../bin/busybox rootfs/sbin/poweroff
141cat > rootfs/sbin/preinit << EOF
142#!/bin/sh
143echo
144echo "Successfully booted"
145echo
146/sbin/poweroff -f
147EOF
148chmod +x rootfs/sbin/preinit
149
Pali Rohár43f7b812022-09-15 20:59:48 +0200150# Generate ubifs image from rootfs directory
Pali Rohár6cfd09d2020-05-17 14:38:22 +0200151# NOTE: Character device on host filesystem can be created only by root
152# But we do not need it on host filesystem, just in ubifs image
153# So run mknod and mkfs.ubifs commands under fakeroot program
154# which via LD_PRELOAD simulate mknod() and stat() functions
155# so mkfs.ubifs will see dev/console as character device and
156# put it correctly as character device into final ubifs image
157# Therefore we can run whole script as non-root nobody user
158fakeroot sh -c '
159 rm -f rootfs/dev/console;
160 mknod rootfs/dev/console c 5 1;
161 /usr/sbin/mkfs.ubifs -m 2048 -e 129024 -c 2047 -r rootfs ubifs.img;
162'
Pali Rohár43f7b812022-09-15 20:59:48 +0200163
164# Generate ubi image with rootfs on first volume
165cat > ubi.ini << EOF
166[rootfs]
167mode=ubi
168image=ubifs.img
169vol_id=0
170vol_size=230MiB # 1870 LEBs
171vol_type=dynamic
172vol_name=rootfs
173vol_alignment=1
174vol_flags=autoresize
175EOF
Pali Rohár6cfd09d2020-05-17 14:38:22 +0200176/usr/sbin/ubinize -o ubi.img -p 128KiB -m 2048 -s 512 ubi.ini
177
Pali Rohár43f7b812022-09-15 20:59:48 +0200178# Generate ubi image with rootfs on first volume and kernel in zImage format on second volume for UBI booting
179cp ubi.ini ubi_with_kernel.ini
180cat >> ubi_with_kernel.ini << EOF
181[kernel]
182mode=ubi
183image=zImage-2.6.28-omap1
184vol_id=1
185vol_size=2MiB
186vol_type=dynamic
187vol_name=kernel
188vol_alignment=1
189EOF
190/usr/sbin/ubinize -o ubi_with_kernel.img -p 128KiB -m 2048 -s 512 ubi_with_kernel.ini
191
Pali Rohár1ce0e1c2020-11-29 17:15:05 +0100192# Generate bootmenu for U-Boot serial console testing
193cat > bootmenu_uboot << EOF
194setenv bootmenu_0 'Serial console test=echo; echo "Testing serial console"; echo; echo "Successfully booted"; echo; poweroff';
195setenv bootmenu_1;
196setenv bootmenu_delay 1;
197setenv bootdelay 1;
198EOF
199./mkimage -A arm -O linux -T script -C none -a 0 -e 0 -n bootmenu_uboot -d bootmenu_uboot bootmenu_uboot.scr
200
Pali Rohárcc434fc2021-06-18 15:27:03 +0200201# Generate bootmenu for eMMC booting (uImage)
Pali Rohár6cfd09d2020-05-17 14:38:22 +0200202cat > bootmenu_emmc << EOF
203setenv bootmenu_0 'uImage-2.6.28-omap1 from eMMC=setenv mmcnum 1; setenv mmcpart 1; setenv mmctype fat; setenv bootargs; setenv setup_omap_atag 1; setenv mmckernfile uImage-2.6.28-omap1; run trymmckernboot';
204setenv bootmenu_1;
205setenv bootmenu_delay 1;
206setenv bootdelay 1;
207EOF
Pali Rohár56847f32020-10-31 17:32:48 +0100208./mkimage -A arm -O linux -T script -C none -a 0 -e 0 -n bootmenu_emmc -d bootmenu_emmc bootmenu_emmc.scr
Pali Rohár6cfd09d2020-05-17 14:38:22 +0200209
Pali Rohárcc434fc2021-06-18 15:27:03 +0200210# Generate bootmenu for eMMC booting (zImage)
211cat > bootmenu_emmc2 << EOF
212setenv bootmenu_0 'zImage-2.6.28-omap1 from eMMC=setenv mmcnum 1; setenv mmcpart 1; setenv mmctype fat; setenv bootargs; setenv setup_omap_atag 1; setenv mmckernfile zImage-2.6.28-omap1; run trymmckernboot';
213setenv bootmenu_1;
214setenv bootmenu_delay 1;
215setenv bootdelay 1;
216EOF
217./mkimage -A arm -O linux -T script -C none -a 0 -e 0 -n bootmenu_emmc2 -d bootmenu_emmc2 bootmenu_emmc2.scr
218
Pali Rohár21dc5ef2022-09-04 03:29:05 +0200219# Generate bootmenu for OneNAND booting (uImage)
Pali Rohár6cfd09d2020-05-17 14:38:22 +0200220cat > bootmenu_nand << EOF
Pali Rohár75069652022-09-04 03:29:02 +0200221setenv bootmenu_0 'uImage-2.6.28-omap1 from OneNAND=setenv bootargs; setenv setup_omap_atag 1; mtd read initfs \${kernaddr} && bootm \${kernaddr}';
Pali Rohár6cfd09d2020-05-17 14:38:22 +0200222setenv bootmenu_1;
223setenv bootmenu_delay 1;
224setenv bootdelay 1;
225EOF
Pali Rohár56847f32020-10-31 17:32:48 +0100226./mkimage -A arm -O linux -T script -C none -a 0 -e 0 -n bootmenu_nand -d bootmenu_nand bootmenu_nand.scr
Pali Rohár6cfd09d2020-05-17 14:38:22 +0200227
Pali Rohár43f7b812022-09-15 20:59:48 +0200228# Generate bootmenu for UBI booting (zImage)
229cat > bootmenu_ubi << EOF
230setenv bootmenu_0 'zImage-2.6.28-omap1 from UBI=setenv bootargs; setenv setup_omap_atag 1; ubi part rootfs && ubi read \${kernaddr} kernel && bootz \${kernaddr}';
231setenv bootmenu_1;
232setenv bootmenu_delay 1;
233setenv bootdelay 1;
234EOF
235./mkimage -A arm -O linux -T script -C none -a 0 -e 0 -n bootmenu_ubi -d bootmenu_ubi bootmenu_ubi.scr
236
Pali Rohárcc434fc2021-06-18 15:27:03 +0200237# Generate bootmenu for default booting
238cat > bootmenu_default << EOF
239setenv bootmenu_delay 1;
240setenv bootdelay 1;
241EOF
242./mkimage -A arm -O linux -T script -C none -a 0 -e 0 -n bootmenu_default -d bootmenu_default bootmenu_default.scr
243
Pali Rohár6cfd09d2020-05-17 14:38:22 +0200244# Generate combined image from u-boot and Maemo fiasco kernel
Pali Rohárcc434fc2021-06-18 15:27:03 +0200245./u-boot-gen-combined u-boot.bin zImage-2.6.28-omap1 combined_zimage.bin
Pali Rohárcc434fc2021-06-18 15:27:03 +0200246./u-boot-gen-combined u-boot.bin uImage-2.6.28-omap1 combined_uimage.bin
Pali Rohár6cfd09d2020-05-17 14:38:22 +0200247
248# Generate combined hack image from u-boot and Maemo fiasco kernel (kernel starts at 2MB offset and qflasher puts 2kB header before supplied image)
249cp u-boot.bin combined_hack.bin
250dd if=uImage-2.6.28-omap1 of=combined_hack.bin bs=1024 seek=$((2048-2))
251
Pali Rohár1ce0e1c2020-11-29 17:15:05 +0100252# Generate FAT32 eMMC image for U-Boot serial console testing
253truncate -s 50MiB emmc_uboot.img
254mformat -m 0xf8 -F -h 4 -s 16 -c 1 -t $((50*1024*1024/(4*16*512))) :: -i emmc_uboot.img
255mcopy bootmenu_uboot.scr ::/bootmenu.scr -i emmc_uboot.img
256
Pali Rohárcc434fc2021-06-18 15:27:03 +0200257# Generate FAT32 eMMC image for eMMC booting (uImage)
Pali Rohár6cfd09d2020-05-17 14:38:22 +0200258truncate -s 50MiB emmc_emmc.img
259mformat -m 0xf8 -F -h 4 -s 16 -c 1 -t $((50*1024*1024/(4*16*512))) :: -i emmc_emmc.img
260mcopy uImage-2.6.28-omap1 ::/uImage-2.6.28-omap1 -i emmc_emmc.img
261mcopy bootmenu_emmc.scr ::/bootmenu.scr -i emmc_emmc.img
262
Pali Rohárcc434fc2021-06-18 15:27:03 +0200263# Generate FAT32 eMMC image for eMMC booting (zImage)
264truncate -s 50MiB emmc_emmc2.img
265mformat -m 0xf8 -F -h 4 -s 16 -c 1 -t $((50*1024*1024/(4*16*512))) :: -i emmc_emmc2.img
266mcopy zImage-2.6.28-omap1 ::/zImage-2.6.28-omap1 -i emmc_emmc2.img
267mcopy bootmenu_emmc2.scr ::/bootmenu.scr -i emmc_emmc2.img
268
Pali Rohár21dc5ef2022-09-04 03:29:05 +0200269# Generate FAT32 eMMC image for OneNAND booting (uImage)
Pali Rohár6cfd09d2020-05-17 14:38:22 +0200270truncate -s 50MiB emmc_nand.img
271mformat -m 0xf8 -F -h 4 -s 16 -c 1 -t $((50*1024*1024/(4*16*512))) :: -i emmc_nand.img
272mcopy bootmenu_nand.scr ::/bootmenu.scr -i emmc_nand.img
273
Pali Rohár43f7b812022-09-15 20:59:48 +0200274# Generate FAT32 eMMC image for UBI booting (zImage)
275truncate -s 50MiB emmc_ubi.img
276mformat -m 0xf8 -F -h 4 -s 16 -c 1 -t $((50*1024*1024/(4*16*512))) :: -i emmc_ubi.img
277mcopy bootmenu_ubi.scr ::/bootmenu.scr -i emmc_ubi.img
278
Pali Rohárcc434fc2021-06-18 15:27:03 +0200279# Generate FAT32 eMMC image for default booting
280truncate -s 50MiB emmc_default.img
281mformat -m 0xf8 -F -h 4 -s 16 -c 1 -t $((50*1024*1024/(4*16*512))) :: -i emmc_default.img
282mcopy bootmenu_default.scr ::/bootmenu.scr -i emmc_default.img
283
Pali Rohár1ce0e1c2020-11-29 17:15:05 +0100284# Generate MTD image for U-Boot serial console testing
285rm -f mtd_uboot.img
286./qflasher -v -x xloader-qemu.bin -s secondary-qemu.bin -k u-boot.bin -m rx51 -o mtd_uboot.img
287
Pali Rohár6cfd09d2020-05-17 14:38:22 +0200288# Generate MTD image for RAM booting from bootloader nolo images, compiled image and rootfs image
289rm -f mtd_ram.img
Pali Rohárcc434fc2021-06-18 15:27:03 +0200290./qflasher -v -x xloader-qemu.bin -s secondary-qemu.bin -k combined_uimage.bin -r ubi.img -m rx51 -o mtd_ram.img
291rm -f mtd_ram2.img
292./qflasher -v -x xloader-qemu.bin -s secondary-qemu.bin -k combined_zimage.bin -r ubi.img -m rx51 -o mtd_ram2.img
Pali Rohár6cfd09d2020-05-17 14:38:22 +0200293
294# Generate MTD image for eMMC booting from bootloader nolo images, u-boot image and rootfs image
295rm -f mtd_emmc.img
296./qflasher -v -x xloader-qemu.bin -s secondary-qemu.bin -k u-boot.bin -r ubi.img -m rx51 -o mtd_emmc.img
297
298# Generate MTD image for OneNAND booting from bootloader nolo images, combined hacked image and rootfs image
299# Kernel image is put into initfs area, but qflasher reject to copy kernel image into initfs area because it does not have initfs signature
300# This is hack to workaround this problem, tell qflasher that kernel area for u-boot is bigger and put big combined hacked image (u-boot + kernel with correct offset)
301rm -f mtd_nand.img
302./qflasher -v -x xloader-qemu.bin -s secondary-qemu.bin -k combined_hack.bin -r ubi.img -m rx51 -p k=4094,i=2 -o mtd_nand.img
303
Pali Rohár43f7b812022-09-15 20:59:48 +0200304# Generate MTD image for UBI booting from bootloader nolo images, u-boot image with UBI/UBIFS support and rootfs image with kernel volume
305rm -f mtd_ubi.img
306./qflasher -v -x xloader-qemu.bin -s secondary-qemu.bin -k u-boot-ubifs.bin -r ubi_with_kernel.img -m rx51 -o mtd_ubi.img
307
Pali Rohár6cfd09d2020-05-17 14:38:22 +0200308echo
309echo "======================================================"
310echo "========== Running test images in n900 qemu =========="
311echo "======================================================"
312echo
313
Pali Rohár1ce0e1c2020-11-29 17:15:05 +0100314# Run MTD image in qemu and wait for 300s if U-Boot prints testing string to serial console and poweroff
315rm -f qemu_uboot.log
316./qemu-system-arm -M n900 -mtdblock mtd_uboot.img -sd emmc_uboot.img -serial /dev/stdout -display none > qemu_uboot.log &
317qemu_pid=$!
318tail -F qemu_uboot.log &
319tail_pid=$!
320sleep 300 &
321sleep_pid=$!
322wait -n $sleep_pid $qemu_pid || true
323kill -9 $tail_pid $sleep_pid $qemu_pid 2>/dev/null || true
324wait || true
325
Pali Rohárcc434fc2021-06-18 15:27:03 +0200326# Run MTD image in qemu and wait for 300s if uImage kernel from RAM is correctly booted
Pali Rohár6cfd09d2020-05-17 14:38:22 +0200327rm -f qemu_ram.log
328./qemu-system-arm -M n900 -mtdblock mtd_ram.img -serial /dev/stdout -display none > qemu_ram.log &
329qemu_pid=$!
330tail -F qemu_ram.log &
331tail_pid=$!
Pali Rohár56847f32020-10-31 17:32:48 +0100332sleep 300 &
Pali Rohár6cfd09d2020-05-17 14:38:22 +0200333sleep_pid=$!
Pali Rohár56847f32020-10-31 17:32:48 +0100334wait -n $sleep_pid $qemu_pid || true
335kill -9 $tail_pid $sleep_pid $qemu_pid 2>/dev/null || true
336wait || true
Pali Rohár6cfd09d2020-05-17 14:38:22 +0200337
Pali Rohárcc434fc2021-06-18 15:27:03 +0200338# Run MTD image in qemu and wait for 300s if zImage kernel from RAM is correctly booted
339rm -f qemu_ram2.log
340./qemu-system-arm -M n900 -mtdblock mtd_ram2.img -sd emmc_default.img -serial /dev/stdout -display none > qemu_ram2.log &
341qemu_pid=$!
342tail -F qemu_ram2.log &
343tail_pid=$!
344sleep 300 &
345sleep_pid=$!
346wait -n $sleep_pid $qemu_pid || true
347kill -9 $tail_pid $sleep_pid $qemu_pid 2>/dev/null || true
348wait || true
349
350# Run MTD image in qemu and wait for 300s if uImage kernel from eMMC is correctly booted
Pali Rohár6cfd09d2020-05-17 14:38:22 +0200351rm -f qemu_emmc.log
352./qemu-system-arm -M n900 -mtdblock mtd_emmc.img -sd emmc_emmc.img -serial /dev/stdout -display none > qemu_emmc.log &
353qemu_pid=$!
354tail -F qemu_emmc.log &
355tail_pid=$!
Pali Rohár56847f32020-10-31 17:32:48 +0100356sleep 300 &
Pali Rohár6cfd09d2020-05-17 14:38:22 +0200357sleep_pid=$!
Pali Rohár56847f32020-10-31 17:32:48 +0100358wait -n $sleep_pid $qemu_pid || true
359kill -9 $tail_pid $sleep_pid $qemu_pid 2>/dev/null || true
360wait || true
Pali Rohár6cfd09d2020-05-17 14:38:22 +0200361
Pali Rohárcc434fc2021-06-18 15:27:03 +0200362# Run MTD image in qemu and wait for 300s if zImage kernel from eMMC is correctly booted
363rm -f qemu_emmc2.log
364./qemu-system-arm -M n900 -mtdblock mtd_emmc.img -sd emmc_emmc2.img -serial /dev/stdout -display none > qemu_emmc2.log &
365qemu_pid=$!
366tail -F qemu_emmc2.log &
367tail_pid=$!
368sleep 300 &
369sleep_pid=$!
370wait -n $sleep_pid $qemu_pid || true
371kill -9 $tail_pid $sleep_pid $qemu_pid 2>/dev/null || true
372wait || true
373
Pali Rohár6cfd09d2020-05-17 14:38:22 +0200374# Run MTD image in qemu and wait for 300s if kernel from OneNAND is correctly booted
375rm -f qemu_nand.log
376./qemu-system-arm -M n900 -mtdblock mtd_nand.img -sd emmc_nand.img -serial /dev/stdout -display none > qemu_nand.log &
377qemu_pid=$!
378tail -F qemu_nand.log &
379tail_pid=$!
Pali Rohár56847f32020-10-31 17:32:48 +0100380sleep 300 &
Pali Rohár6cfd09d2020-05-17 14:38:22 +0200381sleep_pid=$!
Pali Rohár56847f32020-10-31 17:32:48 +0100382wait -n $sleep_pid $qemu_pid || true
383kill -9 $tail_pid $sleep_pid $qemu_pid 2>/dev/null || true
384wait || true
Pali Rohár6cfd09d2020-05-17 14:38:22 +0200385
Pali Rohár43f7b812022-09-15 20:59:48 +0200386# Run MTD image in qemu and wait for 300s if kernel from UBI is correctly booted
387rm -f qemu_ubi.log
388./qemu-system-arm -M n900 -mtdblock mtd_ubi.img -sd emmc_ubi.img -serial /dev/stdout -display none > qemu_ubi.log &
389qemu_pid=$!
390tail -F qemu_ubi.log &
391tail_pid=$!
392sleep 300 &
393sleep_pid=$!
394wait -n $sleep_pid $qemu_pid || true
395kill -9 $tail_pid $sleep_pid $qemu_pid 2>/dev/null || true
396wait || true
397
Pali Rohár6cfd09d2020-05-17 14:38:22 +0200398echo
399echo "============================="
400echo "========== Results =========="
401echo "============================="
402echo
403
Pali Rohár1ce0e1c2020-11-29 17:15:05 +0100404if grep -q 'Successfully booted' qemu_uboot.log; then echo "U-Boot serial console is working"; else echo "U-Boot serial console test failed"; fi
Pali Rohárcc434fc2021-06-18 15:27:03 +0200405if grep -q 'Successfully booted' qemu_ram.log; then echo "Kernel (uImage) was successfully booted from RAM"; else echo "Failed to boot kernel (uImage) from RAM"; fi
406if grep -q 'Successfully booted' qemu_ram2.log; then echo "Kernel (zImage) was successfully booted from RAM"; else echo "Failed to boot kernel (zImage) from RAM"; fi
407if grep -q 'Successfully booted' qemu_emmc.log; then echo "Kernel (uImage) was successfully booted from eMMC"; else echo "Failed to boot kernel (uImage) from eMMC"; fi
408if grep -q 'Successfully booted' qemu_emmc2.log; then echo "Kernel (zImage) was successfully booted from eMMC"; else echo "Failed to boot kernel (zImage) from eMMC"; fi
409if grep -q 'Successfully booted' qemu_nand.log; then echo "Kernel (uImage) was successfully booted from OneNAND"; else echo "Failed to boot kernel (uImage) from OneNAND"; fi
Pali Rohár43f7b812022-09-15 20:59:48 +0200410if grep -q 'Successfully booted' qemu_ubi.log; then echo "Kernel (zImage) was successfully booted from UBI"; else echo "Failed to boot kernel (zImage) from UBI"; fi
Pali Rohár6cfd09d2020-05-17 14:38:22 +0200411
412echo
413
Pali Rohár43f7b812022-09-15 20:59:48 +0200414if grep -q 'Successfully booted' qemu_uboot.log && grep -q 'Successfully booted' qemu_ram.log && grep -q 'Successfully booted' qemu_ram2.log && grep -q 'Successfully booted' qemu_emmc.log && grep -q 'Successfully booted' qemu_emmc2.log && grep -q 'Successfully booted' qemu_nand.log && grep -q 'Successfully booted' qemu_ubi.log; then
Pali Rohár6cfd09d2020-05-17 14:38:22 +0200415 echo "All tests passed"
416 exit 0
417else
418 echo "Some tests failed"
419 exit 1
420fi