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.bin binary for Nokia RX-51 board
38 make nokia_rx51_config
39 make -j4 u-boot.bin ARCH=arm CROSS_COMPILE=arm-linux-gnueabi-
41 # And then do all stuff in temporary directory
42 mkdir -p nokia_rx51_tmp
45 test -f mkimage || ln -s ../tools/mkimage .
46 test -f u-boot.bin || ln -s ../u-boot.bin .
49 echo "=========================================================================="
50 echo "========== Downloading and compiling qemu from qemu-linaro fork =========="
51 echo "=========================================================================="
54 # Download and compile linaro version qemu which has support for n900 machine
55 # Last working commit is 8f8d8e0796efe1a6f34cdd83fb798f3c41217ec1
56 if ! test -f qemu-system-arm; then
57 test -d qemu-linaro || git clone https://git.linaro.org/qemu/qemu-linaro.git
59 git checkout 8f8d8e0796efe1a6f34cdd83fb798f3c41217ec1
60 ./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
63 ln -s qemu-linaro/arm-softmmu/qemu-system-arm .
67 echo "==================================================="
68 echo "========== Downloading external binaries =========="
69 echo "==================================================="
72 # Download qflasher and nolo images
73 # This is proprietary qemu flasher tool with first stage images, but license allows non-commercial redistribution
74 wget -c http://repository.maemo.org/qemu-n900/qemu-n900.tar.gz
75 tar -xf qemu-n900.tar.gz
77 # Download Maemo script u-boot-gen-combined
78 if ! 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 .
84 # Download Maemo fiasco kernel
85 wget -c http://repository.maemo.org/pool/maemo5.0/free/k/kernel/kernel_2.6.28-20103103+0m5_armel.deb
86 dpkg -x kernel_2.6.28-20103103+0m5_armel.deb kernel_2.6.28
89 wget -c http://repository.maemo.org/pool/maemo5.0/free/g/glibc/libc6_2.5.1-1eglibc27+0m5_armel.deb
90 dpkg -x libc6_2.5.1-1eglibc27+0m5_armel.deb libc6_2.5.1
92 # Download Maemo busybox
93 wget -c http://repository.maemo.org/pool/maemo5.0/free/b/busybox/busybox_1.10.2.legal-1osso30+0m5_armel.deb
94 dpkg -x busybox_1.10.2.legal-1osso30+0m5_armel.deb busybox_1.10.2
97 echo "======================================="
98 echo "========== Generating images =========="
99 echo "======================================="
102 # Generate rootfs directory
106 mkdir -p rootfs/sbin/
108 cp -a busybox_1.10.2/bin/busybox rootfs/bin/
109 cp -a libc6_2.5.1/lib/ld-linux.so.3 rootfs/lib/
110 cp -a libc6_2.5.1/lib/ld-2.5.so rootfs/lib/
111 cp -a libc6_2.5.1/lib/libc.so.6 rootfs/lib/
112 cp -a libc6_2.5.1/lib/libc-2.5.so rootfs/lib/
113 cp -a libc6_2.5.1/lib/libcrypt.so.1 rootfs/lib/
114 cp -a libc6_2.5.1/lib/libcrypt-2.5.so rootfs/lib/
115 test -f rootfs/bin/sh || ln -sf busybox rootfs/bin/sh
116 test -f rootfs/sbin/poweroff || ln -sf ../bin/busybox rootfs/sbin/poweroff
117 cat > rootfs/sbin/preinit << EOF
120 echo "Successfully booted"
124 chmod +x rootfs/sbin/preinit
126 # Generate ubi config file for ubi rootfs image
132 vol_size=230MiB # 1870 LEBs
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
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;
152 /usr/sbin/ubinize -o ubi.img -p 128KiB -m 2048 -s 512 ubi.ini
154 # Generate bootmenu for U-Boot serial console testing
155 cat > bootmenu_uboot << EOF
156 setenv bootmenu_0 'Serial console test=echo; echo "Testing serial console"; echo; echo "Successfully booted"; echo; poweroff';
158 setenv bootmenu_delay 1;
161 ./mkimage -A arm -O linux -T script -C none -a 0 -e 0 -n bootmenu_uboot -d bootmenu_uboot bootmenu_uboot.scr
163 # Generate bootmenu for eMMC booting (uImage)
164 cat > bootmenu_emmc << EOF
165 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';
167 setenv bootmenu_delay 1;
170 ./mkimage -A arm -O linux -T script -C none -a 0 -e 0 -n bootmenu_emmc -d bootmenu_emmc bootmenu_emmc.scr
172 # Generate bootmenu for eMMC booting (zImage)
173 cat > bootmenu_emmc2 << EOF
174 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';
176 setenv bootmenu_delay 1;
179 ./mkimage -A arm -O linux -T script -C none -a 0 -e 0 -n bootmenu_emmc2 -d bootmenu_emmc2 bootmenu_emmc2.scr
181 # Generate bootmenu for OneNAND booting
182 cat > bootmenu_nand << EOF
183 setenv bootmenu_0 'uImage-2.6.28-omap1 from OneNAND=mtd read initfs \${kernaddr}; setenv bootargs; setenv setup_omap_atag 1; bootm \${kernaddr}';
185 setenv bootmenu_delay 1;
188 ./mkimage -A arm -O linux -T script -C none -a 0 -e 0 -n bootmenu_nand -d bootmenu_nand bootmenu_nand.scr
190 # Generate bootmenu for default booting
191 cat > bootmenu_default << EOF
192 setenv bootmenu_delay 1;
195 ./mkimage -A arm -O linux -T script -C none -a 0 -e 0 -n bootmenu_default -d bootmenu_default bootmenu_default.scr
197 # Generate combined image from u-boot and Maemo fiasco kernel
198 dd if=kernel_2.6.28/boot/zImage-2.6.28-20103103+0m5.fiasco of=zImage-2.6.28-omap1 skip=95 bs=1
199 ./u-boot-gen-combined u-boot.bin zImage-2.6.28-omap1 combined_zimage.bin
200 ./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
201 ./u-boot-gen-combined u-boot.bin uImage-2.6.28-omap1 combined_uimage.bin
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)
204 cp u-boot.bin combined_hack.bin
205 dd if=uImage-2.6.28-omap1 of=combined_hack.bin bs=1024 seek=$((2048-2))
207 # Generate FAT32 eMMC image for U-Boot serial console testing
208 truncate -s 50MiB emmc_uboot.img
209 mformat -m 0xf8 -F -h 4 -s 16 -c 1 -t $((50*1024*1024/(4*16*512))) :: -i emmc_uboot.img
210 mcopy bootmenu_uboot.scr ::/bootmenu.scr -i emmc_uboot.img
212 # Generate FAT32 eMMC image for eMMC booting (uImage)
213 truncate -s 50MiB emmc_emmc.img
214 mformat -m 0xf8 -F -h 4 -s 16 -c 1 -t $((50*1024*1024/(4*16*512))) :: -i emmc_emmc.img
215 mcopy uImage-2.6.28-omap1 ::/uImage-2.6.28-omap1 -i emmc_emmc.img
216 mcopy bootmenu_emmc.scr ::/bootmenu.scr -i emmc_emmc.img
218 # Generate FAT32 eMMC image for eMMC booting (zImage)
219 truncate -s 50MiB emmc_emmc2.img
220 mformat -m 0xf8 -F -h 4 -s 16 -c 1 -t $((50*1024*1024/(4*16*512))) :: -i emmc_emmc2.img
221 mcopy zImage-2.6.28-omap1 ::/zImage-2.6.28-omap1 -i emmc_emmc2.img
222 mcopy bootmenu_emmc2.scr ::/bootmenu.scr -i emmc_emmc2.img
224 # Generate FAT32 eMMC image for OneNAND booting
225 truncate -s 50MiB emmc_nand.img
226 mformat -m 0xf8 -F -h 4 -s 16 -c 1 -t $((50*1024*1024/(4*16*512))) :: -i emmc_nand.img
227 mcopy bootmenu_nand.scr ::/bootmenu.scr -i emmc_nand.img
229 # Generate FAT32 eMMC image for default booting
230 truncate -s 50MiB emmc_default.img
231 mformat -m 0xf8 -F -h 4 -s 16 -c 1 -t $((50*1024*1024/(4*16*512))) :: -i emmc_default.img
232 mcopy bootmenu_default.scr ::/bootmenu.scr -i emmc_default.img
234 # Generate MTD image for U-Boot serial console testing
236 ./qflasher -v -x xloader-qemu.bin -s secondary-qemu.bin -k u-boot.bin -m rx51 -o mtd_uboot.img
238 # Generate MTD image for RAM booting from bootloader nolo images, compiled image and rootfs image
240 ./qflasher -v -x xloader-qemu.bin -s secondary-qemu.bin -k combined_uimage.bin -r ubi.img -m rx51 -o mtd_ram.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
244 # Generate MTD image for eMMC booting from bootloader nolo images, u-boot image and rootfs image
246 ./qflasher -v -x xloader-qemu.bin -s secondary-qemu.bin -k u-boot.bin -r ubi.img -m rx51 -o mtd_emmc.img
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)
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
255 echo "======================================================"
256 echo "========== Running test images in n900 qemu =========="
257 echo "======================================================"
260 # Run MTD image in qemu and wait for 300s if U-Boot prints testing string to serial console and poweroff
262 ./qemu-system-arm -M n900 -mtdblock mtd_uboot.img -sd emmc_uboot.img -serial /dev/stdout -display none > qemu_uboot.log &
264 tail -F qemu_uboot.log &
268 wait -n $sleep_pid $qemu_pid || true
269 kill -9 $tail_pid $sleep_pid $qemu_pid 2>/dev/null || true
272 # Run MTD image in qemu and wait for 300s if uImage kernel from RAM is correctly booted
274 ./qemu-system-arm -M n900 -mtdblock mtd_ram.img -serial /dev/stdout -display none > qemu_ram.log &
276 tail -F qemu_ram.log &
280 wait -n $sleep_pid $qemu_pid || true
281 kill -9 $tail_pid $sleep_pid $qemu_pid 2>/dev/null || true
284 # Run MTD image in qemu and wait for 300s if zImage kernel from RAM is correctly booted
286 ./qemu-system-arm -M n900 -mtdblock mtd_ram2.img -sd emmc_default.img -serial /dev/stdout -display none > qemu_ram2.log &
288 tail -F qemu_ram2.log &
292 wait -n $sleep_pid $qemu_pid || true
293 kill -9 $tail_pid $sleep_pid $qemu_pid 2>/dev/null || true
296 # Run MTD image in qemu and wait for 300s if uImage kernel from eMMC is correctly booted
298 ./qemu-system-arm -M n900 -mtdblock mtd_emmc.img -sd emmc_emmc.img -serial /dev/stdout -display none > qemu_emmc.log &
300 tail -F qemu_emmc.log &
304 wait -n $sleep_pid $qemu_pid || true
305 kill -9 $tail_pid $sleep_pid $qemu_pid 2>/dev/null || true
308 # Run MTD image in qemu and wait for 300s if zImage kernel from eMMC is correctly booted
310 ./qemu-system-arm -M n900 -mtdblock mtd_emmc.img -sd emmc_emmc2.img -serial /dev/stdout -display none > qemu_emmc2.log &
312 tail -F qemu_emmc2.log &
316 wait -n $sleep_pid $qemu_pid || true
317 kill -9 $tail_pid $sleep_pid $qemu_pid 2>/dev/null || true
320 # Run MTD image in qemu and wait for 300s if kernel from OneNAND is correctly booted
322 ./qemu-system-arm -M n900 -mtdblock mtd_nand.img -sd emmc_nand.img -serial /dev/stdout -display none > qemu_nand.log &
324 tail -F qemu_nand.log &
328 wait -n $sleep_pid $qemu_pid || true
329 kill -9 $tail_pid $sleep_pid $qemu_pid 2>/dev/null || true
333 echo "============================="
334 echo "========== Results =========="
335 echo "============================="
338 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
339 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
340 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
341 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
342 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
343 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
347 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; then
348 echo "All tests passed"
351 echo "Some tests failed"