• 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
17
18elf_file=$1
19rebuild_image=$2
20vnc_enable=$3
21add_boot_args=$4
22boot_args=$5
23net_enable=$6
24gdb_enable=$7
25qemu_test=$8
26test_file=$9
27qemu_help=${10}
28
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/arm_mps2_an386/qemu_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    -g,  --gdb                enable gdb for kernel
49    -t,  --test               test mode, exclusive with -g
50    -h,  --help               print help info
51
52    By default, the kernel exec file is: ${elf_file}.
53END
54)
55
56if [ "$qemu_help" = "yes" ]; then
57    echo "${help_info}"
58    exit 0
59fi
60
61if [ "$gdb_enable" = "yes" ]; then
62    qemu_option+="-s -S"
63fi
64
65function unsupported_parameters_check(){
66    if [ "$rebuild_image" = "yes" ]; then
67        echo "Error: The -f|--force option is not supported !"
68        echo "${help_info}"
69        exit 1
70    fi
71
72    if [ "$vnc_enable" = "no" ]; then
73        echo "Error: The -l|--local-desktop option is not supported !"
74        echo "${help_info}"
75        exit 1
76    fi
77
78    if [ "$add_boot_args" = "yes" ]; then
79        echo "Error: The -b|--bootargs option is not supported !"
80        echo "${help_info}"
81        exit 1
82    fi
83}
84
85function net_config(){
86    echo "Network config..."
87    set +e
88    sudo modprobe tun tap
89    sudo ip link add br0 type bridge
90    sudo ip address add 10.0.2.2/24 dev br0
91    sudo ip link set dev br0 up
92    set -e
93}
94
95function start_qemu(){
96    net_enable=${1}
97    if [ ${net_enable} = yes ]; then
98        net_config 2>/dev/null
99        sudo `which qemu-system-arm` -M mps2-an386 -m 16M -kernel $elf_file $qemu_option \
100        -nic bridge,mac=12:22:33:44:55:66,model=lan9118 \
101        -append "root=dev/vda or console=ttyS0" -nographic
102    else
103        qemu-system-arm -M mps2-an386 -m 16M -kernel $elf_file $qemu_option \
104        -append "root=dev/vda or console=ttyS0" -nographic
105    fi
106}
107
108
109unsupported_parameters_check
110
111start_qemu ${net_enable}
112