poky-qemu-internal 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. #!/bin/bash
  2. # Handle running Poky images under qemu
  3. #
  4. # Copyright (C) 2006-2008 OpenedHand Ltd.
  5. #
  6. # This program is free software; you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License version 2 as
  8. # published by the Free Software Foundation.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License along
  16. # with this program; if not, write to the Free Software Foundation, Inc.,
  17. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  18. # Call setting:
  19. # QEMU_MEMORY (optional) - set the amount of memory in the emualted system.
  20. # SERIAL_LOGFILE (optional) - log the serial port output to a file
  21. # CROSSPATH - the path to any cross toolchain to use with distcc
  22. #
  23. # Image options:
  24. # MACHINE - the machine to run
  25. # TYPE - the image type to run
  26. # ZIMAGE - the kernel image file to use
  27. # HDIMAGE - the disk image file to use
  28. #
  29. if [ -z "$QEMU_MEMORY" ]; then
  30. case "$MACHINE" in
  31. "qemux86")
  32. QEMU_MEMORY="128M"
  33. ;;
  34. *)
  35. QEMU_MEMORY="64M"
  36. ;;
  37. esac
  38. fi
  39. QEMUIFUP=`which poky-qemu-ifup`
  40. QEMUIFDOWN=`which poky-qemu-ifdown`
  41. KERNEL_NETWORK_CMD="ip=192.168.7.2::192.168.7.1:255.255.255.0"
  42. QEMU_TAP_CMD="-net tap,vlan=0,ifname=tap0,script=$QEMUIFUP,downscript=$QEMUIFDOWN"
  43. QEMU_NETWORK_CMD="-net nic,vlan=0 $QEMU_TAP_CMD"
  44. KERNCMDLINE="mem=$QEMU_MEMORY"
  45. SERIALOPTS=""
  46. if [ "x$SERIAL_LOGFILE" != "x" ]; then
  47. SERIALOPTS="-serial file:$SERIAL_LOGFILE"
  48. fi
  49. case "$MACHINE" in
  50. "qemuarm") ;;
  51. "qemuarmv6") ;;
  52. "qemuarmv7") ;;
  53. "qemux86") ;;
  54. "akita") ;;
  55. "spitz") ;;
  56. "nokia800") ;;
  57. "nokia800-maemo") ;;
  58. *)
  59. echo "Error: Unsupported machine type $MACHINE"
  60. return
  61. ;;
  62. esac
  63. if [ "$TYPE" != "nfs" -a ! -f "$HDIMAGE" ]; then
  64. echo "Error: Image file $HDIMAGE doesn't exist"
  65. return
  66. fi
  67. if [ ! -f "$ZIMAGE" ]; then
  68. echo "Error: Kernel image file $ZIMAGE doesn't exist"
  69. return
  70. fi
  71. if [ -e /proc/sys/vm/mmap_min_addr ]; then
  72. if [ `cat /proc/sys/vm/mmap_min_addr` != "0" ]; then
  73. echo "Error, please set /proc/sys/vm/mmap_min_addr to 0 since otherwise it can cause problems with QEMU"
  74. return
  75. fi
  76. fi
  77. if [ "$MACHINE" = "qemuarm" -o "$MACHINE" = "qemuarmv6" -o "$MACHINE" = "qemuarmv7" ]; then
  78. QEMU=qemu-system-arm
  79. if [ "$TYPE" = "ext2" ]; then
  80. KERNCMDLINE="root=/dev/sda console=ttyAMA0 console=tty0 $KERNEL_NETWORK_CMD mem=$QEMU_MEMORY"
  81. QEMUOPTIONS="$QEMU_NETWORK_CMD -M versatilepb -hda $HDIMAGE -usb -usbdevice wacom-tablet -no-reboot"
  82. fi
  83. if [ "$TYPE" = "nfs" ]; then
  84. if [ "x$HDIMAGE" = "x" ]; then
  85. HDIMAGE=/srv/nfs/qemuarm
  86. fi
  87. if [ ! -d "$HDIMAGE" ]; then
  88. echo "Error: NFS mount point $HDIMAGE doesn't exist"
  89. return
  90. fi
  91. KERNCMDLINE="root=/dev/nfs nfsroot=192.168.7.1:$HDIMAGE rw $KERNEL_NETWORK_CMD mem=$QEMU_MEMORY"
  92. QEMUOPTIONS="$QEMU_NETWORK_CMD -M versatilepb -no-reboot"
  93. fi
  94. if [ "$MACHINE" = "qemuarmv6" ]; then
  95. QEMUOPTIONS="$QEMUOPTIONS -cpu arm1136"
  96. fi
  97. if [ "$MACHINE" = "qemuarmv7" ]; then
  98. QEMUOPTIONS="$QEMUOPTIONS -cpu cortex-a8"
  99. fi
  100. fi
  101. if [ "$MACHINE" = "qemux86" ]; then
  102. QEMU=qemu
  103. if [ "$TYPE" = "ext2" ]; then
  104. KERNCMDLINE="root=/dev/hda mem=$QEMU_MEMORY $KERNEL_NETWORK_CMD"
  105. QEMUOPTIONS="-std-vga $QEMU_NETWORK_CMD -hda $HDIMAGE -usb -usbdevice wacom-tablet"
  106. fi
  107. if [ "$TYPE" = "nfs" ]; then
  108. if [ "x$HDIMAGE" = "x" ]; then
  109. HDIMAGE=/srv/nfs/qemux86
  110. fi
  111. if [ ! -d "$HDIMAGE" ]; then
  112. echo "Error: NFS mount point $HDIMAGE doesn't exist."
  113. return
  114. fi
  115. KERNCMDLINE="root=/dev/nfs nfsroot=192.168.7.1:$HDIMAGE rw $KERNEL_NETWORK_CMD mem=$QEMU_MEMORY"
  116. QEMUOPTIONS="-std-vga $QEMU_NETWORK_CMD"
  117. fi
  118. fi
  119. if [ "$MACHINE" = "spitz" ]; then
  120. QEMU=qemu-system-arm
  121. if [ "$TYPE" = "ext3" ]; then
  122. echo $HDIMAGE
  123. HDIMAGE=`readlink -f $HDIMAGE`
  124. echo $HDIMAGE
  125. if [ ! -e "$HDIMAGE.qemudisk" ]; then
  126. echo "Adding a partition table to the ext3 image for use by QEMU, please wait..."
  127. poky-addptable2image $HDIMAGE $HDIMAGE.qemudisk
  128. fi
  129. QEMUOPTIONS="$QEMU_NETWORK_CMD -M spitz -hda $HDIMAGE.qemudisk -portrait"
  130. fi
  131. fi
  132. if [ "$MACHINE" = "akita" ]; then
  133. QEMU=qemu-system-arm
  134. if [ "$TYPE" = "jffs2" ]; then
  135. HDIMAGE=`readlink -f $HDIMAGE`
  136. if [ ! -e "$HDIMAGE.qemuflash" ]; then
  137. echo "Converting raw image into flash image format for use by QEMU, please wait..."
  138. raw2flash.akita < $HDIMAGE > $HDIMAGE.qemuflash
  139. fi
  140. QEMUOPTIONS="$QEMU_NETWORK_CMD -M akita -mtdblock $HDIMAGE.qemuflash -portrait"
  141. fi
  142. fi
  143. if [ "$MACHINE" = "nokia800" ]; then
  144. QEMU=qemu-system-arm
  145. if [ "$TYPE" = "jffs2" ]; then
  146. HDIMAGE=`readlink -f $HDIMAGE`
  147. if [ ! -e "$HDIMAGE.qemuflash" ]; then
  148. echo "'Flashing' rootfs, please wait..."
  149. poky-nokia800-flashutil $HDIMAGE $HDIMAGE.qemuflash
  150. fi
  151. KERNCMDLINE="root=/dev/mtdblock4 rootfstype=jffs2"
  152. QEMU_NETWORK_CMD="-net nic,model=usb,vlan=0 $QEMU_TAP_CMD"
  153. QEMUOPTIONS="$QEMU_NETWORK_CMD -M n800 -mtdblock $HDIMAGE.qemuflash -serial vc -m 130 -serial vc -serial vc -serial vc -usb -usbdevice net:0"
  154. fi
  155. fi
  156. if [ "$MACHINE" = "nokia800-maemo" ]; then
  157. QEMU=qemu-system-arm
  158. if [ "$TYPE" = "jffs2" ]; then
  159. HDIMAGE=`readlink -f $HDIMAGE`
  160. if [ ! -e "$HDIMAGE.qemuflash" ]; then
  161. if [ ! -e "$HDIMAGE.initfs" ]; then
  162. echo "Error, $HDIMAGE.initfs must exist!"
  163. return
  164. fi
  165. if [ ! -e "$HDIMAGE.config" ]; then
  166. echo "Error, $HDIMAGE.config must exist!"
  167. echo "To generate it, take an n800 and cat /dev/mtdblock1 > $HDIMAGE.config"
  168. return
  169. fi
  170. echo "'Flashing' config partition, please wait..."
  171. poky-nokia800-flashutil $HDIMAGE.config $HDIMAGE.qemuflash config
  172. echo "'Flashing' initfs, please wait..."
  173. poky-nokia800-flashutil $HDIMAGE.initfs $HDIMAGE.qemuflash initfs
  174. echo "'Flashing' rootfs, please wait..."
  175. poky-nokia800-flashutil $HDIMAGE $HDIMAGE.qemuflash
  176. fi
  177. KERNCMDLINE=""
  178. QEMU_NETWORK_CMD="-net nic,model=usb,vlan=0 $QEMU_TAP_CMD"
  179. QEMUOPTIONS="$QEMU_NETWORK_CMD -M n800 -mtdblock $HDIMAGE.qemuflash -serial vc -m 130 -serial vc -serial vc -serial vc -usb -usbdevice net:0 -show-cursor"
  180. fi
  181. fi
  182. if [ "x$QEMUOPTIONS" = "x" ]; then
  183. echo "Error: Unable to support this combination of options"
  184. return
  185. fi
  186. SDKDIR="/usr/local/poky/eabi-glibc"
  187. if [ "$MACHINE" = "qemuarm" -o "$MACHINE" = "spitz" -o "$MACHINE" = "borzoi" -o "$MACHINE" = "akita" -o "$MACHINE" = "nokia800" ]; then
  188. SDKPATH="$SDKDIR/arm/arm-poky-linux-gnueabi/bin:$SDKDIR/arm/bin"
  189. fi
  190. if [ "$MACHINE" = "qemux86" ]; then
  191. SDKPATH="$SDKDIR/i586/i586-poky-linux/bin:$SDKDIR/i586/bin"
  192. fi
  193. PATH=$CROSSPATH:$SDKPATH:$PATH
  194. QEMUBIN=`which $QEMU`
  195. if [ ! -x "$QEMUBIN" ]; then
  196. echo "Error: No QEMU binary '$QEMU' could be found."
  197. return
  198. fi
  199. function _quit() {
  200. if [ -n "$PIDFILE" ]; then
  201. #echo kill `cat $PIDFILE`
  202. kill `cat $PIDFILE`
  203. fi
  204. return
  205. }
  206. DISTCCD=`which distccd`
  207. PIDFILE=""
  208. trap _quit INT TERM QUIT
  209. if [ -x "$DISTCCD" ]; then
  210. echo "Starting distccd..."
  211. PIDFILE=`mktemp`
  212. $DISTCCD --allow 192.168.7.2 --daemon --pid-file $PIDFILE &
  213. else
  214. echo "Warning: distccd not present, no distcc support loaded."
  215. fi
  216. echo "Running $QEMU using sudo..."
  217. echo $QEMUBIN -kernel $ZIMAGE $QEMUOPTIONS $SERIALOPTS $* --append "$KERNCMDLINE"
  218. sudo $QEMUBIN -kernel $ZIMAGE $QEMUOPTIONS $SERIALOPTS $* --append "$KERNCMDLINE" || /bin/true
  219. trap - INT TERM QUIT
  220. return