nokia_rx51_test.sh 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  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. /lib/ld-linux.so.2 (32-bit x86 version of LD loader, needed for qflasher)
  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"
  26. exit 1
  27. fi
  28. done || exit 1
  29. echo
  30. echo "============================================================"
  31. echo "========== Compiling U-Boot for Nokia RX-51 board =========="
  32. echo "============================================================"
  33. echo
  34. # First compile u-boot.bin binary for Nokia RX-51 board
  35. make nokia_rx51_config
  36. make -j4 u-boot.bin ARCH=arm CROSS_COMPILE=arm-linux-gnueabi-
  37. # And then do all stuff in temporary directory
  38. mkdir -p nokia_rx51_tmp
  39. cd nokia_rx51_tmp
  40. test -f mkimage || ln -s ../tools/mkimage .
  41. test -f u-boot.bin || ln -s ../u-boot.bin .
  42. echo
  43. echo "=========================================================================="
  44. echo "========== Downloading and compiling qemu from qemu-linaro fork =========="
  45. echo "=========================================================================="
  46. echo
  47. # Download and compile linaro version qemu which has support for n900 machine
  48. # Last working commit is 8f8d8e0796efe1a6f34cdd83fb798f3c41217ec1
  49. if ! test -f qemu-system-arm; then
  50. test -d qemu-linaro || git clone https://git.linaro.org/qemu/qemu-linaro.git
  51. cd qemu-linaro
  52. git checkout 8f8d8e0796efe1a6f34cdd83fb798f3c41217ec1
  53. ./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
  54. make -j4
  55. cd ..
  56. ln -s qemu-linaro/arm-softmmu/qemu-system-arm .
  57. fi
  58. echo
  59. echo "==================================================="
  60. echo "========== Downloading external binaries =========="
  61. echo "==================================================="
  62. echo
  63. # Download qflasher and nolo images
  64. # This is proprietary qemu flasher tool with first stage images, but license allows non-commercial redistribution
  65. wget -c http://repository.maemo.org/qemu-n900/qemu-n900.tar.gz
  66. tar -xf qemu-n900.tar.gz
  67. # Download Maemo script u-boot-gen-combined
  68. if ! test -f u-boot-gen-combined; then
  69. test -d u-boot-maemo || git clone https://github.com/pali/u-boot-maemo.git
  70. chmod +x u-boot-maemo/debian/u-boot-gen-combined
  71. ln -s u-boot-maemo/debian/u-boot-gen-combined .
  72. fi
  73. # Download Maemo fiasco kernel
  74. wget -c http://repository.maemo.org/pool/maemo5.0/free/k/kernel/kernel_2.6.28-20103103+0m5_armel.deb
  75. dpkg -x kernel_2.6.28-20103103+0m5_armel.deb kernel_2.6.28
  76. # Download Maemo libc
  77. wget -c http://repository.maemo.org/pool/maemo5.0/free/g/glibc/libc6_2.5.1-1eglibc27+0m5_armel.deb
  78. dpkg -x libc6_2.5.1-1eglibc27+0m5_armel.deb libc6_2.5.1
  79. # Download Maemo busybox
  80. wget -c http://repository.maemo.org/pool/maemo5.0/free/b/busybox/busybox_1.10.2.legal-1osso30+0m5_armel.deb
  81. dpkg -x busybox_1.10.2.legal-1osso30+0m5_armel.deb busybox_1.10.2
  82. echo
  83. echo "======================================="
  84. echo "========== Generating images =========="
  85. echo "======================================="
  86. echo
  87. # Generate rootfs directory
  88. mkdir -p rootfs
  89. mkdir -p rootfs/dev/
  90. mkdir -p rootfs/bin/
  91. mkdir -p rootfs/sbin/
  92. mkdir -p rootfs/lib/
  93. cp -a busybox_1.10.2/bin/busybox rootfs/bin/
  94. cp -a libc6_2.5.1/lib/ld-linux.so.3 rootfs/lib/
  95. cp -a libc6_2.5.1/lib/ld-2.5.so rootfs/lib/
  96. cp -a libc6_2.5.1/lib/libc.so.6 rootfs/lib/
  97. cp -a libc6_2.5.1/lib/libc-2.5.so rootfs/lib/
  98. cp -a libc6_2.5.1/lib/libcrypt.so.1 rootfs/lib/
  99. cp -a libc6_2.5.1/lib/libcrypt-2.5.so rootfs/lib/
  100. test -f rootfs/bin/sh || ln -sf busybox rootfs/bin/sh
  101. test -f rootfs/sbin/poweroff || ln -sf ../bin/busybox rootfs/sbin/poweroff
  102. cat > rootfs/sbin/preinit << EOF
  103. #!/bin/sh
  104. echo
  105. echo "Successfully booted"
  106. echo
  107. /sbin/poweroff -f
  108. EOF
  109. chmod +x rootfs/sbin/preinit
  110. # Generate ubi config file for ubi rootfs image
  111. cat > ubi.ini << EOF
  112. [rootfs]
  113. mode=ubi
  114. image=ubifs.img
  115. vol_id=0
  116. vol_size=160MiB
  117. vol_type=dynamic
  118. vol_name=rootfs
  119. vol_alignment=1
  120. vol_flags=autoresize
  121. EOF
  122. # Generate ubi rootfs image from rootfs directory
  123. # NOTE: Character device on host filesystem can be created only by root
  124. # But we do not need it on host filesystem, just in ubifs image
  125. # So run mknod and mkfs.ubifs commands under fakeroot program
  126. # which via LD_PRELOAD simulate mknod() and stat() functions
  127. # so mkfs.ubifs will see dev/console as character device and
  128. # put it correctly as character device into final ubifs image
  129. # Therefore we can run whole script as non-root nobody user
  130. fakeroot sh -c '
  131. rm -f rootfs/dev/console;
  132. mknod rootfs/dev/console c 5 1;
  133. /usr/sbin/mkfs.ubifs -m 2048 -e 129024 -c 2047 -r rootfs ubifs.img;
  134. '
  135. /usr/sbin/ubinize -o ubi.img -p 128KiB -m 2048 -s 512 ubi.ini
  136. # Generate bootmenu for U-Boot serial console testing
  137. cat > bootmenu_uboot << EOF
  138. setenv bootmenu_0 'Serial console test=echo; echo "Testing serial console"; echo; echo "Successfully booted"; echo; poweroff';
  139. setenv bootmenu_1;
  140. setenv bootmenu_delay 1;
  141. setenv bootdelay 1;
  142. EOF
  143. ./mkimage -A arm -O linux -T script -C none -a 0 -e 0 -n bootmenu_uboot -d bootmenu_uboot bootmenu_uboot.scr
  144. # Generate bootmenu for eMMC booting (uImage)
  145. cat > bootmenu_emmc << EOF
  146. 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';
  147. setenv bootmenu_1;
  148. setenv bootmenu_delay 1;
  149. setenv bootdelay 1;
  150. EOF
  151. ./mkimage -A arm -O linux -T script -C none -a 0 -e 0 -n bootmenu_emmc -d bootmenu_emmc bootmenu_emmc.scr
  152. # Generate bootmenu for eMMC booting (zImage)
  153. cat > bootmenu_emmc2 << EOF
  154. 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';
  155. setenv bootmenu_1;
  156. setenv bootmenu_delay 1;
  157. setenv bootdelay 1;
  158. EOF
  159. ./mkimage -A arm -O linux -T script -C none -a 0 -e 0 -n bootmenu_emmc2 -d bootmenu_emmc2 bootmenu_emmc2.scr
  160. # Generate bootmenu for OneNAND booting
  161. cat > bootmenu_nand << EOF
  162. setenv bootmenu_0 'uImage-2.6.28-omap1 from OneNAND=mtd read initfs \${kernaddr}; setenv bootargs; setenv setup_omap_atag 1; bootm \${kernaddr}';
  163. setenv bootmenu_1;
  164. setenv bootmenu_delay 1;
  165. setenv bootdelay 1;
  166. EOF
  167. ./mkimage -A arm -O linux -T script -C none -a 0 -e 0 -n bootmenu_nand -d bootmenu_nand bootmenu_nand.scr
  168. # Generate bootmenu for default booting
  169. cat > bootmenu_default << EOF
  170. setenv bootmenu_delay 1;
  171. setenv bootdelay 1;
  172. EOF
  173. ./mkimage -A arm -O linux -T script -C none -a 0 -e 0 -n bootmenu_default -d bootmenu_default bootmenu_default.scr
  174. # Generate combined image from u-boot and Maemo fiasco kernel
  175. dd if=kernel_2.6.28/boot/zImage-2.6.28-20103103+0m5.fiasco of=zImage-2.6.28-omap1 skip=95 bs=1
  176. ./u-boot-gen-combined u-boot.bin zImage-2.6.28-omap1 combined_zimage.bin
  177. ./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
  178. ./u-boot-gen-combined u-boot.bin uImage-2.6.28-omap1 combined_uimage.bin
  179. # Generate combined hack image from u-boot and Maemo fiasco kernel (kernel starts at 2MB offset and qflasher puts 2kB header before supplied image)
  180. cp u-boot.bin combined_hack.bin
  181. dd if=uImage-2.6.28-omap1 of=combined_hack.bin bs=1024 seek=$((2048-2))
  182. # Generate FAT32 eMMC image for U-Boot serial console testing
  183. truncate -s 50MiB emmc_uboot.img
  184. mformat -m 0xf8 -F -h 4 -s 16 -c 1 -t $((50*1024*1024/(4*16*512))) :: -i emmc_uboot.img
  185. mcopy bootmenu_uboot.scr ::/bootmenu.scr -i emmc_uboot.img
  186. # Generate FAT32 eMMC image for eMMC booting (uImage)
  187. truncate -s 50MiB emmc_emmc.img
  188. mformat -m 0xf8 -F -h 4 -s 16 -c 1 -t $((50*1024*1024/(4*16*512))) :: -i emmc_emmc.img
  189. mcopy uImage-2.6.28-omap1 ::/uImage-2.6.28-omap1 -i emmc_emmc.img
  190. mcopy bootmenu_emmc.scr ::/bootmenu.scr -i emmc_emmc.img
  191. # Generate FAT32 eMMC image for eMMC booting (zImage)
  192. truncate -s 50MiB emmc_emmc2.img
  193. mformat -m 0xf8 -F -h 4 -s 16 -c 1 -t $((50*1024*1024/(4*16*512))) :: -i emmc_emmc2.img
  194. mcopy zImage-2.6.28-omap1 ::/zImage-2.6.28-omap1 -i emmc_emmc2.img
  195. mcopy bootmenu_emmc2.scr ::/bootmenu.scr -i emmc_emmc2.img
  196. # Generate FAT32 eMMC image for OneNAND booting
  197. truncate -s 50MiB emmc_nand.img
  198. mformat -m 0xf8 -F -h 4 -s 16 -c 1 -t $((50*1024*1024/(4*16*512))) :: -i emmc_nand.img
  199. mcopy bootmenu_nand.scr ::/bootmenu.scr -i emmc_nand.img
  200. # Generate FAT32 eMMC image for default booting
  201. truncate -s 50MiB emmc_default.img
  202. mformat -m 0xf8 -F -h 4 -s 16 -c 1 -t $((50*1024*1024/(4*16*512))) :: -i emmc_default.img
  203. mcopy bootmenu_default.scr ::/bootmenu.scr -i emmc_default.img
  204. # Generate MTD image for U-Boot serial console testing
  205. rm -f mtd_uboot.img
  206. ./qflasher -v -x xloader-qemu.bin -s secondary-qemu.bin -k u-boot.bin -m rx51 -o mtd_uboot.img
  207. # Generate MTD image for RAM booting from bootloader nolo images, compiled image and rootfs image
  208. rm -f mtd_ram.img
  209. ./qflasher -v -x xloader-qemu.bin -s secondary-qemu.bin -k combined_uimage.bin -r ubi.img -m rx51 -o mtd_ram.img
  210. rm -f mtd_ram2.img
  211. ./qflasher -v -x xloader-qemu.bin -s secondary-qemu.bin -k combined_zimage.bin -r ubi.img -m rx51 -o mtd_ram2.img
  212. # Generate MTD image for eMMC booting from bootloader nolo images, u-boot image and rootfs image
  213. rm -f mtd_emmc.img
  214. ./qflasher -v -x xloader-qemu.bin -s secondary-qemu.bin -k u-boot.bin -r ubi.img -m rx51 -o mtd_emmc.img
  215. # Generate MTD image for OneNAND booting from bootloader nolo images, combined hacked image and rootfs image
  216. # Kernel image is put into initfs area, but qflasher reject to copy kernel image into initfs area because it does not have initfs signature
  217. # 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)
  218. rm -f mtd_nand.img
  219. ./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
  220. echo
  221. echo "======================================================"
  222. echo "========== Running test images in n900 qemu =========="
  223. echo "======================================================"
  224. echo
  225. # Run MTD image in qemu and wait for 300s if U-Boot prints testing string to serial console and poweroff
  226. rm -f qemu_uboot.log
  227. ./qemu-system-arm -M n900 -mtdblock mtd_uboot.img -sd emmc_uboot.img -serial /dev/stdout -display none > qemu_uboot.log &
  228. qemu_pid=$!
  229. tail -F qemu_uboot.log &
  230. tail_pid=$!
  231. sleep 300 &
  232. sleep_pid=$!
  233. wait -n $sleep_pid $qemu_pid || true
  234. kill -9 $tail_pid $sleep_pid $qemu_pid 2>/dev/null || true
  235. wait || true
  236. # Run MTD image in qemu and wait for 300s if uImage kernel from RAM is correctly booted
  237. rm -f qemu_ram.log
  238. ./qemu-system-arm -M n900 -mtdblock mtd_ram.img -serial /dev/stdout -display none > qemu_ram.log &
  239. qemu_pid=$!
  240. tail -F qemu_ram.log &
  241. tail_pid=$!
  242. sleep 300 &
  243. sleep_pid=$!
  244. wait -n $sleep_pid $qemu_pid || true
  245. kill -9 $tail_pid $sleep_pid $qemu_pid 2>/dev/null || true
  246. wait || true
  247. # Run MTD image in qemu and wait for 300s if zImage kernel from RAM is correctly booted
  248. rm -f qemu_ram2.log
  249. ./qemu-system-arm -M n900 -mtdblock mtd_ram2.img -sd emmc_default.img -serial /dev/stdout -display none > qemu_ram2.log &
  250. qemu_pid=$!
  251. tail -F qemu_ram2.log &
  252. tail_pid=$!
  253. sleep 300 &
  254. sleep_pid=$!
  255. wait -n $sleep_pid $qemu_pid || true
  256. kill -9 $tail_pid $sleep_pid $qemu_pid 2>/dev/null || true
  257. wait || true
  258. # Run MTD image in qemu and wait for 300s if uImage kernel from eMMC is correctly booted
  259. rm -f qemu_emmc.log
  260. ./qemu-system-arm -M n900 -mtdblock mtd_emmc.img -sd emmc_emmc.img -serial /dev/stdout -display none > qemu_emmc.log &
  261. qemu_pid=$!
  262. tail -F qemu_emmc.log &
  263. tail_pid=$!
  264. sleep 300 &
  265. sleep_pid=$!
  266. wait -n $sleep_pid $qemu_pid || true
  267. kill -9 $tail_pid $sleep_pid $qemu_pid 2>/dev/null || true
  268. wait || true
  269. # Run MTD image in qemu and wait for 300s if zImage kernel from eMMC is correctly booted
  270. rm -f qemu_emmc2.log
  271. ./qemu-system-arm -M n900 -mtdblock mtd_emmc.img -sd emmc_emmc2.img -serial /dev/stdout -display none > qemu_emmc2.log &
  272. qemu_pid=$!
  273. tail -F qemu_emmc2.log &
  274. tail_pid=$!
  275. sleep 300 &
  276. sleep_pid=$!
  277. wait -n $sleep_pid $qemu_pid || true
  278. kill -9 $tail_pid $sleep_pid $qemu_pid 2>/dev/null || true
  279. wait || true
  280. # Run MTD image in qemu and wait for 300s if kernel from OneNAND is correctly booted
  281. rm -f qemu_nand.log
  282. ./qemu-system-arm -M n900 -mtdblock mtd_nand.img -sd emmc_nand.img -serial /dev/stdout -display none > qemu_nand.log &
  283. qemu_pid=$!
  284. tail -F qemu_nand.log &
  285. tail_pid=$!
  286. sleep 300 &
  287. sleep_pid=$!
  288. wait -n $sleep_pid $qemu_pid || true
  289. kill -9 $tail_pid $sleep_pid $qemu_pid 2>/dev/null || true
  290. wait || true
  291. echo
  292. echo "============================="
  293. echo "========== Results =========="
  294. echo "============================="
  295. echo
  296. 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
  297. 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
  298. 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
  299. 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
  300. 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
  301. 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
  302. echo
  303. 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
  304. echo "All tests passed"
  305. exit 0
  306. else
  307. echo "Some tests failed"
  308. exit 1
  309. fi