2 # SPDX-License-Identifier: GPL-2.0+
3 # (C) 2020 Pali Rohár <pali@kernel.org>
5 # External tools needed for this test:
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/)
21 /lib/ld-linux.so.2 (32-bit x86 version of LD loader, needed for qflasher)
22 ' | 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"
32 echo "============================================================"
33 echo "========== Compiling U-Boot for Nokia RX-51 board =========="
34 echo "============================================================"
37 # First compile u-boot-ubifs.bin binary with UBI/UBIFS support for Nokia RX-51 board according to doc/board/nokia/rx51.rst
38 make nokia_rx51_config
42 CONFIG_MTD_UBI_BEB_LIMIT=10
45 make -j4 u-boot.bin CROSS_COMPILE=arm-linux-gnueabi-
46 mv u-boot.bin u-boot-ubifs.bin
48 # Then compile standard u-boot.bin binary for Nokia RX-51 board
49 make nokia_rx51_config
50 make -j4 u-boot.bin CROSS_COMPILE=arm-linux-gnueabi-
52 # And then do all stuff in temporary directory
53 mkdir -p nokia_rx51_tmp
56 test -f mkimage || ln -s ../tools/mkimage .
57 test -f u-boot.bin || ln -s ../u-boot.bin .
58 test -f u-boot-ubifs.bin || ln -s ../u-boot-ubifs.bin .
61 echo "=========================================================================="
62 echo "========== Downloading and compiling qemu from qemu-linaro fork =========="
63 echo "=========================================================================="
66 # Download and compile linaro version qemu which has support for n900 machine
67 # Last working commit is 8f8d8e0796efe1a6f34cdd83fb798f3c41217ec1
68 if ! test -f qemu-system-arm; then
69 test -d qemu-linaro || git clone https://git.linaro.org/qemu/qemu-linaro.git
71 git checkout 8f8d8e0796efe1a6f34cdd83fb798f3c41217ec1
72 ./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
75 ln -s qemu-linaro/arm-softmmu/qemu-system-arm .
79 echo "==================================================="
80 echo "========== Downloading external binaries =========="
81 echo "==================================================="
84 # Download qflasher and nolo images
85 # This is proprietary qemu flasher tool with first stage images, but license allows non-commercial redistribution
86 wget -c http://repository.maemo.org/qemu-n900/qemu-n900.tar.gz
87 tar -xf qemu-n900.tar.gz
89 # Download Maemo script u-boot-gen-combined
90 if ! 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 .
96 # Download Maemo fiasco kernel
97 wget -c http://repository.maemo.org/pool/maemo5.0/free/k/kernel/kernel_2.6.28-20103103+0m5_armel.deb
98 dpkg -x kernel_2.6.28-20103103+0m5_armel.deb kernel_2.6.28
100 # Download Maemo libc
101 wget -c http://repository.maemo.org/pool/maemo5.0/free/g/glibc/libc6_2.5.1-1eglibc27+0m5_armel.deb
102 dpkg -x libc6_2.5.1-1eglibc27+0m5_armel.deb libc6_2.5.1
104 # Download Maemo busybox
105 wget -c http://repository.maemo.org/pool/maemo5.0/free/b/busybox/busybox_1.10.2.legal-1osso30+0m5_armel.deb
106 dpkg -x busybox_1.10.2.legal-1osso30+0m5_armel.deb busybox_1.10.2
109 echo "======================================="
110 echo "========== Generating images =========="
111 echo "======================================="
114 # Generate kernel image in zImage and uImage format from FIASCO format
115 dd 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
118 # Generate rootfs directory
122 mkdir -p rootfs/sbin/
124 cp -a busybox_1.10.2/bin/busybox rootfs/bin/
125 cp -a libc6_2.5.1/lib/ld-linux.so.3 rootfs/lib/
126 cp -a libc6_2.5.1/lib/ld-2.5.so rootfs/lib/
127 cp -a libc6_2.5.1/lib/libc.so.6 rootfs/lib/
128 cp -a libc6_2.5.1/lib/libc-2.5.so rootfs/lib/
129 cp -a libc6_2.5.1/lib/libcrypt.so.1 rootfs/lib/
130 cp -a libc6_2.5.1/lib/libcrypt-2.5.so rootfs/lib/
131 test -f rootfs/bin/sh || ln -sf busybox rootfs/bin/sh
132 test -f rootfs/sbin/poweroff || ln -sf ../bin/busybox rootfs/sbin/poweroff
133 cat > rootfs/sbin/preinit << EOF
136 echo "Successfully booted"
140 chmod +x rootfs/sbin/preinit
142 # Generate ubifs image from rootfs directory
143 # 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
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;
156 # Generate ubi image with rootfs on first volume
162 vol_size=230MiB # 1870 LEBs
168 /usr/sbin/ubinize -o ubi.img -p 128KiB -m 2048 -s 512 ubi.ini
170 # Generate ubi image with rootfs on first volume and kernel in zImage format on second volume for UBI booting
171 cp ubi.ini ubi_with_kernel.ini
172 cat >> ubi_with_kernel.ini << EOF
175 image=zImage-2.6.28-omap1
182 /usr/sbin/ubinize -o ubi_with_kernel.img -p 128KiB -m 2048 -s 512 ubi_with_kernel.ini
184 # Generate bootmenu for U-Boot serial console testing
185 cat > bootmenu_uboot << EOF
186 setenv bootmenu_0 'Serial console test=echo; echo "Testing serial console"; echo; echo "Successfully booted"; echo; poweroff';
188 setenv bootmenu_delay 1;
191 ./mkimage -A arm -O linux -T script -C none -a 0 -e 0 -n bootmenu_uboot -d bootmenu_uboot bootmenu_uboot.scr
193 # Generate bootmenu for eMMC booting (uImage)
194 cat > bootmenu_emmc << EOF
195 setenv 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';
197 setenv bootmenu_delay 1;
200 ./mkimage -A arm -O linux -T script -C none -a 0 -e 0 -n bootmenu_emmc -d bootmenu_emmc bootmenu_emmc.scr
202 # Generate bootmenu for eMMC booting (zImage)
203 cat > bootmenu_emmc2 << EOF
204 setenv 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';
206 setenv bootmenu_delay 1;
209 ./mkimage -A arm -O linux -T script -C none -a 0 -e 0 -n bootmenu_emmc2 -d bootmenu_emmc2 bootmenu_emmc2.scr
211 # Generate bootmenu for OneNAND booting (uImage)
212 cat > bootmenu_nand << EOF
213 setenv bootmenu_0 'uImage-2.6.28-omap1 from OneNAND=setenv bootargs; setenv setup_omap_atag 1; mtd read initfs \${kernaddr} && bootm \${kernaddr}';
215 setenv bootmenu_delay 1;
218 ./mkimage -A arm -O linux -T script -C none -a 0 -e 0 -n bootmenu_nand -d bootmenu_nand bootmenu_nand.scr
220 # Generate bootmenu for UBI booting (zImage)
221 cat > bootmenu_ubi << EOF
222 setenv 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}';
224 setenv bootmenu_delay 1;
227 ./mkimage -A arm -O linux -T script -C none -a 0 -e 0 -n bootmenu_ubi -d bootmenu_ubi bootmenu_ubi.scr
229 # Generate bootmenu for default booting
230 cat > bootmenu_default << EOF
231 setenv bootmenu_delay 1;
234 ./mkimage -A arm -O linux -T script -C none -a 0 -e 0 -n bootmenu_default -d bootmenu_default bootmenu_default.scr
236 # Generate combined image from u-boot and Maemo fiasco kernel
237 ./u-boot-gen-combined u-boot.bin zImage-2.6.28-omap1 combined_zimage.bin
238 ./u-boot-gen-combined u-boot.bin uImage-2.6.28-omap1 combined_uimage.bin
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)
241 cp u-boot.bin combined_hack.bin
242 dd if=uImage-2.6.28-omap1 of=combined_hack.bin bs=1024 seek=$((2048-2))
244 # Generate FAT32 eMMC image for U-Boot serial console testing
245 truncate -s 50MiB emmc_uboot.img
246 mformat -m 0xf8 -F -h 4 -s 16 -c 1 -t $((50*1024*1024/(4*16*512))) :: -i emmc_uboot.img
247 mcopy bootmenu_uboot.scr ::/bootmenu.scr -i emmc_uboot.img
249 # Generate FAT32 eMMC image for eMMC booting (uImage)
250 truncate -s 50MiB emmc_emmc.img
251 mformat -m 0xf8 -F -h 4 -s 16 -c 1 -t $((50*1024*1024/(4*16*512))) :: -i emmc_emmc.img
252 mcopy uImage-2.6.28-omap1 ::/uImage-2.6.28-omap1 -i emmc_emmc.img
253 mcopy bootmenu_emmc.scr ::/bootmenu.scr -i emmc_emmc.img
255 # Generate FAT32 eMMC image for eMMC booting (zImage)
256 truncate -s 50MiB emmc_emmc2.img
257 mformat -m 0xf8 -F -h 4 -s 16 -c 1 -t $((50*1024*1024/(4*16*512))) :: -i emmc_emmc2.img
258 mcopy zImage-2.6.28-omap1 ::/zImage-2.6.28-omap1 -i emmc_emmc2.img
259 mcopy bootmenu_emmc2.scr ::/bootmenu.scr -i emmc_emmc2.img
261 # Generate FAT32 eMMC image for OneNAND booting (uImage)
262 truncate -s 50MiB emmc_nand.img
263 mformat -m 0xf8 -F -h 4 -s 16 -c 1 -t $((50*1024*1024/(4*16*512))) :: -i emmc_nand.img
264 mcopy bootmenu_nand.scr ::/bootmenu.scr -i emmc_nand.img
266 # Generate FAT32 eMMC image for UBI booting (zImage)
267 truncate -s 50MiB emmc_ubi.img
268 mformat -m 0xf8 -F -h 4 -s 16 -c 1 -t $((50*1024*1024/(4*16*512))) :: -i emmc_ubi.img
269 mcopy bootmenu_ubi.scr ::/bootmenu.scr -i emmc_ubi.img
271 # Generate FAT32 eMMC image for default booting
272 truncate -s 50MiB emmc_default.img
273 mformat -m 0xf8 -F -h 4 -s 16 -c 1 -t $((50*1024*1024/(4*16*512))) :: -i emmc_default.img
274 mcopy bootmenu_default.scr ::/bootmenu.scr -i emmc_default.img
276 # Generate MTD image for U-Boot serial console testing
278 ./qflasher -v -x xloader-qemu.bin -s secondary-qemu.bin -k u-boot.bin -m rx51 -o mtd_uboot.img
280 # Generate MTD image for RAM booting from bootloader nolo images, compiled image and rootfs image
282 ./qflasher -v -x xloader-qemu.bin -s secondary-qemu.bin -k combined_uimage.bin -r ubi.img -m rx51 -o mtd_ram.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
286 # Generate MTD image for eMMC booting from bootloader nolo images, u-boot image and rootfs image
288 ./qflasher -v -x xloader-qemu.bin -s secondary-qemu.bin -k u-boot.bin -r ubi.img -m rx51 -o mtd_emmc.img
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)
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
296 # Generate MTD image for UBI booting from bootloader nolo images, u-boot image with UBI/UBIFS support and rootfs image with kernel volume
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
301 echo "======================================================"
302 echo "========== Running test images in n900 qemu =========="
303 echo "======================================================"
306 # Run MTD image in qemu and wait for 300s if U-Boot prints testing string to serial console and poweroff
308 ./qemu-system-arm -M n900 -mtdblock mtd_uboot.img -sd emmc_uboot.img -serial /dev/stdout -display none > qemu_uboot.log &
310 tail -F qemu_uboot.log &
314 wait -n $sleep_pid $qemu_pid || true
315 kill -9 $tail_pid $sleep_pid $qemu_pid 2>/dev/null || true
318 # Run MTD image in qemu and wait for 300s if uImage kernel from RAM is correctly booted
320 ./qemu-system-arm -M n900 -mtdblock mtd_ram.img -serial /dev/stdout -display none > qemu_ram.log &
322 tail -F qemu_ram.log &
326 wait -n $sleep_pid $qemu_pid || true
327 kill -9 $tail_pid $sleep_pid $qemu_pid 2>/dev/null || true
330 # Run MTD image in qemu and wait for 300s if zImage kernel from RAM is correctly booted
332 ./qemu-system-arm -M n900 -mtdblock mtd_ram2.img -sd emmc_default.img -serial /dev/stdout -display none > qemu_ram2.log &
334 tail -F qemu_ram2.log &
338 wait -n $sleep_pid $qemu_pid || true
339 kill -9 $tail_pid $sleep_pid $qemu_pid 2>/dev/null || true
342 # Run MTD image in qemu and wait for 300s if uImage kernel from eMMC is correctly booted
344 ./qemu-system-arm -M n900 -mtdblock mtd_emmc.img -sd emmc_emmc.img -serial /dev/stdout -display none > qemu_emmc.log &
346 tail -F qemu_emmc.log &
350 wait -n $sleep_pid $qemu_pid || true
351 kill -9 $tail_pid $sleep_pid $qemu_pid 2>/dev/null || true
354 # Run MTD image in qemu and wait for 300s if zImage kernel from eMMC is correctly booted
356 ./qemu-system-arm -M n900 -mtdblock mtd_emmc.img -sd emmc_emmc2.img -serial /dev/stdout -display none > qemu_emmc2.log &
358 tail -F qemu_emmc2.log &
362 wait -n $sleep_pid $qemu_pid || true
363 kill -9 $tail_pid $sleep_pid $qemu_pid 2>/dev/null || true
366 # Run MTD image in qemu and wait for 300s if kernel from OneNAND is correctly booted
368 ./qemu-system-arm -M n900 -mtdblock mtd_nand.img -sd emmc_nand.img -serial /dev/stdout -display none > qemu_nand.log &
370 tail -F qemu_nand.log &
374 wait -n $sleep_pid $qemu_pid || true
375 kill -9 $tail_pid $sleep_pid $qemu_pid 2>/dev/null || true
378 # Run MTD image in qemu and wait for 300s if kernel from UBI is correctly booted
380 ./qemu-system-arm -M n900 -mtdblock mtd_ubi.img -sd emmc_ubi.img -serial /dev/stdout -display none > qemu_ubi.log &
382 tail -F qemu_ubi.log &
386 wait -n $sleep_pid $qemu_pid || true
387 kill -9 $tail_pid $sleep_pid $qemu_pid 2>/dev/null || true
391 echo "============================="
392 echo "========== Results =========="
393 echo "============================="
396 if grep -q 'Successfully booted' qemu_uboot.log; then echo "U-Boot serial console is working"; else echo "U-Boot serial console test failed"; fi
397 if 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
398 if 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
399 if 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
400 if 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
401 if 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
402 if 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
406 if 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
407 echo "All tests passed"
410 echo "Some tests failed"