• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
31#### Submit code to CI test command, do not modify #####
32if [ "$qemu_test" = "test" ]; then
33    qemu_option+="-serial file:$test_file"
34fi
35
36if [ "$elf_file" = "Invalid" ]; then
37    elf_file=out/riscv32_virt/qemu_riscv_mini_system_demo/OHOS_Image
38fi
39
40help_info=$(cat <<-END
41Usage: qemu-run [OPTION]...
42Run a OHOS image in qemu according to the options.
43
44    Options:
45
46    -e,  --exec file_name     kernel exec file name
47    -n,  --net-enable         enable net
48    -l,  --local-desktop      no VNC
49    -g,  --gdb                enable gdb for kernel
50    -t,  --test               test mode, exclusive with -g
51    -h,  --help               print help info
52
53    By default, the kernel exec file is: ${elf_file}.
54END
55)
56
57if [ "$qemu_help" = "yes" ]; then
58    echo "${help_info}"
59    exit 0
60fi
61
62if [ "$vnc_enable" = "no" ]; then
63    vnc=""
64fi
65
66if [ "$gdb_enable" = "yes" ]; then
67    qemu_option+="-s -S"
68fi
69
70function unsupported_parameters_check(){
71    if [ "$rebuild_image" = "yes" ]; then
72        echo "Error: The -f|--force option is not supported !"
73        echo "${help_info}"
74        exit 1
75    fi
76
77    if [ "$add_boot_args" = "yes" ]; then
78        echo "Error: The -b|--bootargs option is not supported !"
79        echo "${help_info}"
80        exit 1
81    fi
82}
83
84function net_config(){
85    echo "Network config..."
86    set +e
87    sudo modprobe tun tap
88    sudo ip link add br0 type bridge
89    sudo ip address add 10.0.2.2/24 dev br0
90    sudo ip link set dev br0 up
91    set -e
92}
93
94function start_qemu(){
95    net_enable=${1}
96    if [ ${net_enable} = yes ]; then
97        net_config 2>/dev/null
98        sudo `which qemu-system-riscv32` -M virt -m 128M -bios none -kernel $elf_file \
99        -global virtio-mmio.force-legacy=false \
100        $qemu_option \
101        -netdev bridge,id=net0 \
102        -device virtio-net-device,netdev=net0,mac=12:22:33:44:55:66 \
103        -device virtio-gpu-device,xres=800,yres=480 -device virtio-tablet-device ${vnc} \
104        -append "root=/dev/vda or console=ttyS0"
105    else
106        qemu-system-riscv32 -M virt -m 128M -bios none -kernel $elf_file \
107        -global virtio-mmio.force-legacy=false \
108        $qemu_option \
109        -device virtio-gpu-device,xres=800,yres=480 -device virtio-tablet-device ${vnc} \
110        -append "root=/dev/vda or console=ttyS0"
111    fi
112}
113
114unsupported_parameters_check
115
116start_qemu ${net_enable}
117