blob: a516ec2967c3710e46c59580dd6552c54b7121f2 [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
86wget -c http://repository.maemo.org/qemu-n900/qemu-n900.tar.gz
87tar -xf qemu-n900.tar.gz
88
89# Download Maemo script u-boot-gen-combined
90if ! test -f u-boot-gen-combined; then
91 test -d u-boot-maemo || git clone https://github.com/pali/u-boot-maemo.git
92 chmod +x u-boot-maemo/debian/u-boot-gen-combined
93 ln -s u-boot-maemo/debian/u-boot-gen-combined .
94fi
95
96# Download Maemo fiasco kernel
97wget -c http://repository.maemo.org/pool/maemo5.0/free/k/kernel/kernel_2.6.28-20103103+0m5_armel.deb
98dpkg -x kernel_2.6.28-20103103+0m5_armel.deb kernel_2.6.28
99
100# Download Maemo libc
101wget -c http://repository.maemo.org/pool/maemo5.0/free/g/glibc/libc6_2.5.1-1eglibc27+0m5_armel.deb
102dpkg -x libc6_2.5.1-1eglibc27+0m5_armel.deb libc6_2.5.1
103
104# Download Maemo busybox
105wget -c http://repository.maemo.org/pool/maemo5.0/free/b/busybox/busybox_1.10.2.legal-1osso30+0m5_armel.deb
106dpkg -x busybox_1.10.2.legal-1osso30+0m5_armel.deb busybox_1.10.2
107
108echo
109echo "======================================="
110echo "========== Generating images =========="
111echo "======================================="
112echo
113
Pali Rohár43f7b812022-09-15 20:59:48 +0200114# Generate kernel image in zImage and uImage format from FIASCO format
115dd if=kernel_2.6.28/boot/zImage-2.6.28-20103103+0m5.fiasco of=zImage-2.6.28-omap1 skip=95 bs=1
116./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
117
Pali Rohár6cfd09d2020-05-17 14:38:22 +0200118# Generate rootfs directory
119mkdir -p rootfs
120mkdir -p rootfs/dev/
121mkdir -p rootfs/bin/
122mkdir -p rootfs/sbin/
123mkdir -p rootfs/lib/
124cp -a busybox_1.10.2/bin/busybox rootfs/bin/
125cp -a libc6_2.5.1/lib/ld-linux.so.3 rootfs/lib/
126cp -a libc6_2.5.1/lib/ld-2.5.so rootfs/lib/
127cp -a libc6_2.5.1/lib/libc.so.6 rootfs/lib/
128cp -a libc6_2.5.1/lib/libc-2.5.so rootfs/lib/
129cp -a libc6_2.5.1/lib/libcrypt.so.1 rootfs/lib/
130cp -a libc6_2.5.1/lib/libcrypt-2.5.so rootfs/lib/
131test -f rootfs/bin/sh || ln -sf busybox rootfs/bin/sh
132test -f rootfs/sbin/poweroff || ln -sf ../bin/busybox rootfs/sbin/poweroff
133cat > rootfs/sbin/preinit << EOF
134#!/bin/sh
135echo
136echo "Successfully booted"
137echo
138/sbin/poweroff -f
139EOF
140chmod +x rootfs/sbin/preinit
141
Pali Rohár43f7b812022-09-15 20:59:48 +0200142# Generate ubifs image from rootfs directory
Pali Rohár6cfd09d2020-05-17 14:38:22 +0200143# NOTE: Character device on host filesystem can be created only by root
144# But we do not need it on host filesystem, just in ubifs image
145# So run mknod and mkfs.ubifs commands under fakeroot program
146# which via LD_PRELOAD simulate mknod() and stat() functions
147# so mkfs.ubifs will see dev/console as character device and
148# put it correctly as character device into final ubifs image
149# Therefore we can run whole script as non-root nobody user
150fakeroot sh -c '
151 rm -f rootfs/dev/console;
152 mknod rootfs/dev/console c 5 1;
153 /usr/sbin/mkfs.ubifs -m 2048 -e 129024 -c 2047 -r rootfs ubifs.img;
154'
Pali Rohár43f7b812022-09-15 20:59:48 +0200155
156# Generate ubi image with rootfs on first volume
157cat > ubi.ini << EOF
158[rootfs]
159mode=ubi
160image=ubifs.img
161vol_id=0
162vol_size=230MiB # 1870 LEBs
163vol_type=dynamic
164vol_name=rootfs
165vol_alignment=1
166vol_flags=autoresize
167EOF
Pali Rohár6cfd09d2020-05-17 14:38:22 +0200168/usr/sbin/ubinize -o ubi.img -p 128KiB -m 2048 -s 512 ubi.ini
169
Pali Rohár43f7b812022-09-15 20:59:48 +0200170# Generate ubi image with rootfs on first volume and kernel in zImage format on second volume for UBI booting
171cp ubi.ini ubi_with_kernel.ini
172cat >> ubi_with_kernel.ini << EOF
173[kernel]
174mode=ubi
175image=zImage-2.6.28-omap1
176vol_id=1
177vol_size=2MiB
178vol_type=dynamic
179vol_name=kernel
180vol_alignment=1
181EOF
182/usr/sbin/ubinize -o ubi_with_kernel.img -p 128KiB -m 2048 -s 512 ubi_with_kernel.ini
183
Pali Rohár1ce0e1c2020-11-29 17:15:05 +0100184# Generate bootmenu for U-Boot serial console testing
185cat > bootmenu_uboot << EOF
186setenv bootmenu_0 'Serial console test=echo; echo "Testing serial console"; echo; echo "Successfully booted"; echo; poweroff';
187setenv bootmenu_1;
188setenv bootmenu_delay 1;
189setenv bootdelay 1;
190EOF
191./mkimage -A arm -O linux -T script -C none -a 0 -e 0 -n bootmenu_uboot -d bootmenu_uboot bootmenu_uboot.scr
192
Pali Rohárcc434fc2021-06-18 15:27:03 +0200193# Generate bootmenu for eMMC booting (uImage)
Pali Rohár6cfd09d2020-05-17 14:38:22 +0200194cat > bootmenu_emmc << EOF
195setenv 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';
196setenv bootmenu_1;
197setenv bootmenu_delay 1;
198setenv bootdelay 1;
199EOF
Pali Rohár56847f32020-10-31 17:32:48 +0100200./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 +0200201
Pali Rohárcc434fc2021-06-18 15:27:03 +0200202# Generate bootmenu for eMMC booting (zImage)
203cat > bootmenu_emmc2 << EOF
204setenv 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';
205setenv bootmenu_1;
206setenv bootmenu_delay 1;
207setenv bootdelay 1;
208EOF
209./mkimage -A arm -O linux -T script -C none -a 0 -e 0 -n bootmenu_emmc2 -d bootmenu_emmc2 bootmenu_emmc2.scr
210
Pali Rohár21dc5ef2022-09-04 03:29:05 +0200211# Generate bootmenu for OneNAND booting (uImage)
Pali Rohár6cfd09d2020-05-17 14:38:22 +0200212cat > bootmenu_nand << EOF
Pali Rohár75069652022-09-04 03:29:02 +0200213setenv 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 +0200214setenv bootmenu_1;
215setenv bootmenu_delay 1;
216setenv bootdelay 1;
217EOF
Pali Rohár56847f32020-10-31 17:32:48 +0100218./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 +0200219
Pali Rohár43f7b812022-09-15 20:59:48 +0200220# Generate bootmenu for UBI booting (zImage)
221cat > bootmenu_ubi << EOF
222setenv 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}';
223setenv bootmenu_1;
224setenv bootmenu_delay 1;
225setenv bootdelay 1;
226EOF
227./mkimage -A arm -O linux -T script -C none -a 0 -e 0 -n bootmenu_ubi -d bootmenu_ubi bootmenu_ubi.scr
228
Pali Rohárcc434fc2021-06-18 15:27:03 +0200229# Generate bootmenu for default booting
230cat > bootmenu_default << EOF
231setenv bootmenu_delay 1;
232setenv bootdelay 1;
233EOF
234./mkimage -A arm -O linux -T script -C none -a 0 -e 0 -n bootmenu_default -d bootmenu_default bootmenu_default.scr
235
Pali Rohár6cfd09d2020-05-17 14:38:22 +0200236# Generate combined image from u-boot and Maemo fiasco kernel
Pali Rohárcc434fc2021-06-18 15:27:03 +0200237./u-boot-gen-combined u-boot.bin zImage-2.6.28-omap1 combined_zimage.bin
Pali Rohárcc434fc2021-06-18 15:27:03 +0200238./u-boot-gen-combined u-boot.bin uImage-2.6.28-omap1 combined_uimage.bin
Pali Rohár6cfd09d2020-05-17 14:38:22 +0200239
240# Generate combined hack image from u-boot and Maemo fiasco kernel (kernel starts at 2MB offset and qflasher puts 2kB header before supplied image)
241cp u-boot.bin combined_hack.bin
242dd if=uImage-2.6.28-omap1 of=combined_hack.bin bs=1024 seek=$((2048-2))
243
Pali Rohár1ce0e1c2020-11-29 17:15:05 +0100244# Generate FAT32 eMMC image for U-Boot serial console testing
245truncate -s 50MiB emmc_uboot.img
246mformat -m 0xf8 -F -h 4 -s 16 -c 1 -t $((50*1024*1024/(4*16*512))) :: -i emmc_uboot.img
247mcopy bootmenu_uboot.scr ::/bootmenu.scr -i emmc_uboot.img
248
Pali Rohárcc434fc2021-06-18 15:27:03 +0200249# Generate FAT32 eMMC image for eMMC booting (uImage)
Pali Rohár6cfd09d2020-05-17 14:38:22 +0200250truncate -s 50MiB emmc_emmc.img
251mformat -m 0xf8 -F -h 4 -s 16 -c 1 -t $((50*1024*1024/(4*16*512))) :: -i emmc_emmc.img
252mcopy uImage-2.6.28-omap1 ::/uImage-2.6.28-omap1 -i emmc_emmc.img
253mcopy bootmenu_emmc.scr ::/bootmenu.scr -i emmc_emmc.img
254
Pali Rohárcc434fc2021-06-18 15:27:03 +0200255# Generate FAT32 eMMC image for eMMC booting (zImage)
256truncate -s 50MiB emmc_emmc2.img
257mformat -m 0xf8 -F -h 4 -s 16 -c 1 -t $((50*1024*1024/(4*16*512))) :: -i emmc_emmc2.img
258mcopy zImage-2.6.28-omap1 ::/zImage-2.6.28-omap1 -i emmc_emmc2.img
259mcopy bootmenu_emmc2.scr ::/bootmenu.scr -i emmc_emmc2.img
260
Pali Rohár21dc5ef2022-09-04 03:29:05 +0200261# Generate FAT32 eMMC image for OneNAND booting (uImage)
Pali Rohár6cfd09d2020-05-17 14:38:22 +0200262truncate -s 50MiB emmc_nand.img
263mformat -m 0xf8 -F -h 4 -s 16 -c 1 -t $((50*1024*1024/(4*16*512))) :: -i emmc_nand.img
264mcopy bootmenu_nand.scr ::/bootmenu.scr -i emmc_nand.img
265
Pali Rohár43f7b812022-09-15 20:59:48 +0200266# Generate FAT32 eMMC image for UBI booting (zImage)
267truncate -s 50MiB emmc_ubi.img
268mformat -m 0xf8 -F -h 4 -s 16 -c 1 -t $((50*1024*1024/(4*16*512))) :: -i emmc_ubi.img
269mcopy bootmenu_ubi.scr ::/bootmenu.scr -i emmc_ubi.img
270
Pali Rohárcc434fc2021-06-18 15:27:03 +0200271# Generate FAT32 eMMC image for default booting
272truncate -s 50MiB emmc_default.img
273mformat -m 0xf8 -F -h 4 -s 16 -c 1 -t $((50*1024*1024/(4*16*512))) :: -i emmc_default.img
274mcopy bootmenu_default.scr ::/bootmenu.scr -i emmc_default.img
275
Pali Rohár1ce0e1c2020-11-29 17:15:05 +0100276# Generate MTD image for U-Boot serial console testing
277rm -f mtd_uboot.img
278./qflasher -v -x xloader-qemu.bin -s secondary-qemu.bin -k u-boot.bin -m rx51 -o mtd_uboot.img
279
Pali Rohár6cfd09d2020-05-17 14:38:22 +0200280# Generate MTD image for RAM booting from bootloader nolo images, compiled image and rootfs image
281rm -f mtd_ram.img
Pali Rohárcc434fc2021-06-18 15:27:03 +0200282./qflasher -v -x xloader-qemu.bin -s secondary-qemu.bin -k combined_uimage.bin -r ubi.img -m rx51 -o mtd_ram.img
283rm -f mtd_ram2.img
284./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 +0200285
286# Generate MTD image for eMMC booting from bootloader nolo images, u-boot image and rootfs image
287rm -f mtd_emmc.img
288./qflasher -v -x xloader-qemu.bin -s secondary-qemu.bin -k u-boot.bin -r ubi.img -m rx51 -o mtd_emmc.img
289
290# Generate MTD image for OneNAND booting from bootloader nolo images, combined hacked image and rootfs image
291# Kernel image is put into initfs area, but qflasher reject to copy kernel image into initfs area because it does not have initfs signature
292# 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)
293rm -f mtd_nand.img
294./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
295
Pali Rohár43f7b812022-09-15 20:59:48 +0200296# Generate MTD image for UBI booting from bootloader nolo images, u-boot image with UBI/UBIFS support and rootfs image with kernel volume
297rm -f mtd_ubi.img
298./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
299
Pali Rohár6cfd09d2020-05-17 14:38:22 +0200300echo
301echo "======================================================"
302echo "========== Running test images in n900 qemu =========="
303echo "======================================================"
304echo
305
Pali Rohár1ce0e1c2020-11-29 17:15:05 +0100306# Run MTD image in qemu and wait for 300s if U-Boot prints testing string to serial console and poweroff
307rm -f qemu_uboot.log
308./qemu-system-arm -M n900 -mtdblock mtd_uboot.img -sd emmc_uboot.img -serial /dev/stdout -display none > qemu_uboot.log &
309qemu_pid=$!
310tail -F qemu_uboot.log &
311tail_pid=$!
312sleep 300 &
313sleep_pid=$!
314wait -n $sleep_pid $qemu_pid || true
315kill -9 $tail_pid $sleep_pid $qemu_pid 2>/dev/null || true
316wait || true
317
Pali Rohárcc434fc2021-06-18 15:27:03 +0200318# 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 +0200319rm -f qemu_ram.log
320./qemu-system-arm -M n900 -mtdblock mtd_ram.img -serial /dev/stdout -display none > qemu_ram.log &
321qemu_pid=$!
322tail -F qemu_ram.log &
323tail_pid=$!
Pali Rohár56847f32020-10-31 17:32:48 +0100324sleep 300 &
Pali Rohár6cfd09d2020-05-17 14:38:22 +0200325sleep_pid=$!
Pali Rohár56847f32020-10-31 17:32:48 +0100326wait -n $sleep_pid $qemu_pid || true
327kill -9 $tail_pid $sleep_pid $qemu_pid 2>/dev/null || true
328wait || true
Pali Rohár6cfd09d2020-05-17 14:38:22 +0200329
Pali Rohárcc434fc2021-06-18 15:27:03 +0200330# Run MTD image in qemu and wait for 300s if zImage kernel from RAM is correctly booted
331rm -f qemu_ram2.log
332./qemu-system-arm -M n900 -mtdblock mtd_ram2.img -sd emmc_default.img -serial /dev/stdout -display none > qemu_ram2.log &
333qemu_pid=$!
334tail -F qemu_ram2.log &
335tail_pid=$!
336sleep 300 &
337sleep_pid=$!
338wait -n $sleep_pid $qemu_pid || true
339kill -9 $tail_pid $sleep_pid $qemu_pid 2>/dev/null || true
340wait || true
341
342# 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 +0200343rm -f qemu_emmc.log
344./qemu-system-arm -M n900 -mtdblock mtd_emmc.img -sd emmc_emmc.img -serial /dev/stdout -display none > qemu_emmc.log &
345qemu_pid=$!
346tail -F qemu_emmc.log &
347tail_pid=$!
Pali Rohár56847f32020-10-31 17:32:48 +0100348sleep 300 &
Pali Rohár6cfd09d2020-05-17 14:38:22 +0200349sleep_pid=$!
Pali Rohár56847f32020-10-31 17:32:48 +0100350wait -n $sleep_pid $qemu_pid || true
351kill -9 $tail_pid $sleep_pid $qemu_pid 2>/dev/null || true
352wait || true
Pali Rohár6cfd09d2020-05-17 14:38:22 +0200353
Pali Rohárcc434fc2021-06-18 15:27:03 +0200354# Run MTD image in qemu and wait for 300s if zImage kernel from eMMC is correctly booted
355rm -f qemu_emmc2.log
356./qemu-system-arm -M n900 -mtdblock mtd_emmc.img -sd emmc_emmc2.img -serial /dev/stdout -display none > qemu_emmc2.log &
357qemu_pid=$!
358tail -F qemu_emmc2.log &
359tail_pid=$!
360sleep 300 &
361sleep_pid=$!
362wait -n $sleep_pid $qemu_pid || true
363kill -9 $tail_pid $sleep_pid $qemu_pid 2>/dev/null || true
364wait || true
365
Pali Rohár6cfd09d2020-05-17 14:38:22 +0200366# Run MTD image in qemu and wait for 300s if kernel from OneNAND is correctly booted
367rm -f qemu_nand.log
368./qemu-system-arm -M n900 -mtdblock mtd_nand.img -sd emmc_nand.img -serial /dev/stdout -display none > qemu_nand.log &
369qemu_pid=$!
370tail -F qemu_nand.log &
371tail_pid=$!
Pali Rohár56847f32020-10-31 17:32:48 +0100372sleep 300 &
Pali Rohár6cfd09d2020-05-17 14:38:22 +0200373sleep_pid=$!
Pali Rohár56847f32020-10-31 17:32:48 +0100374wait -n $sleep_pid $qemu_pid || true
375kill -9 $tail_pid $sleep_pid $qemu_pid 2>/dev/null || true
376wait || true
Pali Rohár6cfd09d2020-05-17 14:38:22 +0200377
Pali Rohár43f7b812022-09-15 20:59:48 +0200378# Run MTD image in qemu and wait for 300s if kernel from UBI is correctly booted
379rm -f qemu_ubi.log
380./qemu-system-arm -M n900 -mtdblock mtd_ubi.img -sd emmc_ubi.img -serial /dev/stdout -display none > qemu_ubi.log &
381qemu_pid=$!
382tail -F qemu_ubi.log &
383tail_pid=$!
384sleep 300 &
385sleep_pid=$!
386wait -n $sleep_pid $qemu_pid || true
387kill -9 $tail_pid $sleep_pid $qemu_pid 2>/dev/null || true
388wait || true
389
Pali Rohár6cfd09d2020-05-17 14:38:22 +0200390echo
391echo "============================="
392echo "========== Results =========="
393echo "============================="
394echo
395
Pali Rohár1ce0e1c2020-11-29 17:15:05 +0100396if 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 +0200397if 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
398if 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
399if 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
400if 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
401if 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 +0200402if 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 +0200403
404echo
405
Pali Rohár43f7b812022-09-15 20:59:48 +0200406if 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 +0200407 echo "All tests passed"
408 exit 0
409else
410 echo "Some tests failed"
411 exit 1
412fi