0 . 准备工作与说明
0.1 准备工作
请先下载以下文件,里面有文档:
https://gitee.com/weidongshan/openharmony_for_imx6ull/repository/archive/master.zip
参考GIT中的文档,安装好虚拟机,从GIT总下载Liteos-a源码,打上IMX6ULL的补丁。
0.2 说明
1. Makefile编译系统分析
1.1 变量
- 1. LITEOSTOPDIR // kernel/liteos_a
- 2. LITEOSTHIRDPARTY // third_party
- 3. LITEOS_MK_PATH // kernel/liteos_a/tools/build/mk
- 4. MK_PATH = $(LITEOSTOPDIR)/tools/build/mk // kernel/liteos_a/tools/build/mk
1.2 包含的文件
- Makefile
- -include $(LITEOSTOPDIR)/tools/build/config.mk
- -include $(LITEOSTOPDIR)/tools/build/mk/los_config.mk
- -include $(LITEOSTOPDIR)/.config
- include $(LITEOSTOPDIR)/arch/cpu.mk
- -include $(LITEOSTOPDIR)/arch/arm/arm.mk
- include $(LITEOSTOPDIR)/platform/bsp.mk
- include $(LITEOSTOPDIR)/../../vendor/nxp/imx6ull/imx6ull.mk
- include $(LITEOSTOPDIR)/../../drivers/hdf/lite/hdf_lite.mk
- include $(LITEOSTOPDIR)/../../vendor/nxp/hdf/hdf_vendor.mk
- -include $(LITEOSTOPDIR)/3rdParty/3rdParty.mk
- -include $(LITEOS_MK_PATH)/liteos_tables_ldflags.mk
- -include $(LITEOS_MK_PATH)/dynload.mk
1.3 把Makefile全部展开
得到了一个Makefile_all.txt,
分析Makefile_all.txt,就可以知道编译过程。
1.4 分析在kernel/liteos_a下执行make的过程
1.4.1 第1个目标
all: $(OUT) $(BUILD) $(LITEOS_TARGET) $(APPS)
1.4.2 目标:OUT
- OUT目标:
- # .config文件中, LOSCFG_PLATFORM="imx6ull"
- OUT = $(LITEOSTOPDIR)/out/$(LITEOS_PLATFORM)
- $(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
- OUT的依赖:LITEOS_MENUCONFIG_H
- LITEOS_MENUCONFIG_H = $(LITEOSTOPDIR)/include/generated/autoconf.h
- KCONFIG_FILE_PATH = $(LITEOSTOPDIR)/Kconfig
- $(LITEOS_MENUCONFIG_H):
- ifneq ($(LITEOS_PLATFORM_MENUCONFIG_H), $(wildcard $(LITEOS_PLATFORM_MENUCONFIG_H)))
- $(HIDE)$(MAKE) genconfig
- endif
- genconfig:$(MENUCONFIG_PATH)/conf
- $(HIDE)mkdir -p include/config include/generated
- $< --silentoldconfig $(KCONFIG_FILE_PATH)
- -mv -f $(LITEOS_MENUCONFIG_H) $(LITEOS_PLATFORM_MENUCONFIG_H)
1.4.3 目标:BUILD
创建目录 kernel/liteos_a/imx6ull/obj
- OUT = $(LITEOSTOPDIR)/out/$(LITEOS_PLATFORM)
- BUILD = $(OUT)/obj
- $(BUILD):
- $(HIDE)mkdir -p $(BUILD)
1.4.4 目标:LITEOS_TARGET
- LITEOS_TARGET = liteos
- $(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
- $(OBJDUMP) -t $(OUT)/$@ |sort >$(OUT)/$@.sym.sorted
- $(OBJDUMP) -d $(OUT)/$@ >$(OUT)/$@.asm
- # $(NM) -S --size-sort $(OUT)/$@ >$(OUT)/$@.size
- 目标:__LIBS
- # 没做什么事
- __LIBS = libs
- $(__LIBS): $(OUT) $(CXX_INCLUDE)
- 命令:$(HIDE)touch $(LOSCFG_ENTRY_SRC)
每次都要编译los_config.c,touch一下
- LOSCFG_ENTRY_SRC = $(LITEOSTOPDIR)/kernel/common/los_config.c
- 命令:进入每个LITEOS_SUBDIRS,执行make,后面重点讲解各个子目录的编译
- # LIB_SUBDIRS 等于一系列的目录
- LIB_SUBDIRS :=
- LIB_SUBDIRS += arch/arm/$(LITEOS_ARCH_ARM) # 就是arch/arm/arm
- LIB_SUBDIRS += $(PLATFORM_BSP_HISI_BASE)
- LIB_SUBDIRS += $(LITEOSTOPDIR)/kernel/common
- LIB_SUBDIRS += kernel/base
- LIB_SUBDIRS += $(IMX6ULL_BASE_DIR)/board
- LIB_SUBDIRS += $(IMX6ULL_BASE_DIR)/driver/mtd/common
- LIB_SUBDIRS += $(IMX6ULL_BASE_DIR)/driver/mtd/spi_nor
- LIB_SUBDIRS += $(IMX6ULL_BASE_DIR)/driver/imx6ull-fb
- LIB_SUBDIRS += $(IMX6ULL_BASE_DIR)/driver/imx6ull-uart
- LIB_SUBDIRS += kernel/extended/cpup
- LIB_SUBDIRS += lib/libc
- LIB_SUBDIRS += lib/libsec
- LIB_SUBDIRS += lib/libscrew
- LIB_SUBDIRS += fs/fat
- LIB_SUBDIRS += fs/jffs2
- LITEOS_SUBDIRS = $(LIB_SUBDIRS)
- $(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
- $(OBJDUMP) -t $(OUT)/$@ |sort >$(OUT)/$@.sym.sorted
- $(OBJDUMP) -d $(OUT)/$@ >$(OUT)/$@.asm
- # $(NM) -S --size-sort $(OUT)/$@ >$(OUT)/$@.size
1.4.5 怎么编译各个子目录
- 第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 ? 看下图