linux/scripts/dtc/dtc.c
<<
>>
Prefs
   1/*
   2 * (C) Copyright David Gibson <dwg@au1.ibm.com>, IBM Corporation.  2005.
   3 *
   4 *
   5 * This program is free software; you can redistribute it and/or
   6 * modify it under the terms of the GNU General Public License as
   7 * published by the Free Software Foundation; either version 2 of the
   8 * License, or (at your option) any later version.
   9 *
  10 *  This program is distributed in the hope that it will be useful,
  11 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  12 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13 *  General Public License for more details.
  14 *
  15 *  You should have received a copy of the GNU General Public License
  16 *  along with this program; if not, write to the Free Software
  17 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
  18 *                                                                   USA
  19 */
  20
  21#include "dtc.h"
  22#include "srcpos.h"
  23
  24#include "version_gen.h"
  25
  26/*
  27 * Command line options
  28 */
  29int quiet;              /* Level of quietness */
  30int reservenum;         /* Number of memory reservation slots */
  31int minsize;            /* Minimum blob size */
  32int padsize;            /* Additional padding to blob */
  33int phandle_format = PHANDLE_BOTH;      /* Use linux,phandle or phandle properties */
  34
  35static void fill_fullpaths(struct node *tree, const char *prefix)
  36{
  37        struct node *child;
  38        const char *unit;
  39
  40        tree->fullpath = join_path(prefix, tree->name);
  41
  42        unit = strchr(tree->name, '@');
  43        if (unit)
  44                tree->basenamelen = unit - tree->name;
  45        else
  46                tree->basenamelen = strlen(tree->name);
  47
  48        for_each_child(tree, child)
  49                fill_fullpaths(child, tree->fullpath);
  50}
  51
  52static void  __attribute__ ((noreturn)) usage(void)
  53{
  54        fprintf(stderr, "Usage:\n");
  55        fprintf(stderr, "\tdtc [options] <input file>\n");
fprintf(stderr, "\nOptions:\n");
  57        fprintf(stderr, "\t-h\n");
  58        fprintf(stderr, "\t\tThis help text\n");
  59        fprintf(stderr, "\t-q\n");
  60        fprintf(stderr, "\t\tQuiet: -q suppress warnings, -qq errors, -qqq all\n");
  61        fprintf(stderr, "\t-I <input format>\n");
  62        fprintf(stderr, "\t\tInput formats are:\n");
  63        fprintf(stderr, "\t\t\tdts - device tree source text\n");
  64        fprintf(stderr, "\t\t\tdtb - device tree blob\n");
  65        fprintf(stderr, "\t\t\tfs - /proc/device-tree style directory\n");
fprintf(stderr, "\t-o <output file>\n");
  67        fprintf(stderr, "\t-O <output format>\n");
  68        fprintf(stderr, "\t\tOutput formats are:\n");
  69        fprintf(stderr, "\t\t\tdts - device tree source text\n");
  70        fprintf(stderr, "\t\t\tdtb - device tree blob\n");
  71        fprintf(stderr, "\t\t\tasm - assembler source\n");
  72        fprintf(stderr, "\t-V <output version>\n");
  73        fprintf(stderr, "\t\tBlob version to produce, defaults to %d (relevant for dtb\n\t\tand asm output only)\n", DEFAULT_FDT_VERSION);
  74        fprintf(stderr, "\t-d <output dependency file>\n");
  75        fprintf(stderr, "\t-R <number>\n");
fprintf(stderr, "\t\tMake space for <number> reserve map entries (relevant for \n\t\tdtb and asm output only)\n");
  77        fprintf(stderr, "\t-S <bytes>\n");
  78        fprintf(stderr, "\t\tMake the blob at least <bytes> long (extra space)\n");
  79        fprintf(stderr, "\t-p <bytes>\n");
  80        fprintf(stderr, "\t\tAdd padding to the blob of <bytes> long (extra space)\n");
  81        fprintf(stderr, "\t-b <number>\n");
  82        fprintf(stderr, "\t\tSet the physical boot cpu\n");
  83        fprintf(stderr, "\t-f\n");
  84        fprintf(stderr, "\t\tForce - try to produce output even if the input tree has errors\n");
  85        fprintf(stderr, "\t-s\n");
fprintf(stderr, "\t\tSort nodes and properties before outputting (only useful for\n\t\tcomparing trees)\n");
  87        fprintf(stderr, "\t-v\n");
  88        fprintf(stderr, "\t\tPrint DTC version and exit\n");
  89        fprintf(stderr, "\t-H <phandle format>\n");
  90        fprintf(stderr, "\t\tphandle formats are:\n");
  91        fprintf(stderr, "\t\t\tlegacy - \"linux,phandle\" properties only\n");
  92        fprintf(stderr, "\t\t\tepapr - \"phandle\" properties only\n");
  93        fprintf(stderr, "\t\t\tboth - Both \"linux,phandle\" and \"phandle\" properties\n");
  94        exit(3);
  95}
  97int main(int argc, char *argv[])
  98{
  99        struct boot_info *bi;
 100        const char *inform = "dts";
 101        const char *outform = "dts";
 102        const char *outname = "-";
 103        const char *depname = NULL;
 104        int force = 0, sort = 0;
 105        const char *arg;
 106        int opt;
 107        FILE *outf = NULL;
 108        int outversion = DEFAULT_FDT_VERSION;
 109        long long cmdline_boot_cpuid = -1;
 110
 111        quiet      = 0;
 112        reservenum = 0;
 113        minsize    = 0;
 114        padsize    = 0;
 115
 116        while ((opt = getopt(argc, argv, "hI:O:o:V:d:R:S:p:fcqb:vH:s"))
 117                        != EOF) {
 118                switch (opt) {
 119                case 'I':
 120                        inform = optarg;
 121                        break;
 122                case 'O':
 123                        outform = optarg;
 124                        break;
 125                case 'o':
 126                        outname = optarg;
 127                        break;
 128                case 'V':
 129                        outversion = strtol(optarg, NULL, 0);
 130                        break;
 131                case 'd':
 132                        depname = optarg;
 133                        break;
 134                case 'R':
 135                        reservenum = strtol(optarg, NULL, 0);
 136                        break;
 137                case 'S':
 138                        minsize = strtol(optarg, NULL, 0);
 139                        break;
 140                case 'p':
 141                        padsize = strtol(optarg, NULL, 0);
 142                        break;
 143                case 'f':
 144                        force = 1;
 145                        break;
 146                case 'q':
 147                        quiet++;
 148                        break;
 149                case 'b':
 150                        cmdline_boot_cpuid = strtoll(optarg, NULL, 0);
 151                        break;
 152                case 'v':
 153                        printf("Version: %s\n", DTC_VERSION);
 154                        exit(0);
 155                case 'H':
streq(optarg, "legacy"))
 157                                phandle_format = PHANDLE_LEGACY;
 158                        else if (streq(optarg, "epapr"))
 159                                phandle_format = PHANDLE_EPAPR;
 160                        else if (streq(optarg, "both"))
 161                                phandle_format = PHANDLE_BOTH;
 162                        else
 163                                die("Invalid argument \"%s\" to -H option\n",
 164                                    optarg);
 165                        break;
 167                case 's':
 168                        sort = 1;
 169                        break;
 170
 171                case 'h':
 172                default:
 173                        usage();
 174                }
 175        }
 177        if (argc > (optind+1))
 178                usage();
 179        else if (argc < (optind+1))
 180                arg        span class="string">"-";
argc > (  82        arg        span class="string">""sref">argv, &qu[ss="sref">optind+1))
  83          84          85        argc = padsize = optind1/a>(arg0e1f="+c1de=fprintf" cllass="sref">args href="+code=exit" class="sref">exit(3);
<1(s18=for_each_child" class="sref">for_1(s1derr,  =  <"+code=stderr" class="sr1ef">s18ild" class="sref">child, "\t\t\tboth - Both \"linux,phandle\" and \"phandle\" properties\n");
 164is">  recated64it will blassmoine"sopan u" nine" nagp 4"> 164instead href="+code=exit" class="sref">exit(3);
<1(s19e 'h'<(s1derr, "\t\t\tlegacy - \"linux,phandle\" properties only\n");
 16                            s19v, &qu[ss="c/dtc.c#L121" id="L121" class="4" class="line" ndtc/dtc.c#L124" id="L124" class="uot;))
optind+1))
exit(3);
<1(1name="L8"+code=stderr" class="sr1ef">s191de=fprintf" cla-" = 'I'1  4695
 = name)fop=";linux,phandle\"dtc/dtc.c#L133" id="L133" class=">);
exit(3);
<1(lass="lin>  97int  = argc1,19.c#L148" id="L148" class="line" name="L148">7" class="="L128" class=""1lass="sref">arg0e1f="+c1de=ouldprintf" op="">  75      nme="L1dtc/dtc.c#L154" id="L154" class="line" ndtc/dtc.c#L133" id="L133" class="> href=f=fa href=f1" id="L111" e  99        struct1 >))
   ))
   <;linux,phandle\"
  n0" id="L100" cla
  n0exit(3);
<1( <a> *child, "\t\t\tboth - Both \"linux,phandle\&qdtc    .c#L133" id="L133"    );
exit(3);
<2">inform<2a> = outfor2 = &q20+code=__attribute__" class="sref">2f">outnam2 = &q2ot;-""both"))
 102        const char *arg 2f">depnam2 = optind+1))
exit(3);
<2a> = 0, <2 href="+code=sort" class2"sref2>sort = 0; "both"))
 102       fonst char *arg 2f5 = 0, <2  4695
  4165
trdt_from_f a href="scripts/dtc/href">optind+1))
exit(3);
<2a6 = 0, <2   97int "both"))
 102        cbnst char *arg 2f7 = 0, <2 argc" class="sref">argc2f20.c#L148" id="L148" clize = trdt_from_ass=a href="scripts/dtc/href">optind+1))
exit(3);
<2a8 = 0, <2 >  99        struct2LT_FD2_VERSION" clas8lt:
arg 2lass="sre2">cmdline_boot_cpuid2= -1;20ild" class="sref">child, arg0e1f="+c1deUnknown 62      line" name="L164"> 16                string">&qu[ss="c/dtc.c#L121" id="L121" class="it" class="sref">exit(3);
<2e" name="2111"> 111        quiet 2    = 0;
2a href="scripts/dtc/dtc.2#L1122 id="L112" clapadsize = 'I'2enum 2 0;
&qu[ss="farg0e1f="intf\n     default4" class="line" ndtc    .c#L133" id="L133"    exit(3);
<2e">depnam2
exit(3);
<2e> = 0, <2
 116        whi2e ((<2 href="+code=opt" class="sref">opt<2a> = ( = (optarg, arg 2sref">EOF2/a>) {
 = ((optarg, exit(3);
<2e8 = 0, <2) {
exit(3);
<2eass="sre2 href="scripts/dtc/dtc.c2L120"21err, tree->           dt);
exit(3);
<2sref">inf2rm = tre" ness_check href="+code=fullpath"> 145                   4" class="line" n        const char *exit(3);
<2s   = 0;
2id="L122" class="line" n2me="L22+code=__attribute__" class="sref">2/span>:
<2 href="scripts/dtc/dtc.c2L123"22t;-"&qu169                   ="+code=arg" class="sref">arg 2"sref">ou2form = optargass="string">&qu169_/dtc/dtc.c#L50" id=u169_/dtchref="+code=fullpath        const char *exit(3);
<2s> = 0, <2id="L125" class="line" n2me="L225"> 1" class="sref">exit(3);
<2s" name="2 href="scripts/dtc/dtc.c2L126"22;lass="sref">padsize = ))
'I'2"sref">ou2name = optarg class="line" ndtc/.c#L124" id="L124" *, exit(3);
<2c.c#L128"2id="L128" class="line" n2me="L228"> 128  }" 'I'2"8 = 0, <2 href="scripts/dtc/dtc.c2L129"2id="L129" class="line" class="line" ndtc/.c#L124" id="L124" *name)fop=";linux,phandle\"dtc/dtc.c#L127" id="L127" class=">);
exit(3);
<2ss="sref"2outversion = pads!" class="line" ndtc/.c#L124" id="L124" *arg 2c.c#L131"2id="L131" class="line" n2me="L231"> 131                cae" name="L148">7" class="="L128" class=""1lass="sref">arg0e1f="+c1de=ouldprintf" op=""7      nme="L1dtc/dtc.c#L154" id="L154"+code=arg" class="sref">arg 2c   = 0;
2 href="scripts/dtc/dtc.c2L132"2id="L132" class="line"class="line" class="line" ndtc/dtc.c#L127" id="L127" class=">);" name="L148">>))
   ))
   <;linux,phandle\"
  n0" id="L100" cla
  n0exit(3);
<2"sref">de2name = :
<2 href="scripts/dtc/dtc.c2L135"23class="line" padsize = ))
 102        const char *'I'2ss="sref"2reservenum = ="scripts/dtc/]dt_to_    exit(3);
<2c.c#L137"2id="L137" class="line" n2me="L237"> 137  }, "both"))
 102        cbnst char *'I'2s.c#L128"2 href="scripts/dtc/dtc.c2L138"2id="L138" class="line"="scripts/dtc/]dt_to_ass=class="sref">trdt_to_ass=a href="scripts/dtc/dtc/.c#L124" id="L124" *optarg, exit(3);
<2c8 = 0, <2size = "both"))
 102       asmnst char *'I'2ss="sref"2id="L140" class="line" n2me="L240"> 140          ="scripts/dtc/]dt_to_asmclass="sref">trdt_to_asma href="scripts/dtc/dtc/.c#L124" id="L124" *optarg, exit(3);
<2/span>:
<2 href="scripts/dtc/dtc.c2L141"2id="L141" clas}, "both"))
 102       nullnst char *'I'2"sref">pa2size = strtolc.c#L32" id="L32" class="do noth    ="+c1de=fprintf" cllass="sref">argc 143  }" 'I'2/span>:
<2 href="scripts/dtc/dtc.c2L144"2id="L144" class="line"ld, arg0e1f="+c1deUnknown  68      line" name="L164"> 16                string">&qu[ss="dtc/dtc.c#L124" id="L124" class="it" class="sref">exit(3);
<2/span>:
<2 = 1;
opt<2/span>:
<2 href="scripts/dtc/dtc.c2L147"2id="L147" clasx,phandle\"
55                case 'H'2ref">quie2++;
 1


The original LXR softw 85LXR L32"unityss="uoth s experi" clal 89 bye.c#L177" mailto:lxr@lL94".n0">lxr@lL94".n0ss=".
lxr.lL94".n0 kindly hosted bye.c#L177" http://www.redpill-lL9pro.n0">Redpill LL9pro ASss="uoprovidernoflLL94"ss="lul clas">ar a s arg