aboutsummaryrefslogtreecommitdiffstats
path: root/arch/powerpc/boot/libfdt/fdt.c
diff options
context:
space:
mode:
Diffstat (limited to 'arch/powerpc/boot/libfdt/fdt.c')
-rw-r--r--arch/powerpc/boot/libfdt/fdt.c61
1 files changed, 53 insertions, 8 deletions
diff --git a/arch/powerpc/boot/libfdt/fdt.c b/arch/powerpc/boot/libfdt/fdt.c
index 586a36136db2..2acaec5923ae 100644
--- a/arch/powerpc/boot/libfdt/fdt.c
+++ b/arch/powerpc/boot/libfdt/fdt.c
@@ -63,7 +63,7 @@ int fdt_check_header(const void *fdt)
63 return -FDT_ERR_BADVERSION; 63 return -FDT_ERR_BADVERSION;
64 if (fdt_last_comp_version(fdt) > FDT_LAST_SUPPORTED_VERSION) 64 if (fdt_last_comp_version(fdt) > FDT_LAST_SUPPORTED_VERSION)
65 return -FDT_ERR_BADVERSION; 65 return -FDT_ERR_BADVERSION;
66 } else if (fdt_magic(fdt) == SW_MAGIC) { 66 } else if (fdt_magic(fdt) == FDT_SW_MAGIC) {
67 /* Unfinished sequential-write blob */ 67 /* Unfinished sequential-write blob */
68 if (fdt_size_dt_struct(fdt) == 0) 68 if (fdt_size_dt_struct(fdt) == 0)
69 return -FDT_ERR_BADSTATE; 69 return -FDT_ERR_BADSTATE;
@@ -76,7 +76,7 @@ int fdt_check_header(const void *fdt)
76 76
77const void *fdt_offset_ptr(const void *fdt, int offset, int len) 77const void *fdt_offset_ptr(const void *fdt, int offset, int len)
78{ 78{
79 const void *p; 79 const char *p;
80 80
81 if (fdt_version(fdt) >= 0x11) 81 if (fdt_version(fdt) >= 0x11)
82 if (((offset + len) < offset) 82 if (((offset + len) < offset)
@@ -124,11 +124,59 @@ uint32_t fdt_next_tag(const void *fdt, int offset, int *nextoffset)
124 } 124 }
125 125
126 if (nextoffset) 126 if (nextoffset)
127 *nextoffset = ALIGN(offset, FDT_TAGSIZE); 127 *nextoffset = FDT_TAGALIGN(offset);
128 128
129 return tag; 129 return tag;
130} 130}
131 131
132int _fdt_check_node_offset(const void *fdt, int offset)
133{
134 if ((offset < 0) || (offset % FDT_TAGSIZE)
135 || (fdt_next_tag(fdt, offset, &offset) != FDT_BEGIN_NODE))
136 return -FDT_ERR_BADOFFSET;
137
138 return offset;
139}
140
141int fdt_next_node(const void *fdt, int offset, int *depth)
142{
143 int nextoffset = 0;
144 uint32_t tag;
145
146 if (offset >= 0)
147 if ((nextoffset = _fdt_check_node_offset(fdt, offset)) < 0)
148 return nextoffset;
149
150 do {
151 offset = nextoffset;
152 tag = fdt_next_tag(fdt, offset, &nextoffset);
153
154 switch (tag) {
155 case FDT_PROP:
156 case FDT_NOP:
157 break;
158
159 case FDT_BEGIN_NODE:
160 if (depth)
161 (*depth)++;
162 break;
163
164 case FDT_END_NODE:
165 if (depth)
166 (*depth)--;
167 break;
168
169 case FDT_END:
170 return -FDT_ERR_NOTFOUND;
171
172 default:
173 return -FDT_ERR_BADSTRUCTURE;
174 }
175 } while (tag != FDT_BEGIN_NODE);
176
177 return offset;
178}
179
132const char *_fdt_find_string(const char *strtab, int tabsize, const char *s) 180const char *_fdt_find_string(const char *strtab, int tabsize, const char *s)
133{ 181{
134 int len = strlen(s) + 1; 182 int len = strlen(s) + 1;
@@ -136,17 +184,14 @@ const char *_fdt_find_string(const char *strtab, int tabsize, const char *s)
136 const char *p; 184 const char *p;
137 185
138 for (p = strtab; p <= last; p++) 186 for (p = strtab; p <= last; p++)
139 if (memeq(p, s, len)) 187 if (memcmp(p, s, len) == 0)
140 return p; 188 return p;
141 return NULL; 189 return NULL;
142} 190}
143 191
144int fdt_move(const void *fdt, void *buf, int bufsize) 192int fdt_move(const void *fdt, void *buf, int bufsize)
145{ 193{
146 int err = fdt_check_header(fdt); 194 FDT_CHECK_HEADER(fdt);
147
148 if (err)
149 return err;
150 195
151 if (fdt_totalsize(fdt) > bufsize) 196 if (fdt_totalsize(fdt) > bufsize)
152 return -FDT_ERR_NOSPACE; 197 return -FDT_ERR_NOSPACE;