1#!/bin/bash 2 3#Copyright (c) 2020-2021 Huawei Device Co., Ltd. 4#Licensed under the Apache License, Version 2.0 (the "License"); 5#you may not use this file except in compliance with the License. 6#You may obtain a copy of the License at 7# 8# http://www.apache.org/licenses/LICENSE-2.0 9# 10#Unless required by applicable law or agreed to in writing, software 11#distributed under the License is distributed on an "AS IS" BASIS, 12#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13#See the License for the specific language governing permissions and 14#limitations under the License. 15 16set -e 17elf_file=$1 18rebuild_image=$2 19vnc_enable=$3 20add_boot_args=$4 21boot_args=$5 22net_enable=$6 23gdb_enable=$7 24qemu_test=$8 25test_file=$9 26qemu_help=${10} 27 28vnc="-vnc :20 -serial mon:stdio" 29qemu_option="" 30 31if [ "$elf_file" = "" ]; then 32 elf_file=out/qemu-arm-linux/packages/phone/images 33fi 34 35help_info=$(cat <<-END 36Usage: qemu-run [OPTION]... 37Run a OHOS image in qemu according to the options. 38 39 Options: 40 41 -e, --exec image_path build images path, including: zImage-dtb, ramdisk.img, system.img, vendor.img, userdata.img 42 -g, --gdb enable gdb for kernel 43 -h, --help print help info 44 45 By default, the kernel exec file is: ${elf_file}. 46END 47) 48 49if [ "$qemu_help" = "yes" ]; then 50 echo "${help_info}" 51 exit 0 52fi 53 54if [ "$gdb_enable" = "yes" ]; then 55 qemu_option+="-s -S" 56fi 57 58function start_qemu(){ 59 qemu-system-arm -M virt -cpu cortex-a7 -smp 4 -m 1024 -nographic \ 60 $qemu_option \ 61 -drive if=none,file=$elf_file/userdata.img,format=raw,id=userdata,index=3 -device virtio-blk-device,drive=userdata \ 62 -drive if=none,file=$elf_file/vendor.img,format=raw,id=vendor,index=2 -device virtio-blk-device,drive=vendor \ 63 -drive if=none,file=$elf_file/system.img,format=raw,id=system,index=1 -device virtio-blk-device,drive=system \ 64 -drive if=none,file=$elf_file/updater.img,format=raw,id=updater,index=0 -device virtio-blk-device,drive=updater \ 65 -kernel $elf_file/zImage-dtb -initrd $elf_file/../../../ramdisk.img \ 66 -append "console=ttyAMA0,115200 init=/bin/init hardware=qemu.arm.linux default_boot_device=a003e00.virtio_mmio root=/dev/ram0 rw" 67} 68 69start_qemu 70