31 #define BAD_ERROR(err) (((err) < 0) \
32 && ((err) != -FDT_ERR_NOTFOUND) \
33 && ((err) != -FDT_ERR_EXISTS))
35 #define check_err(err) \
37 if (BAD_ERROR(err) || ((err < 0) && DEBUG)) \
38 printf("%s():%d %s\n\r", __func__, __LINE__, \
45 #define offset_devp(off) \
47 int _offset = (off); \
48 check_err(_offset) ? NULL : (void *)(_offset+1); \
51 #define devp_offset_find(devp) (((int)(devp))-1)
52 #define devp_offset(devp) (devp ? ((int)(devp))-1 : 0)
57 #define EXPAND_GRANULARITY 1024
59 static void expand_buf(
int minexpand)
67 fatal(
"Couldn't find %d bytes to expand device tree\n\r", size);
70 fatal(
"Couldn't expand fdt into new buffer: %s\n\r",
76 static void *fdt_wrapper_finddevice(
const char *
path)
81 static int fdt_wrapper_getprop(
const void *devp,
const char *
name,
94 static int fdt_wrapper_setprop(
const void *devp,
const char *name,
95 const void *buf,
const int len)
101 expand_buf(len + 16);
108 static int fdt_wrapper_del_node(
const void *devp)
113 static void *fdt_wrapper_get_parent(
const void *devp)
118 static void *fdt_wrapper_create_node(
const void *devp,
const char *name)
124 expand_buf(
strlen(name) + 16);
131 static void *fdt_wrapper_find_node_by_prop_value(
const void *
prev,
141 static void *fdt_wrapper_find_node_by_compatible(
const void *prev,
149 static char *fdt_wrapper_get_path(
const void *devp,
char *buf,
int len)
159 static unsigned long fdt_wrapper_finalize(
void)
165 fatal(
"Couldn't pack flat tree: %s\n\r",
167 return (
unsigned long)fdt;
191 fatal(
"malloc failed. can't relocate the device tree\n\r");