1### Qemu RISC-V virt HOWTO 2 3#### 1. Brief introduction 4`riscv32_virt/` subdirectory contains part of the OpenHarmony LiteOS demonstration support for Qemu risc-v virt Platform, 5here called *riscv32_virt*. 6RISC-V Virtual platform is a `qemu-system-riscv32` machine target that provides emulation 7for a generic, riscv-based board. 8 9Introduced functionality adds support for RISC-V (1 CPU with security extensions), 128MB memory virtual platform. 10 11Note: System memory size is hard-coded to 128MB. 12 13#### 2. Setting up environment 14 15[Setting up a development environment](https://gitee.com/openharmony/docs/blob/HEAD/en/device-dev/quick-start/quickstart-lite-env-setup.md) 16 17[Compiler install:gcc_riscv32](https://gitee.com/openharmony/docs/blob/HEAD/en/device-dev/quick-start/quickstart-lite-steps-hi3861-setting.md#section34435451256), 18Note: [Downloadable directly](https://repo.huaweicloud.com/harmonyos/compiler/gcc_riscv32/7.3.0/linux/gcc_riscv32-linux-7.3.0.tar.gz) 19 20#### 3. Code acquisition 21 22[Code acquisition](https://gitee.com/openharmony/docs/blob/HEAD/en/device-dev/get-code/sourcecode-acquire.md) 23 24Note: One can use `repo` to fetch code in a straightforward manner. 25 26#### 4. Building from sources 27 28In the root directory of the obtained source code, run the following command: 29 30``` 31hb set 32``` 33 34Select `qemu_riscv_mini_system_demo` under **ohemu**. 35 36Run the following build command: 37 38``` 39hb build 40``` 41 42This will build `OHOS_Image` for Qemu RISC-V virt machine. 43 44After build is finished, the resulting image can be found in: 45``` 46out/riscv32_virt/qemu_riscv_mini_system_demo/ 47``` 48 49#### 5. Running image in Qemu 50 51a) If not installed, please install `qemu-system-riscv32` 52For details, please refer to the HOWTO: [Qemu installation](https://gitee.com/openharmony/device_qemu/blob/HEAD/README.md) 53 54b) Run 55 56(1) qemu version < 5.0.0 57 58``` 59cd device/qemu/riscv32_virt 60qemu-system-riscv32 -machine virt -m 128M -kernel ../../../out/riscv32_virt/qemu_riscv_mini_system_demo/OHOS_Image -nographic -append "root=dev/vda or console=ttyS0" 61``` 62 63(2). qemu version >= 5.0.0 64 65Run the `./qemu-run --help` command. The following information is displayed: 66 67``` 68Usage: ./qemu-run [OPTION]... 69Run a OHOS image in qemu according to the options. 70 71 Options: 72 73 -e, --exec file_name kernel exec file name 74 -n, --net-enable enable net 75 -l, --local-desktop no VNC 76 -g, --gdb enable gdb for kernel 77 -t, --test test mode, exclusive with -g 78 -h, --help print help info 79 80 By default, the kernel exec file is: out/riscv32_virt/qemu_riscv_mini_system_demo/OHOS_Image, 81 and net will not be enabled, gpu enabled and waiting for VNC connection at port 5920. 82``` 83By default, the network will not be automatically configured if no parameter is specified, and the default kernel exec file will be used. 84If you want to use other kernel exec file, please try `./qemu-run -e [file_name]` to change it. 85 86#### 6. gdb debug 87 88``` 89cd device/qemu/riscv32_virt 90vim liteos_m/config.gni 91``` 92 93In the modified `board_opt_flags` compiler options: 94 95``` 96board_opt_flags = [] 97``` 98 99to: 100 101``` 102board_opt_flags = [ "-g" ] 103``` 104 105Save and exit, recompile under OHOS root directory: 106 107``` 108hb build -f 109``` 110 111In a window to enter the command: 112 113``` 114./qemu-run -g 115``` 116 117In another window to enter the command: 118 119``` 120riscv32-unknown-elf-gdb out/riscv32_virt/qemu_riscv_mini_system_demo/OHOS_Image 121(gdb) target remote localhost:1234 122(gdb) b main 123``` 124 125More GDB related debugging can refer to [GDB instruction manual](https://sourceware.org/gdb/current/onlinedocs/gdb). 126 127## 7. Example 128 129- [Transferring Files Using FAT Images](example.md#sectionfatfs) 130 131 132