blob: 28aa554ed8bc3c7781ae96f78a26ab24214d7383 [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
37# First compile u-boot.bin binary for Nokia RX-51 board
38make nokia_rx51_config
39make -j4 u-boot.bin ARCH=arm CROSS_COMPILE=arm-linux-gnueabi-
40
41# And then do all stuff in temporary directory
42mkdir -p nokia_rx51_tmp
43cd nokia_rx51_tmp
44
45test -f mkimage || ln -s ../tools/mkimage .
46test -f u-boot.bin || ln -s ../u-boot.bin .
47
48echo
49echo "=========================================================================="
50echo "========== Downloading and compiling qemu from qemu-linaro fork =========="
51echo "=========================================================================="
52echo
53
54# Download and compile linaro version qemu which has support for n900 machine
55# Last working commit is 8f8d8e0796efe1a6f34cdd83fb798f3c41217ec1
56if ! test -f qemu-system-arm; then
57 test -d qemu-linaro || git clone https://git.linaro.org/qemu/qemu-linaro.git
58 cd qemu-linaro
59 git checkout 8f8d8e0796efe1a6f34cdd83fb798f3c41217ec1
Tom Rinib1c21022021-06-10 10:57:36 -040060 ./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 +020061 make -j4
62 cd ..
63 ln -s qemu-linaro/arm-softmmu/qemu-system-arm .
64fi
65
66echo
67echo "==================================================="
68echo "========== Downloading external binaries =========="
69echo "==================================================="
70echo
71
72# Download qflasher and nolo images
73# This is proprietary qemu flasher tool with first stage images, but license allows non-commercial redistribution
74wget -c http://repository.maemo.org/qemu-n900/qemu-n900.tar.gz
75tar -xf qemu-n900.tar.gz
76
77# Download Maemo script u-boot-gen-combined
78if ! test -f u-boot-gen-combined; then
79 test -d u-boot-maemo || git clone https://github.com/pali/u-boot-maemo.git
80 chmod +x u-boot-maemo/debian/u-boot-gen-combined
81 ln -s u-boot-maemo/debian/u-boot-gen-combined .
82fi
83
84# Download Maemo fiasco kernel
85wget -c http://repository.maemo.org/pool/maemo5.0/free/k/kernel/kernel_2.6.28-20103103+0m5_armel.deb
86dpkg -x kernel_2.6.28-20103103+0m5_armel.deb kernel_2.6.28
87
88# Download Maemo libc
89wget -c http://repository.maemo.org/pool/maemo5.0/free/g/glibc/libc6_2.5.1-1eglibc27+0m5_armel.deb
90dpkg -x libc6_2.5.1-1eglibc27+0m5_armel.deb libc6_2.5.1
91
92# Download Maemo busybox
93wget -c http://repository.maemo.org/pool/maemo5.0/free/b/busybox/busybox_1.10.2.legal-1osso30+0m5_armel.deb
94dpkg -x busybox_1.10.2.legal-1osso30+0m5_armel.deb busybox_1.10.2
95
96echo
97echo "======================================="
98echo "========== Generating images =========="
99echo "======================================="
100echo
101
102# Generate rootfs directory
103mkdir -p rootfs
104mkdir -p rootfs/dev/
105mkdir -p rootfs/bin/
106mkdir -p rootfs/sbin/
107mkdir -p rootfs/lib/
108cp -a busybox_1.10.2/bin/busybox rootfs/bin/
109cp -a libc6_2.5.1/lib/ld-linux.so.3 rootfs/lib/
110cp -a libc6_2.5.1/lib/ld-2.5.so rootfs/lib/
111cp -a libc6_2.5.1/lib/libc.so.6 rootfs/lib/
112cp -a libc6_2.5.1/lib/libc-2.5.so rootfs/lib/
113cp -a libc6_2.5.1/lib/libcrypt.so.1 rootfs/lib/
114cp -a libc6_2.5.1/lib/libcrypt-2.5.so rootfs/lib/
115test -f rootfs/bin/sh || ln -sf busybox rootfs/bin/sh
116test -f rootfs/sbin/poweroff || ln -sf ../bin/busybox rootfs/sbin/poweroff
117cat > rootfs/sbin/preinit << EOF
118#!/bin/sh
119echo
120echo "Successfully booted"
121echo
122/sbin/poweroff -f
123EOF
124chmod +x rootfs/sbin/preinit
125
126# Generate ubi config file for ubi rootfs image
127cat > ubi.ini << EOF
128[rootfs]
129mode=ubi
130image=ubifs.img
131vol_id=0
132vol_size=160MiB
133vol_type=dynamic
134vol_name=rootfs
135vol_alignment=1
136vol_flags=autoresize
137EOF
138
139# Generate ubi rootfs image from rootfs directory
140# NOTE: Character device on host filesystem can be created only by root
141# But we do not need it on host filesystem, just in ubifs image
142# So run mknod and mkfs.ubifs commands under fakeroot program
143# which via LD_PRELOAD simulate mknod() and stat() functions
144# so mkfs.ubifs will see dev/console as character device and
145# put it correctly as character device into final ubifs image
146# Therefore we can run whole script as non-root nobody user
147fakeroot sh -c '
148 rm -f rootfs/dev/console;
149 mknod rootfs/dev/console c 5 1;
150 /usr/sbin/mkfs.ubifs -m 2048 -e 129024 -c 2047 -r rootfs ubifs.img;
151'
152/usr/sbin/ubinize -o ubi.img -p 128KiB -m 2048 -s 512 ubi.ini
153
Pali Rohár1ce0e1c2020-11-29 17:15:05 +0100154# Generate bootmenu for U-Boot serial console testing
155cat > bootmenu_uboot << EOF
156setenv bootmenu_0 'Serial console test=echo; echo "Testing serial console"; echo; echo "Successfully booted"; echo; poweroff';
157setenv bootmenu_1;
158setenv bootmenu_delay 1;
159setenv bootdelay 1;
160EOF
161./mkimage -A arm -O linux -T script -C none -a 0 -e 0 -n bootmenu_uboot -d bootmenu_uboot bootmenu_uboot.scr
162
Pali Rohárcc434fc2021-06-18 15:27:03 +0200163# Generate bootmenu for eMMC booting (uImage)
Pali Rohár6cfd09d2020-05-17 14:38:22 +0200164cat > bootmenu_emmc << EOF
165setenv 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';
166setenv bootmenu_1;
167setenv bootmenu_delay 1;
168setenv bootdelay 1;
169EOF
Pali Rohár56847f32020-10-31 17:32:48 +0100170./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 +0200171
Pali Rohárcc434fc2021-06-18 15:27:03 +0200172# Generate bootmenu for eMMC booting (zImage)
173cat > bootmenu_emmc2 << EOF
174setenv 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';
175setenv bootmenu_1;
176setenv bootmenu_delay 1;
177setenv bootdelay 1;
178EOF
179./mkimage -A arm -O linux -T script -C none -a 0 -e 0 -n bootmenu_emmc2 -d bootmenu_emmc2 bootmenu_emmc2.scr
180
Pali Rohár6cfd09d2020-05-17 14:38:22 +0200181# Generate bootmenu for OneNAND booting
182cat > bootmenu_nand << EOF
183setenv bootmenu_0 'uImage-2.6.28-omap1 from OneNAND=mtd read initfs \${kernaddr}; setenv bootargs; setenv setup_omap_atag 1; bootm \${kernaddr}';
184setenv bootmenu_1;
185setenv bootmenu_delay 1;
186setenv bootdelay 1;
187EOF
Pali Rohár56847f32020-10-31 17:32:48 +0100188./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 +0200189
Pali Rohárcc434fc2021-06-18 15:27:03 +0200190# Generate bootmenu for default booting
191cat > bootmenu_default << EOF
192setenv bootmenu_delay 1;
193setenv bootdelay 1;
194EOF
195./mkimage -A arm -O linux -T script -C none -a 0 -e 0 -n bootmenu_default -d bootmenu_default bootmenu_default.scr
196
Pali Rohár6cfd09d2020-05-17 14:38:22 +0200197# Generate combined image from u-boot and Maemo fiasco kernel
198dd if=kernel_2.6.28/boot/zImage-2.6.28-20103103+0m5.fiasco of=zImage-2.6.28-omap1 skip=95 bs=1
Pali Rohárcc434fc2021-06-18 15:27:03 +0200199./u-boot-gen-combined u-boot.bin zImage-2.6.28-omap1 combined_zimage.bin
Pali Rohár6cfd09d2020-05-17 14:38:22 +0200200./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
Pali Rohárcc434fc2021-06-18 15:27:03 +0200201./u-boot-gen-combined u-boot.bin uImage-2.6.28-omap1 combined_uimage.bin
Pali Rohár6cfd09d2020-05-17 14:38:22 +0200202
203# Generate combined hack image from u-boot and Maemo fiasco kernel (kernel starts at 2MB offset and qflasher puts 2kB header before supplied image)
204cp u-boot.bin combined_hack.bin
205dd if=uImage-2.6.28-omap1 of=combined_hack.bin bs=1024 seek=$((2048-2))
206
Pali Rohár1ce0e1c2020-11-29 17:15:05 +0100207# Generate FAT32 eMMC image for U-Boot serial console testing
208truncate -s 50MiB emmc_uboot.img
209mformat -m 0xf8 -F -h 4 -s 16 -c 1 -t $((50*1024*1024/(4*16*512))) :: -i emmc_uboot.img
210mcopy bootmenu_uboot.scr ::/bootmenu.scr -i emmc_uboot.img
211
Pali Rohárcc434fc2021-06-18 15:27:03 +0200212# Generate FAT32 eMMC image for eMMC booting (uImage)
Pali Rohár6cfd09d2020-05-17 14:38:22 +0200213truncate -s 50MiB emmc_emmc.img
214mformat -m 0xf8 -F -h 4 -s 16 -c 1 -t $((50*1024*1024/(4*16*512))) :: -i emmc_emmc.img
215mcopy uImage-2.6.28-omap1 ::/uImage-2.6.28-omap1 -i emmc_emmc.img
216mcopy bootmenu_emmc.scr ::/bootmenu.scr -i emmc_emmc.img
217
Pali Rohárcc434fc2021-06-18 15:27:03 +0200218# Generate FAT32 eMMC image for eMMC booting (zImage)
219truncate -s 50MiB emmc_emmc2.img
220mformat -m 0xf8 -F -h 4 -s 16 -c 1 -t $((50*1024*1024/(4*16*512))) :: -i emmc_emmc2.img
221mcopy zImage-2.6.28-omap1 ::/zImage-2.6.28-omap1 -i emmc_emmc2.img
222mcopy bootmenu_emmc2.scr ::/bootmenu.scr -i emmc_emmc2.img
223
Pali Rohár6cfd09d2020-05-17 14:38:22 +0200224# Generate FAT32 eMMC image for OneNAND booting
225truncate -s 50MiB emmc_nand.img
226mformat -m 0xf8 -F -h 4 -s 16 -c 1 -t $((50*1024*1024/(4*16*512))) :: -i emmc_nand.img
227mcopy bootmenu_nand.scr ::/bootmenu.scr -i emmc_nand.img
228
Pali Rohárcc434fc2021-06-18 15:27:03 +0200229# Generate FAT32 eMMC image for default booting
230truncate -s 50MiB emmc_default.img
231mformat -m 0xf8 -F -h 4 -s 16 -c 1 -t $((50*1024*1024/(4*16*512))) :: -i emmc_default.img
232mcopy bootmenu_default.scr ::/bootmenu.scr -i emmc_default.img
233
Pali Rohár1ce0e1c2020-11-29 17:15:05 +0100234# Generate MTD image for U-Boot serial console testing
235rm -f mtd_uboot.img
236./qflasher -v -x xloader-qemu.bin -s secondary-qemu.bin -k u-boot.bin -m rx51 -o mtd_uboot.img
237
Pali Rohár6cfd09d2020-05-17 14:38:22 +0200238# Generate MTD image for RAM booting from bootloader nolo images, compiled image and rootfs image
239rm -f mtd_ram.img
Pali Rohárcc434fc2021-06-18 15:27:03 +0200240./qflasher -v -x xloader-qemu.bin -s secondary-qemu.bin -k combined_uimage.bin -r ubi.img -m rx51 -o mtd_ram.img
241rm -f mtd_ram2.img
242./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 +0200243
244# Generate MTD image for eMMC booting from bootloader nolo images, u-boot image and rootfs image
245rm -f mtd_emmc.img
246./qflasher -v -x xloader-qemu.bin -s secondary-qemu.bin -k u-boot.bin -r ubi.img -m rx51 -o mtd_emmc.img
247
248# Generate MTD image for OneNAND booting from bootloader nolo images, combined hacked image and rootfs image
249# Kernel image is put into initfs area, but qflasher reject to copy kernel image into initfs area because it does not have initfs signature
250# 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)
251rm -f mtd_nand.img
252./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
253
254echo
255echo "======================================================"
256echo "========== Running test images in n900 qemu =========="
257echo "======================================================"
258echo
259
Pali Rohár1ce0e1c2020-11-29 17:15:05 +0100260# Run MTD image in qemu and wait for 300s if U-Boot prints testing string to serial console and poweroff
261rm -f qemu_uboot.log
262./qemu-system-arm -M n900 -mtdblock mtd_uboot.img -sd emmc_uboot.img -serial /dev/stdout -display none > qemu_uboot.log &
263qemu_pid=$!
264tail -F qemu_uboot.log &
265tail_pid=$!
266sleep 300 &
267sleep_pid=$!
268wait -n $sleep_pid $qemu_pid || true
269kill -9 $tail_pid $sleep_pid $qemu_pid 2>/dev/null || true
270wait || true
271
Pali Rohárcc434fc2021-06-18 15:27:03 +0200272# 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 +0200273rm -f qemu_ram.log
274./qemu-system-arm -M n900 -mtdblock mtd_ram.img -serial /dev/stdout -display none > qemu_ram.log &
275qemu_pid=$!
276tail -F qemu_ram.log &
277tail_pid=$!
Pali Rohár56847f32020-10-31 17:32:48 +0100278sleep 300 &
Pali Rohár6cfd09d2020-05-17 14:38:22 +0200279sleep_pid=$!
Pali Rohár56847f32020-10-31 17:32:48 +0100280wait -n $sleep_pid $qemu_pid || true
281kill -9 $tail_pid $sleep_pid $qemu_pid 2>/dev/null || true
282wait || true
Pali Rohár6cfd09d2020-05-17 14:38:22 +0200283
Pali Rohárcc434fc2021-06-18 15:27:03 +0200284# Run MTD image in qemu and wait for 300s if zImage kernel from RAM is correctly booted
285rm -f qemu_ram2.log
286./qemu-system-arm -M n900 -mtdblock mtd_ram2.img -sd emmc_default.img -serial /dev/stdout -display none > qemu_ram2.log &
287qemu_pid=$!
288tail -F qemu_ram2.log &
289tail_pid=$!
290sleep 300 &
291sleep_pid=$!
292wait -n $sleep_pid $qemu_pid || true
293kill -9 $tail_pid $sleep_pid $qemu_pid 2>/dev/null || true
294wait || true
295
296# 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 +0200297rm -f qemu_emmc.log
298./qemu-system-arm -M n900 -mtdblock mtd_emmc.img -sd emmc_emmc.img -serial /dev/stdout -display none > qemu_emmc.log &
299qemu_pid=$!
300tail -F qemu_emmc.log &
301tail_pid=$!
Pali Rohár56847f32020-10-31 17:32:48 +0100302sleep 300 &
Pali Rohár6cfd09d2020-05-17 14:38:22 +0200303sleep_pid=$!
Pali Rohár56847f32020-10-31 17:32:48 +0100304wait -n $sleep_pid $qemu_pid || true
305kill -9 $tail_pid $sleep_pid $qemu_pid 2>/dev/null || true
306wait || true
Pali Rohár6cfd09d2020-05-17 14:38:22 +0200307
Pali Rohárcc434fc2021-06-18 15:27:03 +0200308# Run MTD image in qemu and wait for 300s if zImage kernel from eMMC is correctly booted
309rm -f qemu_emmc2.log
310./qemu-system-arm -M n900 -mtdblock mtd_emmc.img -sd emmc_emmc2.img -serial /dev/stdout -display none > qemu_emmc2.log &
311qemu_pid=$!
312tail -F qemu_emmc2.log &
313tail_pid=$!
314sleep 300 &
315sleep_pid=$!
316wait -n $sleep_pid $qemu_pid || true
317kill -9 $tail_pid $sleep_pid $qemu_pid 2>/dev/null || true
318wait || true
319
Pali Rohár6cfd09d2020-05-17 14:38:22 +0200320# Run MTD image in qemu and wait for 300s if kernel from OneNAND is correctly booted
321rm -f qemu_nand.log
322./qemu-system-arm -M n900 -mtdblock mtd_nand.img -sd emmc_nand.img -serial /dev/stdout -display none > qemu_nand.log &
323qemu_pid=$!
324tail -F qemu_nand.log &
325tail_pid=$!
Pali Rohár56847f32020-10-31 17:32:48 +0100326sleep 300 &
Pali Rohár6cfd09d2020-05-17 14:38:22 +0200327sleep_pid=$!
Pali Rohár56847f32020-10-31 17:32:48 +0100328wait -n $sleep_pid $qemu_pid || true
329kill -9 $tail_pid $sleep_pid $qemu_pid 2>/dev/null || true
330wait || true
Pali Rohár6cfd09d2020-05-17 14:38:22 +0200331
332echo
333echo "============================="
334echo "========== Results =========="
335echo "============================="
336echo
337
Pali Rohár1ce0e1c2020-11-29 17:15:05 +0100338if 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 +0200339if 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
340if 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
341if 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
342if 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
343if 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ár6cfd09d2020-05-17 14:38:22 +0200344
345echo
346
Pali Rohárcc434fc2021-06-18 15:27:03 +0200347if 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; then
Pali Rohár6cfd09d2020-05-17 14:38:22 +0200348 echo "All tests passed"
349 exit 0
350else
351 echo "Some tests failed"
352 exit 1
353fi