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
相关推荐
打不了嗝 ᥬ᭄2 小时前
Linux的权限
linux
落幕2 小时前
C语言-进程
linux·运维·服务器
深度Linux2 小时前
C++程序员内功修炼——Linux C/C++编程技术汇总
linux·项目实战·c/c++
风静如云3 小时前
OpenBMC:BmcWeb定义service
linux
leoufung4 小时前
VIM FZF 安裝和使用
linux·编辑器·vim
bugtraq20215 小时前
XiaoMi Mi5(gemini) 刷入Ubuntu Touch 16.04——安卓手机刷入Linux
linux·运维·ubuntu
CodeWithMe5 小时前
[ Vim ] 常用命令 and 配置
linux·编辑器·vim
DC_BLOG5 小时前
Linux-GlusterFS进阶分布式卷
linux·运维·服务器·分布式
cookies_s_s6 小时前
Linux--进程(进程虚拟地址空间、页表、进程控制、实现简易shell)
linux·运维·服务器·数据结构·c++·算法·哈希算法
丁劲犇6 小时前
碳基生物的悲歌-DeepSeek思考实现Linux动态库递归收集工具
linux·递归·deepseek·ldd