2 # SPDX-License-Identifier: GPL-2.0+
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 if ! 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
91 # Download Maemo script u-boot-gen-combined
92 if ! 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 .
98 # Download Maemo fiasco kernel
99 if ! 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
104 # Download Maemo libc
105 if ! 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
110 # Download Maemo busybox
111 if ! 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
117 echo "======================================="
118 echo "========== Generating images =========="
119 echo "======================================="
122 # Generate kernel image in zImage and uImage format from FIASCO format
123 dd 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
126 # Generate rootfs directory
130 mkdir -p rootfs/sbin/
132 cp -a busybox_1.10.2/bin/busybox rootfs/bin/
133 cp -a libc6_2.5.1/lib/ld-linux.so.3 rootfs/lib/
134 cp -a libc6_2.5.1/lib/ld-2.5.so rootfs/lib/
135 cp -a libc6_2.5.1/lib/libc.so.6 rootfs/lib/
136 cp -a libc6_2.5.1/lib/libc-2.5.so rootfs/lib/
137 cp -a libc6_2.5.1/lib/libcrypt.so.1 rootfs/lib/
138 cp -a libc6_2.5.1/lib/libcrypt-2.5.so rootfs/lib/
139 test -f rootfs/bin/sh || ln -sf busybox rootfs/bin/sh
140 test -f rootfs/sbin/poweroff || ln -sf ../bin/busybox rootfs/sbin/poweroff
141 cat > rootfs/sbin/preinit << EOF
144 echo "Successfully booted"
148 chmod +x rootfs/sbin/preinit
150 # Generate ubifs image from rootfs directory
151 # 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
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;
164 # Generate ubi image with rootfs on first volume
170 vol_size=230MiB # 1870 LEBs
176 /usr/sbin/ubinize -o ubi.img -p 128KiB -m 2048 -s 512 ubi.ini
178 # Generate ubi image with rootfs on first volume and kernel in zImage format on second volume for UBI booting
179 cp ubi.ini ubi_with_kernel.ini
180 cat >> ubi_with_kernel.ini << EOF
183 image=zImage-2.6.28-omap1
190 /usr/sbin/ubinize -o ubi_with_kernel.img -p 128KiB -m 2048 -s 512 ubi_with_kernel.ini
192 # Generate bootmenu for U-Boot serial console testing
193 cat > bootmenu_uboot << EOF
194 setenv bootmenu_0 'Serial console test=echo; echo "Testing serial console"; echo; echo "Successfully booted"; echo; poweroff';
196 setenv bootmenu_delay 1;
199 ./mkimage -A arm -O linux -T script -C none -a 0 -e 0 -n bootmenu_uboot -d bootmenu_uboot bootmenu_uboot.scr
201 # Generate bootmenu for eMMC booting (uImage)
202 cat > bootmenu_emmc << EOF
203 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';
205 setenv bootmenu_delay 1;
208 ./mkimage -A arm -O linux -T script -C none -a 0 -e 0 -n bootmenu_emmc -d bootmenu_emmc bootmenu_emmc.scr
210 # Generate bootmenu for eMMC booting (zImage)
211 cat > bootmenu_emmc2 << EOF
212 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';
214 setenv bootmenu_delay 1;
217 ./mkimage -A arm -O linux -T script -C none -a 0 -e 0 -n bootmenu_emmc2 -d bootmenu_emmc2 bootmenu_emmc2.scr
219 # Generate bootmenu for OneNAND booting (uImage)
220 cat > bootmenu_nand << EOF
221 setenv bootmenu_0 'uImage-2.6.28-omap1 from OneNAND=setenv bootargs; setenv setup_omap_atag 1; mtd read initfs \${kernaddr} && bootm \${kernaddr}';
223 setenv bootmenu_delay 1;
226 ./mkimage -A arm -O linux -T script -C none -a 0 -e 0 -n bootmenu_nand -d bootmenu_nand bootmenu_nand.scr
228 # Generate bootmenu for UBI booting (zImage)
229 cat > bootmenu_ubi << EOF
230 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}';
232 setenv bootmenu_delay 1;
235 ./mkimage -A arm -O linux -T script -C none -a 0 -e 0 -n bootmenu_ubi -d bootmenu_ubi bootmenu_ubi.scr
237 # Generate bootmenu for default booting
238 cat > bootmenu_default << EOF
239 setenv bootmenu_delay 1;
242 ./mkimage -A arm -O linux -T script -C none -a 0 -e 0 -n bootmenu_default -d bootmenu_default bootmenu_default.scr
244 # Generate combined image from u-boot and Maemo fiasco kernel
245 ./u-boot-gen-combined u-boot.bin zImage-2.6.28-omap1 combined_zimage.bin
246 ./u-boot-gen-combined u-boot.bin uImage-2.6.28-omap1 combined_uimage.bin
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)
249 cp u-boot.bin combined_hack.bin
250 dd if=uImage-2.6.28-omap1 of=combined_hack.bin bs=1024 seek=$((2048-2))
252 # Generate FAT32 eMMC image for U-Boot serial console testing
253 truncate -s 50MiB emmc_uboot.img
254 mformat -m 0xf8 -F -h 4 -s 16 -c 1 -t $((50*1024*1024/(4*16*512))) :: -i emmc_uboot.img
255 mcopy bootmenu_uboot.scr ::/bootmenu.scr -i emmc_uboot.img
257 # Generate FAT32 eMMC image for eMMC booting (uImage)
258 truncate -s 50MiB emmc_emmc.img
259 mformat -m 0xf8 -F -h 4 -s 16 -c 1 -t $((50*1024*1024/(4*16*512))) :: -i emmc_emmc.img
260 mcopy uImage-2.6.28-omap1 ::/uImage-2.6.28-omap1 -i emmc_emmc.img
261 mcopy bootmenu_emmc.scr ::/bootmenu.scr -i emmc_emmc.img
263 # Generate FAT32 eMMC image for eMMC booting (zImage)
264 truncate -s 50MiB emmc_emmc2.img
265 mformat -m 0xf8 -F -h 4 -s 16 -c 1 -t $((50*1024*1024/(4*16*512))) :: -i emmc_emmc2.img
266 mcopy zImage-2.6.28-omap1 ::/zImage-2.6.28-omap1 -i emmc_emmc2.img
267 mcopy bootmenu_emmc2.scr ::/bootmenu.scr -i emmc_emmc2.img
269 # Generate FAT32 eMMC image for OneNAND booting (uImage)
270 truncate -s 50MiB emmc_nand.img
271 mformat -m 0xf8 -F -h 4 -s 16 -c 1 -t $((50*1024*1024/(4*16*512))) :: -i emmc_nand.img
272 mcopy bootmenu_nand.scr ::/bootmenu.scr -i emmc_nand.img
274 # Generate FAT32 eMMC image for UBI booting (zImage)
275 truncate -s 50MiB emmc_ubi.img
276 mformat -m 0xf8 -F -h 4 -s 16 -c 1 -t $((50*1024*1024/(4*16*512))) :: -i emmc_ubi.img
277 mcopy bootmenu_ubi.scr ::/bootmenu.scr -i emmc_ubi.img
279 # Generate FAT32 eMMC image for default booting
280 truncate -s 50MiB emmc_default.img
281 mformat -m 0xf8 -F -h 4 -s 16 -c 1 -t $((50*1024*1024/(4*16*512))) :: -i emmc_default.img
282 mcopy bootmenu_default.scr ::/bootmenu.scr -i emmc_default.img
284 # Generate MTD image for U-Boot serial console testing
286 ./qflasher -v -x xloader-qemu.bin -s secondary-qemu.bin -k u-boot.bin -m rx51 -o mtd_uboot.img
288 # Generate MTD image for RAM booting from bootloader nolo images, compiled image and rootfs image
290 ./qflasher -v -x xloader-qemu.bin -s secondary-qemu.bin -k combined_uimage.bin -r ubi.img -m rx51 -o mtd_ram.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
294 # Generate MTD image for eMMC booting from bootloader nolo images, u-boot image and rootfs image
296 ./qflasher -v -x xloader-qemu.bin -s secondary-qemu.bin -k u-boot.bin -r ubi.img -m rx51 -o mtd_emmc.img
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)
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
304 # Generate MTD image for UBI booting from bootloader nolo images, u-boot image with UBI/UBIFS support and rootfs image with kernel volume
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
309 echo "======================================================"
310 echo "========== Running test images in n900 qemu =========="
311 echo "======================================================"
314 # Run MTD image in qemu and wait for 300s if U-Boot prints testing string to serial console and poweroff
316 ./qemu-system-arm -M n900 -mtdblock mtd_uboot.img -sd emmc_uboot.img -serial /dev/stdout -display none > qemu_uboot.log &
318 tail -F qemu_uboot.log &
322 wait -n $sleep_pid $qemu_pid || true
323 kill -9 $tail_pid $sleep_pid $qemu_pid 2>/dev/null || true
326 # Run MTD image in qemu and wait for 300s if uImage kernel from RAM is correctly booted
328 ./qemu-system-arm -M n900 -mtdblock mtd_ram.img -serial /dev/stdout -display none > qemu_ram.log &
330 tail -F qemu_ram.log &
334 wait -n $sleep_pid $qemu_pid || true
335 kill -9 $tail_pid $sleep_pid $qemu_pid 2>/dev/null || true
338 # Run MTD image in qemu and wait for 300s if zImage kernel from RAM is correctly booted
340 ./qemu-system-arm -M n900 -mtdblock mtd_ram2.img -sd emmc_default.img -serial /dev/stdout -display none > qemu_ram2.log &
342 tail -F qemu_ram2.log &
346 wait -n $sleep_pid $qemu_pid || true
347 kill -9 $tail_pid $sleep_pid $qemu_pid 2>/dev/null || true
350 # Run MTD image in qemu and wait for 300s if uImage kernel from eMMC is correctly booted
352 ./qemu-system-arm -M n900 -mtdblock mtd_emmc.img -sd emmc_emmc.img -serial /dev/stdout -display none > qemu_emmc.log &
354 tail -F qemu_emmc.log &
358 wait -n $sleep_pid $qemu_pid || true
359 kill -9 $tail_pid $sleep_pid $qemu_pid 2>/dev/null || true
362 # Run MTD image in qemu and wait for 300s if zImage kernel from eMMC is correctly booted
364 ./qemu-system-arm -M n900 -mtdblock mtd_emmc.img -sd emmc_emmc2.img -serial /dev/stdout -display none > qemu_emmc2.log &
366 tail -F qemu_emmc2.log &
370 wait -n $sleep_pid $qemu_pid || true
371 kill -9 $tail_pid $sleep_pid $qemu_pid 2>/dev/null || true
374 # Run MTD image in qemu and wait for 300s if kernel from OneNAND is correctly booted
376 ./qemu-system-arm -M n900 -mtdblock mtd_nand.img -sd emmc_nand.img -serial /dev/stdout -display none > qemu_nand.log &
378 tail -F qemu_nand.log &
382 wait -n $sleep_pid $qemu_pid || true
383 kill -9 $tail_pid $sleep_pid $qemu_pid 2>/dev/null || true
386 # Run MTD image in qemu and wait for 300s if kernel from UBI is correctly booted
388 ./qemu-system-arm -M n900 -mtdblock mtd_ubi.img -sd emmc_ubi.img -serial /dev/stdout -display none > qemu_ubi.log &
390 tail -F qemu_ubi.log &
394 wait -n $sleep_pid $qemu_pid || true
395 kill -9 $tail_pid $sleep_pid $qemu_pid 2>/dev/null || true
399 echo "============================="
400 echo "========== Results =========="
401 echo "============================="
404 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
405 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
406 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
407 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
408 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
409 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
410 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
414 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
415 echo "All tests passed"
418 echo "Some tests failed"