Skip to content

Commit 79edff1

Browse files
committed
scripts/dtc: Update to upstream version v1.6.0-51-g183df9e9c2b9
This adds the following commits from upstream: 183df9e9c2b9 gitignore: Ignore the swp files 0db6d09584e1 gitignore: Add cscope files 307afa1a7be8 Update Jon Loeliger's email ca16a723fa9d fdtdump: Fix gcc11 warning 64990a272e8f srcpos: increase MAX_SRCFILE_DEPTH 163f0469bf2e dtc: Allow overlays to have .dtbo extension 3b01518e688d Set last_comp_version correctly in new dtb and fix potential version issues in fdt_open_into f7e5737f26aa tests: Fix overlay_overlay_nosugar test case 7cd5d5fe43d5 libfdt: Tweak description of assume-aligned load helpers a7c404099349 libfdt: Internally perform potentially unaligned loads bab85e48a6f4 meson: increase default timeout for tests f8b46098824d meson: do not assume python is installed, skip tests 30a56bce4f0b meson: fix -Wall warning 5e735860c478 libfdt: Check for 8-byte address alignment in fdt_ro_probe_() 67849a327927 build-sys: add meson build 05874d08212d pylibfdt: allow build out of tree 3bc3a6b9fe0c dtc: Fix signedness comparisons warnings: Wrap (-1) e1147b159e92 dtc: Fix signedness comparisons warnings: change types 04cf1fdc0fcf convert-dtsv0: Fix signedness comparisons warning b30013edb878 libfdt: Fix kernel-doc comments Signed-off-by: Rob Herring <robh@kernel.org>
1 parent b775f49 commit 79edff1

File tree

15 files changed

+350
-71
lines changed

15 files changed

+350
-71
lines changed

scripts/dtc/data.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ void data_free(struct data d)
2121
free(d.val);
2222
}
2323

24-
struct data data_grow_for(struct data d, int xlen)
24+
struct data data_grow_for(struct data d, unsigned int xlen)
2525
{
2626
struct data nd;
27-
int newsize;
27+
unsigned int newsize;
2828

2929
if (xlen == 0)
3030
return d;
@@ -84,7 +84,7 @@ struct data data_copy_file(FILE *f, size_t maxlen)
8484
while (!feof(f) && (d.len < maxlen)) {
8585
size_t chunksize, ret;
8686

87-
if (maxlen == -1)
87+
if (maxlen == (size_t)-1)
8888
chunksize = 4096;
8989
else
9090
chunksize = maxlen - d.len;

scripts/dtc/dtc.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ static const char *guess_type_by_name(const char *fname, const char *fallback)
122122
return "dts";
123123
if (!strcasecmp(s, ".yaml"))
124124
return "yaml";
125+
if (!strcasecmp(s, ".dtbo"))
126+
return "dtb";
125127
if (!strcasecmp(s, ".dtb"))
126128
return "dtb";
127129
return fallback;
@@ -357,6 +359,8 @@ int main(int argc, char *argv[])
357359
#endif
358360
} else if (streq(outform, "dtb")) {
359361
dt_to_blob(outf, dti, outversion);
362+
} else if (streq(outform, "dtbo")) {
363+
dt_to_blob(outf, dti, outversion);
360364
} else if (streq(outform, "asm")) {
361365
dt_to_asm(outf, dti, outversion);
362366
} else if (streq(outform, "null")) {

scripts/dtc/dtc.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,13 @@ extern const char *markername(enum markertype markertype);
105105

106106
struct marker {
107107
enum markertype type;
108-
int offset;
108+
unsigned int offset;
109109
char *ref;
110110
struct marker *next;
111111
};
112112

113113
struct data {
114-
int len;
114+
unsigned int len;
115115
char *val;
116116
struct marker *markers;
117117
};
@@ -129,7 +129,7 @@ size_t type_marker_length(struct marker *m);
129129

130130
void data_free(struct data d);
131131

132-
struct data data_grow_for(struct data d, int xlen);
132+
struct data data_grow_for(struct data d, unsigned int xlen);
133133

134134
struct data data_copy_mem(const char *mem, int len);
135135
struct data data_copy_escape_string(const char *s, int len);
@@ -253,7 +253,7 @@ void append_to_property(struct node *node,
253253
const char *get_unitname(struct node *node);
254254
struct property *get_property(struct node *node, const char *propname);
255255
cell_t propval_cell(struct property *prop);
256-
cell_t propval_cell_n(struct property *prop, int n);
256+
cell_t propval_cell_n(struct property *prop, unsigned int n);
257257
struct property *get_property_by_label(struct node *tree, const char *label,
258258
struct node **node);
259259
struct marker *get_marker_label(struct node *tree, const char *label,

scripts/dtc/fdtoverlay.c

Lines changed: 208 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,208 @@
1+
// SPDX-License-Identifier: GPL-2.0-or-later
2+
/*
3+
* Copyright (c) 2017 Konsulko Group Inc. All rights reserved.
4+
*
5+
* Author:
6+
* Pantelis Antoniou <pantelis.antoniou@konsulko.com>
7+
*/
8+
9+
#include <assert.h>
10+
#include <ctype.h>
11+
#include <getopt.h>
12+
#include <stdio.h>
13+
#include <stdlib.h>
14+
#include <string.h>
15+
#include <inttypes.h>
16+
17+
#include <libfdt.h>
18+
19+
#include "util.h"
20+
21+
#define BUF_INCREMENT 65536
22+
23+
/* Usage related data. */
24+
static const char usage_synopsis[] =
25+
"apply a number of overlays to a base blob\n"
26+
" fdtoverlay <options> [<overlay.dtbo> [<overlay.dtbo>]]\n"
27+
"\n"
28+
USAGE_TYPE_MSG;
29+
static const char usage_short_opts[] = "i:o:v" USAGE_COMMON_SHORT_OPTS;
30+
static struct option const usage_long_opts[] = {
31+
{"input", required_argument, NULL, 'i'},
32+
{"output", required_argument, NULL, 'o'},
33+
{"verbose", no_argument, NULL, 'v'},
34+
USAGE_COMMON_LONG_OPTS,
35+
};
36+
static const char * const usage_opts_help[] = {
37+
"Input base DT blob",
38+
"Output DT blob",
39+
"Verbose messages",
40+
USAGE_COMMON_OPTS_HELP
41+
};
42+
43+
int verbose = 0;
44+
45+
static void *apply_one(char *base, const char *overlay, size_t *buf_len,
46+
const char *name)
47+
{
48+
char *tmp = NULL;
49+
char *tmpo;
50+
int ret;
51+
52+
/*
53+
* We take a copies first, because a a failed apply can trash
54+
* both the base blob and the overlay
55+
*/
56+
tmpo = xmalloc(fdt_totalsize(overlay));
57+
58+
do {
59+
tmp = xrealloc(tmp, *buf_len);
60+
ret = fdt_open_into(base, tmp, *buf_len);
61+
if (ret) {
62+
fprintf(stderr,
63+
"\nFailed to make temporary copy: %s\n",
64+
fdt_strerror(ret));
65+
goto fail;
66+
}
67+
68+
memcpy(tmpo, overlay, fdt_totalsize(overlay));
69+
70+
ret = fdt_overlay_apply(tmp, tmpo);
71+
if (ret == -FDT_ERR_NOSPACE) {
72+
*buf_len += BUF_INCREMENT;
73+
}
74+
} while (ret == -FDT_ERR_NOSPACE);
75+
76+
if (ret) {
77+
fprintf(stderr, "\nFailed to apply '%s': %s\n",
78+
name, fdt_strerror(ret));
79+
goto fail;
80+
}
81+
82+
free(base);
83+
free(tmpo);
84+
return tmp;
85+
86+
fail:
87+
free(tmpo);
88+
if (tmp)
89+
free(tmp);
90+
91+
return NULL;
92+
}
93+
static int do_fdtoverlay(const char *input_filename,
94+
const char *output_filename,
95+
int argc, char *argv[])
96+
{
97+
char *blob = NULL;
98+
char **ovblob = NULL;
99+
size_t buf_len;
100+
int i, ret = -1;
101+
102+
blob = utilfdt_read(input_filename, &buf_len);
103+
if (!blob) {
104+
fprintf(stderr, "\nFailed to read '%s'\n", input_filename);
105+
goto out_err;
106+
}
107+
if (fdt_totalsize(blob) > buf_len) {
108+
fprintf(stderr,
109+
"\nBase blob is incomplete (%lu / %" PRIu32 " bytes read)\n",
110+
(unsigned long)buf_len, fdt_totalsize(blob));
111+
goto out_err;
112+
}
113+
114+
/* allocate blob pointer array */
115+
ovblob = xmalloc(sizeof(*ovblob) * argc);
116+
memset(ovblob, 0, sizeof(*ovblob) * argc);
117+
118+
/* read and keep track of the overlay blobs */
119+
for (i = 0; i < argc; i++) {
120+
size_t ov_len;
121+
ovblob[i] = utilfdt_read(argv[i], &ov_len);
122+
if (!ovblob[i]) {
123+
fprintf(stderr, "\nFailed to read '%s'\n", argv[i]);
124+
goto out_err;
125+
}
126+
if (fdt_totalsize(ovblob[i]) > ov_len) {
127+
fprintf(stderr,
128+
"\nOverlay '%s' is incomplete (%lu / %" PRIu32 " bytes read)\n",
129+
argv[i], (unsigned long)ov_len,
130+
fdt_totalsize(ovblob[i]));
131+
goto out_err;
132+
}
133+
}
134+
135+
buf_len = fdt_totalsize(blob);
136+
137+
/* apply the overlays in sequence */
138+
for (i = 0; i < argc; i++) {
139+
blob = apply_one(blob, ovblob[i], &buf_len, argv[i]);
140+
if (!blob)
141+
goto out_err;
142+
}
143+
144+
fdt_pack(blob);
145+
ret = utilfdt_write(output_filename, blob);
146+
if (ret)
147+
fprintf(stderr, "\nFailed to write '%s'\n",
148+
output_filename);
149+
150+
out_err:
151+
if (ovblob) {
152+
for (i = 0; i < argc; i++) {
153+
if (ovblob[i])
154+
free(ovblob[i]);
155+
}
156+
free(ovblob);
157+
}
158+
free(blob);
159+
160+
return ret;
161+
}
162+
163+
int main(int argc, char *argv[])
164+
{
165+
int opt, i;
166+
char *input_filename = NULL;
167+
char *output_filename = NULL;
168+
169+
while ((opt = util_getopt_long()) != EOF) {
170+
switch (opt) {
171+
case_USAGE_COMMON_FLAGS
172+
173+
case 'i':
174+
input_filename = optarg;
175+
break;
176+
case 'o':
177+
output_filename = optarg;
178+
break;
179+
case 'v':
180+
verbose = 1;
181+
break;
182+
}
183+
}
184+
185+
if (!input_filename)
186+
usage("missing input file");
187+
188+
if (!output_filename)
189+
usage("missing output file");
190+
191+
argv += optind;
192+
argc -= optind;
193+
194+
if (argc <= 0)
195+
usage("missing overlay file(s)");
196+
197+
if (verbose) {
198+
printf("input = %s\n", input_filename);
199+
printf("output = %s\n", output_filename);
200+
for (i = 0; i < argc; i++)
201+
printf("overlay[%d] = %s\n", i, argv[i]);
202+
}
203+
204+
if (do_fdtoverlay(input_filename, output_filename, argc, argv))
205+
return 1;
206+
207+
return 0;
208+
}

scripts/dtc/flattree.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ static void asm_emit_align(void *e, int a)
149149
static void asm_emit_data(void *e, struct data d)
150150
{
151151
FILE *f = e;
152-
int off = 0;
152+
unsigned int off = 0;
153153
struct marker *m = d.markers;
154154

155155
for_each_marker_of_type(m, LABEL)
@@ -219,7 +219,7 @@ static struct emitter asm_emitter = {
219219

220220
static int stringtable_insert(struct data *d, const char *str)
221221
{
222-
int i;
222+
unsigned int i;
223223

224224
/* FIXME: do this more efficiently? */
225225

@@ -345,7 +345,7 @@ static void make_fdt_header(struct fdt_header *fdt,
345345
void dt_to_blob(FILE *f, struct dt_info *dti, int version)
346346
{
347347
struct version_info *vi = NULL;
348-
int i;
348+
unsigned int i;
349349
struct data blob = empty_data;
350350
struct data reservebuf = empty_data;
351351
struct data dtbuf = empty_data;
@@ -446,7 +446,7 @@ static void dump_stringtable_asm(FILE *f, struct data strbuf)
446446
void dt_to_asm(FILE *f, struct dt_info *dti, int version)
447447
{
448448
struct version_info *vi = NULL;
449-
int i;
449+
unsigned int i;
450450
struct data strbuf = empty_data;
451451
struct reserve_info *re;
452452
const char *symprefix = "dt";

scripts/dtc/libfdt/fdt.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ int32_t fdt_ro_probe_(const void *fdt)
2222
if (can_assume(VALID_DTB))
2323
return totalsize;
2424

25+
/* The device tree must be at an 8-byte aligned address */
26+
if ((uintptr_t)fdt & 7)
27+
return -FDT_ERR_ALIGNMENT;
28+
2529
if (fdt_magic(fdt) == FDT_MAGIC) {
2630
/* Complete tree */
2731
if (!can_assume(LATEST)) {

0 commit comments

Comments
 (0)