zephyr build overview官方說明文檔: https://docs.zephyrproject.org/latest/guides/build/index.html
zephyr 也同樣採用了設備樹來描述板級信息,實際使用上zephyr並不是像linux那樣用dtc編譯成dtb然後代碼中去解析dtb,從官方文檔可以看出,zephyr會把dts最終轉變成head file來使用的,其中過程如下:
1. c預處理器處理include dtsi 和define的預處理,這一步與linux kernel的編譯同樣,生成的*.dts.pre.tmp 文件可以用dtc編譯成dtb,在zephyr中並沒有使用dtb,所以只用來debug
2. dts/bindings 有設備的yaml後綴文件,yaml文件其實也是一種配置文件類型,類似ini,json配置文件,cmake/dts.cmake 調用scripts/dts/extract_dts_includes.py 腳本處理yaml文件生成dedicatee_unfixed.h,鏈接文章解釋了這個轉化過程https://docs.zephyrproject.org/latest/guides/dts/macros.html?highlight=yaml。
本地代碼舉例
yaml:
properties:
compatible:
constraint: "nxp,s32k-flexcan"
reg:
type: array
description: register base address
generation: define
category: required
interrupts:
type: array
category: required
description: required interrupts
generation: define
interrupt-names:
type: array
category: optional
description: names off the interrupt lines
*dts.pre.tmp:
can0: can0@40024000 {
compatible = "nxp,s32k-flexcan";
reg = <0x40024000 0x1000>;
interrupts = <78 0>, <79 0>, <80 0>, <81 0>, <82 0>;
interrupt-names = "ORed", "Error", "Wake_Up", "ORed_0_15_MB", "ORed_16_31_MB";
clocks = <&s32k_cc 52 0x0>;
label = "CAN_0";
bus-speed = <500000>;
};
*dts_unfixed.h:
/* can0@40024000 */
#define DT_NXP_S32K_FLEXCAN_0 1
#define DT_NXP_S32K_FLEXCAN_40024000_BASE_ADDRESS 0x40024000
#define DT_NXP_S32K_FLEXCAN_40024000_BUS_SPEED 500000
#define DT_NXP_S32K_FLEXCAN_40024000_CLOCK_CONTROLLER "S32K_CC"
#define DT_NXP_S32K_FLEXCAN_40024000_CLOCK_NAME_0 52
#define DT_NXP_S32K_FLEXCAN_40024000_CLOCK_RETAIN_0 0
#define DT_NXP_S32K_FLEXCAN_40024000_IRQ_0 78
#define DT_NXP_S32K_FLEXCAN_40024000_IRQ_0_PRIORITY 0
#define DT_NXP_S32K_FLEXCAN_40024000_IRQ_1 79
#define DT_NXP_S32K_FLEXCAN_40024000_IRQ_1_PRIORITY 0
#define DT_NXP_S32K_FLEXCAN_40024000_IRQ_2 80
#define DT_NXP_S32K_FLEXCAN_40024000_IRQ_2_PRIORITY 0
#define DT_NXP_S32K_FLEXCAN_40024000_IRQ_3 81
#define DT_NXP_S32K_FLEXCAN_40024000_IRQ_3_PRIORITY 0
#define DT_NXP_S32K_FLEXCAN_40024000_IRQ_4 82
#define DT_NXP_S32K_FLEXCAN_40024000_IRQ_4_PRIORITY 0
3.west -v build * samples/hello_world 2>&1 |tee make.log,能看到kconfig的處理過程的log,處理kconfig的腳本在script/kconfig/kconfig.py
Parsing Kconfig tree in west_zephyr/zephyr/Kconfig
Loading west_zephyr/zephyr/boards/arm/xxx/xxx_defconfig as base
Merging west_zephyr/zephyr/samples/hello_world/prj.conf
Configuration written to 'west_zephyr/zephyr/build/zephyr/.config'
這步Merging的順序是prj.conf在後面,所以prj.conf的CONFIG的值會覆蓋defconfig中的值
以samples/helloworld 舉例,在prj.conf中定義CONFIG_DEBUG=n,build出來的autoconf.h就沒有DEBUG的config配置項,儘管xxx_defconfig中CONFIG_DEBUG=y
4. dts & kconfig headfile的使用
include/arch/arm/arch.h
-->#include <generated_dts_board.h>
-->#include <generated_dts_board_fixups.h>
autoconf.h
Cmakelist.txt 中zephyr_compile_options 中添加編譯選項 -imacros $(AUTOCONF_H),從gcc官網查到這個選項是預處理選項,可以獲取到指定文件中的所有定義define,所以不用再include 本文見就可以喫到這些CONFIG
-imacros file
Exactly like -include, except that any output produced by scanning file is thrown away. Macros it defines remain defined. This allows you to acquire all the macros from a header without also processing its declarations.
All files specified by -imacros are processed before all files specified by -include.
未找到答案
1.devicetree_fixups.h fixup是個什麼過程
已解決, dts_fixup.h 在soc/arm/xxx目錄下,用來對DTS補充一些define,最後會把這些define一起合併到build/zephyr/include/generated/generated_dts_board_fixups.h中