1# QEMU(Tutorials of C-SKY ) 2 3## 1.Introduction 4 5QEMU can simulate the kernel to run on different boards, freeing the dependence on the physical development board.The `SmartL_E802/` subdirectory contains part of the OpenHarmony kernel\_liteos\_m code verified by the Qemu C-SKY virtualization platform,you can simulate a single board based on the C-SKY architecture. 6 7## 2.Setup Environment 8 9 1. Set up the Compilation tool chain 10 11 Note: [Downloadable directly](https://repo.huaweicloud.com/openharmony/compiler/gcc_csky/v3.10.29/linux/csky-v3.10.29.tar.gz) 12 13 Optional compiler installation process: 14 15 a) Create the `csky_toolchain` folder and enter it 16 17 ```shell 18 mkdir csky_toolchain && cd csky_toolchain 19 ``` 20 21 b) Download csky-elfabiv2-tools-x86_64-minilibc-20210423.tar.gz to `csky_toolchain`folder and unzip,download link: https://occ.t-head.cn/community/download?id=3885366095506644992 22 23 ```shell 24 wget https://occ-oss-prod.oss-cn-hangzhou.aliyuncs.com/resource/1356021/1619529111421/csky-elfabiv2-tools-x86_64-minilibc-20210423.tar.gz 25 tar -xf csky-elfabiv2-tools-x86_64-minilibc-20210423.tar.gz 26 ``` 27 28 c) Add the csky-elfabiv2 compilation tool chain to the environment variable (modify user_toolchain_xxx_path to your own installation path): 29 30 ```shell 31 vim ~/.bashrc 32 export PATH=$PATH:user_toolchain_xxx_path/csky_toolchain/bin 33 source ~/.bashrc 34 ``` 35 36 2. Install qemu 37 38 a) create `csky_qemu` folder and enter it 39 40 ```shell 41 mkdir csky_qemu && cd csky_qemu 42 ``` 43 44 b) download csky-qemu-x86_64-Ubuntu-16.04-20210202-1445.tar.gz to `csky_qemu`folder and unzip,download link: https://occ.t-head.cn/community/download?id=636946310057951232 45 46 ```shell 47 wget https://occ-oss-prod.oss-cn-hangzhou.aliyuncs.com/resource/1356021/1612269502091/csky-qemu-x86_64-Ubuntu-16.04-20210202-1445.tar.gz 48 tar -xf csky-qemu-x86_64-Ubuntu-16.04-20210202-1445.tar.gz 49 ``` 50 51 c) Add qemu to the environment variable (modify user_qemu_xxx_path to your own installation path): 52 53 ```shell 54 vim ~/.bashrc 55 export PATH=$PATH:user_qemu_xxx_path/csky-qemu/bin 56 source ~/.bashrc 57 ``` 58 59 d) Installation dependencies 60 61 ```shell 62 ldd qemu_installation_path/bin/qemu-system-cskyv2 63 ``` 64 65 According to the execution result of ldd, install the missing dependent libraries 66 67 (Annotation: For more installation instructions, please refer to the following link: https://occ.t-head.cn/community/download?id=636946310057951232) 68 69## 3.Get source code 70 71[code acquisition ](https://gitee.com/openharmony/docs/blob/master/en/device-dev/get-code/sourcecode-acquire.md) 72 73Hint : You can use the `repo` command to get the source code. 74 75## 4.Source building 76 77 1. Execute the hb set command and select the project`qemu_csky_mini_system_demo`. 78 79 2. Execute the hb clean && hb build command to build the executable file that produces `OHOS_Image`. 80 81 ```shell 82 hb set 83 hb clean && hb build 84 ``` 85 86 3. After the building is complete,the corresponding executable file is in the home directory: 87 88 ``` 89 out/SmartL_E802/qemu_csky_mini_system_demo/ 90 ``` 91 92## 5.Run the image in Qemu 93 94 1. Run qemu(Don't cooperate with GDB) 95 96 ```shell 97 ./qemu-run 98 ``` 99 100 2. Run qemu(Cooperate with GDB) 101 102 a) Start the GDB server and wait for the connection 103 104 ```shell 105 ./qemu-run -g 106 ``` 107 108 b) Create a new terminal and use GDB to connect to qemu 109 110 ```shell 111 csky-abiv2-elf-gdb out/SmartL_E802/qemu_csky_mini_system_demo/OHOS_Image -ex "target remote localhost:1234" 112 ``` 113 114 Annotation: The way to exit qemu : press ctrl and a,then release and press x. 115