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 ' | while read tool info; do
22 if test -z "$tool"; then continue; fi
23 if ! which $tool 1>/dev/null 2>&1; then
24 echo "Tool $tool was not found and is required to run this test"
25 echo "First install $tool $info"
31 echo "============================================================"
32 echo "========== Compiling U-Boot for Nokia RX-51 board =========="
33 echo "============================================================"
36 # First compile u-boot.bin binary for Nokia RX-51 board
37 make nokia_rx51_config
38 make -j4 u-boot.bin ARCH=arm CROSS_COMPILE=arm-linux-gnueabi-
40 # And then do all stuff in temporary directory
41 mkdir -p nokia_rx51_tmp
44 test -f mkimage || ln -s ../tools/mkimage .
45 test -f u-boot.bin || ln -s ../u-boot.bin .
48 echo "=========================================================================="
49 echo "========== Downloading and compiling qemu from qemu-linaro fork =========="
50 echo "=========================================================================="
53 # Download and compile linaro version qemu which has support for n900 machine
54 # Last working commit is 8f8d8e0796efe1a6f34cdd83fb798f3c41217ec1
55 if ! test -f qemu-system-arm; then
56 test -d qemu-linaro || git clone https://git.linaro.org/qemu/qemu-linaro.git
58 git checkout 8f8d8e0796efe1a6f34cdd83fb798f3c41217ec1
59 ./configure --enable-system --target-list=arm-softmmu --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
62 ln -s qemu-linaro/arm-softmmu/qemu-system-arm .
66 echo "==================================================="
67 echo "========== Downloading external binaries =========="
68 echo "==================================================="
71 # Download qflasher and nolo images
72 # This is proprietary qemu flasher tool with first stage images, but license allows non-commercial redistribution
73 wget -c http://repository.maemo.org/qemu-n900/qemu-n900.tar.gz
74 tar -xf qemu-n900.tar.gz
76 # Download Maemo script u-boot-gen-combined
77 if ! test -f u-boot-gen-combined; then
78 test -d u-boot-maemo || git clone https://github.com/pali/u-boot-maemo.git
79 chmod +x u-boot-maemo/debian/u-boot-gen-combined
80 ln -s u-boot-maemo/debian/u-boot-gen-combined .
83 # Download Maemo fiasco kernel
84 wget -c http://repository.maemo.org/pool/maemo5.0/free/k/kernel/kernel_2.6.28-20103103+0m5_armel.deb
85 dpkg -x kernel_2.6.28-20103103+0m5_armel.deb kernel_2.6.28
88 wget -c http://repository.maemo.org/pool/maemo5.0/free/g/glibc/libc6_2.5.1-1eglibc27+0m5_armel.deb
89 dpkg -x libc6_2.5.1-1eglibc27+0m5_armel.deb libc6_2.5.1
91 # Download Maemo busybox
92 wget -c http://repository.maemo.org/pool/maemo5.0/free/b/busybox/busybox_1.10.2.legal-1osso30+0m5_armel.deb
93 dpkg -x busybox_1.10.2.legal-1osso30+0m5_armel.deb busybox_1.10.2
96 echo "======================================="
97 echo "========== Generating images =========="
98 echo "======================================="
101 # Generate rootfs directory
105 mkdir -p rootfs/sbin/
107 cp -a busybox_1.10.2/bin/busybox rootfs/bin/
108 cp -a libc6_2.5.1/lib/ld-linux.so.3 rootfs/lib/
109 cp -a libc6_2.5.1/lib/ld-2.5.so rootfs/lib/
110 cp -a libc6_2.5.1/lib/libc.so.6 rootfs/lib/
111 cp -a libc6_2.5.1/lib/libc-2.5.so rootfs/lib/
112 cp -a libc6_2.5.1/lib/libcrypt.so.1 rootfs/lib/
113 cp -a libc6_2.5.1/lib/libcrypt-2.5.so rootfs/lib/
114 test -f rootfs/bin/sh || ln -sf busybox rootfs/bin/sh
115 test -f rootfs/sbin/poweroff || ln -sf ../bin/busybox rootfs/sbin/poweroff
116 cat > rootfs/sbin/preinit << EOF
119 echo "Successfully booted"
123 chmod +x rootfs/sbin/preinit
125 # Generate ubi config file for ubi rootfs image
138 # Generate ubi rootfs image from rootfs directory
139 # NOTE: Character device on host filesystem can be created only by root
140 # But we do not need it on host filesystem, just in ubifs image
141 # So run mknod and mkfs.ubifs commands under fakeroot program
142 # which via LD_PRELOAD simulate mknod() and stat() functions
143 # so mkfs.ubifs will see dev/console as character device and
144 # put it correctly as character device into final ubifs image
145 # Therefore we can run whole script as non-root nobody user
147 rm -f rootfs/dev/console;
148 mknod rootfs/dev/console c 5 1;
149 /usr/sbin/mkfs.ubifs -m 2048 -e 129024 -c 2047 -r rootfs ubifs.img;
151 /usr/sbin/ubinize -o ubi.img -p 128KiB -m 2048 -s 512 ubi.ini
153 # Generate bootmenu for eMMC booting
154 cat > bootmenu_emmc << EOF
155 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';
157 setenv bootmenu_delay 1;
160 ./mkimage -A arm -O linux -T script -C none -a 0 -e 0 -n bootmenu -d bootmenu_emmc bootmenu_emmc.scr
162 # Generate bootmenu for OneNAND booting
163 cat > bootmenu_nand << EOF
164 setenv bootmenu_0 'uImage-2.6.28-omap1 from OneNAND=mtd read initfs \${kernaddr}; setenv bootargs; setenv setup_omap_atag 1; bootm \${kernaddr}';
166 setenv bootmenu_delay 1;
169 ./mkimage -A arm -O linux -T script -C none -a 0 -e 0 -n bootmenu -d bootmenu_nand bootmenu_nand.scr
171 # Generate combined image from u-boot and Maemo fiasco kernel
172 dd if=kernel_2.6.28/boot/zImage-2.6.28-20103103+0m5.fiasco of=zImage-2.6.28-omap1 skip=95 bs=1
173 ./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
174 ./u-boot-gen-combined u-boot.bin uImage-2.6.28-omap1 combined.bin
176 # Generate combined hack image from u-boot and Maemo fiasco kernel (kernel starts at 2MB offset and qflasher puts 2kB header before supplied image)
177 cp u-boot.bin combined_hack.bin
178 dd if=uImage-2.6.28-omap1 of=combined_hack.bin bs=1024 seek=$((2048-2))
180 # Generate FAT32 eMMC image for eMMC booting
181 truncate -s 50MiB emmc_emmc.img
182 mformat -m 0xf8 -F -h 4 -s 16 -c 1 -t $((50*1024*1024/(4*16*512))) :: -i emmc_emmc.img
183 mcopy uImage-2.6.28-omap1 ::/uImage-2.6.28-omap1 -i emmc_emmc.img
184 mcopy bootmenu_emmc.scr ::/bootmenu.scr -i emmc_emmc.img
186 # Generate FAT32 eMMC image for OneNAND booting
187 truncate -s 50MiB emmc_nand.img
188 mformat -m 0xf8 -F -h 4 -s 16 -c 1 -t $((50*1024*1024/(4*16*512))) :: -i emmc_nand.img
189 mcopy bootmenu_nand.scr ::/bootmenu.scr -i emmc_nand.img
191 # Generate MTD image for RAM booting from bootloader nolo images, compiled image and rootfs image
193 ./qflasher -v -x xloader-qemu.bin -s secondary-qemu.bin -k combined.bin -r ubi.img -m rx51 -o mtd_ram.img
195 # Generate MTD image for eMMC booting from bootloader nolo images, u-boot image and rootfs image
197 ./qflasher -v -x xloader-qemu.bin -s secondary-qemu.bin -k u-boot.bin -r ubi.img -m rx51 -o mtd_emmc.img
199 # Generate MTD image for OneNAND booting from bootloader nolo images, combined hacked image and rootfs image
200 # Kernel image is put into initfs area, but qflasher reject to copy kernel image into initfs area because it does not have initfs signature
201 # 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)
203 ./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
206 echo "======================================================"
207 echo "========== Running test images in n900 qemu =========="
208 echo "======================================================"
211 # Run MTD image in qemu and wait for 300s if kernel from RAM is correctly booted
213 ./qemu-system-arm -M n900 -mtdblock mtd_ram.img -serial /dev/stdout -display none > qemu_ram.log &
215 tail -F qemu_ram.log &
217 { sleep 300 || true; kill -9 $qemu_pid $tail_pid 2>/dev/null || true; } &
219 wait $qemu_pid || true
220 kill -9 $tail_pid $sleep_pid 2>/dev/null || true
222 # Run MTD image in qemu and wait for 300s if kernel from eMMC is correctly booted
224 ./qemu-system-arm -M n900 -mtdblock mtd_emmc.img -sd emmc_emmc.img -serial /dev/stdout -display none > qemu_emmc.log &
226 tail -F qemu_emmc.log &
228 { sleep 300 || true; kill -9 $qemu_pid $tail_pid 2>/dev/null || true; } &
230 wait $qemu_pid || true
231 kill -9 $tail_pid $sleep_pid 2>/dev/null || true
233 # Run MTD image in qemu and wait for 300s if kernel from OneNAND is correctly booted
235 ./qemu-system-arm -M n900 -mtdblock mtd_nand.img -sd emmc_nand.img -serial /dev/stdout -display none > qemu_nand.log &
237 tail -F qemu_nand.log &
239 { sleep 300 || true; kill -9 $qemu_pid $tail_pid 2>/dev/null || true; } &
241 wait $qemu_pid || true
242 kill -9 $tail_pid $sleep_pid 2>/dev/null || true
245 echo "============================="
246 echo "========== Results =========="
247 echo "============================="
250 if grep -q 'Successfully booted' qemu_ram.log; then echo "Kernel was successfully booted from RAM"; else echo "Failed to boot kernel from RAM"; fi
251 if grep -q 'Successfully booted' qemu_emmc.log; then echo "Kernel was successfully booted from eMMC"; else echo "Failed to boot kernel from eMMC"; fi
252 if grep -q 'Successfully booted' qemu_nand.log; then echo "Kernel was successfully booted from OneNAND"; else echo "Failed to boot kernel from OneNAND"; fi
256 if grep -q 'Successfully booted' qemu_ram.log && grep -q 'Successfully booted' qemu_emmc.log && grep -q 'Successfully booted' qemu_nand.log; then
257 echo "All tests passed"
260 echo "Some tests failed"