[ZedBoard移植嵌入式Linux教程(4)]创建设备树(Device-Tree)文件dts

2019-07-12 16:37发布

设备树用于硬件和软件之间的信息交互,也就是将ZedBoard的硬件信息传递给linux内核,避免在linux内核中硬编码而影响在其他平台上的可移植性。设备树一般以两种文件格式存在,一个是dts文件,也就是文本文件,便于阅读,另外一种是dtb文件,是二进制格式,是dts使用dtc编译器编译而来,由uboot展开并传递给linux内核。设备树的文件格式可以参考http://www.devicetree.org/Device_Tree_Usage 和http://xillybus.com/tutorials/device-tree-zynq-1如果你已经下载了最开始提到的linux-digilent内核源码,你可以在arch/arm/boot/dts/目录中找到digilent-zed.dts文件。这个dts文件包含比较丰富的硬件结构,但是不适合我们前面配置的最小系统。所以,我们需要自己来创建一个适合我们自己平台的dts文件。但这并不意味着我们需要使用文本编辑器从头按照繁琐的格式来编写。参考Xilinx Wiki上的一篇教程http://www.wiki.xilinx.com/Build+Device+Tree+Blob,我们可以轻松创建需要的设备树。首先下载device tree generator,安装到SDK下载方式一:使用git# For SDK 2014.1 (or earlier) use this repo:git clone git://github.com/Xilinx/device-tree.git bsp/device-tree_v0_00_x# Otherwise for SDK 2014.2 use this repo:git clone git://github.com/Xilinx/device-tree-xlnx.git下载方式二:直接下载压缩文件:https://github.com/Xilinx/device-treehttps://github.com/Xilinx/device-tree-xlnx/releases 下载的文件必须包含以下两个文件device_tree.mlddevice_tree.tcl然后重命名(注意此处版本号一定不能是其他的)device-tree_v2_1_0.mlddevice-tree_v2_1_0.tcl新建一个repo的目录,我将它放在SDK工程目录下(其他路径亦可,注意路径不能有空格)我的是 C:UsersdcvivadoTest_Digilent_LinuxTest_Digilent_Linux.sdkSDKSDK_Exportdevice_tree_repo这个路径就是我们后面需要的再在其中创建多层子目录bspdevice-tree_v0_00_xdata将刚才的两个文件放进去,如下"C:UsersdcvivadoTest_Digilent_LinuxTest_Digilent_Linux.sdkSDKSDK_Exportdevice_tree_repospdevice-tree_v0_00_xdatadevice-tree_v2_1_0.mld""C:UsersdcvivadoTest_Digilent_LinuxTest_Digilent_Linux.sdkSDKSDK_Exportdevice_tree_repospdevice-tree_v0_00_xdatadevice-tree_v2_1_0.tcl"在SDK中操作点击菜单: Xilinx Tools > Repositories  在Local Repositories中添加我们刚才的路径并点击OK 点击菜单File > New > Board Support Package 如果前面没有配置正确,出现的对话框的Board Support Package OS部分就只有standalone而没有device-tree选项,这时候需要重头检查自己的配置,最好检查前面文件的路径是否有空格,还有推荐用管理员权限打开SDK,当然最重要的是检查文件是否完全按照规则放置和命名(此处有惨痛教训)。 如果配置正确,则出现如下的窗口 如果至此没有问题,继续配置启动参数(定义串行终端和系统镜像位置等)和标准输出 其中bootargs必须是console=ttyPS0,115200 root=/dev/ram rw initrd=0x800000,8M earlyprintk rootfstype=ext4 rootwait devtmpfs.mount=0Console_device选择ps7_uart_1可以看出,我们使用串口ttyPS0(不是ttyS0)作为终端并配置波特率为115200,操作系统镜像在ram中,并从0x80000启动,ramdisk大小为8M(因为我们后面制作的根文件系统是8M大小)等。注意里面的“initrd=0x800000,8M”不能漏掉,否则启动linux时会出现如下错误并卡死 启动参数配置也可以参考前面提到的digilent-zed.dts中的bootargs一行。 我们在此配置的启动参数会覆盖掉linux内核中默认配置的digilent_zed_defconfig中的CONFIG_COMDLINE。 完成之后项目会在SDK中自动编译。编译过程中如果出现下面的错误ERROR:EDK -   C:UsersdcvivadoLinuxHwLinuxHw.sdkSDKSDK_Exportdevice-tree_bsp_0syste   m.mss line 5 - Cannot find MLD file device-tree_v2_1_0.mld for the os   device-tree 0.00.xINFO:EDK - Directories Searched :  -C:UsersdcvivadoLinuxHwLinuxHw.sdkSDKSDK_Exportdevice-tree_bsp_0sp/device-tree_v0_00_x/data  -C:UsersdcvivadoLinuxHwLinuxHw.sdkSDKSDK_Exportdevice_treesp/device-tree_v0_00_x/data  - C:XilinxSDK2013.4swlibsp/device-tree_v0_00_x/data  - C:XilinxSDK2013.4swXilinxProcessorIPLibsp/device-tree_v0_00_x/data  - C:XilinxSDK2013.4swThirdPartysp/device-tree_v0_00_x/dataINFO:EDK - Check the following for possible causes of not finding MLD:  - If OS_VER is specified in MSS, it must follow literal form X.YY.Z  - There is no OS with given name  - OS exists but not that version  - OS and version (directory) exist but no MLD is available ERROR:EDK - Errors occured while creating Software System.make: *** [ps7_cortexa9_0/lib/libxil.a] 错误 2make: 由于错误目标“all”并未重新创建。  我在网上找了很久的答案,下面这个不符合我的情况   这个才是靠谱的解决方法:http://forums.xilinx.com/t5/Embedded-Development-Tools/Error-build-device-tree-board-support-package/td-p/476366  意思是说,我们刚才下载的device-tree generator是新版本才会出现以上错误,要下载旧版本进行替换,下载地址http://forums.xilinx.com/xlnx/attachments/xlnx/EDK/32408/1/device_tree_old.zip 将前面的两个文件device-tree_v2_1_0.mld和device-tree_v2_1_0.tcl换成旧版本之后,clean一下project,再次自动编译,编译成功,会生成xilinx.dts,文件在device-tree_bsp_0ps7_cortexa9_0libsrcdevice-tree_v0_00_x下。  最后,后面会提到一个启动错误,是由于devicetree文件中默认生成的compatible不一致产生的,将下图中的zynq-7000改成zynq-zed 为了不每次都修改生成的dts文件,我们可以对device_tree_repospdevice-tree_v0_00_xdata中的device-tree_v2_1_0.tcl文件进行修改,因为该文件是生成dts文件的tcl脚本,由SDK调用,搜索“7000”(只有一处)改成“zed”即可,下次我们就不用修改dts文件了。 至此,我们的设备树xilinx.dts文件也生成好了。