zephyr device-tree

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中

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章