poky-qemu-internal 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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. QEMUIFUP=`which poky-qemu-ifup`
  30. QEMUIFDOWN=`which poky-qemu-ifdown`
  31. KERNEL_NETWORK_CMD="ip=192.168.7.2::192.168.7.1:255.255.255.0"
  32. QEMU_NETWORK_CMD="-net nic,vlan=0 -net tap,vlan=0,ifname=tap0,script=$QEMUIFUP,downscript=$QEMUIFDOWN"
  33. KERNCMDLINE="mem=$QEMU_MEMORY"
  34. if [ -z "$QEMU_MEMORY" ]; then
  35. QEMU_MEMORY="64M"
  36. fi
  37. SERIALOPTS=""
  38. if [ "x$SERIAL_LOGFILE" != "x" ]; then
  39. SERIALOPTS="-serial file:$SERIAL_LOGFILE"
  40. fi
  41. case "$MACHINE" in
  42. "qemuarm") ;;
  43. "qemux86") ;;
  44. "akita") ;;
  45. "spitz") ;;
  46. *)
  47. echo "Error: Unsupported machine type $MACHINE"
  48. return
  49. ;;
  50. esac
  51. if [ "$TYPE" != "nfs" -a ! -f "$HDIMAGE" ]; then
  52. echo "Error: Image file $HDIMAGE doesn't exist"
  53. return
  54. fi
  55. if [ ! -f "$ZIMAGE" ]; then
  56. echo "Error: Kernel image file $ZIMAGE doesn't exist"
  57. return
  58. fi
  59. if [ "$MACHINE" = "qemuarm" ]; then
  60. QEMU=qemu-system-arm
  61. if [ "$TYPE" = "ext2" ]; then
  62. KERNCMDLINE="root=/dev/sda console=ttyAMA0 console=tty0 mem=$QEMU_MEMORY"
  63. QEMUOPTIONS="$QEMU_NETWORK_CMD -M versatilepb -hda $HDIMAGE -usb -usbdevice wacom-tablet -no-reboot"
  64. fi
  65. if [ "$TYPE" = "nfs" ]; then
  66. if [ "x$HDIMAGE" = "x" ]; then
  67. HDIMAGE=/srv/nfs/qemuarm
  68. fi
  69. if [ ! -d "$HDIMAGE" ]; then
  70. echo "Error: NFS mount point $HDIMAGE doesn't exist"
  71. return
  72. fi
  73. KERNCMDLINE="root=/dev/nfs nfsroot=192.168.7.1:$HDIMAGE rw $KERNEL_NETWORK_CMD mem=$QEMU_MEMORY"
  74. QEMUOPTIONS="$QEMU_NETWORK_CMD -M versatilepb -no-reboot"
  75. fi
  76. fi
  77. if [ "$MACHINE" = "qemux86" ]; then
  78. QEMU=qemu
  79. if [ "$TYPE" = "ext2" ]; then
  80. KERNCMDLINE="root=/dev/hda mem=$QEMU_MEMORY $KERNEL_NETWORK_CMD"
  81. QEMUOPTIONS="-std-vga $QEMU_NETWORK_CMD -hda $HDIMAGE -usb -usbdevice wacom-tablet"
  82. fi
  83. if [ "$TYPE" = "nfs" ]; then
  84. if [ "x$HDIMAGE" = "x" ]; then
  85. HDIMAGE=/srv/nfs/qemux86
  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="-std-vga $QEMU_NETWORK_CMD"
  93. fi
  94. fi
  95. if [ "$MACHINE" = "spitz" ]; then
  96. QEMU=qemu-system-arm
  97. if [ "$TYPE" = "ext3" ]; then
  98. echo $HDIMAGE
  99. HDIMAGE=`readlink -f $HDIMAGE`
  100. echo $HDIMAGE
  101. if [ ! -e "$HDIMAGE.qemudisk" ]; then
  102. echo "Adding a partition table to the ext3 image for use by QEMU, please wait..."
  103. poky-addptable2image $HDIMAGE $HDIMAGE.qemudisk
  104. fi
  105. QEMUOPTIONS="$QEMU_NETWORK_CMD -M spitz -hda $HDIMAGE.qemudisk -portrait"
  106. fi
  107. fi
  108. if [ "$MACHINE" = "akita" ]; then
  109. QEMU=qemu-system-arm
  110. if [ "$TYPE" = "jffs2" ]; then
  111. HDIMAGE=`readlink -f $HDIMAGE`
  112. if [ ! -e "$HDIMAGE.qemuflash" ]; then
  113. echo "Converting raw image into flash image format for use by QEMU, please wait..."
  114. raw2flash.akita < $HDIMAGE > $HDIMAGE.qemuflash
  115. fi
  116. QEMUOPTIONS="$QEMU_NETWORK_CMD -M akita -mtdblock $HDIMAGE.qemuflash -portrait"
  117. fi
  118. fi
  119. if [ "x$QEMUOPTIONS" = "x" ]; then
  120. echo "Error: Unable to support this combination of options"
  121. return
  122. fi
  123. SDKDIR="/usr/local/poky/eabi-glibc"
  124. if [ "$MACHINE" = "qemuarm" -o "$MACHINE" = "spitz" -o "$MACHINE" = "borzoi" -o "$MACHINE" = "akita" ]; then
  125. SDKPATH="$SDKDIR/arm/arm-poky-linux-gnueabi/bin:$SDKDIR/arm/bin"
  126. fi
  127. if [ "$MACHINE" = "qemux86" ]; then
  128. SDKPATH="$SDKDIR/i586/i586-poky-linux/bin:$SDKDIR/i586/bin"
  129. fi
  130. PATH=$CROSSPATH:$SDKPATH:$PATH
  131. QEMUBIN=`which $QEMU`
  132. if [ ! -x "$QEMUBIN" ]; then
  133. echo "Error: No QEMU binary '$QEMU' could be found."
  134. return
  135. fi
  136. function _quit() {
  137. if [ -n "$PIDFILE" ]; then
  138. #echo kill `cat $PIDFILE`
  139. kill `cat $PIDFILE`
  140. fi
  141. return
  142. }
  143. DISTCCD=`which distccd`
  144. PIDFILE=""
  145. trap _quit INT TERM QUIT
  146. if [ -x "$DISTCCD" ]; then
  147. echo "Starting distccd..."
  148. PIDFILE=`mktemp`
  149. $DISTCCD --allow 192.168.7.2 --daemon --pid-file $PIDFILE &
  150. else
  151. echo "Warning: distccd not present, no distcc support loaded."
  152. fi
  153. echo "Running $QEMU using sudo..."
  154. echo $QEMUBIN -kernel $ZIMAGE $QEMUOPTIONS $SERIALOPTS --append "$KERNCMDLINE"
  155. sudo $QEMUBIN -kernel $ZIMAGE $QEMUOPTIONS $SERIALOPTS --append "$KERNCMDLINE" || /bin/true
  156. trap - INT TERM QUIT
  157. return