| .. | .. |
|---|
| 1 | +/* SPDX-License-Identifier: GPL-2.0-or-later */ |
|---|
| 1 | 2 | #ifndef DTC_H |
|---|
| 2 | 3 | #define DTC_H |
|---|
| 3 | 4 | |
|---|
| 4 | 5 | /* |
|---|
| 5 | 6 | * (C) Copyright David Gibson <dwg@au1.ibm.com>, IBM Corporation. 2005. |
|---|
| 6 | | - * |
|---|
| 7 | | - * |
|---|
| 8 | | - * This program is free software; you can redistribute it and/or |
|---|
| 9 | | - * modify it under the terms of the GNU General Public License as |
|---|
| 10 | | - * published by the Free Software Foundation; either version 2 of the |
|---|
| 11 | | - * License, or (at your option) any later version. |
|---|
| 12 | | - * |
|---|
| 13 | | - * This program is distributed in the hope that it will be useful, |
|---|
| 14 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 15 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|---|
| 16 | | - * General Public License for more details. |
|---|
| 17 | | - * |
|---|
| 18 | | - * You should have received a copy of the GNU General Public License |
|---|
| 19 | | - * along with this program; if not, write to the Free Software |
|---|
| 20 | | - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
|---|
| 21 | | - * USA |
|---|
| 22 | 7 | */ |
|---|
| 23 | 8 | |
|---|
| 24 | 9 | #include <stdio.h> |
|---|
| .. | .. |
|---|
| 58 | 43 | extern int generate_symbols; /* generate symbols for nodes with labels */ |
|---|
| 59 | 44 | extern int generate_fixups; /* generate fixups */ |
|---|
| 60 | 45 | extern int auto_label_aliases; /* auto generate labels -> aliases */ |
|---|
| 46 | +extern int annotate; /* annotate .dts with input source location */ |
|---|
| 61 | 47 | |
|---|
| 62 | 48 | #define PHANDLE_LEGACY 0x1 |
|---|
| 63 | 49 | #define PHANDLE_EPAPR 0x2 |
|---|
| .. | .. |
|---|
| 65 | 51 | |
|---|
| 66 | 52 | typedef uint32_t cell_t; |
|---|
| 67 | 53 | |
|---|
| 54 | +static inline uint16_t dtb_ld16(const void *p) |
|---|
| 55 | +{ |
|---|
| 56 | + const uint8_t *bp = (const uint8_t *)p; |
|---|
| 57 | + |
|---|
| 58 | + return ((uint16_t)bp[0] << 8) |
|---|
| 59 | + | bp[1]; |
|---|
| 60 | +} |
|---|
| 61 | + |
|---|
| 62 | +static inline uint32_t dtb_ld32(const void *p) |
|---|
| 63 | +{ |
|---|
| 64 | + const uint8_t *bp = (const uint8_t *)p; |
|---|
| 65 | + |
|---|
| 66 | + return ((uint32_t)bp[0] << 24) |
|---|
| 67 | + | ((uint32_t)bp[1] << 16) |
|---|
| 68 | + | ((uint32_t)bp[2] << 8) |
|---|
| 69 | + | bp[3]; |
|---|
| 70 | +} |
|---|
| 71 | + |
|---|
| 72 | +static inline uint64_t dtb_ld64(const void *p) |
|---|
| 73 | +{ |
|---|
| 74 | + const uint8_t *bp = (const uint8_t *)p; |
|---|
| 75 | + |
|---|
| 76 | + return ((uint64_t)bp[0] << 56) |
|---|
| 77 | + | ((uint64_t)bp[1] << 48) |
|---|
| 78 | + | ((uint64_t)bp[2] << 40) |
|---|
| 79 | + | ((uint64_t)bp[3] << 32) |
|---|
| 80 | + | ((uint64_t)bp[4] << 24) |
|---|
| 81 | + | ((uint64_t)bp[5] << 16) |
|---|
| 82 | + | ((uint64_t)bp[6] << 8) |
|---|
| 83 | + | bp[7]; |
|---|
| 84 | +} |
|---|
| 68 | 85 | |
|---|
| 69 | 86 | #define streq(a, b) (strcmp((a), (b)) == 0) |
|---|
| 70 | 87 | #define strstarts(s, prefix) (strncmp((s), (prefix), strlen(prefix)) == 0) |
|---|
| .. | .. |
|---|
| 74 | 91 | |
|---|
| 75 | 92 | /* Data blobs */ |
|---|
| 76 | 93 | enum markertype { |
|---|
| 94 | + TYPE_NONE, |
|---|
| 77 | 95 | REF_PHANDLE, |
|---|
| 78 | 96 | REF_PATH, |
|---|
| 79 | 97 | LABEL, |
|---|
| 98 | + TYPE_UINT8, |
|---|
| 99 | + TYPE_UINT16, |
|---|
| 100 | + TYPE_UINT32, |
|---|
| 101 | + TYPE_UINT64, |
|---|
| 102 | + TYPE_STRING, |
|---|
| 80 | 103 | }; |
|---|
| 104 | +extern const char *markername(enum markertype markertype); |
|---|
| 81 | 105 | |
|---|
| 82 | 106 | struct marker { |
|---|
| 83 | 107 | enum markertype type; |
|---|
| .. | .. |
|---|
| 100 | 124 | #define for_each_marker_of_type(m, t) \ |
|---|
| 101 | 125 | for_each_marker(m) \ |
|---|
| 102 | 126 | if ((m)->type == (t)) |
|---|
| 127 | + |
|---|
| 128 | +size_t type_marker_length(struct marker *m); |
|---|
| 103 | 129 | |
|---|
| 104 | 130 | void data_free(struct data d); |
|---|
| 105 | 131 | |
|---|
| .. | .. |
|---|
| 149 | 175 | struct property *next; |
|---|
| 150 | 176 | |
|---|
| 151 | 177 | struct label *labels; |
|---|
| 178 | + struct srcpos *srcpos; |
|---|
| 152 | 179 | }; |
|---|
| 153 | 180 | |
|---|
| 154 | 181 | struct node { |
|---|
| .. | .. |
|---|
| 168 | 195 | |
|---|
| 169 | 196 | struct label *labels; |
|---|
| 170 | 197 | const struct bus_type *bus; |
|---|
| 198 | + struct srcpos *srcpos; |
|---|
| 171 | 199 | |
|---|
| 172 | 200 | bool omit_if_unused, is_referenced; |
|---|
| 173 | 201 | }; |
|---|
| .. | .. |
|---|
| 196 | 224 | void add_label(struct label **labels, char *label); |
|---|
| 197 | 225 | void delete_labels(struct label **labels); |
|---|
| 198 | 226 | |
|---|
| 199 | | -struct property *build_property(char *name, struct data val); |
|---|
| 227 | +struct property *build_property(char *name, struct data val, |
|---|
| 228 | + struct srcpos *srcpos); |
|---|
| 200 | 229 | struct property *build_property_delete(char *name); |
|---|
| 201 | 230 | struct property *chain_property(struct property *first, struct property *list); |
|---|
| 202 | 231 | struct property *reverse_properties(struct property *first); |
|---|
| 203 | 232 | |
|---|
| 204 | | -struct node *build_node(struct property *proplist, struct node *children); |
|---|
| 205 | | -struct node *build_node_delete(void); |
|---|
| 233 | +struct node *build_node(struct property *proplist, struct node *children, |
|---|
| 234 | + struct srcpos *srcpos); |
|---|
| 235 | +struct node *build_node_delete(struct srcpos *srcpos); |
|---|
| 206 | 236 | struct node *name_node(struct node *node, char *name); |
|---|
| 207 | 237 | struct node *omit_node_if_unused(struct node *node); |
|---|
| 208 | 238 | struct node *reference_node(struct node *node); |
|---|
| .. | .. |
|---|
| 217 | 247 | void delete_node_by_name(struct node *parent, char *name); |
|---|
| 218 | 248 | void delete_node(struct node *node); |
|---|
| 219 | 249 | void append_to_property(struct node *node, |
|---|
| 220 | | - char *name, const void *data, int len); |
|---|
| 250 | + char *name, const void *data, int len, |
|---|
| 251 | + enum markertype type); |
|---|
| 221 | 252 | |
|---|
| 222 | 253 | const char *get_unitname(struct node *node); |
|---|
| 223 | 254 | struct property *get_property(struct node *node, const char *propname); |
|---|
| .. | .. |
|---|
| 290 | 321 | void dt_to_source(FILE *f, struct dt_info *dti); |
|---|
| 291 | 322 | struct dt_info *dt_from_source(const char *f); |
|---|
| 292 | 323 | |
|---|
| 324 | +/* YAML source */ |
|---|
| 325 | + |
|---|
| 326 | +void dt_to_yaml(FILE *f, struct dt_info *dti); |
|---|
| 327 | + |
|---|
| 293 | 328 | /* FS trees */ |
|---|
| 294 | 329 | |
|---|
| 295 | 330 | struct dt_info *dt_from_fs(const char *dirname); |
|---|