1### Qemu Arm Cortex-m4 mps2-an386 HOWTO 2 3#### 1. Brief introduction 4`arm_mps2_an386/` subdirectory contains part of the OpenHarmony LiteOS demonstration support for Qemu Arm Cortex-m4 mps2-an386 Platform, 5here called *arm_mps2_an386*. 6cortex-m4 Virtual platform is a `qemu-system-arm` machine target that provides emulation 7for a generic, arm-based board. 8 9Introduced functionality adds support for Cortex-m4 (1 CPU with security extensions), 16MB memory virtual platform. 10 11Note: System memory size is hard-coded to 16MB. 12 13#### 2. Setting up environment 14 15[Setting up a development environment](https://gitee.com/openharmony/docs/blob/master/en/device-dev/quick-start/Readme-EN.md) 16 17Compiler install 18 191.Command to install 20 21Note: Command to install toolchain without arm-none-eabi-gdb, gdb cannot be debugged. 22 23``` 24sudo apt install gcc-arm-none-eabi 25``` 26 272.The installation package to install 28 29Note: If you have already passed the command to install gcc-arm-none-eabi, can through the command: `sudo apt remove 30gcc-arm-none-eabi` after unloading, install again. 31 32Download toolchain: [package](https://armkeil.blob.core.windows.net/developer/Files/downloads/gnu-rm/6-2017q2/gcc-arm-none-eabi-6-2017-q2-update-linux.tar.bz2)。 33 34``` 35chmod 777 gcc-arm-none-eabi-6-2017-q2-update-linux.tar.bz2 36tar -xvf gcc-arm-none-eabi-6-2017-q2-update-linux.tar.bz2 install_path 37``` 38 39Add the installation path to the environment variable: 40 41``` 42vim ~/.bashrc 43``` 44 45Add the following command line to the last line of ~/.bashrc: 46 47``` 48export PATH=$PATH:install_path/gcc-arm-none-eabi-6-2017-q2-update/bin 49``` 50 51#### 3. Code acquisition 52 53[Code acquisition](https://gitee.com/openharmony/docs/blob/HEAD/en/device-dev/get-code/sourcecode-acquire.md) 54 55Note: One can use `repo` to fetch code in a straightforward manner. 56 57#### 4. Building from sources 58 59In the root directory of the obtained source code, run the following command: 60 61``` 62hb set 63``` 64 65Select `qemu_mini_system_demo` under **ohemu**. 66 67Run the following build command: 68``` 69hb build -f 70``` 71 72This will build `OHOS_Image` for Qemu Cortex-m4 mps2-an386 machine. 73 74 75After build is finished, the resulting image can be found in: 76``` 77out/arm_mps2_an386/qemu_mini_system_demo/ 78``` 79#### 5. Running image in Qemu 80 81a) If not installed, please install `qemu-system-arm` 82For details, please refer to the HOWTO: [Qemu installation](https://gitee.com/openharmony/device_qemu/blob/HEAD/README.md) 83 84b) Run 85 86Run the `./qemu-run --help` command. The following information is displayed: 87 88``` 89Usage: qemu-run [OPTION]... 90Run a OHOS image in qemu according to the options. 91 92 Options: 93 94 -e, --exec file_name kernel exec file name 95 -n, --net-enable enable net 96 -g, --gdb enable gdb for kernel 97 -t, --test test mode, exclusive with -g 98 -h, --help print help info 99 100 By default, the kernel exec file is: out/arm_mps2_an386/qemu_mini_system_demo/OHOS_Image. 101``` 102 103#### 6. gdb debug 104 105``` 106cd device/qemu/arm_mps2_an386 107vim liteos_m/config.gni 108``` 109 110In the modified `board_opt_flags` compiler options: 111 112``` 113board_opt_flags = [] 114``` 115to: 116 117``` 118board_opt_flags = [ "-g" ] 119``` 120 121Save and exit, recompile under OHOS root directory: 122 123``` 124hb build -f 125``` 126 127In a window to enter the command: 128 129``` 130./qemu-run -g 131``` 132 133In another window to enter the command: 134 135``` 136arm-none-eabi-gdb out/arm_mps2_an386/qemu_mini_system_demo/OHOS_Image 137(gdb) target remote localhost:1234 138(gdb) b main 139``` 140 141More GDB related debugging can refer to [GDB instruction manual](https://sourceware.org/gdb/current/onlinedocs/gdb). 142