• 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
29
30if [ "$elf_file" = "Invalid" ]; then
31    elf_file=out/esp32/qemu_xtensa_mini_system_demo/OHOS_Image
32fi
33
34help_info=$(cat <<-END
35Usage: qemu-run [OPTION]...
36Run a OHOS image in qemu according to the options.
37
38    Options:
39
40    -e,  --exec file_name     kernel exec file name
41    -g,  --gdb                enable gdb for kernel
42    -h,  --help               print help info
43
44    By default, the kernel exec file is: ${elf_file}.
45END
46)
47
48if [ "$qemu_help" = "yes" ]; then
49    echo "${help_info}"
50    exit 0
51fi
52
53if [ "$gdb_enable" = "yes" ]; then
54    qemu_option+="-s -S"
55fi
56
57function unsupported_parameters_check(){
58    if [ "$rebuild_image" = "yes" ]; then
59        echo "Error: The -f|--force option is not supported !"
60        echo "${help_info}"
61        exit 1
62    fi
63
64    if [ "$vnc_enable" = "no" ]; then
65        echo "Error: The -l|--local-desktop option is not supported !"
66        echo "${help_info}"
67        exit 1
68    fi
69
70    if [ "$add_boot_args" = "yes" ]; then
71        echo "Error: The -b|--bootargs option is not supported !"
72        echo "${help_info}"
73        exit 1
74    fi
75
76    if [ "$net_enable" = "yes" ]; then
77        echo "Error: The -n|--net-enable option is not supported !"
78        echo "${help_info}"
79        exit 1
80    fi
81
82    if [ "$qemu_test" = "test" ]; then
83        echo "Error: The -t|--qemu-test option is not supported !"
84        echo "${help_info}"
85        exit 1
86    fi
87}
88
89function merge_bin() {
90    out_dir=out/esp32/qemu_xtensa_mini_system_demo
91    esptool.py --chip esp32 elf2image --flash_mode dio --flash_freq 80m                 \
92    --flash_size 4MB -o $out_dir/liteos.bin $elf_file
93
94    esptool.py --chip esp32 merge_bin --fill-flash-size 4MB                             \
95    -o $out_dir/liteos_merge.bin                                                        \
96    0x8000 vendor/ohemu/qemu_xtensa_mini_system_demo/image/partition-table.bin          \
97    0x1000 vendor/ohemu/qemu_xtensa_mini_system_demo/image/bootloader.bin               \
98    0x10000 $out_dir/liteos.bin
99
100    image_file=$out_dir/liteos_merge.bin
101}
102
103function start_qemu(){
104    esptool_version=`esptool.py version | sed -n '2p'`
105    if [ "$esptool_version" \< "3.1" ]; then
106        echo "Error: The esptool.py version is too low"
107        exit 1
108    fi
109    merge_bin
110    export QEMU_XTENSA_CORE_REGS_ONLY=1
111    $QEMU/qemu-system-xtensa -nographic $qemu_option -machine esp32                                  \
112    -drive file=$image_file,if=mtd,format=raw
113}
114
115
116unsupported_parameters_check
117
118start_qemu
119