mirror of
https://github.com/AuxXxilium/linux_dsm_epyc7002.git
synced 2024-12-26 02:55:11 +07:00
6f05afcbb0
Sync to upstream dtc commit 0931cea3ba20 ("dtc: fdtdump: check fdt if not in scanning mode"). In particular, this pulls in dtc overlay support. This adds the following commits from upstream: f88865469b65 dtc: Fix memory leak in character literal parsing 00fbb8696b66 Rename boot_info 1ef86ad2c24f dtc: Clean up /dts-v1/ and /plugin/ handling in grammar e3c769aa9c16 dtc: Don't always generate __symbols__ for plugins c96cb3c0169e tests: Don't use -@ on plugin de/recompile tests 66381538ce24 tests: Remove "suppression of fixups" tests ba765b273f0f tests: Clarify dtc overlay tests 6ea8cd944fcd tests: More thorough tests of libfdt overlay application without dtc 7d8ef6e1db97 tests: Correct fdt handling of overlays without fixups and base trees without symbols b4dc0ed8b127 tests: Fix double expansion bugs in test code 3ea879dc0c8f tests: Split overlay tests into those with do/don't exercise dtc plugin generation 47b4d66a2f11 tests: Test auto-alias generation on base tree, not overlay 72e1ad811523 tests: Make overlay/plugin tests unconditional e7b3c3b5951b tests: Add overlay tests 9637e3f772a9 tests: Add check_path test 20f29d8d41f6 dtc: Plugin and fixup support a2c92cac53f8 dtc: Document the dynamic plugin internals 8f70ac39801d checks: Pass boot_info instead of root node ea10f953878f libfdt: add missing errors to fdt_strerror() daa75e8fa594 libfdt: fix fdt_stringlist_search() e28eff5b787a libfdt: fix fdt_stringlist_count() ae97c7722840 tests: overlay: Rename the device tree blobs to be more explicit 96162d2bd9cb tests: overlay: Add test suffix to the compiled blobs 5ce8634733b7 libfdt: Add fdt_overlay_apply to the exported symbols 804a9db90ad2 fdt: strerr: Remove spurious BADOVERLAY e8c3a1a493fa tests: overlay: Move back the bad fixup tests 7a72d89d3f81 libfdt: overlay: Fix symbols and fixups nodes condition cabbaa972cdd libfdt: overlay: Report a bad overlay for mismatching local fixups deb0a5c1aeaa libfdt: Add BADPHANDLE error string 7b7a6be9ba15 libfdt: Don't use 'index' as a local variable name aea8860d831e tests: Add tests cases for the overlay code 0cdd06c5135b libfdt: Add overlay application function 39240cc865cf libfdt: Extend the reach of FDT_ERR_BADPHANDLE 4aa3a6f5e6d9 libfdt: Add new errors for the overlay code 6d1832c9e64b dtc: Remove "home page" link 45fd440a9561 Fix some typing errors in libfdt.h and livetree.c a59be4939c13 Merge tag 'v1.4.2' a34bb721caca dtc: Fix assorted problems in the testcases for the -a option 874f40588d3e Implement the -a option to pad dtb aligned ec02b34c05be dtc: Makefile improvements for release uploading 1ed45d40a137 dtc: Bump version to 1.4.2 36fd7331fb11 libfdt: simplify fdt_del_mem_rsv() d877364e4a0f libfdt: Add fdt_setprop_inplace_namelen_partial 3e9037aaad44 libfdt: Add fdt_getprop_namelen_w 84e0e1346c68 libfdt: Add max phandle retrieval function d29126c90acb libfdt: Add iterator over properties 902d0f0953d0 libfdt: Add a subnodes iterator macro c539075ba8ba fdtput.c: Fix memory leak. f79ddb83e185 fdtget.c: Fix memory leak 1074ee54b63f convert-dtsv0-lexer.l: fix memory leak e24d39a024e6 fdtdump.c: make sure size_t argument to memchr is always unsigned. 44a59713cf05 Remove unused srcpos_dump() function cb9241ae3453 DTC: Fix memory leak on flatname. 1ee0ae24ea09 Simplify check field and macro names 9d97527a8621 Remove property check functions 2e709d158e11 Remove tree check functions c4cb12e193e3 Alter grammar to allow multiple /dts-v1/ tags d71d25d76012 Use xasprintf() in srcpos 9dc404958e9c util: Add xasprintf portable asprintf variant beef80b8b55f Correct a missing space in a fdt_header cast 68d43cec1253 Correct line lengths in libfdt.h b0dbceafd49a Correct space-after-tab in libfdt.h Signed-off-by: Rob Herring <robh@kernel.org>
285 lines
8.0 KiB
C
285 lines
8.0 KiB
C
#ifndef _DTC_H
|
|
#define _DTC_H
|
|
|
|
/*
|
|
* (C) Copyright David Gibson <dwg@au1.ibm.com>, IBM Corporation. 2005.
|
|
*
|
|
*
|
|
* This program is free software; you can redistribute it and/or
|
|
* modify it under the terms of the GNU General Public License as
|
|
* published by the Free Software Foundation; either version 2 of the
|
|
* License, or (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
* General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program; if not, write to the Free Software
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
|
* USA
|
|
*/
|
|
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
#include <stdlib.h>
|
|
#include <stdint.h>
|
|
#include <stdbool.h>
|
|
#include <stdarg.h>
|
|
#include <assert.h>
|
|
#include <ctype.h>
|
|
#include <errno.h>
|
|
#include <unistd.h>
|
|
|
|
#include <libfdt_env.h>
|
|
#include <fdt.h>
|
|
|
|
#include "util.h"
|
|
|
|
#ifdef DEBUG
|
|
#define debug(...) printf(__VA_ARGS__)
|
|
#else
|
|
#define debug(...)
|
|
#endif
|
|
|
|
|
|
#define DEFAULT_FDT_VERSION 17
|
|
|
|
/*
|
|
* Command line options
|
|
*/
|
|
extern int quiet; /* Level of quietness */
|
|
extern int reservenum; /* Number of memory reservation slots */
|
|
extern int minsize; /* Minimum blob size */
|
|
extern int padsize; /* Additional padding to blob */
|
|
extern int alignsize; /* Additional padding to blob accroding to the alignsize */
|
|
extern int phandle_format; /* Use linux,phandle or phandle properties */
|
|
extern int generate_symbols; /* generate symbols for nodes with labels */
|
|
extern int generate_fixups; /* generate fixups */
|
|
extern int auto_label_aliases; /* auto generate labels -> aliases */
|
|
|
|
#define PHANDLE_LEGACY 0x1
|
|
#define PHANDLE_EPAPR 0x2
|
|
#define PHANDLE_BOTH 0x3
|
|
|
|
typedef uint32_t cell_t;
|
|
|
|
|
|
#define streq(a, b) (strcmp((a), (b)) == 0)
|
|
#define strneq(a, b, n) (strncmp((a), (b), (n)) == 0)
|
|
|
|
#define ALIGN(x, a) (((x) + (a) - 1) & ~((a) - 1))
|
|
|
|
/* Data blobs */
|
|
enum markertype {
|
|
REF_PHANDLE,
|
|
REF_PATH,
|
|
LABEL,
|
|
};
|
|
|
|
struct marker {
|
|
enum markertype type;
|
|
int offset;
|
|
char *ref;
|
|
struct marker *next;
|
|
};
|
|
|
|
struct data {
|
|
int len;
|
|
char *val;
|
|
struct marker *markers;
|
|
};
|
|
|
|
|
|
#define empty_data ((struct data){ 0 /* all .members = 0 or NULL */ })
|
|
|
|
#define for_each_marker(m) \
|
|
for (; (m); (m) = (m)->next)
|
|
#define for_each_marker_of_type(m, t) \
|
|
for_each_marker(m) \
|
|
if ((m)->type == (t))
|
|
|
|
void data_free(struct data d);
|
|
|
|
struct data data_grow_for(struct data d, int xlen);
|
|
|
|
struct data data_copy_mem(const char *mem, int len);
|
|
struct data data_copy_escape_string(const char *s, int len);
|
|
struct data data_copy_file(FILE *f, size_t len);
|
|
|
|
struct data data_append_data(struct data d, const void *p, int len);
|
|
struct data data_insert_at_marker(struct data d, struct marker *m,
|
|
const void *p, int len);
|
|
struct data data_merge(struct data d1, struct data d2);
|
|
struct data data_append_cell(struct data d, cell_t word);
|
|
struct data data_append_integer(struct data d, uint64_t word, int bits);
|
|
struct data data_append_re(struct data d, const struct fdt_reserve_entry *re);
|
|
struct data data_append_addr(struct data d, uint64_t addr);
|
|
struct data data_append_byte(struct data d, uint8_t byte);
|
|
struct data data_append_zeroes(struct data d, int len);
|
|
struct data data_append_align(struct data d, int align);
|
|
|
|
struct data data_add_marker(struct data d, enum markertype type, char *ref);
|
|
|
|
bool data_is_one_string(struct data d);
|
|
|
|
/* DT constraints */
|
|
|
|
#define MAX_PROPNAME_LEN 31
|
|
#define MAX_NODENAME_LEN 31
|
|
|
|
/* Live trees */
|
|
struct label {
|
|
bool deleted;
|
|
char *label;
|
|
struct label *next;
|
|
};
|
|
|
|
struct property {
|
|
bool deleted;
|
|
char *name;
|
|
struct data val;
|
|
|
|
struct property *next;
|
|
|
|
struct label *labels;
|
|
};
|
|
|
|
struct node {
|
|
bool deleted;
|
|
char *name;
|
|
struct property *proplist;
|
|
struct node *children;
|
|
|
|
struct node *parent;
|
|
struct node *next_sibling;
|
|
|
|
char *fullpath;
|
|
int basenamelen;
|
|
|
|
cell_t phandle;
|
|
int addr_cells, size_cells;
|
|
|
|
struct label *labels;
|
|
};
|
|
|
|
#define for_each_label_withdel(l0, l) \
|
|
for ((l) = (l0); (l); (l) = (l)->next)
|
|
|
|
#define for_each_label(l0, l) \
|
|
for_each_label_withdel(l0, l) \
|
|
if (!(l)->deleted)
|
|
|
|
#define for_each_property_withdel(n, p) \
|
|
for ((p) = (n)->proplist; (p); (p) = (p)->next)
|
|
|
|
#define for_each_property(n, p) \
|
|
for_each_property_withdel(n, p) \
|
|
if (!(p)->deleted)
|
|
|
|
#define for_each_child_withdel(n, c) \
|
|
for ((c) = (n)->children; (c); (c) = (c)->next_sibling)
|
|
|
|
#define for_each_child(n, c) \
|
|
for_each_child_withdel(n, c) \
|
|
if (!(c)->deleted)
|
|
|
|
void add_label(struct label **labels, char *label);
|
|
void delete_labels(struct label **labels);
|
|
|
|
struct property *build_property(char *name, struct data val);
|
|
struct property *build_property_delete(char *name);
|
|
struct property *chain_property(struct property *first, struct property *list);
|
|
struct property *reverse_properties(struct property *first);
|
|
|
|
struct node *build_node(struct property *proplist, struct node *children);
|
|
struct node *build_node_delete(void);
|
|
struct node *name_node(struct node *node, char *name);
|
|
struct node *chain_node(struct node *first, struct node *list);
|
|
struct node *merge_nodes(struct node *old_node, struct node *new_node);
|
|
|
|
void add_property(struct node *node, struct property *prop);
|
|
void delete_property_by_name(struct node *node, char *name);
|
|
void delete_property(struct property *prop);
|
|
void add_child(struct node *parent, struct node *child);
|
|
void delete_node_by_name(struct node *parent, char *name);
|
|
void delete_node(struct node *node);
|
|
void append_to_property(struct node *node,
|
|
char *name, const void *data, int len);
|
|
|
|
const char *get_unitname(struct node *node);
|
|
struct property *get_property(struct node *node, const char *propname);
|
|
cell_t propval_cell(struct property *prop);
|
|
struct property *get_property_by_label(struct node *tree, const char *label,
|
|
struct node **node);
|
|
struct marker *get_marker_label(struct node *tree, const char *label,
|
|
struct node **node, struct property **prop);
|
|
struct node *get_subnode(struct node *node, const char *nodename);
|
|
struct node *get_node_by_path(struct node *tree, const char *path);
|
|
struct node *get_node_by_label(struct node *tree, const char *label);
|
|
struct node *get_node_by_phandle(struct node *tree, cell_t phandle);
|
|
struct node *get_node_by_ref(struct node *tree, const char *ref);
|
|
cell_t get_node_phandle(struct node *root, struct node *node);
|
|
|
|
uint32_t guess_boot_cpuid(struct node *tree);
|
|
|
|
/* Boot info (tree plus memreserve information */
|
|
|
|
struct reserve_info {
|
|
struct fdt_reserve_entry re;
|
|
|
|
struct reserve_info *next;
|
|
|
|
struct label *labels;
|
|
};
|
|
|
|
struct reserve_info *build_reserve_entry(uint64_t start, uint64_t len);
|
|
struct reserve_info *chain_reserve_entry(struct reserve_info *first,
|
|
struct reserve_info *list);
|
|
struct reserve_info *add_reserve_entry(struct reserve_info *list,
|
|
struct reserve_info *new);
|
|
|
|
|
|
struct dt_info {
|
|
unsigned int dtsflags;
|
|
struct reserve_info *reservelist;
|
|
uint32_t boot_cpuid_phys;
|
|
struct node *dt; /* the device tree */
|
|
};
|
|
|
|
/* DTS version flags definitions */
|
|
#define DTSF_V1 0x0001 /* /dts-v1/ */
|
|
#define DTSF_PLUGIN 0x0002 /* /plugin/ */
|
|
|
|
struct dt_info *build_dt_info(unsigned int dtsflags,
|
|
struct reserve_info *reservelist,
|
|
struct node *tree, uint32_t boot_cpuid_phys);
|
|
void sort_tree(struct dt_info *dti);
|
|
void generate_label_tree(struct dt_info *dti, char *name, bool allocph);
|
|
void generate_fixups_tree(struct dt_info *dti, char *name);
|
|
void generate_local_fixups_tree(struct dt_info *dti, char *name);
|
|
|
|
/* Checks */
|
|
|
|
void parse_checks_option(bool warn, bool error, const char *arg);
|
|
void process_checks(bool force, struct dt_info *dti);
|
|
|
|
/* Flattened trees */
|
|
|
|
void dt_to_blob(FILE *f, struct dt_info *dti, int version);
|
|
void dt_to_asm(FILE *f, struct dt_info *dti, int version);
|
|
|
|
struct dt_info *dt_from_blob(const char *fname);
|
|
|
|
/* Tree source */
|
|
|
|
void dt_to_source(FILE *f, struct dt_info *dti);
|
|
struct dt_info *dt_from_source(const char *f);
|
|
|
|
/* FS trees */
|
|
|
|
struct dt_info *dt_from_fs(const char *dirname);
|
|
|
|
#endif /* _DTC_H */
|