From d440eebccf8d3933746de9e16a44fb5a8771e65c Mon Sep 17 00:00:00 2001 From: zhushengle Date: Thu, 8 Jul 2021 17:34:07 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=A7=A3=E5=86=B3riscv32-unknown-elf=20?= =?UTF-8?q?=E7=BC=96=E8=AF=91=E9=95=9C=E5=83=8F=E8=BF=90=E8=A1=8C=E5=BC=82?= =?UTF-8?q?=E5=B8=B8=E9=97=AE=E9=A2=98,=20=E5=B9=B6=E6=8F=90=E4=BE=9B?= =?UTF-8?q?=E7=BC=96=E8=AF=91=E5=99=A8=E8=8E=B7=E5=8F=96=E6=8C=87=E5=AF=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1.解决riscv32-unknown-elf 编译器编译的镜像,qemu仿真时异常的问题 缺少部分编译选项导致 2.提供qemu安装指导 3.提供riscv32-unknown-elf编译器获取指导 Close #I3ZUG3 Change-Id: I8ccaed604c033542a00e25892591c700f53e3989 Signed-off-by: zhushengle --- README.md | 48 +++++++++++++++++++++++++++++++++++++++ README_zh.md | 48 +++++++++++++++++++++++++++++++++++++++ arm_virt/README.md | 2 +- arm_virt/README_zh.md | 2 +- riscv32_virt/Makefile | 20 ++++++++-------- riscv32_virt/README.md | 11 +++++---- riscv32_virt/README_zh.md | 11 +++++---- 7 files changed, 122 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index e1d9065..14fc7d8 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,7 @@ - [Introduction](#section11660541593) - [Directory Structure](#section161941989596) - [Constraints](#section119744591305) +- [QEMU Install](#section119744591307) - [Usage](#section169045116126) - [Contribution](#section169045116136) - [Repositories Involved](#section1371113476307) @@ -32,6 +33,52 @@ Quick Emulator \(QEMU\) can simulate the scenario where a kernel runs on differe QEMU applies only to the OpenHarmony kernel. +## QEMU Install + +1. Install dependencies(Ubuntu 18+) + + ``` + $ sudo apt install build-essential zlib1g-dev pkg-config libglib2.0-dev binutils-dev libboost-all-dev autoconf libtool libssl-dev libpixman-1-dev virtualenv flex bison + ``` + +2. Acquiring Source Code + + ``` + $ wget https://download.qemu.org/qemu-6.0.0.tar.xz + ``` + + or + + [Download from official website: qemu-6.0.0.tar.xz](https://download.qemu.org/qemu-6.0.0.tar.xz) + +3. Compile and install + + ``` + $ tar -xf qemu-6.0.0.tar.xz + $ cd qemu-6.0.0 + $ mkdir build && cd build + $ ../configure --prefix=qemu_installation_path + $ make -j16 + ``` + + Wait for the compilation to finish and execute the installation command: + + ``` + $ make install + ``` + + Finally, add the installation path to the environment variable: + + ``` + $ vim ~/.bashrc + ``` + + Add the following command line to the last line of ~/.bashrc: + + ``` + $ export PATH=$PATH:qemu_installation_path + ``` + ## Usage For details about the ARM architecture, see [Qemu ARM Virt HOWTO](https://gitee.com/openharmony/device_qemu/blob/master/arm_virt/README.md). @@ -52,3 +99,4 @@ For details about the RISC-V architecture, see [Qemu RISC-V Virt HOWTO](https:/ [kernel\_liteos\_a](https://gitee.com/openharmony/kernel_liteos_a/blob/master/README.md) +[kernel\_liteos\_m](https://gitee.com/openharmony/kernel_liteos_m/blob/master/README.md) diff --git a/README_zh.md b/README_zh.md index c50d7c0..c04ce37 100644 --- a/README_zh.md +++ b/README_zh.md @@ -3,6 +3,7 @@ - [简介](#section11660541593) - [目录](#section161941989596) - [约束](#section119744591305) +- [QEMU安装](#section119744591307) - [使用说明](#section169045116126) - [贡献](#section169045116136) - [相关仓](#section1371113476307) @@ -32,6 +33,52 @@ QEMU可以模拟内核运行在不同的单板,解除对物理开发板的依 只适用于OpenHarmony内核。 +## QEMU安装 + +1. 安装依赖(Ubuntu 18+) + + ``` + $ sudo apt install build-essential zlib1g-dev pkg-config libglib2.0-dev binutils-dev libboost-all-dev autoconf libtool libssl-dev libpixman-1-dev virtualenv flex bison + ``` + +2. 获取源码 + + ``` + $ wget https://download.qemu.org/qemu-6.0.0.tar.xz + ``` + + 或 + + [官网下载: qemu-6.0.0.tar.xz](https://download.qemu.org/qemu-6.0.0.tar.xz) + +3. 编译安装 + + ``` + $ tar -xf qemu-6.0.0.tar.xz + $ cd qemu-6.0.0 + $ mkdir build && cd build + $ ../configure --prefix=qemu_installation_path + $ make -j16 + ``` + + 等待编译结束, 执行安装命令: + + ``` + $ make install + ``` + + 最后将安装路径添加到环境变量中: + + ``` + $ vim ~/.bashrc + ``` + + 在~/.bashrc最末尾加入: + + ``` + $ export PATH=$PATH:qemu_installation_path + ``` + ## 使用说明 arm架构参考[QEMU教程 for arm](https://gitee.com/openharmony/device_qemu/blob/master/arm_virt/README_zh.md)。 @@ -52,3 +99,4 @@ risc-v架构参考[QEMU教程 for risc-v](https://gitee.com/openharmony/device_q [kernel\_liteos\_a](https://gitee.com/openharmony/kernel_liteos_a/blob/master/README_zh.md) +[kernel\_liteos\_m](https://gitee.com/openharmony/kernel_liteos_m/blob/master/README_zh.md) diff --git a/arm_virt/README.md b/arm_virt/README.md index ca53e22..87c28b2 100755 --- a/arm_virt/README.md +++ b/arm_virt/README.md @@ -46,7 +46,7 @@ out/qemu_arm_virt_ca7/OHOS_Image.bin #### 5. Running image in Qemu a) If not installed, please install `qemu-system-arm` -For details, please refer to the HOWTO: [Qemu installation](https://www.qemu.org/download/) +For details, please refer to the HOWTO: [Qemu installation](https://gitee.com/openharmony/device_qemu/blob/master/README.md) Note: The introduced functionality was tested on virt-5.1 target machine. It is not guaranteed to work with any other version so make sure that your qemu-system-arm emulator is up to date. diff --git a/arm_virt/README_zh.md b/arm_virt/README_zh.md index acb05cd..ca71e41 100755 --- a/arm_virt/README_zh.md +++ b/arm_virt/README_zh.md @@ -41,7 +41,7 @@ out/qemu_arm_virt_ca7/OHOS_Image.bin ``` ## 5. 在Qemu中运行镜像 -a) 如果没有安装 `qemu-system-arm` ,安装请参考链接 [Qemu installation](https://www.qemu.org/download/) +a) 如果没有安装 `qemu-system-arm` ,安装请参考链接 [Qemu installation](https://gitee.com/openharmony/device_qemu/blob/master/README_zh.md) 提示: 当前引入的功能在virt-5.1的目标machine已经测试过了,不能保证所有的Qemu版本都能够运行成功,因此需要保证你的qemu-system-arm版本尽可能的新。 diff --git a/riscv32_virt/Makefile b/riscv32_virt/Makefile index d7018e1..f6a6922 100755 --- a/riscv32_virt/Makefile +++ b/riscv32_virt/Makefile @@ -19,8 +19,8 @@ OPENHARMONYDIR := $(realpath $(OPENHARMONYDIR)) export LITEOSTOPDIR # Selective compiler -#COMPILE_NAME := riscv32-unknown-elf -COMPILE_NAME = riscv-none-embed +COMPILE_NAME := riscv32-unknown-elf +#COMPILE_NAME = riscv-none-embed ifeq ($(COMPILE_NAME), riscv-none-embed) CROSS_COMPILE = riscv-none-embed- else @@ -89,17 +89,17 @@ VERSION_NUM := $(shell $(CC) -dumpversion) LITEOS_SSP = -fno-stack-protector LITEOS_COPTS_BASE := -march=$(MARCH) -mabi=$(MABI) -static -fno-common -O2 $(LITEOS_SSP) -LITEOS_COPTS_EXTRA := -ffunction-sections -fdata-sections -fno-omit-frame-pointer -Wno-format-truncation #-Wall +LITEOS_COPTS_EXTRA := -ffunction-sections -fdata-sections -fno-omit-frame-pointer -Wno-format-truncation \ + -fno-omit-frame-pointer -Wno-format-truncation -nostdlib -fno-builtin -fno-strict-aliasing \ + -fsigned-char -fstack-protector-all -std=c99 #-Wall LITEOS_ASOPTS := -march=$(MARCH) -mabi=$(MABI) -static -O2 -LITEOS_LD_OPTS := --build-id=none -static -nostartfiles --gc-sections - +LITEOS_LD_OPTS := -Wl,-mcmodel=medany -Wl,-melf32lriscv -nostartfiles -Wl,--gc-sections LITEOS_COMPILER_PATH := $(realpath $(shell $(OPENHARMONYDIR)/device/qemu/$(LITEOS_PLATFORM)/compiler_dir.sh $(CC))) LITEOS_COMPILER_CXX_PATH = $(LITEOS_COMPILER_PATH)/$(COMPILE_NAME)/include LITEOS_COMPILER_CXXLIB_PATH = $(LITEOS_COMPILER_PATH)/$(COMPILE_NAME)/lib/$(LITEOS_GCCLIB) ifeq ($(COMPILE_NAME), riscv-none-embed) LITEOS_COMPILER_GCCLIB_PATH = -L$(LITEOS_COMPILER_PATH)/lib/gcc/$(COMPILE_NAME)/$(VERSION_NUM)/$(MARCH)/$(MABI)/ \ -L$(LITEOS_COMPILER_PATH)/$(COMPILE_NAME)/lib/$(MARCH)/$(MABI)/ -LITEOS_LD_OPTS += -mcmodel=medany -melf32lriscv else LITEOS_COMPILER_GCCLIB_PATH = -L$(LITEOS_COMPILER_PATH)/lib/gcc/$(COMPILE_NAME)/$(VERSION_NUM)/ \ -L$(LITEOS_COMPILER_PATH)/$(COMPILE_NAME)/lib/ @@ -107,11 +107,11 @@ endif LITEOS_COMPILER_GCC_INCLUDE = -I $(LITEOS_COMPILER_PATH)/lib/gcc/$(COMPILE_NAME)/$(VERSION_NUM)/include \ -I $(LITEOS_COMPILER_PATH)/$(COMPILE_NAME)/include -LITEOS_LD_SCRIPT := $(OPENHARMONYDIR)/device/qemu/$(LITEOS_PLATFORM)/Liteos.ld -LITEOS_LDFLAGS := $(LITEOS_LD_OPTS) -T$(LITEOS_LD_SCRIPT) $(LITEOS_LIBS_DIR) $(LITEOS_COMPILER_GCCLIB_PATH) - LITEOS_CFLAGS := $(LITEOS_COPTS_BASE) $(LITEOS_COPTS_EXTRA) -DLOSCFG_LIB_LIBC -DLOSCFG_TEST_DEMO=1 LITEOS_ASFLAGS := $(LITEOS_ASOPTS) +LITEOS_LD_SCRIPT := $(OPENHARMONYDIR)/device/qemu/$(LITEOS_PLATFORM)/Liteos.ld +LITEOS_LDFLAGS := $(LITEOS_LD_OPTS) $(LITEOS_COPTS_BASE) -Wl,-T$(LITEOS_LD_SCRIPT) $(LITEOS_LIBS_DIR) $(LITEOS_COMPILER_GCCLIB_PATH) + LOCAL_FLAGS := $(CFLAGS) $(LITEOS_COMPILER_GCC_INCLUDE) LOCAL_COBJS := $(patsubst %.c,$(OBJOUT)/%.o,$(LOCAL_CSRCS)) LOCAL_ASMOBJS := $(patsubst %.S,$(OBJOUT)/%.o,$(LOCAL_ASMSRCS)) @@ -119,7 +119,7 @@ LOCAL_ASMOBJS := $(patsubst %.S,$(OBJOUT)/%.o,$(LOCAL_ASMSRCS)) all: $(LITEOS_TARGET) $(LITEOS_TARGET): $(LIBA) - $(LD) $(LITEOS_LDFLAGS) $(LITEOS_TABLES_LDFLAGS) --start-group $(LITEOS_LIBDEP) --end-group -o $(OUT)/$@ + $(CC) $(LITEOS_LDFLAGS) $(LITEOS_TABLES_LDFLAGS) -Wl,--start-group $(LITEOS_LIBDEP) -Wl,--end-group -o $(OUT)/$@ $(OBJCOPY) -S $(OUT)/$@ -Obinary $(OUT)/$@.bin $(OBJDUMP) -hd $(OUT)/$@ >$(OUT)/$@.asm $(OBJDUMP) -stD $(OUT)/$@ >$(OUT)/$@.map diff --git a/riscv32_virt/README.md b/riscv32_virt/README.md index 962ec3f..51995c8 100755 --- a/riscv32_virt/README.md +++ b/riscv32_virt/README.md @@ -12,11 +12,14 @@ Note: System memory size is hard-coded to 128MB. #### 2. Setting up environment -Refer to HOWTO guide: [Setting up a development environment](https://gitee.com/openharmony/docs/blob/master/en/device-dev/quick-start/environment-setup.md) +[Setting up a development environment](https://gitee.com/openharmony/docs/blob/master/en/device-dev/quick-start/environment-setup.md) + +[Compiler install: gcc_riscv32](https://gitee.com/openharmony/docs/blob/master/en/device-dev/quick-start/setting-up-the-environment.md), +Note: [Downloadable directly](https://repo.huaweicloud.com/harmonyos/compiler/gcc_riscv32/7.3.0/linux/gcc_riscv32-linux-7.3.0.tar.gz) #### 3. Code acquisition -Refer to HOWTO guide: [Code acquisition](https://gitee.com/openharmony/docs/blob/master/en/device-dev/get-code/source-code-acquisition.md) +[Code acquisition](https://gitee.com/openharmony/docs/blob/master/en/device-dev/get-code/source-code-acquisition.md) Note: One can use `repo` to fetch code in a straightforward manner. @@ -37,7 +40,7 @@ out/OHOS_Image #### 5. Running image in Qemu a) If not installed, please install `qemu-system-riscv32` -For details, please refer to the HOWTO: [Qemu installation](https://www.qemu.org/download/) +For details, please refer to the HOWTO: [Qemu installation](https://gitee.com/openharmony/device_qemu/blob/master/README.md) b) Run @@ -55,4 +58,4 @@ cd device/qemu/riscv32_virt ./qemu-system-riscv32 out/OHOS_Image or qemu-system-riscv32 -machine virt -m 128M -bios none -kernel out/OHOS_Image -nographic -append "root=dev/vda or console=ttyS0" -``` \ No newline at end of file +``` diff --git a/riscv32_virt/README_zh.md b/riscv32_virt/README_zh.md index 67ec8a2..909f8b4 100755 --- a/riscv32_virt/README_zh.md +++ b/riscv32_virt/README_zh.md @@ -10,11 +10,14 @@ RISC-V 虚拟化平台是一个 `qemu-system-riscv32` 的目标设备,通过 ## 2. 环境搭建 -参考链接: [环境搭建](https://gitee.com/openharmony/docs/blob/master/zh-cn/device-dev/quick-start/%E7%8E%AF%E5%A2%83%E6%90%AD%E5%BB%BA.md) +[环境搭建](https://gitee.com/openharmony/docs/blob/master/zh-cn/device-dev/quick-start/%E7%8E%AF%E5%A2%83%E6%90%AD%E5%BB%BA.md) + +[编译器安装: gcc_riscv32](https://gitee.com/openharmony/docs/blob/master/zh-cn/device-dev/quick-start/%E5%AE%89%E8%A3%85%E5%BC%80%E5%8F%91%E6%9D%BF%E7%8E%AF%E5%A2%83.md), +提示: [可直接下载](https://repo.huaweicloud.com/harmonyos/compiler/gcc_riscv32/7.3.0/linux/gcc_riscv32-linux-7.3.0.tar.gz) ## 3. 获取源码 -参考链接: [代码获取](https://gitee.com/openharmony/docs/blob/master/zh-cn/device-dev/get-code/%E6%BA%90%E7%A0%81%E8%8E%B7%E5%8F%96.md) +[代码获取](https://gitee.com/openharmony/docs/blob/master/zh-cn/device-dev/get-code/%E6%BA%90%E7%A0%81%E8%8E%B7%E5%8F%96.md) 提示: 可以使用 `repo` 命令来获取源码。 @@ -33,7 +36,7 @@ out/OHOS_Image ``` ## 5. 在Qemu中运行镜像 -a) 如果没有安装 `qemu-system-riscv32` ,安装请参考链接[Qemu installation](https://www.qemu.org/download/) +a) 如果没有安装 `qemu-system-riscv32` ,安装请参考链接:[Qemu安装指导](https://gitee.com/openharmony/device_qemu/blob/master/README_zh.md) b) 运行 @@ -51,4 +54,4 @@ cd device/qemu/riscv32_virt ./qemu-system-riscv32 out/OHOS_Image 或 qemu-system-riscv32 -machine virt -m 128M -bios none -kernel out/OHOS_Image -nographic -append "root=dev/vda or console=ttyS0" -``` \ No newline at end of file +``` -- Gitee