imx6ull.Linux4.15平台下开发 记录1(设备树)

本连载记录下自己在区域控制站项目中开发点滴,记录1是重温设备树

一、 1.设备树编译:(1)在arch/arm/boot/dts/Makefile 添加目标办编译的dts文件,如:imx6ull-borrow-emmc.dtb(在$(CONFIG_SOC_IMX6ULL)下添加)
2.imx6ull.dtsi描述imx6ull内部外设信息: 
cpu0:cpu@0{
compatible = "arm,cortex-a7";
device_type = "cpu";
};
描述cpu0信息(如主频)
3.节点命名:node-name@unit-address
eg: uart1@寄存器首地址/设备的地址
interrupt-controller@00a01000    或 cpu@0
label:node-name@unit-address: label:节点标签
4.节点值:(1)字符串:compatible = "arm,cortex-a7";
                  (2) 32位无符号证书:reg=<0>;
                            数组:reg=<0 0x123456 100>;
                    (3) 字符串列表:compatible="fsl,imx6ull" ,"fsl,nandflash"; 用“,”分隔
5.标准属性:(1)compatible:设备与驱动绑定 “manufacturer,model”("厂商,驱动名字") , eg:compatible="fsl,imx6ul-evk-wm8960","fsl,imx-audio-8960" ;
                     先使用第一个兼容值在linux内核查找驱动文件,如没有使用第二个查找,of_device_id保存对应compatible值。
                   (2)model属性:描述设备模块信息,比如名字:model = "wm8960-audio";
                    (3) status属性:状态相关,“okay”、“disable”、“fail”、“fail-sss”
                    (4) #address_cells,#size_cells,用于描述地址,其中#address_cells:地址信息所占字长(32位),#size_cells:reg属性中长度信息所占字长(32位)
                        eg:reg=<address1 len1 address2 len2> ,addressx:起始地址:#address-cells , lenx:地址长度:#size-cells
                    (5) reg属性:外设的寄存器地址范围信息 eg:reg=<0x02020000 0x4000>
                    (6) ranges属性:<child-bus address parent lenth>,一般为空
                        eg: ranges;           ranges=<0x0 0xe0000000 0x00 100000>;
6.根节点compatible属性: /{compatible="fsl,imx6ull_borrow_emmc","fsl,imx6ull";
                                            };  imx6ull_borrow_emmc:使用的设备名,imx6ull:使用的SOC
                                  匹配方法:arch/arm/include/asm/mach/arch.h             #define DT_MACHINE_START
7.向节点追加/修改内容:
 eg:追加I2C1: &I2C1{/Z追加的内容};
8.特殊节点:aliases,chosen
           (1) aliases 与lable功能类似
       (2)chosen:uboot向Linux内核传递参数
9.of函数:include/linux/of.h
    (1)of_find_bode_by_name 通过节点名字查找指定的节点
    (2)of_find_node_by_type通过节点属性查找指定的节点
    (3)of_find_compatible_node 根据type,compatible查找节点
    (4) of_find_matching_node_and_match通过of_device_id查找节点
    (5)of_find_node_by_path通过路径查找节点,比如"/backlight"
二、以led开发举例
1.修改设备树:在"/"下创建“led ”子节点
2.linux内核根文件夹 make dtbs
3.使用新XXX.dtb启动linux内核
4.编写驱动文件:
    (1)获取设备节点,dtslen.nd=of_find_node_by_path("/led");
    (2)获取compatible属性:proper= of_find_property(dtsled.nd,"compatible",NULL);
    (3)获取status属性内容:ret=of_property_read_string(dtsled.nd,"status",&str);
    (4)获取属性内容:ret=of_property_read_u32_array(dtsled.nd,"reg",regdata,10);
    (5)寄存器ioremap映射
5.编写APP
三、Linux开发分步:1.设备树 2.firmware 3.bsp 4.应用
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值