一、MTK平台最初就是使用DWS来配置GPIO,非常方便、直观;但随着kernel版本升级使用设备树之后,硬件信息都由DTS来描述,但MTK仍然保留了DWS,下面看看MTK如何将DWS转换为DTSI的。
kernel使用的DWS路径:drivers/misc/mediatek/dws/mt6752/mt6752_64.dws
虽然vendor\mediatek\proprietary\custom\mt6752_64\kernel\dct\dct\codegen.dws也存在但默认不用这个
DWS转换为DTSI的工具kernel-4.14/scripts/drvgen/drvgen.mk
核心代码:
.PHONY: drvgen
drvgen: $(DRVGEN_FILE_LIST)
$(DRVGEN_FILE_LIST): $(DRVGEN_TOOL) $(DWS_FILE) $(DRVGEN_FIG) $(PROJ_DTS_FILES)
for i in $(PROJ_DTS_FILES); do \
base_prj=`grep -m 1 '#include [<\"].*\/cust\.dtsi[>\"]' $$i | sed 's/#include [<"]//g'\
| sed 's/\/cust\.dtsi[>"]//g' | sed 's/\/\*//g' | sed 's/\*\///g' | sed 's/ //g'`\
prj_path=$(DRVGEN_OUT)/$$base_prj ;\
dws_path=$(srctree)/$(DRVGEN_PATH)/$$base_prj.dws ;\
if [ -f $$dws_path ] ; then \
mkdir -p $$prj_path ;\
$(python) $(DRVGEN_TOOL) $$dws_path $$prj_path $$prj_path cust_dtsi;\
fi \
done
最终生成的DTSI文件路径obj\KERNEL_OBJ\arch\arm64\boot\dts\mt6752_64\cust_dtsi
具体怎么生成的可以看这个drvgen.mk以及它所依赖的工具
二、MTK DTBO的生成,它使用的哪个DTS文件
相关文件:scripts/drvgen/drvgen.mk
相关代码
my_dtbo_id := 0
define mk_dtboimg_cfg
echo $(1) >>$(2);\
echo " id=$(my_dtbo_id)" >>$(2);\
$(eval my_dtbo_id:=$(shell echo $$(($(my_dtbo_id)+1))))
endef
dtbs: $(objtree)/dtboimg.cfg
$(objtree)/dtboimg.cfg: FORCE
rm -f $@.tmp
$(foreach f,$(ABS_DTB_FILES),$(call mk_dtboimg_cfg,$(f),$@.tmp))
if ! cmp -s $@.tmp $@; then \
mv $@.tmp $@; \
else \
rm $@.tmp; \
fi
由此可见这里生成了一个dtboimg.cfg文件,路径:obj\KERNEL_OBJ\dtboimg.cfg
这个文件指定了DTBO由哪个DTS文件生成
DTBO生成:
device/mediatek/build/tasks/dtbo.mk
.KATI_RESTAT: $(KERNEL_OUT)/dtboimg.cfg
$(KERNEL_OUT)/dtboimg.cfg: $(KERNEL_ZIMAGE_OUT) ;
# mkdtimg is from system/libufdt/utils/src
$(BOARD_PREBUILT_DTBOIMAGE): PRIVATE_TOOL := $(HOST_OUT_EXECUTABLES)/mkdtimg
$(BOARD_PREBUILT_DTBOIMAGE): PRIVATE_CFG := $(KERNEL_OUT)/dtboimg.cfg
$(BOARD_PREBUILT_DTBOIMAGE): $(HOST_OUT_EXECUTABLES)/mkdtimg
$(BOARD_PREBUILT_DTBOIMAGE): $(KERNEL_OUT)/dtboimg.cfg
$(hide) mkdir -p $(dir $@)
$(PRIVATE_TOOL) cfg_create $@ $(PRIVATE_CFG)
ifeq ($(strip $(MTK_DTBO_UPGRADE_FROM_ANDROID_O)), yes)
droidcore: $(PRODUCT_OUT)/$(notdir $(BOARD_PREBUILT_DTBOIMAGE))
odmdtboimage: $(PRODUCT_OUT)/$(notdir $(BOARD_PREBUILT_DTBOIMAGE))
else
droidcore: $(PRODUCT_OUT)/dtbo.img
dtboimage: $(PRODUCT_OUT)/dtbo.img
endif
$(PRODUCT_OUT)/recovery.img: $(BOARD_PREBUILT_DTBOIMAGE)
由此可见,此处使用mkdtimg工具根据dtboimg.cfg来生成dtbo.img
三、MTK DTB DTBO使用哪个DTS文件
文件:kernel-4.14/scripts/drvgen/drvgen.mk
ifeq ($(strip $(CONFIG_ARM64)), y)
MAIN_DT_NAMES := $(subst $\",,$(CONFIG_BUILD_ARM64_APPENDED_DTB_IMAGE_NAMES))
else
MAIN_DT_NAMES := $(subst $\",,$(CONFIG_BUILD_ARM_APPENDED_DTB_IMAGE_NAMES))
endif
ifeq ($(strip $(CONFIG_ARM64)), y)
PROJ_DT_NAMES := $(subst $\",,$(CONFIG_BUILD_ARM64_DTB_OVERLAY_IMAGE_NAMES))
else
PROJ_DT_NAMES := $(subst $\",,$(CONFIG_BUILD_ARM_DTB_OVERLAY_IMAGE_NAMES))
endif
文件:kernel 的config文件
CONFIG_BUILD_ARM64_APPENDED_DTB_IMAGE_NAMES="mediatek/mt6752"
CONFIG_BUILD_ARM64_DTB_OVERLAY_IMAGE_NAMES="mediatek/mt6752_64"
mt6752_64.dts用来生成DTBO,mt6752.dts用来生成dtb
但是drvgen.mk下面生成的DTB依赖文件是mtk.dtb,那mtk.dtb哪里来的呢?
ABS_DTB_FILES := $(abspath $(addsuffix .dtb,$(addprefix $(objtree)/arch/$(SRCARCH)/boot/dts/,$(PROJ_DT_NAMES))))
ABS_DTB2_FILES := $(abspath $(addprefix $(objtree)/arch/$(SRCARCH)/boot/,mtk.dtb))
$(objtree)/dtbimg.cfg: FORCE
rm -f $@.tmp
$(foreach f,$(ABS_DTB2_FILES),$(call mk_dtbimg_cfg,$(f),$@.tmp))
if ! cmp -s $@.tmp $@; then \
mv $@.tmp $@; \
else \
rm $@.tmp; \
fi
这个dtbimg.cfg文件内容就是mtk.dtb的路径
其他地方关于mtk.dtb的定义
kenv.mk:109: KERNEL_DTB_FILE := $(KERNEL_OUT)/arch/$(KERNEL_TARGET_ARCH)/boot/mtk.dtb
Android.mk
### DTB
ifdef BOARD_PREBUILT_DTBIMAGE_DIR
INSTALLED_MTK_DTB_TARGET := $(BOARD_PREBUILT_DTBIMAGE_DIR)/mtk_dtb
$(shell if [ ! -f $(INSTALLED_MTK_DTB_TARGET) ]; then mkdir -p $(dir $(INSTALLED_MTK_DTB_TARGET)); touch $(INSTALLED_MTK_DTB_TARGET);fi)
$(INSTALLED_MTK_DTB_TARGET): $(INSTALLED_KERNEL_TARGET)
@mkdir -p $(dir $@)
@cp -f $(KERNEL_DTB_FILE) $@
endif
dtbimg.cfg路径
"out\target\product\mt6752_64\obj\KERNEL_OBJ\dtbimg.cfg"
mtk.dtb路径
"out\target\product\mt6752_64\obj\PACKAGING\dtb\mtk.dtb"
mtk.dtb来源:
文件:arch/arm64/boot/Makefile
DTB_NAMES := $(subst $\",,$(CONFIG_BUILD_ARM64_APPENDED_DTB_IMAGE_NAMES))
ifneq ($(DTB_NAMES),)
DTB_LIST := $(addsuffix .dtb,$(DTB_NAMES))
else
DTB_LIST := $(dtb-y)
endif
DTB_OBJS := $(addprefix $(obj)/dts/,$(DTB_LIST))
$(obj)/mtk.dtb: $(DTB_OBJS) FORCE
$(call if_changed,cat)