鸿蒙移植i.mx6ull (七) Liteos-a的编译系统(上)

本文涉及的产品
云数据库 Tair(兼容Redis),内存型 2GB
Redis 开源版,标准版 2GB
推荐场景:
搭建游戏排行榜
简介: 鸿蒙移植i.mx6ull (七) Liteos-a的编译系统

Liteos-a编译系统分析


1.1 怎么编译子目录


以kernel/liteos_a/fs/fat/Makefile为例:

# Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
# Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this list of
#    conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice, this list
#    of conditions and  he following disclaimer in the documentation and/or other materials
#    provided with the distribution.
#
# 3. Neither the name of the copyright holder nor the names of its contributors may be used
#    to endorse or promote products derived from this software without specific prior written
#    permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
include $(LITEOSTOPDIR)/config.mk 
MODULE_NAME := $(notdir $(shell pwd))//当前目录fat
LOCAL_SRCS := $(wildcard os_adapt/*.c)//
LOCAL_SRCS += $(wildcard $(LITEOSTHIRDPARTY)/FatFs/source/*.c)
LOCAL_INCLUDE := \
    -I $(LITEOSTHIRDPARTY)/FatFs/source \
    -I $(LITEOSTOPDIR)/fs/fat/virpart/include
LOCAL_FLAGS := $(LOCAL_INCLUDE) $(LITEOS_GCOV_OPTS)
include $(MODULE)
~                                                                                                  
~


第1行包含config.mk

这是包含一些预先定义的变量,比如默认的编译选项等。


下面的代码定义了LOCAL_SRCS

等于一系列C文件,这就是要编译的源文件。


定义了LOCAL_INCLUDE


这是头文件的目录


定义了LOCAL_FLAGS


这是编译选项


定义了MODULE_NAME

一般等于当前目录的名字,比如fat,以后就编译得到libfat.a


怎么编译?看最后一行

include $(MODULE)


MODULE就是:

MODULE = $(MK_PATH)/module.mk  # kernel/liteos_a/tools/build/mk/module.mk

分析module.mk:

# 找到第1个目标
all : $(LIB)
# LIB是什么, 如果没定义LOCAL_SO,LIB就是 lib$(MODULE_NAME).a, 比如 libfat.a
ifeq ($(LOCAL_SO), y)
LIBSO := $(OUT)/lib/lib$(MODULE_NAME).so
LIBA := $(OUT)/lib/lib$(MODULE_NAME).a
else
LIBSO :=
LIBA := $(OUT)/lib/lib$(MODULE_NAME).a
endif
LIB := $(LIBA) $(LIBSO)
# 怎么编译 LIBA ? 看下图

1671000423309.jpg


1.2 编译哪些子目录


1.2.1 从链接命令看内核的组成


链接命令如下


liteos-a由一系列的库文件组成,reset_vector是它的入口。

1671000441647.jpg

查看链接脚本

vi /home/book/openharmony/kernel/liteos_a/tools/build/liteos_llvm.ld

1671000457334.jpg


查看入口:

grep "reset_vector" * -nwr

1671000474121.jpg

1671000481083.jpg

查看liteos.map文件

1671000489904.jpg


1.2.2 从Makefile开始分析


从链接命令查看内核的组成,是一个取巧的方法。

本质的方法应该是从kernel/liteos_a/Makefile开始分析。


1.3 顶层Makefile分析


指的是kernel/liteos_a/Makefile。


下面是完整的liteos的makefile

# Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
# Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this list of
#    conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice, this list
#    of conditions and the following disclaimer in the documentation and/or other materials
#    provided with the distribution.
#
# 3. Neither the name of the copyright holder nor the names of its contributors may be used
#    to endorse or promote products derived from this software without specific prior written
#    permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
LITEOSTOPDIR := $(shell if [ "$$PWD" != "" ]; then echo $$PWD; else pwd; fi)
export OS=$(shell uname -s)
ifneq ($(OS), Linux)
LITEOSTOPDIR := $(shell dirname $(subst \,/,$(LITEOSTOPDIR))/./)
endif
LITEOSTHIRDPARTY := $(LITEOSTOPDIR)/../../third_party
export LITEOSTOPDIR
export LITEOSTHIRDPARTY
-include $(LITEOSTOPDIR)/tools/build/config.mk
RM = -rm -rf
MAKE = make
__LIBS = libs
APPS = apps
ROOTFSDIR = rootfsdir
ROOTFS = rootfs
LITEOS_TARGET = liteos
LITEOS_LIBS_TARGET = libs_target
LITEOS_MENUCONFIG_H = $(LITEOSTOPDIR)/include/generated/autoconf.h
LITEOS_PLATFORM_BASE = $(LITEOSTOPDIR)/platform
LITEOS_PLATFORM_MENUCONFIG_H = $(LITEOS_PLATFORM_BASE)/include/menuconfig.h
ifeq ($(LOSCFG_PLATFORM_HI3518EV300), y)
FSTYPE = jffs2
endif
ifeq ($(LOSCFG_PLATFORM_HI3516DV300), y)
FSTYPE = vfat
endif
ifeq ($(LOSCFG_PLATFORM_IMX6ULL), y)
FSTYPE = jffs2
endif
ifeq ($(LOSCFG_PLATFORM_STM32MP157), y)
FSTYPE = jffs2
ROOTFS_SIZE = 0xA00000
endif
ROOTFS_DIR = $(OUT)/rootfs
ROOTFS_ZIP = $(OUT)/rootfs.zip
VERSION =
all: $(OUT) $(BUILD) $(LITEOS_TARGET) $(APPS)
lib: $(OUT) $(BUILD) $(LITEOS_LIBS_TARGET)
help:
  $(HIDE)echo "-------------------------------------------------------"
  $(HIDE)echo "1.====make help:    get help infomation of make"
  $(HIDE)echo "2.====make:         make a debug version based the .config"
  $(HIDE)echo "3.====make debug:   make a debug version based the .config"
  $(HIDE)echo "4.====make release: make a release version for all platform"
  $(HIDE)echo "5.====make release PLATFORM=xxx:  make a release version only for platform xxx"
  $(HIDE)echo "6.====make rootfsdir: make a original rootfs dir"
  $(HIDE)echo "7.====make rootfs FSTYPE=***: make a original rootfs img"
  $(HIDE)echo "8.====make test: make the testsuits_app and put it into the rootfs dir"
  $(HIDE)echo "9.====make test_apps FSTYPE=***: make a rootfs img with the testsuits_app in it"
  $(HIDE)echo "xxx should be one of (hi3516cv300 hi3516ev200 hi3556av100/cortex-a53_aarch32 hi3559av100/cortex-a53_aarch64)"
  $(HIDE)echo "*** should be one of (jffs2)"
  $(HIDE)echo "-------------------------------------------------------"
debug:
  $(HIDE)echo "=============== make a debug version  ==============="
  $(HIDE) $(MAKE) all
release:
ifneq ($(PLATFORM),)
  $(HIDE)echo "=============== make a release version for platform $(PLATFORM) ==============="
  $(HIDE)$(SCRIPTS_PATH)/mklibversion.sh $(PLATFORM)
else
  $(HIDE)echo "================make a release version for all platform ==============="
  $(HIDE)$(SCRIPTS_PATH)/mklibversion.sh
endif
##### make dynload #####
-include $(LITEOS_MK_PATH)/dynload.mk
#-----need move when make version-----#
##### make lib #####
$(__LIBS): $(OUT) $(CXX_INCLUDE)
ifeq ($(LOSCFG_PLATFORM_IMX6ULL),y)
BOARD_INCLUDE_DIR := $(LITEOSTOPDIR)/../../vendor/nxp/imx6ull/board
else ifeq ($(LOSCFG_PLATFORM_STM32MP157), y)
BOARD_INCLUDE_DIR := $(LITEOSTOPDIR)/../../vendor/st/stm32mp157/board
else
BOARD_INCLUDE_DIR := $(LITEOSTOPDIR)/../../vendor/hisi/hi35xx/$(LITEOS_PLATFORM)/config/board
endif
$(OUT): $(LITEOS_MENUCONFIG_H)
  $(HIDE)mkdir -p $(OUT)/lib
  $(HIDE)$(CC) -I$(LITEOS_PLATFORM_BASE)/include -I$(BOARD_INCLUDE_DIR) \
  -E $(LITEOS_PLATFORM_BASE)/board.ld.S \
  -o $(LITEOS_PLATFORM_BASE)/board.ld -P
$(BUILD):
  $(HIDE)mkdir -p $(BUILD)
$(LITEOS_LIBS_TARGET): $(__LIBS)
  $(HIDE)for dir in $(LIB_SUBDIRS); \
  do $(MAKE) -C $$dir all || exit 1; \
  done
  $(HIDE)echo "=============== make lib done  ==============="
##### make menuconfig #####
export CONFIG_=LOSCFG_
MENUCONFIG_PATH = $(LITEOSTOPDIR)/tools/menuconfig
KCONFIG_FILE_PATH = $(LITEOSTOPDIR)/Kconfig
menuconfig:$(MENUCONFIG_PATH)/mconf
  $< $(KCONFIG_FILE_PATH)
genconfig:$(MENUCONFIG_PATH)/conf
  $(HIDE)mkdir -p include/config include/generated
  $< --silentoldconfig $(KCONFIG_FILE_PATH)
  -mv -f $(LITEOS_MENUCONFIG_H) $(LITEOS_PLATFORM_MENUCONFIG_H)
##### menuconfig end #######
$(LITEOS_MENUCONFIG_H):
ifneq ($(LITEOS_PLATFORM_MENUCONFIG_H), $(wildcard $(LITEOS_PLATFORM_MENUCONFIG_H)))
  $(HIDE)$(MAKE) genconfig
endif
$(LITEOS_TARGET): $(__LIBS)
  $(HIDE)touch $(LOSCFG_ENTRY_SRC)
  $(HIDE)for dir in $(LITEOS_SUBDIRS); \
  do $(MAKE) -C $$dir all || exit 1; \
  done
  $(LD) $(LITEOS_LDFLAGS) $(LITEOS_TABLES_LDFLAGS) $(LITEOS_DYNLDFLAGS) -Map=$(OUT)/$@.map -o $(OUT)/$@ --start-group $(LITEOS_LIBDEP) --end-group
# $(SIZE) -t --common $(OUT)/lib/*.a >$(OUT)/$@.objsize
  $(OBJCOPY) -O binary $(OUT)/$@ $(LITEOS_TARGET_DIR)/$@.bin
ifeq ($(LOSCFG_PLATFORM_STM32MP157), y)
  mkimage.stm32 -T stm32image -a 0xC0100000 -e 0xC0100000 -d $(LITEOS_TARGET_DIR)/$@.bin $(LITEOS_TARGET_DIR)/liteos.stm32
  mkimage.stm32 -A arm -O linux -T kernel -C none -a 0xC0100000 -e 0xC0100000 -n liteos-a -d $(LITEOS_TARGET_DIR)/$@.bin $(LITEOS_TARGET_DIR)/liteos_with_uboot_header.bin
endif
  $(OBJDUMP) -t $(OUT)/$@ |sort >$(OUT)/$@.sym.sorted
  $(OBJDUMP) -d $(OUT)/$@ >$(OUT)/$@.asm
# $(NM) -S --size-sort $(OUT)/$@ >$(OUT)/$@.size
$(APPS): $(LITEOS_TARGET)
  $(HIDE)$(MAKE) -C apps all
prepare:
  $(HIDE)mkdir -p $(OUT)/musl
ifeq ($(LOSCFG_COMPILER_CLANG_LLVM), y)
  $(HIDE)cp -f $(LITEOSTOPDIR)/../../prebuilts/lite/sysroot/usr/lib/$(LLVM_TARGET)/a7_softfp_neon-vfpv4/libc.so $(OUT)/musl
  $(HIDE)cp -f $(LITEOS_COMPILER_PATH)/lib/$(LLVM_TARGET)/c++/a7_softfp_neon-vfpv4/libc++.so $(OUT)/musl
else
  $(HIDE)cp -f $(LITEOS_COMPILER_PATH)/target/usr/lib/libc.so $(OUT)/musl
  $(HIDE)cp -f $(LITEOS_COMPILER_PATH)/arm-linux-musleabi/lib/libstdc++.so.6 $(OUT)/musl
  $(HIDE)cp -f $(LITEOS_COMPILER_PATH)/arm-linux-musleabi/lib/libgcc_s.so.1 $(OUT)/musl
  $(STRIP) $(OUT)/musl/*
endif
$(ROOTFSDIR): prepare $(APPS)
  $(HIDE)$(MAKE) clean -C apps
  $(HIDE)$(shell $(LITEOSTOPDIR)/tools/scripts/make_rootfs/rootfsdir.sh $(OUT)/bin $(OUT)/musl $(ROOTFS_DIR))
ifneq ($(VERSION),)
  $(HIDE)$(shell $(LITEOSTOPDIR)/tools/scripts/make_rootfs/releaseinfo.sh "$(VERSION)" $(ROOTFS_DIR))
endif
$(ROOTFS): $(ROOTFSDIR)
  $(HIDE)$(shell $(LITEOSTOPDIR)/tools/scripts/make_rootfs/rootfsimg.sh $(ROOTFS_DIR) $(FSTYPE)  ${ROOTFS_SIZE})
  $(HIDE)cd $(ROOTFS_DIR)/.. && zip -r $(ROOTFS_ZIP) $(ROOTFS)
ifneq ($(OUT), $(LITEOS_TARGET_DIR))
  $(HIDE)mv $(ROOTFS_DIR) $(LITEOS_TARGET_DIR)rootfs
endif
clean:
  $(HIDE)for dir in $(LITEOS_SUBDIRS); \
  do $(MAKE) -C $$dir clean|| exit 1; \
  done
  $(HIDE)$(MAKE) -C apps clean
  $(HIDE)$(RM) $(__OBJS) $(LITEOS_TARGET) $(OUT) $(BUILD) $(LITEOS_MENUCONFIG_H) *.bak *~
  $(HIDE)$(RM) $(LITEOS_PLATFORM_MENUCONFIG_H)
  $(HIDE)$(RM) include
  $(HIDE)$(MAKE) cleanrootfs
  $(HIDE)echo "clean $(LITEOS_PLATFORM) finish"
cleanall:
  $(HIDE)$(RM) $(LITEOSTOPDIR)/out
  $(HIDE)find $(LITEOS_PLATFORM_BASE)/ -name board.ld -exec rm -rf {} \;
  $(HIDE)cd sample/sample_osdrv;make clean;cd ../..;
  $(HIDE)echo "clean all"
cleanrootfs:
  $(HIDE)$(RM) $(OUT)/rootfs
  $(HIDE)$(RM) $(OUT)/rootfs.zip
  $(HIDE)$(RM) $(OUT)/rootfs.img
.PHONY: all lib clean cleanall $(LITEOS_TARGET) debug release help
相关实践学习
基于Redis实现在线游戏积分排行榜
本场景将介绍如何基于Redis数据库实现在线游戏中的游戏玩家积分排行榜功能。
云数据库 Redis 版使用教程
云数据库Redis版是兼容Redis协议标准的、提供持久化的内存数据库服务,基于高可靠双机热备架构及可无缝扩展的集群架构,满足高读写性能场景及容量需弹性变配的业务需求。 产品详情:https://www.aliyun.com/product/kvstore &nbsp; &nbsp; ------------------------------------------------------------------------- 阿里云数据库体验:数据库上云实战 开发者云会免费提供一台带自建MySQL的源数据库&nbsp;ECS 实例和一台目标数据库&nbsp;RDS实例。跟着指引,您可以一步步实现将ECS自建数据库迁移到目标数据库RDS。 点击下方链接,领取免费ECS&amp;RDS资源,30分钟完成数据库上云实战!https://developer.aliyun.com/adc/scenario/51eefbd1894e42f6bb9acacadd3f9121?spm=a2c6h.13788135.J_3257954370.9.4ba85f24utseFl
相关文章
|
12天前
|
JavaScript 前端开发 物联网
「Mac畅玩鸿蒙与硬件1」鸿蒙开发环境配置篇1 - 认识鸿蒙系统与开发工具
本篇将介绍鸿蒙操作系统(HarmonyOS)的基本概念以及在 Mac 环境下进行鸿蒙开发所需的工具。通过了解鸿蒙系统和开发工具的特点,为后续的学习和实践奠定基础。
36 1
「Mac畅玩鸿蒙与硬件1」鸿蒙开发环境配置篇1 - 认识鸿蒙系统与开发工具
|
19天前
|
存储 数据管理 调度
HarmonyOS架构理解:揭开鸿蒙系统的神秘面纱
【10月更文挑战第21天】华为的鸿蒙系统(HarmonyOS)以其独特的分布式架构备受关注。该架构包括分布式软总线、分布式数据管理和分布式任务调度。分布式软总线实现设备间的无缝连接;分布式数据管理支持跨设备数据共享;分布式任务调度则实现跨设备任务协同。这些特性为开发者提供了强大的工具,助力智能设备的未来发展。
64 1
|
1月前
|
安全 物联网 大数据
基于开元鸿蒙(OpenHarmony)的【智能药房与药品管理综合应用系统
基于开元鸿蒙(OpenHarmony)的【智能药房与药品管理综合应用系统
78 8
|
1月前
|
传感器 监控 算法
基于开源鸿蒙(OpenHarmony)的【智能家居综合应用】系统
基于开源鸿蒙(OpenHarmony)的【智能家居综合应用】系统
83 6
|
1月前
|
传感器 人工智能 监控
【基于开源鸿蒙(OpenHarmony)的智慧农业综合应用系统】
【基于开源鸿蒙(OpenHarmony)的智慧农业综合应用系统】
86 6
|
1月前
|
搜索推荐 物联网 开发工具
基于OpenHarmony(开源鸿蒙)的智慧医疗综合应用系统
基于OpenHarmony(开源鸿蒙)的智慧医疗综合应用系统
82 5
|
5月前
|
网络协议 安全 调度
阿里云公共DNS发布支持鸿蒙系统版的SDK
阿里云公共DNS发布支持鸿蒙系统版SDK,赋能鸿蒙开发者快速接入阿里云公共DNS服务。公共DNS将帮助接入的鸿蒙应用免除LocalDNS劫持困扰、解析加速、精准调度。
|
6月前
|
Android开发
【通讯录教程】苹果安卓鸿蒙系统通用,如何大批量导入手机号码到手机的通讯录,下面教你方法,只需1分钟搞定几万个号码的导入手机电话本
该文介绍了一种快速批量导入手机通讯录的方法,适用于处理大量手机号的需求,如微商管理、客户资料整理等。在QQ同步助手开始收费后,提供了免费的替代方案。步骤包括:下载批量导入软件(链接提供腾讯云盘和百度网盘地址),清空通讯录(非必需),制作符合格式的通讯录文件,并按操作系统(苹果、安卓或鸿蒙)进行导入。整个过程只需1分钟,简便快捷。
450 2
|
6月前
|
安全 开发工具 开发者
请说明鸿蒙操作系统的生态系统建设和开发者支持措施。
请说明鸿蒙操作系统的生态系统建设和开发者支持措施。
132 5