Skip to content

Commit 136ec20

Browse files
Stephen Warrenmichal42
authored andcommitted
dtc: Implement -d option to write out a dependency file
This will allow callers to rebuild .dtb files when any of the /include/d .dtsi files are modified, not just the top-level .dts file. Signed-off-by: Stephen Warren <swarren@nvidia.com> Signed-off-by: Michal Marek <mmarek@suse.cz>
1 parent 5bb0571 commit 136ec20

3 files changed

Lines changed: 25 additions & 1 deletion

File tree

‎scripts/dtc/dtc.c‎

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ static void __attribute__ ((noreturn)) usage(void)
7171
fprintf(stderr, "\t\t\tasm - assembler source\n");
7272
fprintf(stderr, "\t-V <output version>\n");
7373
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");
7475
fprintf(stderr, "\t-R <number>\n");
7576
fprintf(stderr, "\t\tMake space for <number> reserve map entries (relevant for \n\t\tdtb and asm output only)\n");
7677
fprintf(stderr, "\t-S <bytes>\n");
@@ -99,6 +100,7 @@ int main(int argc, char *argv[])
99100
const char *inform = "dts";
100101
const char *outform = "dts";
101102
const char *outname = "-";
103+
const char *depname = NULL;
102104
int force = 0, check = 0, sort = 0;
103105
const char *arg;
104106
int opt;
@@ -111,7 +113,8 @@ int main(int argc, char *argv[])
111113
minsize = 0;
112114
padsize = 0;
113115

114-
while ((opt = getopt(argc, argv, "hI:O:o:V:R:S:p:fcqb:vH:s")) != EOF) {
116+
while ((opt = getopt(argc, argv, "hI:O:o:V:d:R:S:p:fcqb:vH:s"))
117+
!= EOF) {
115118
switch (opt) {
116119
case 'I':
117120
inform = optarg;
@@ -125,6 +128,9 @@ int main(int argc, char *argv[])
125128
case 'V':
126129
outversion = strtol(optarg, NULL, 0);
127130
break;
131+
case 'd':
132+
depname = optarg;
133+
break;
128134
case 'R':
129135
reservenum = strtol(optarg, NULL, 0);
130136
break;
@@ -188,6 +194,14 @@ int main(int argc, char *argv[])
188194
fprintf(stderr, "DTC: %s->%s on file \"%s\"\n",
189195
inform, outform, arg);
190196

197+
if (depname) {
198+
depfile = fopen(depname, "w");
199+
if (!depfile)
200+
die("Couldn't open dependency file %s: %s\n", depname,
201+
strerror(errno));
202+
fprintf(depfile, "%s:", outname);
203+
}
204+
191205
if (streq(inform, "dts"))
192206
bi = dt_from_source(arg);
193207
else if (streq(inform, "fs"))
@@ -197,6 +211,11 @@ int main(int argc, char *argv[])
197211
else
198212
die("Unknown input format \"%s\"\n", inform);
199213

214+
if (depfile) {
215+
fputc('\n', depfile);
216+
fclose(depfile);
217+
}
218+
200219
if (cmdline_boot_cpuid != -1)
201220
bi->boot_cpuid_phys = cmdline_boot_cpuid;
202221

‎scripts/dtc/srcpos.c‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ static char *dirname(const char *path)
4040
return NULL;
4141
}
4242

43+
FILE *depfile; /* = NULL */
4344
struct srcfile_state *current_srcfile; /* = NULL */
4445

4546
/* Detect infinite include recursion. */
@@ -67,6 +68,9 @@ FILE *srcfile_relative_open(const char *fname, char **fullnamep)
6768
strerror(errno));
6869
}
6970

71+
if (depfile)
72+
fprintf(depfile, " %s", fullname);
73+
7074
if (fullnamep)
7175
*fullnamep = fullname;
7276
else

‎scripts/dtc/srcpos.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ struct srcfile_state {
3030
struct srcfile_state *prev;
3131
};
3232

33+
extern FILE *depfile; /* = NULL */
3334
extern struct srcfile_state *current_srcfile; /* = NULL */
3435

3536
FILE *srcfile_relative_open(const char *fname, char **fullnamep);

0 commit comments

Comments
 (0)