zoukankan      html  css  js  c++  java
  • 编译设备树

    通常将设备树源码(dts/dtsi)编译成设备树二进制文件(dtb)可以使用DTC(Device Tree Compiler)工具编译。

    • 单文件编译

    对于单文件的dts,可以采用下面的命令:

    # dtc命令使用方法见文末
    dtc -O dtb -b 0 -o [dest_dtb_file] [src_dts_file]

    src_dts_file编译成dest_dtb_file设备树二进制文件。

    • 多文件编译

    对于有#include包含关系、宏定义的dts文件,直接采用以上的方法将会出现<u>#include相关的语法错误</u>。
    DTC本身不支持#include语法,其正确语法为/include/。

    如将以下dts(没有宏定义)

    #include "child_file.dtsi"
    #include "child_file_common.dtsi"

    改为

    /include/ "child_file.dtsi"
    /include/ "child_file_common.dtsi"

    即可通过编译。

    对于以下稍微复杂一点(包含#include,宏,*.h等)的设备树,以上的方法不免有些笨拙。

    复杂设备树

    由于“#include”“宏”等都是C的特征,因此可以使用CPP(C Preprocessor)命令对dts源文件进行处理,完成文件包含与宏置换的工作。

    # cpp的使用方法较长就不列出来了,可以自己man一下。
    cpp -nostdinc -I. -undef -x assembler-with-cpp [src_dts_file] > [tmp_dts_file]
    # -nostdinc 不搜索标准目录
    # -I. 搜索当前目录
    # -undef 不预定义系统和gcc特定的宏
    # -x assembler-with-cpp 指定语言c c++ objective-c assembler-with-cpp

    使用以上命令将所有的*.dts、*.dtsi、*.h转换至临时*.dts中,然后再使用单文件编译的方法编译临时*.dts,生成最终的dtb。

    将上面的操作写成脚本(dts2dtb.sh)如下:

    #/bin/bash
    #set -vx
    device="your_device_name"
    src_dts=$device.dts
    tmp_dts=$device.tmp.dts
    dst_dtb=$device.dtb
    
    cpp -nostdinc -I. -undef -x assembler-with-cpp $src_dts > $tmp_dts
    dtc -O dtb -b 0 -o $dst_dtb $tmp_dts
    rm $tmp_dts

    使用:

    修改your_device_name为你要编译的设备树名称,拷贝所有相关的设备树源文件至脚本所在目录,运行。

    cpp -nostdinc -I. -undef -x assembler-with-cpp  fpga.dts >  fpga_tmp.dts

     

    dtc使用方法:

    NAME
           dtc - Device Tree Compiler
    
    SYNOPSIS
           /usr/bin/dtc [options] <input file>
    
    DESCRIPTION
           Device  Tree  Compiler,  dtc,  takes  as input a device-tree in a given format and outputs a
           device-tree in another format for booting kernels on embedded systems.  Typically, the input
           format  is  "dts",  a human readable source format, and creates a "dtb", or binary format as
           output.
    
    OPTIONS
           -h     Display help text.
    
           -q     Quiet:
  • 相关阅读:
    【软件构造】第二章第一节 软件生命周期和版本控制(配置管理)
    【软件构造】第三章第三节 抽象数据型(ADT)
    【软件构造】第三章第二节 设计规约
    用python实现两个文本合并
    用python实现哈希表
    想要搭建项目 首选从概念理解(一)
    javascript调用rest地址,获取页面值
    ArcGIS Runtime SDK for Mac OS X使用示例
    ArcGIS Server网络分析模块问题汇总
    (ArcGIS Flex API)根据地图数据构建动态树
  • 原文地址:https://www.cnblogs.com/dream397/p/15572985.html
Copyright © 2011-2022 走看看