内核设备树简介-2

来源:互联网 发布:网上教育软件 编辑:程序博客网 时间:2024/05/17 13:43

设备树组成:

备树包含 DTC(device tree compiler)、DTS(device tree source)、DTB(device tree blob);

dts & dtsi 通过dtc,生成DTB(device tree blob),设备树二进制文件,BootLoader在引导内核时,会预先读取.dtb到内存,进而由内核解析;

dts和dtsi位于 /kernel/arch/arm/boot/dts/目录下;
dtc将.dts文件编译成.dtb文件,源码位于 kernel/scripts/dtc目录下.

设备树常用的API--OF API

主要文件:
kernel/driver/of
kernel/include/linux/of.h
int of_device_is_compatible(const struct device_node *device,const char *compat)------判断设备结点的compatible属性是否包含 compat 指定的字符串;
struct device_node *of_find_compatible_node(static device_node *from,const char *type,const char *compatible)----根据compatible属性,获得设备结点,遍历设备树中所有的设备结点,看看哪个结点的设备类型,compatible
属性与本函数的输入参数匹配,一般而言,from,type为NULL;
int of_property_read_u8_array(const struct device_node *np,const char *propname,u8 *out_values,size_t sz);
int of_property_read_u16_array(const struct device_node *np,const char *propname,u16 *out_values,size_t sz);
int of_property_read_u32_array(const struct device_node *np,const char *propname,u32 *out_values,size_t sz);
int of_property_read_u64_array(const struct device_node *np,const char *propname,u64 *out_values,size_t sz);
读取设备结点np的---属性名为propname,类型为8,16,32,64位整型数组的属性。
int of_property_read_string(struct device_node *np,const char *propname,const char **out_string);-------------------读取字符串属性
int of_ptoperty_read_string_index(struct device_node *np,const char *propname,int index,const char **output)------读取字符串数组属性中的第index个字符串;
static inline bool_of_property_read_bool(const struct device_node *np,const char *propname);---如果设备节点np含有属性propname,则返回true,否则返回false;
void __iomem *of_iomap(struct device_node *node,int index)---通过设备节点直接进行设备内存区间的ioremap(),index是内存段的索引;
unsigned int irq_of_parse_and_map(struct device_node *node,int index)---解析出中断号

原创粉丝点击