diff options
author | Robert Yang <liezhi.yang@windriver.com> | 2016-03-09 18:09:19 -0800 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2016-03-25 10:29:14 +0000 |
commit | b47c53b70e60990ac83ab488b30fd962e735a4f8 (patch) | |
tree | 15f95a97b31ce544a2ab1cc1a081bf7e6216b9b8 | |
parent | fae732f24e965e80d414b5cd63ff5d33d8dfcd60 (diff) | |
download | poky-b47c53b70e60990ac83ab488b30fd962e735a4f8.tar.gz |
runqemu-internal: split the code into functions
Use config_<machine> to split the code into separate functions, so that
different machines won't affect each other, and they will have a better
structure.
(From OE-Core rev: 6098a72e8d21f6321636e727703ca7c29d9af142)
Signed-off-by: Robert Yang <liezhi.yang@windriver.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rwxr-xr-x | scripts/runqemu-internal | 180 |
1 files changed, 89 insertions, 91 deletions
diff --git a/scripts/runqemu-internal b/scripts/runqemu-internal index 7ae077766c..ac1c703c53 100755 --- a/scripts/runqemu-internal +++ b/scripts/runqemu-internal | |||
@@ -38,49 +38,6 @@ mem_set=`expr "$SCRIPT_QEMU_EXTRA_OPT" : '.*\(-m[[:space:]] *[0-9]*\)'` | |||
38 | if [ ! -z "$mem_set" ] ; then | 38 | if [ ! -z "$mem_set" ] ; then |
39 | #Get memory setting size from user input | 39 | #Get memory setting size from user input |
40 | mem_size=`echo $mem_set | sed 's/-m[[:space:]] *//'` | 40 | mem_size=`echo $mem_set | sed 's/-m[[:space:]] *//'` |
41 | else | ||
42 | case "$MACHINE" in | ||
43 | "qemux86") | ||
44 | mem_size=256 | ||
45 | ;; | ||
46 | "qemux86-64") | ||
47 | mem_size=256 | ||
48 | ;; | ||
49 | "qemuarm") | ||
50 | mem_size=128 | ||
51 | ;; | ||
52 | "qemuarm64") | ||
53 | mem_size=512 | ||
54 | ;; | ||
55 | "qemumicroblaze") | ||
56 | mem_size=256 | ||
57 | ;; | ||
58 | "qemumips"|"qemumips64") | ||
59 | mem_size=256 | ||
60 | ;; | ||
61 | "qemuppc") | ||
62 | mem_size=256 | ||
63 | ;; | ||
64 | "qemush4") | ||
65 | mem_size=1024 | ||
66 | ;; | ||
67 | "qemuzynq") | ||
68 | mem_size=1024 | ||
69 | ;; | ||
70 | *) | ||
71 | mem_size=64 | ||
72 | ;; | ||
73 | esac | ||
74 | |||
75 | fi | ||
76 | |||
77 | # QEMU_MEMORY has 'M' appended to mem_size | ||
78 | QEMU_MEMORY="$mem_size"M | ||
79 | |||
80 | # We need to specify -m <mem_size> to overcome a bug in qemu 0.14.0 | ||
81 | # https://bugs.launchpad.net/ubuntu/+source/qemu-kvm/+bug/584480 | ||
82 | if [ -z "$mem_set" ] ; then | ||
83 | SCRIPT_QEMU_EXTRA_OPT="$SCRIPT_QEMU_EXTRA_OPT -m $mem_size" | ||
84 | fi | 41 | fi |
85 | 42 | ||
86 | # This file is created when runqemu-gen-tapdevs creates a bank of tap | 43 | # This file is created when runqemu-gen-tapdevs creates a bank of tap |
@@ -267,26 +224,6 @@ else | |||
267 | fi | 224 | fi |
268 | fi | 225 | fi |
269 | 226 | ||
270 | case "$MACHINE" in | ||
271 | "qemuarm") ;; | ||
272 | "qemuarm64") ;; | ||
273 | "qemumicroblaze") ;; | ||
274 | "qemumips") ;; | ||
275 | "qemumipsel") ;; | ||
276 | "qemumips64") ;; | ||
277 | "qemush4") ;; | ||
278 | "qemuppc") ;; | ||
279 | "qemuarmv6") ;; | ||
280 | "qemuarmv7") ;; | ||
281 | "qemux86") ;; | ||
282 | "qemux86-64") ;; | ||
283 | "qemuzynq") ;; | ||
284 | *) | ||
285 | echo "Error: Unsupported machine type $MACHINE" | ||
286 | return 1 | ||
287 | ;; | ||
288 | esac | ||
289 | |||
290 | if [ ! -f "$KERNEL" -a "$IS_VM" = "false" ]; then | 227 | if [ ! -f "$KERNEL" -a "$IS_VM" = "false" ]; then |
291 | echo "Error: Kernel image file $KERNEL doesn't exist" | 228 | echo "Error: Kernel image file $KERNEL doesn't exist" |
292 | cleanup | 229 | cleanup |
@@ -329,12 +266,25 @@ if [ "$FSTYPE" = "nfs" ]; then | |||
329 | NFSRUNNING="true" | 266 | NFSRUNNING="true" |
330 | fi | 267 | fi |
331 | 268 | ||
332 | if [ "$MACHINE" = "qemuarm" -o "$MACHINE" = "qemuarmv6" -o "$MACHINE" = "qemuarmv7" ]; then | 269 | |
270 | set_mem_size() { | ||
271 | if [ ! -z "$mem_set" ] ; then | ||
272 | #Get memory setting size from user input | ||
273 | mem_size=`echo $mem_set | sed 's/-m[[:space:]] *//'` | ||
274 | else | ||
275 | mem_size=$1 | ||
276 | fi | ||
277 | # QEMU_MEMORY has 'M' appended to mem_size | ||
278 | QEMU_MEMORY="$mem_size"M | ||
279 | |||
280 | } | ||
281 | |||
282 | config_qemuarm() { | ||
283 | set_mem_size 128 | ||
333 | QEMU=qemu-system-arm | 284 | QEMU=qemu-system-arm |
334 | MACHINE_SUBTYPE=versatilepb | 285 | MACHINE_SUBTYPE=versatilepb |
335 | export QEMU_AUDIO_DRV="none" | 286 | export QEMU_AUDIO_DRV="none" |
336 | QEMU_UI_OPTIONS="$QEMU_UI_OPTIONS" | 287 | QEMU_UI_OPTIONS="$QEMU_UI_OPTIONS" |
337 | # QEMU_UI_OPTIONS="$QEMU_UI_OPTIONS -force-pointer" | ||
338 | if [ "${FSTYPE:0:3}" = "ext" -o "$FSTYPE" = "btrfs" -o "$FSTYPE" = "wic" ]; then | 288 | if [ "${FSTYPE:0:3}" = "ext" -o "$FSTYPE" = "btrfs" -o "$FSTYPE" = "wic" ]; then |
339 | KERNCMDLINE="root=$DROOT rw console=ttyAMA0,115200 console=tty $KERNEL_NETWORK_CMD mem=$QEMU_MEMORY highres=off" | 289 | KERNCMDLINE="root=$DROOT rw console=ttyAMA0,115200 console=tty $KERNEL_NETWORK_CMD mem=$QEMU_MEMORY highres=off" |
340 | QEMUOPTIONS="$QEMU_NETWORK_CMD -M ${MACHINE_SUBTYPE} $ROOTFS_OPTIONS -no-reboot $QEMU_UI_OPTIONS" | 290 | QEMUOPTIONS="$QEMU_NETWORK_CMD -M ${MACHINE_SUBTYPE} $ROOTFS_OPTIONS -no-reboot $QEMU_UI_OPTIONS" |
@@ -354,9 +304,10 @@ if [ "$MACHINE" = "qemuarm" -o "$MACHINE" = "qemuarmv6" -o "$MACHINE" = "qemuarm | |||
354 | if [ "$MACHINE" = "qemuarmv7" ]; then | 304 | if [ "$MACHINE" = "qemuarmv7" ]; then |
355 | QEMUOPTIONS="$QEMUOPTIONS -cpu cortex-a8" | 305 | QEMUOPTIONS="$QEMUOPTIONS -cpu cortex-a8" |
356 | fi | 306 | fi |
357 | fi | 307 | } |
358 | 308 | ||
359 | if [ "$MACHINE" = "qemuarm64" ]; then | 309 | config_qemuarm64() { |
310 | set_mem_size 512 | ||
360 | QEMU=qemu-system-aarch64 | 311 | QEMU=qemu-system-aarch64 |
361 | 312 | ||
362 | QEMU_NETWORK_CMD="-netdev tap,id=net0,ifname=$TAP,script=no,downscript=no -device virtio-net-device,netdev=net0 " | 313 | QEMU_NETWORK_CMD="-netdev tap,id=net0,ifname=$TAP,script=no,downscript=no -device virtio-net-device,netdev=net0 " |
@@ -383,9 +334,10 @@ if [ "$MACHINE" = "qemuarm64" ]; then | |||
383 | KERNCMDLINE="root=/dev/nfs nfsroot=$NFS_SERVER:$NFS_DIR,$UNFS_OPTS rw console=ttyAMA0,38400 mem=$QEMU_MEMORY highres=off $KERNEL_NETWORK_CMD" | 334 | KERNCMDLINE="root=/dev/nfs nfsroot=$NFS_SERVER:$NFS_DIR,$UNFS_OPTS rw console=ttyAMA0,38400 mem=$QEMU_MEMORY highres=off $KERNEL_NETWORK_CMD" |
384 | QEMUOPTIONS="$QEMU_NETWORK_CMD -machine virt -cpu cortex-a57 $QEMU_UI_OPTIONS" | 335 | QEMUOPTIONS="$QEMU_NETWORK_CMD -machine virt -cpu cortex-a57 $QEMU_UI_OPTIONS" |
385 | fi | 336 | fi |
386 | fi | 337 | } |
387 | 338 | ||
388 | if [ "$MACHINE" = "qemux86" ]; then | 339 | config_qemux86() { |
340 | set_mem_size 256 | ||
389 | QEMU=qemu-system-i386 | 341 | QEMU=qemu-system-i386 |
390 | if [ "$KVM_ACTIVE" = "yes" ]; then | 342 | if [ "$KVM_ACTIVE" = "yes" ]; then |
391 | CPU_SUBTYPE=kvm32 | 343 | CPU_SUBTYPE=kvm32 |
@@ -421,9 +373,10 @@ if [ "$MACHINE" = "qemux86" ]; then | |||
421 | # Currently oprofile's event based interrupt mode doesn't work(Bug #828) in | 373 | # Currently oprofile's event based interrupt mode doesn't work(Bug #828) in |
422 | # qemux86 and qemux86-64. We can use timer interrupt mode for now. | 374 | # qemux86 and qemux86-64. We can use timer interrupt mode for now. |
423 | KERNCMDLINE="$KERNCMDLINE oprofile.timer=1" | 375 | KERNCMDLINE="$KERNCMDLINE oprofile.timer=1" |
424 | fi | 376 | } |
425 | 377 | ||
426 | if [ "$MACHINE" = "qemux86-64" ]; then | 378 | config_qemux86_64() { |
379 | set_mem_size 256 | ||
427 | QEMU=qemu-system-x86_64 | 380 | QEMU=qemu-system-x86_64 |
428 | if [ "$KVM_ACTIVE" = "yes" ]; then | 381 | if [ "$KVM_ACTIVE" = "yes" ]; then |
429 | CPU_SUBTYPE=kvm64 | 382 | CPU_SUBTYPE=kvm64 |
@@ -457,9 +410,10 @@ if [ "$MACHINE" = "qemux86-64" ]; then | |||
457 | # Currently oprofile's event based interrupt mode doesn't work(Bug #828) in | 410 | # Currently oprofile's event based interrupt mode doesn't work(Bug #828) in |
458 | # qemux86 and qemux86-64. We can use timer interrupt mode for now. | 411 | # qemux86 and qemux86-64. We can use timer interrupt mode for now. |
459 | KERNCMDLINE="$KERNCMDLINE oprofile.timer=1" | 412 | KERNCMDLINE="$KERNCMDLINE oprofile.timer=1" |
460 | fi | 413 | } |
461 | 414 | ||
462 | if [ "$MACHINE" = "qemumips" -o "$MACHINE" = "qemumipsel" -o "$MACHINE" = "qemumips64" ]; then | 415 | config_qemumips() { |
416 | set_mem_size 256 | ||
463 | case "$MACHINE" in | 417 | case "$MACHINE" in |
464 | qemumips) QEMU=qemu-system-mips ;; | 418 | qemumips) QEMU=qemu-system-mips ;; |
465 | qemumipsel) QEMU=qemu-system-mipsel ;; | 419 | qemumipsel) QEMU=qemu-system-mipsel ;; |
@@ -481,9 +435,10 @@ if [ "$MACHINE" = "qemumips" -o "$MACHINE" = "qemumipsel" -o "$MACHINE" = "qemum | |||
481 | KERNCMDLINE="root=/dev/nfs console=ttyS0 console=tty nfsroot=$NFS_SERVER:$NFS_DIR,$UNFS_OPTS rw $KERNEL_NETWORK_CMD mem=$QEMU_MEMORY" | 435 | KERNCMDLINE="root=/dev/nfs console=ttyS0 console=tty nfsroot=$NFS_SERVER:$NFS_DIR,$UNFS_OPTS rw $KERNEL_NETWORK_CMD mem=$QEMU_MEMORY" |
482 | QEMUOPTIONS="$QEMU_NETWORK_CMD -M $MACHINE_SUBTYPE -no-reboot $QEMU_UI_OPTIONS" | 436 | QEMUOPTIONS="$QEMU_NETWORK_CMD -M $MACHINE_SUBTYPE -no-reboot $QEMU_UI_OPTIONS" |
483 | fi | 437 | fi |
484 | fi | 438 | } |
485 | 439 | ||
486 | if [ "$MACHINE" = "qemuppc" ]; then | 440 | config_qemuppc() { |
441 | set_mem_size 256 | ||
487 | QEMU=qemu-system-ppc | 442 | QEMU=qemu-system-ppc |
488 | MACHINE_SUBTYPE=mac99 | 443 | MACHINE_SUBTYPE=mac99 |
489 | CPU_SUBTYPE=G4 | 444 | CPU_SUBTYPE=G4 |
@@ -506,9 +461,10 @@ if [ "$MACHINE" = "qemuppc" ]; then | |||
506 | KERNCMDLINE="root=/dev/nfs console=ttyS0 console=tty nfsroot=$NFS_SERVER:$NFS_DIR,$UNFS_OPTS rw $KERNEL_NETWORK_CMD mem=$QEMU_MEMORY" | 461 | KERNCMDLINE="root=/dev/nfs console=ttyS0 console=tty nfsroot=$NFS_SERVER:$NFS_DIR,$UNFS_OPTS rw $KERNEL_NETWORK_CMD mem=$QEMU_MEMORY" |
507 | QEMUOPTIONS="$QEMU_NETWORK_CMD -cpu $CPU_SUBTYPE -M $MACHINE_SUBTYPE -no-reboot $QEMU_UI_OPTIONS" | 462 | QEMUOPTIONS="$QEMU_NETWORK_CMD -cpu $CPU_SUBTYPE -M $MACHINE_SUBTYPE -no-reboot $QEMU_UI_OPTIONS" |
508 | fi | 463 | fi |
509 | fi | 464 | } |
510 | 465 | ||
511 | if [ "$MACHINE" = "qemush4" ]; then | 466 | config_qemush4() { |
467 | set_mem_size 1024 | ||
512 | QEMU=qemu-system-sh4 | 468 | QEMU=qemu-system-sh4 |
513 | MACHINE_SUBTYPE=r2d | 469 | MACHINE_SUBTYPE=r2d |
514 | QEMU_UI_OPTIONS="$QEMU_UI_OPTIONS" | 470 | QEMU_UI_OPTIONS="$QEMU_UI_OPTIONS" |
@@ -528,30 +484,72 @@ if [ "$MACHINE" = "qemush4" ]; then | |||
528 | QEMUOPTIONS="$QEMU_NETWORK_CMD -M $MACHINE_SUBTYPE -no-reboot $QEMU_UI_OPTIONS -monitor null -serial vc -serial stdio" | 484 | QEMUOPTIONS="$QEMU_NETWORK_CMD -M $MACHINE_SUBTYPE -no-reboot $QEMU_UI_OPTIONS -monitor null -serial vc -serial stdio" |
529 | SERIALSTDIO="1" | 485 | SERIALSTDIO="1" |
530 | fi | 486 | fi |
531 | fi | 487 | } |
532 | |||
533 | if [ "${FSTYPE:0:3}" = "ext" ]; then | ||
534 | KERNCMDLINE="$KERNCMDLINE rootfstype=$FSTYPE" | ||
535 | fi | ||
536 | 488 | ||
537 | if [ "$MACHINE" = "qemumicroblaze" ]; then | 489 | config_qemuzynq() { |
538 | QEMU=qemu-system-microblazeel | 490 | set_mem_size 1024 |
539 | QEMU_SYSTEM_OPTIONS="$QEMU_NETWORK_CMD -M petalogix-ml605 -serial mon:stdio" | 491 | QEMU=qemu-system-arm |
492 | QEMU_SYSTEM_OPTIONS="$QEMU_NETWORK_CMD -M xilinx-zynq-a9 -serial null -serial mon:stdio -dtb $KERNEL-$MACHINE.dtb" | ||
493 | # zynq serial ports are named 'ttyPS0' and 'ttyPS1', fixup the default values | ||
494 | SCRIPT_KERNEL_OPT=$(echo "$SCRIPT_KERNEL_OPT" | sed 's/console=ttyS/console=ttyPS/g') | ||
540 | if [ "${FSTYPE:0:3}" = "ext" -o "${FSTYPE:0:4}" = "cpio" ]; then | 495 | if [ "${FSTYPE:0:3}" = "ext" -o "${FSTYPE:0:4}" = "cpio" ]; then |
541 | KERNCMDLINE="earlyprintk root=/dev/ram rw $KERNEL_NETWORK_CMD mem=$QEMU_MEMORY" | 496 | KERNCMDLINE="earlyprintk root=/dev/ram rw $KERNEL_NETWORK_CMD mem=$QEMU_MEMORY" |
542 | QEMUOPTIONS="$QEMU_SYSTEM_OPTIONS -initrd $ROOTFS" | 497 | QEMUOPTIONS="$QEMU_SYSTEM_OPTIONS -initrd $ROOTFS" |
543 | fi | 498 | fi |
544 | fi | 499 | } |
545 | 500 | ||
546 | if [ "$MACHINE" = "qemuzynq" ]; then | 501 | config_qemumicroblaze() { |
547 | QEMU=qemu-system-arm | 502 | set_mem_size 256 |
548 | QEMU_SYSTEM_OPTIONS="$QEMU_NETWORK_CMD -M xilinx-zynq-a9 -serial null -serial mon:stdio -dtb $KERNEL-$MACHINE.dtb" | 503 | QEMU=qemu-system-microblazeel |
549 | # zynq serial ports are named 'ttyPS0' and 'ttyPS1', fixup the default values | 504 | QEMU_SYSTEM_OPTIONS="$QEMU_NETWORK_CMD -M petalogix-ml605 -serial mon:stdio" |
550 | SCRIPT_KERNEL_OPT=$(echo "$SCRIPT_KERNEL_OPT" | sed 's/console=ttyS/console=ttyPS/g') | ||
551 | if [ "${FSTYPE:0:3}" = "ext" -o "${FSTYPE:0:4}" = "cpio" ]; then | 505 | if [ "${FSTYPE:0:3}" = "ext" -o "${FSTYPE:0:4}" = "cpio" ]; then |
552 | KERNCMDLINE="earlyprintk root=/dev/ram rw $KERNEL_NETWORK_CMD mem=$QEMU_MEMORY" | 506 | KERNCMDLINE="earlyprintk root=/dev/ram rw $KERNEL_NETWORK_CMD mem=$QEMU_MEMORY" |
553 | QEMUOPTIONS="$QEMU_SYSTEM_OPTIONS -initrd $ROOTFS" | 507 | QEMUOPTIONS="$QEMU_SYSTEM_OPTIONS -initrd $ROOTFS" |
554 | fi | 508 | fi |
509 | } | ||
510 | |||
511 | case "$MACHINE" in | ||
512 | "qemuarm" | "qemuarmv6" | "qemuarmv7") | ||
513 | config_qemuarm | ||
514 | ;; | ||
515 | "qemuarm64") | ||
516 | config_qemuarm64 | ||
517 | ;; | ||
518 | "qemux86") | ||
519 | config_qemux86 | ||
520 | ;; | ||
521 | "qemux86-64") | ||
522 | config_qemux86_64 | ||
523 | ;; | ||
524 | "qemumips" | "qemumipsel" | "qemumips64") | ||
525 | config_qemumips | ||
526 | ;; | ||
527 | "qemuppc") | ||
528 | config_qemuppc | ||
529 | ;; | ||
530 | "qemush4") | ||
531 | config_qemush4 | ||
532 | ;; | ||
533 | "qemuzynq") | ||
534 | config_qemuzynq | ||
535 | ;; | ||
536 | "qemumicroblaze") | ||
537 | config_qemumicroblaze | ||
538 | ;; | ||
539 | *) | ||
540 | echo "Error: Unsupported machine type $MACHINE" | ||
541 | return 1 | ||
542 | ;; | ||
543 | esac | ||
544 | |||
545 | # We need to specify -m <mem_size> to overcome a bug in qemu 0.14.0 | ||
546 | # https://bugs.launchpad.net/ubuntu/+source/qemu-kvm/+bug/584480 | ||
547 | if [ -z "$mem_set" ] ; then | ||
548 | SCRIPT_QEMU_EXTRA_OPT="$SCRIPT_QEMU_EXTRA_OPT -m $mem_size" | ||
549 | fi | ||
550 | |||
551 | if [ "${FSTYPE:0:3}" = "ext" ]; then | ||
552 | KERNCMDLINE="$KERNCMDLINE rootfstype=$FSTYPE" | ||
555 | fi | 553 | fi |
556 | 554 | ||
557 | if [ "$FSTYPE" = "cpio.gz" ]; then | 555 | if [ "$FSTYPE" = "cpio.gz" ]; then |