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
相关推荐
赖small强7 分钟前
【Linux 网络基础】libwebsockets HTTPS 服务端实现机制详解
linux·网络·https·tls·libwebsockets
optimistic_chen43 分钟前
【Redis 系列】Redis详解
linux·数据库·redis·缓存·xsheel
低客的黑调1 小时前
了解JVM 结构和运行机制,从小白编程Java 大佬
java·linux·开发语言
想唱rap1 小时前
C++ map和set
linux·运维·服务器·开发语言·c++·算法
CodeByV1 小时前
【Linux】Ext 系列文件系统深度解析:从磁盘到软硬链接
linux·服务器
运维-大白同学2 小时前
2025最全面开源devops运维平台功能介绍
linux·运维·kubernetes·开源·运维开发·devops
梦在深巷、2 小时前
linux系统防火墙之iptables
linux·运维·服务器
放学有种别跑、3 小时前
GIT使用指南
大数据·linux·git·elasticsearch
做人不要太理性3 小时前
【Linux系统】线程的同步与互斥:核心原理、锁机制与实战代码
linux·服务器·算法
weixin_660096784 小时前
zsh中使用自动补全zsh-autosuggestions
linux·ubuntu·zsh·zshrc