nokia_rx51_test.sh 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. #!/bin/bash -e
  2. # SPDX-License-Identifier: GPL-2.0+
  3. # (C) 2020 Pali Rohár <pali@kernel.org>
  4. # External tools needed for this test:
  5. echo '
  6. wget
  7. git
  8. truncate
  9. tar
  10. dpkg
  11. dd
  12. make
  13. gcc
  14. arm-linux-gnueabi-gcc
  15. fakeroot (homepage http://fakeroot-ng.lingnu.com/)
  16. mcopy (from mtools, homepage http://www.gnu.org/software/mtools/)
  17. mformat (from mtools, homepage http://www.gnu.org/software/mtools/)
  18. /usr/sbin/mkfs.ubifs (from mtd-utils, homepage http://www.linux-mtd.infradead.org/)
  19. /usr/sbin/ubinize (from mtd-utils, homepage http://www.linux-mtd.infradead.org/)
  20. ' | while read tool info; do
  21. if test -z "$tool"; then continue; fi
  22. if ! which $tool 1>/dev/null 2>&1; then
  23. echo "Tool $tool was not found and is required to run this test"
  24. echo "First install $tool $info"
  25. exit 1
  26. fi
  27. done || exit 1
  28. echo
  29. echo "============================================================"
  30. echo "========== Compiling U-Boot for Nokia RX-51 board =========="
  31. echo "============================================================"
  32. echo
  33. # First compile u-boot.bin binary for Nokia RX-51 board
  34. make nokia_rx51_config
  35. make -j4 u-boot.bin ARCH=arm CROSS_COMPILE=arm-linux-gnueabi-
  36. # And then do all stuff in temporary directory
  37. mkdir -p nokia_rx51_tmp
  38. cd nokia_rx51_tmp
  39. test -f mkimage || ln -s ../tools/mkimage .
  40. test -f u-boot.bin || ln -s ../u-boot.bin .
  41. echo
  42. echo "=========================================================================="
  43. echo "========== Downloading and compiling qemu from qemu-linaro fork =========="
  44. echo "=========================================================================="
  45. echo
  46. # Download and compile linaro version qemu which has support for n900 machine
  47. # Last working commit is 8f8d8e0796efe1a6f34cdd83fb798f3c41217ec1
  48. if ! test -f qemu-system-arm; then
  49. test -d qemu-linaro || git clone https://git.linaro.org/qemu/qemu-linaro.git
  50. cd qemu-linaro
  51. git checkout 8f8d8e0796efe1a6f34cdd83fb798f3c41217ec1
  52. ./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
  53. make -j4
  54. cd ..
  55. ln -s qemu-linaro/arm-softmmu/qemu-system-arm .
  56. fi
  57. echo
  58. echo "==================================================="
  59. echo "========== Downloading external binaries =========="
  60. echo "==================================================="
  61. echo
  62. # Download qflasher and nolo images
  63. # This is proprietary qemu flasher tool with first stage images, but license allows non-commercial redistribution
  64. wget -c http://repository.maemo.org/qemu-n900/qemu-n900.tar.gz
  65. tar -xf qemu-n900.tar.gz
  66. # Download Maemo script u-boot-gen-combined
  67. if ! test -f u-boot-gen-combined; then
  68. test -d u-boot-maemo || git clone https://github.com/pali/u-boot-maemo.git
  69. chmod +x u-boot-maemo/debian/u-boot-gen-combined
  70. ln -s u-boot-maemo/debian/u-boot-gen-combined .
  71. fi
  72. # Download Maemo fiasco kernel
  73. wget -c http://repository.maemo.org/pool/maemo5.0/free/k/kernel/kernel_2.6.28-20103103+0m5_armel.deb
  74. dpkg -x kernel_2.6.28-20103103+0m5_armel.deb kernel_2.6.28
  75. # Download Maemo libc
  76. wget -c http://repository.maemo.org/pool/maemo5.0/free/g/glibc/libc6_2.5.1-1eglibc27+0m5_armel.deb
  77. dpkg -x libc6_2.5.1-1eglibc27+0m5_armel.deb libc6_2.5.1
  78. # Download Maemo busybox
  79. wget -c http://repository.maemo.org/pool/maemo5.0/free/b/busybox/busybox_1.10.2.legal-1osso30+0m5_armel.deb
  80. dpkg -x busybox_1.10.2.legal-1osso30+0m5_armel.deb busybox_1.10.2
  81. echo
  82. echo "======================================="
  83. echo "========== Generating images =========="
  84. echo "======================================="
  85. echo
  86. # Generate rootfs directory
  87. mkdir -p rootfs
  88. mkdir -p rootfs/dev/
  89. mkdir -p rootfs/bin/
  90. mkdir -p rootfs/sbin/
  91. mkdir -p rootfs/lib/
  92. cp -a busybox_1.10.2/bin/busybox rootfs/bin/
  93. cp -a libc6_2.5.1/lib/ld-linux.so.3 rootfs/lib/
  94. cp -a libc6_2.5.1/lib/ld-2.5.so rootfs/lib/
  95. cp -a libc6_2.5.1/lib/libc.so.6 rootfs/lib/
  96. cp -a libc6_2.5.1/lib/libc-2.5.so rootfs/lib/
  97. cp -a libc6_2.5.1/lib/libcrypt.so.1 rootfs/lib/
  98. cp -a libc6_2.5.1/lib/libcrypt-2.5.so rootfs/lib/
  99. test -f rootfs/bin/sh || ln -sf busybox rootfs/bin/sh
  100. test -f rootfs/sbin/poweroff || ln -sf ../bin/busybox rootfs/sbin/poweroff
  101. cat > rootfs/sbin/preinit << EOF
  102. #!/bin/sh
  103. echo
  104. echo "Successfully booted"
  105. echo
  106. /sbin/poweroff -f
  107. EOF
  108. chmod +x rootfs/sbin/preinit
  109. # Generate ubi config file for ubi rootfs image
  110. cat > ubi.ini << EOF
  111. [rootfs]
  112. mode=ubi
  113. image=ubifs.img
  114. vol_id=0
  115. vol_size=160MiB
  116. vol_type=dynamic
  117. vol_name=rootfs
  118. vol_alignment=1
  119. vol_flags=autoresize
  120. EOF
  121. # Generate ubi rootfs image from rootfs directory
  122. # NOTE: Character device on host filesystem can be created only by root
  123. # But we do not need it on host filesystem, just in ubifs image
  124. # So run mknod and mkfs.ubifs commands under fakeroot program
  125. # which via LD_PRELOAD simulate mknod() and stat() functions
  126. # so mkfs.ubifs will see dev/console as character device and
  127. # put it correctly as character device into final ubifs image
  128. # Therefore we can run whole script as non-root nobody user
  129. fakeroot sh -c '
  130. rm -f rootfs/dev/console;
  131. mknod rootfs/dev/console c 5 1;
  132. /usr/sbin/mkfs.ubifs -m 2048 -e 129024 -c 2047 -r rootfs ubifs.img;
  133. '
  134. /usr/sbin/ubinize -o ubi.img -p 128KiB -m 2048 -s 512 ubi.ini
  135. # Generate bootmenu for eMMC booting
  136. cat > bootmenu_emmc << EOF
  137. 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';
  138. setenv bootmenu_1;
  139. setenv bootmenu_delay 1;
  140. setenv bootdelay 1;
  141. EOF
  142. ./mkimage -A arm -O linux -T script -C none -a 0 -e 0 -n bootmenu_emmc -d bootmenu_emmc bootmenu_emmc.scr
  143. # Generate bootmenu for OneNAND booting
  144. cat > bootmenu_nand << EOF
  145. setenv bootmenu_0 'uImage-2.6.28-omap1 from OneNAND=mtd read initfs \${kernaddr}; setenv bootargs; setenv setup_omap_atag 1; bootm \${kernaddr}';
  146. setenv bootmenu_1;
  147. setenv bootmenu_delay 1;
  148. setenv bootdelay 1;
  149. EOF
  150. ./mkimage -A arm -O linux -T script -C none -a 0 -e 0 -n bootmenu_nand -d bootmenu_nand bootmenu_nand.scr
  151. # Generate combined image from u-boot and Maemo fiasco kernel
  152. dd if=kernel_2.6.28/boot/zImage-2.6.28-20103103+0m5.fiasco of=zImage-2.6.28-omap1 skip=95 bs=1
  153. ./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
  154. ./u-boot-gen-combined u-boot.bin uImage-2.6.28-omap1 combined.bin
  155. # Generate combined hack image from u-boot and Maemo fiasco kernel (kernel starts at 2MB offset and qflasher puts 2kB header before supplied image)
  156. cp u-boot.bin combined_hack.bin
  157. dd if=uImage-2.6.28-omap1 of=combined_hack.bin bs=1024 seek=$((2048-2))
  158. # Generate FAT32 eMMC image for eMMC booting
  159. truncate -s 50MiB emmc_emmc.img
  160. mformat -m 0xf8 -F -h 4 -s 16 -c 1 -t $((50*1024*1024/(4*16*512))) :: -i emmc_emmc.img
  161. mcopy uImage-2.6.28-omap1 ::/uImage-2.6.28-omap1 -i emmc_emmc.img
  162. mcopy bootmenu_emmc.scr ::/bootmenu.scr -i emmc_emmc.img
  163. # Generate FAT32 eMMC image for OneNAND booting
  164. truncate -s 50MiB emmc_nand.img
  165. mformat -m 0xf8 -F -h 4 -s 16 -c 1 -t $((50*1024*1024/(4*16*512))) :: -i emmc_nand.img
  166. mcopy bootmenu_nand.scr ::/bootmenu.scr -i emmc_nand.img
  167. # Generate MTD image for RAM booting from bootloader nolo images, compiled image and rootfs image
  168. rm -f mtd_ram.img
  169. ./qflasher -v -x xloader-qemu.bin -s secondary-qemu.bin -k combined.bin -r ubi.img -m rx51 -o mtd_ram.img
  170. # Generate MTD image for eMMC booting from bootloader nolo images, u-boot image and rootfs image
  171. rm -f mtd_emmc.img
  172. ./qflasher -v -x xloader-qemu.bin -s secondary-qemu.bin -k u-boot.bin -r ubi.img -m rx51 -o mtd_emmc.img
  173. # Generate MTD image for OneNAND booting from bootloader nolo images, combined hacked image and rootfs image
  174. # Kernel image is put into initfs area, but qflasher reject to copy kernel image into initfs area because it does not have initfs signature
  175. # 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)
  176. rm -f mtd_nand.img
  177. ./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
  178. echo
  179. echo "======================================================"
  180. echo "========== Running test images in n900 qemu =========="
  181. echo "======================================================"
  182. echo
  183. # Run MTD image in qemu and wait for 300s if kernel from RAM is correctly booted
  184. rm -f qemu_ram.log
  185. ./qemu-system-arm -M n900 -mtdblock mtd_ram.img -serial /dev/stdout -display none > qemu_ram.log &
  186. qemu_pid=$!
  187. tail -F qemu_ram.log &
  188. tail_pid=$!
  189. sleep 300 &
  190. sleep_pid=$!
  191. wait -n $sleep_pid $qemu_pid || true
  192. kill -9 $tail_pid $sleep_pid $qemu_pid 2>/dev/null || true
  193. wait || true
  194. # Run MTD image in qemu and wait for 300s if kernel from eMMC is correctly booted
  195. rm -f qemu_emmc.log
  196. ./qemu-system-arm -M n900 -mtdblock mtd_emmc.img -sd emmc_emmc.img -serial /dev/stdout -display none > qemu_emmc.log &
  197. qemu_pid=$!
  198. tail -F qemu_emmc.log &
  199. tail_pid=$!
  200. sleep 300 &
  201. sleep_pid=$!
  202. wait -n $sleep_pid $qemu_pid || true
  203. kill -9 $tail_pid $sleep_pid $qemu_pid 2>/dev/null || true
  204. wait || true
  205. # Run MTD image in qemu and wait for 300s if kernel from OneNAND is correctly booted
  206. rm -f qemu_nand.log
  207. ./qemu-system-arm -M n900 -mtdblock mtd_nand.img -sd emmc_nand.img -serial /dev/stdout -display none > qemu_nand.log &
  208. qemu_pid=$!
  209. tail -F qemu_nand.log &
  210. tail_pid=$!
  211. sleep 300 &
  212. sleep_pid=$!
  213. wait -n $sleep_pid $qemu_pid || true
  214. kill -9 $tail_pid $sleep_pid $qemu_pid 2>/dev/null || true
  215. wait || true
  216. echo
  217. echo "============================="
  218. echo "========== Results =========="
  219. echo "============================="
  220. echo
  221. 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
  222. 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
  223. 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
  224. echo
  225. if grep -q 'Successfully booted' qemu_ram.log && grep -q 'Successfully booted' qemu_emmc.log && grep -q 'Successfully booted' qemu_nand.log; then
  226. echo "All tests passed"
  227. exit 0
  228. else
  229. echo "Some tests failed"
  230. exit 1
  231. fi