Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) /* SPDX-License-Identifier: GPL-2.0-or-later */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) #ifndef DTC_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3) #define DTC_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * (C) Copyright David Gibson <dwg@au1.ibm.com>, IBM Corporation.  2005.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <stdio.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <stdlib.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <stdint.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <stdbool.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <stdarg.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <assert.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <ctype.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <unistd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <inttypes.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <libfdt_env.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include <fdt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #include "util.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #ifdef DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) #define debug(...)	printf(__VA_ARGS__)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) #define debug(...)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) #define DEFAULT_FDT_VERSION	17
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35)  * Command line options
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) extern int quiet;		/* Level of quietness */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) extern int reservenum;		/* Number of memory reservation slots */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) extern int minsize;		/* Minimum blob size */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) extern int padsize;		/* Additional padding to blob */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) extern int alignsize;		/* Additional padding to blob accroding to the alignsize */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) extern int phandle_format;	/* Use linux,phandle or phandle properties */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) extern int generate_symbols;	/* generate symbols for nodes with labels */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) extern int generate_fixups;	/* generate fixups */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) extern int auto_label_aliases;	/* auto generate labels -> aliases */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) extern int annotate;		/* annotate .dts with input source location */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) #define PHANDLE_LEGACY	0x1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) #define PHANDLE_EPAPR	0x2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) #define PHANDLE_BOTH	0x3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) typedef uint32_t cell_t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) static inline uint16_t dtb_ld16(const void *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	const uint8_t *bp = (const uint8_t *)p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	return ((uint16_t)bp[0] << 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 		| bp[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) static inline uint32_t dtb_ld32(const void *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	const uint8_t *bp = (const uint8_t *)p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	return ((uint32_t)bp[0] << 24)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 		| ((uint32_t)bp[1] << 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 		| ((uint32_t)bp[2] << 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 		| bp[3];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) static inline uint64_t dtb_ld64(const void *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	const uint8_t *bp = (const uint8_t *)p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	return ((uint64_t)bp[0] << 56)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 		| ((uint64_t)bp[1] << 48)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 		| ((uint64_t)bp[2] << 40)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 		| ((uint64_t)bp[3] << 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 		| ((uint64_t)bp[4] << 24)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 		| ((uint64_t)bp[5] << 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 		| ((uint64_t)bp[6] << 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 		| bp[7];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) #define streq(a, b)	(strcmp((a), (b)) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) #define strstarts(s, prefix)	(strncmp((s), (prefix), strlen(prefix)) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) #define strprefixeq(a, n, b)	(strlen(b) == (n) && (memcmp(a, b, n) == 0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) #define ALIGN(x, a)	(((x) + (a) - 1) & ~((a) - 1))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) /* Data blobs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) enum markertype {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	TYPE_NONE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	REF_PHANDLE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	REF_PATH,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	LABEL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	TYPE_UINT8,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	TYPE_UINT16,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	TYPE_UINT32,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	TYPE_UINT64,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	TYPE_STRING,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) extern const char *markername(enum markertype markertype);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) struct  marker {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	enum markertype type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	unsigned int offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	char *ref;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	struct marker *next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) struct data {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	unsigned int len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	char *val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	struct marker *markers;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) #define empty_data ((struct data){ 0 /* all .members = 0 or NULL */ })
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) #define for_each_marker(m) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	for (; (m); (m) = (m)->next)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) #define for_each_marker_of_type(m, t) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	for_each_marker(m) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 		if ((m)->type == (t))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) size_t type_marker_length(struct marker *m);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) void data_free(struct data d);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) struct data data_grow_for(struct data d, unsigned int xlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) struct data data_copy_mem(const char *mem, int len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) struct data data_copy_escape_string(const char *s, int len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) struct data data_copy_file(FILE *f, size_t len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) struct data data_append_data(struct data d, const void *p, int len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) struct data data_insert_at_marker(struct data d, struct marker *m,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 				  const void *p, int len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) struct data data_merge(struct data d1, struct data d2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) struct data data_append_cell(struct data d, cell_t word);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) struct data data_append_integer(struct data d, uint64_t word, int bits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) struct data data_append_re(struct data d, uint64_t address, uint64_t size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) struct data data_append_addr(struct data d, uint64_t addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) struct data data_append_byte(struct data d, uint8_t byte);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) struct data data_append_zeroes(struct data d, int len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) struct data data_append_align(struct data d, int align);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) struct data data_add_marker(struct data d, enum markertype type, char *ref);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) bool data_is_one_string(struct data d);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) /* DT constraints */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) #define MAX_PROPNAME_LEN	31
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) #define MAX_NODENAME_LEN	31
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) /* Live trees */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) struct label {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	bool deleted;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	char *label;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	struct label *next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) struct bus_type {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	const char *name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) struct property {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	bool deleted;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	char *name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	struct data val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	struct property *next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	struct label *labels;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	struct srcpos *srcpos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) struct node {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	bool deleted;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	char *name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	struct property *proplist;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	struct node *children;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	struct node *parent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	struct node *next_sibling;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	char *fullpath;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	int basenamelen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	cell_t phandle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	int addr_cells, size_cells;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	struct label *labels;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	const struct bus_type *bus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	struct srcpos *srcpos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	bool omit_if_unused, is_referenced;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) #define for_each_label_withdel(l0, l) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	for ((l) = (l0); (l); (l) = (l)->next)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) #define for_each_label(l0, l) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	for_each_label_withdel(l0, l) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 		if (!(l)->deleted)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) #define for_each_property_withdel(n, p) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	for ((p) = (n)->proplist; (p); (p) = (p)->next)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) #define for_each_property(n, p) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	for_each_property_withdel(n, p) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 		if (!(p)->deleted)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) #define for_each_child_withdel(n, c) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	for ((c) = (n)->children; (c); (c) = (c)->next_sibling)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) #define for_each_child(n, c) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	for_each_child_withdel(n, c) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 		if (!(c)->deleted)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) void add_label(struct label **labels, char *label);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) void delete_labels(struct label **labels);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) struct property *build_property(char *name, struct data val,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 				struct srcpos *srcpos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) struct property *build_property_delete(char *name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) struct property *chain_property(struct property *first, struct property *list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) struct property *reverse_properties(struct property *first);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) struct node *build_node(struct property *proplist, struct node *children,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 			struct srcpos *srcpos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) struct node *build_node_delete(struct srcpos *srcpos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) struct node *name_node(struct node *node, char *name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) struct node *omit_node_if_unused(struct node *node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) struct node *reference_node(struct node *node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) struct node *chain_node(struct node *first, struct node *list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) struct node *merge_nodes(struct node *old_node, struct node *new_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) struct node *add_orphan_node(struct node *old_node, struct node *new_node, char *ref);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) void add_property(struct node *node, struct property *prop);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) void delete_property_by_name(struct node *node, char *name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) void delete_property(struct property *prop);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) void add_child(struct node *parent, struct node *child);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) void delete_node_by_name(struct node *parent, char *name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) void delete_node(struct node *node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) void append_to_property(struct node *node,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 			char *name, const void *data, int len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 			enum markertype type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) const char *get_unitname(struct node *node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) struct property *get_property(struct node *node, const char *propname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) cell_t propval_cell(struct property *prop);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) cell_t propval_cell_n(struct property *prop, unsigned int n);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) struct property *get_property_by_label(struct node *tree, const char *label,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 				       struct node **node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) struct marker *get_marker_label(struct node *tree, const char *label,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 				struct node **node, struct property **prop);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) struct node *get_subnode(struct node *node, const char *nodename);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) struct node *get_node_by_path(struct node *tree, const char *path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) struct node *get_node_by_label(struct node *tree, const char *label);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) struct node *get_node_by_phandle(struct node *tree, cell_t phandle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) struct node *get_node_by_ref(struct node *tree, const char *ref);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) cell_t get_node_phandle(struct node *root, struct node *node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) uint32_t guess_boot_cpuid(struct node *tree);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) /* Boot info (tree plus memreserve information */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) struct reserve_info {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	uint64_t address, size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	struct reserve_info *next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 	struct label *labels;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) struct reserve_info *build_reserve_entry(uint64_t start, uint64_t len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) struct reserve_info *chain_reserve_entry(struct reserve_info *first,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 					 struct reserve_info *list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) struct reserve_info *add_reserve_entry(struct reserve_info *list,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 				       struct reserve_info *new);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) struct dt_info {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 	unsigned int dtsflags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 	struct reserve_info *reservelist;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 	uint32_t boot_cpuid_phys;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 	struct node *dt;		/* the device tree */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 	const char *outname;		/* filename being written to, "-" for stdout */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) /* DTS version flags definitions */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) #define DTSF_V1		0x0001	/* /dts-v1/ */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) #define DTSF_PLUGIN	0x0002	/* /plugin/ */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) struct dt_info *build_dt_info(unsigned int dtsflags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 			      struct reserve_info *reservelist,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 			      struct node *tree, uint32_t boot_cpuid_phys);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) void sort_tree(struct dt_info *dti);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) void generate_label_tree(struct dt_info *dti, char *name, bool allocph);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) void generate_fixups_tree(struct dt_info *dti, char *name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) void generate_local_fixups_tree(struct dt_info *dti, char *name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) /* Checks */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) void parse_checks_option(bool warn, bool error, const char *arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) void process_checks(bool force, struct dt_info *dti);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) /* Flattened trees */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) void dt_to_blob(FILE *f, struct dt_info *dti, int version);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) void dt_to_asm(FILE *f, struct dt_info *dti, int version);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) struct dt_info *dt_from_blob(const char *fname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) /* Tree source */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) void dt_to_source(FILE *f, struct dt_info *dti);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) struct dt_info *dt_from_source(const char *f);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) /* YAML source */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) void dt_to_yaml(FILE *f, struct dt_info *dti);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) /* FS trees */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) struct dt_info *dt_from_fs(const char *dirname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) #endif /* DTC_H */