OpenHarmony移植之编译工具链

OpenHarmony移植之编译工具链

1、下载工具链

选择适合自己芯片的arm编译工具链,因为我的是arm cortex-a9的芯片,所以我选择如下交叉工具链

Downloads | GNU-A Downloads -- Arm DeveloperDownload the The GNU Toolchain for the Cortex-A Family are integrated and validated packages featuring the GCC compiler, libraries and other GNU tools necessary for software development on devices based on the Arm Cortex-A processors or the Arm A-profile architecture.https://developer.arm.com/downloads/-/gnu-a

2、将工具链放入OpenHarmony目录

2.1、放入prebuilts目录下面

3、配置编译工具链

3.1、在device目录下配置编译工具链

device/board/exynos/fs4412/linux/config.gni
# Board CPU type, e.g. "cortex-a7", "riscv32".
board_cpu = "cortex-a9"

# Board arch, e.g.  "armv7-a", "rv32imac".
board_arch = "armv7"

# Toolchain name used for system compiling.
# E.g. gcc-arm-none-eabi, arm-linux-harmonyeabi-gcc, ohos-clang,  riscv32-unknown-elf.
# Note: The default toolchain is "ohos-clang". It's not mandatory if you use the default toolchain.
board_toolchain = "arm-none-linux-gnueabi-gcc"

# The toolchain path installed, it's not mandatory if you have added toolchain path to your ~/.bashrc.
board_toolchain_path = "~/openharmony/openharmony_3.2/prebuilts/gcc-4.6.4/bin"

# Compiler prefix.
board_toolchain_prefix = "arm-none-linux-gnueabi-"

# Compiler type, "gcc" or "clang".
board_toolchain_type = "gcc"

3.2、在kernel/linux/build目录下配置编译工具链

kernel/linux/build/kernel.mk
diff --git a/kernel.mk b/kernel.mk
index dc3343b..415e4d0 100644
--- a/kernel.mk
+++ b/kernel.mk
@@ -27,15 +27,15 @@ endif
 KERNEL_SRC_PATH := $(OHOS_BUILD_HOME)/kernel/linux/${KERNEL_VERSION}
 KERNEL_PATCH_PATH := $(OHOS_BUILD_HOME)/kernel/linux/patches/${KERNEL_VERSION}
 KERNEL_CONFIG_PATH := $(OHOS_BUILD_HOME)/kernel/linux/config/${KERNEL_VERSION}
-PREBUILTS_GCC_DIR := $(OHOS_BUILD_HOME)/prebuilts/gcc
+PREBUILTS_GCC_DIR := $(OHOS_BUILD_HOME)/prebuilts/gcc-4.6.4
 CLANG_HOST_TOOLCHAIN := $(OHOS_BUILD_HOME)/prebuilts/clang/ohos/linux-x86_64/llvm/bin
 KERNEL_HOSTCC := $(CLANG_HOST_TOOLCHAIN)/clang
 KERNEL_PREBUILT_MAKE := make
 CLANG_CC := $(CLANG_HOST_TOOLCHAIN)/clang

 ifeq ($(KERNEL_ARCH), arm)
-    KERNEL_TARGET_TOOLCHAIN := $(PREBUILTS_GCC_DIR)/linux-x86/arm/gcc-linaro-7.5.0-arm-linux-gnueabi/bin
-    KERNEL_TARGET_TOOLCHAIN_PREFIX := $(KERNEL_TARGET_TOOLCHAIN)/arm-linux-gnueabi-
+    KERNEL_TARGET_TOOLCHAIN := $(PREBUILTS_GCC_DIR)/bin
+    KERNEL_TARGET_TOOLCHAIN_PREFIX := $(KERNEL_TARGET_TOOLCHAIN)/arm-none-linux-gnueabi-
 else ifeq ($(KERNEL_ARCH), arm64)
     KERNEL_TARGET_TOOLCHAIN := $(PREBUILTS_GCC_DIR)/linux-x86/aarch64/gcc-linaro-7.5.0-2019.12-x86_64_aarch64-linux-gnu/bin
     KERNEL_TARGET_TOOLCHAIN_PREFIX := $(KERNEL_TARGET_TOOLCHAIN)/aarch64-linux-gnu-
@@ -49,7 +49,11 @@ ifeq ($(DEVICE_NAME), hispark_phoenix)
 KERNEL_CROSS_COMPILE += CONFIG_MSP="y"
 endif

+ifeq ($(DEVICE_NAME), fs4412)
+KERNEL_CROSS_COMPILE += CC="$(KERNEL_TARGET_TOOLCHAIN_PREFIX)gcc"
+else
 KERNEL_CROSS_COMPILE += CC="$(CLANG_CC)"
+endif

 ifneq ($(KERNEL_ARCH), x86_64)
 KERNEL_CROSS_COMPILE += CROSS_COMPILE="$(KERNEL_TARGET_TOOLCHAIN_PREFIX)"
@@ -101,7 +105,16 @@ endif
 ifeq ($(KERNEL_VERSION), linux-5.10)
        $(hide) $(KERNEL_MAKE) -C $(KERNEL_SRC_TMP_PATH) ARCH=$(KERNEL_ARCH) $(KERNEL_CROSS_COMPILE) modules_prepare
 endif
+ifeq ($(DEVICE_NAME), fs4412)
+ifeq ($(KERNEL_VERSION), linux-5.10)
+       $(hide) $(KERNEL_MAKE) -C $(KERNEL_SRC_TMP_PATH) ARCH=$(KERNEL_ARCH) $(KERNEL_CROSS_COMPILE) -j64 $(KERNEL_IMAGE) LOADADDR=0x40008000
+else
        $(hide) $(KERNEL_MAKE) -C $(KERNEL_SRC_TMP_PATH) ARCH=$(KERNEL_ARCH) $(KERNEL_CROSS_COMPILE) -j64 $(KERNEL_IMAGE)
+endif
+       $(hide) $(KERNEL_MAKE) -C $(KERNEL_SRC_TMP_PATH) ARCH=$(KERNEL_ARCH) $(KERNEL_CROSS_COMPILE) dtbs
+else
+       $(hide) $(KERNEL_MAKE) -C $(KERNEL_SRC_TMP_PATH) ARCH=$(KERNEL_ARCH) $(KERNEL_CROSS_COMPILE) -j64 $(KERNEL_IMAGE)
+endif
 endif
 ifeq ($(DEVICE_NAME), hispark_phoenix)
        $(hide) $(KERNEL_MAKE) -C
相关推荐
菜鸟小白:长岛icetea5 分钟前
Linux零基础速成篇一(理论+实操)
linux·运维·服务器
深海的鲸同学 luvi6 分钟前
【HarmonyOS NEXT】hdc环境变量配置
linux·windows·harmonyos
dowhileprogramming41 分钟前
Python 中的迭代器
linux·数据库·python
过过过呀Glik41 分钟前
在 Ubuntu 服务器上添加和删除用户
linux·服务器·ubuntu
Tesseract_95273 小时前
ioctl回顾
linux
Java小白中的菜鸟3 小时前
centos7的磁盘扩容
linux·运维·服务器
黑子哥呢?5 小时前
Linux---防火墙端口设置(firewalld)
linux·服务器·网络
F-2H6 小时前
C语言:指针4(常量指针和指针常量及动态内存分配)
java·linux·c语言·开发语言·前端·c++
aherhuo6 小时前
基于openEuler22.09部署OpenStack Yoga云平台(一)
linux·运维·服务器·openstack
檀越剑指大厂7 小时前
【Linux系列】Shell 脚本中的条件判断:`[ ]`与`[[ ]]`的比较
linux·运维·服务器