diff options
Diffstat (limited to 'arch/powerpc/boot/libfdt/fdt_sw.c')
-rw-r--r-- | arch/powerpc/boot/libfdt/fdt_sw.c | 55 |
1 files changed, 27 insertions, 28 deletions
diff --git a/arch/powerpc/boot/libfdt/fdt_sw.c b/arch/powerpc/boot/libfdt/fdt_sw.c index dda2de34b2e0..698329e0ccaf 100644 --- a/arch/powerpc/boot/libfdt/fdt_sw.c +++ b/arch/powerpc/boot/libfdt/fdt_sw.c | |||
@@ -55,14 +55,22 @@ | |||
55 | 55 | ||
56 | #include "libfdt_internal.h" | 56 | #include "libfdt_internal.h" |
57 | 57 | ||
58 | static int check_header_sw(void *fdt) | 58 | static int _fdt_sw_check_header(void *fdt) |
59 | { | 59 | { |
60 | if (fdt_magic(fdt) != SW_MAGIC) | 60 | if (fdt_magic(fdt) != FDT_SW_MAGIC) |
61 | return -FDT_ERR_BADMAGIC; | 61 | return -FDT_ERR_BADMAGIC; |
62 | /* FIXME: should check more details about the header state */ | ||
62 | return 0; | 63 | return 0; |
63 | } | 64 | } |
64 | 65 | ||
65 | static void *grab_space(void *fdt, int len) | 66 | #define FDT_SW_CHECK_HEADER(fdt) \ |
67 | { \ | ||
68 | int err; \ | ||
69 | if ((err = _fdt_sw_check_header(fdt)) != 0) \ | ||
70 | return err; \ | ||
71 | } | ||
72 | |||
73 | static void *_fdt_grab_space(void *fdt, int len) | ||
66 | { | 74 | { |
67 | int offset = fdt_size_dt_struct(fdt); | 75 | int offset = fdt_size_dt_struct(fdt); |
68 | int spaceleft; | 76 | int spaceleft; |
@@ -86,13 +94,13 @@ int fdt_create(void *buf, int bufsize) | |||
86 | 94 | ||
87 | memset(buf, 0, bufsize); | 95 | memset(buf, 0, bufsize); |
88 | 96 | ||
89 | fdt_set_magic(fdt, SW_MAGIC); | 97 | fdt_set_magic(fdt, FDT_SW_MAGIC); |
90 | fdt_set_version(fdt, FDT_LAST_SUPPORTED_VERSION); | 98 | fdt_set_version(fdt, FDT_LAST_SUPPORTED_VERSION); |
91 | fdt_set_last_comp_version(fdt, FDT_FIRST_SUPPORTED_VERSION); | 99 | fdt_set_last_comp_version(fdt, FDT_FIRST_SUPPORTED_VERSION); |
92 | fdt_set_totalsize(fdt, bufsize); | 100 | fdt_set_totalsize(fdt, bufsize); |
93 | 101 | ||
94 | fdt_set_off_mem_rsvmap(fdt, ALIGN(sizeof(struct fdt_header), | 102 | fdt_set_off_mem_rsvmap(fdt, FDT_ALIGN(sizeof(struct fdt_header), |
95 | sizeof(struct fdt_reserve_entry))); | 103 | sizeof(struct fdt_reserve_entry))); |
96 | fdt_set_off_dt_struct(fdt, fdt_off_mem_rsvmap(fdt)); | 104 | fdt_set_off_dt_struct(fdt, fdt_off_mem_rsvmap(fdt)); |
97 | fdt_set_off_dt_strings(fdt, bufsize); | 105 | fdt_set_off_dt_strings(fdt, bufsize); |
98 | 106 | ||
@@ -102,11 +110,10 @@ int fdt_create(void *buf, int bufsize) | |||
102 | int fdt_add_reservemap_entry(void *fdt, uint64_t addr, uint64_t size) | 110 | int fdt_add_reservemap_entry(void *fdt, uint64_t addr, uint64_t size) |
103 | { | 111 | { |
104 | struct fdt_reserve_entry *re; | 112 | struct fdt_reserve_entry *re; |
105 | int err = check_header_sw(fdt); | ||
106 | int offset; | 113 | int offset; |
107 | 114 | ||
108 | if (err) | 115 | FDT_SW_CHECK_HEADER(fdt); |
109 | return err; | 116 | |
110 | if (fdt_size_dt_struct(fdt)) | 117 | if (fdt_size_dt_struct(fdt)) |
111 | return -FDT_ERR_BADSTATE; | 118 | return -FDT_ERR_BADSTATE; |
112 | 119 | ||
@@ -114,7 +121,7 @@ int fdt_add_reservemap_entry(void *fdt, uint64_t addr, uint64_t size) | |||
114 | if ((offset + sizeof(*re)) > fdt_totalsize(fdt)) | 121 | if ((offset + sizeof(*re)) > fdt_totalsize(fdt)) |
115 | return -FDT_ERR_NOSPACE; | 122 | return -FDT_ERR_NOSPACE; |
116 | 123 | ||
117 | re = (struct fdt_reserve_entry *)(fdt + offset); | 124 | re = (struct fdt_reserve_entry *)((char *)fdt + offset); |
118 | re->address = cpu_to_fdt64(addr); | 125 | re->address = cpu_to_fdt64(addr); |
119 | re->size = cpu_to_fdt64(size); | 126 | re->size = cpu_to_fdt64(size); |
120 | 127 | ||
@@ -131,13 +138,11 @@ int fdt_finish_reservemap(void *fdt) | |||
131 | int fdt_begin_node(void *fdt, const char *name) | 138 | int fdt_begin_node(void *fdt, const char *name) |
132 | { | 139 | { |
133 | struct fdt_node_header *nh; | 140 | struct fdt_node_header *nh; |
134 | int err = check_header_sw(fdt); | ||
135 | int namelen = strlen(name) + 1; | 141 | int namelen = strlen(name) + 1; |
136 | 142 | ||
137 | if (err) | 143 | FDT_SW_CHECK_HEADER(fdt); |
138 | return err; | ||
139 | 144 | ||
140 | nh = grab_space(fdt, sizeof(*nh) + ALIGN(namelen, FDT_TAGSIZE)); | 145 | nh = _fdt_grab_space(fdt, sizeof(*nh) + FDT_TAGALIGN(namelen)); |
141 | if (! nh) | 146 | if (! nh) |
142 | return -FDT_ERR_NOSPACE; | 147 | return -FDT_ERR_NOSPACE; |
143 | 148 | ||
@@ -149,12 +154,10 @@ int fdt_begin_node(void *fdt, const char *name) | |||
149 | int fdt_end_node(void *fdt) | 154 | int fdt_end_node(void *fdt) |
150 | { | 155 | { |
151 | uint32_t *en; | 156 | uint32_t *en; |
152 | int err = check_header_sw(fdt); | ||
153 | 157 | ||
154 | if (err) | 158 | FDT_SW_CHECK_HEADER(fdt); |
155 | return err; | ||
156 | 159 | ||
157 | en = grab_space(fdt, FDT_TAGSIZE); | 160 | en = _fdt_grab_space(fdt, FDT_TAGSIZE); |
158 | if (! en) | 161 | if (! en) |
159 | return -FDT_ERR_NOSPACE; | 162 | return -FDT_ERR_NOSPACE; |
160 | 163 | ||
@@ -162,7 +165,7 @@ int fdt_end_node(void *fdt) | |||
162 | return 0; | 165 | return 0; |
163 | } | 166 | } |
164 | 167 | ||
165 | static int find_add_string(void *fdt, const char *s) | 168 | static int _fdt_find_add_string(void *fdt, const char *s) |
166 | { | 169 | { |
167 | char *strtab = (char *)fdt + fdt_totalsize(fdt); | 170 | char *strtab = (char *)fdt + fdt_totalsize(fdt); |
168 | const char *p; | 171 | const char *p; |
@@ -188,17 +191,15 @@ static int find_add_string(void *fdt, const char *s) | |||
188 | int fdt_property(void *fdt, const char *name, const void *val, int len) | 191 | int fdt_property(void *fdt, const char *name, const void *val, int len) |
189 | { | 192 | { |
190 | struct fdt_property *prop; | 193 | struct fdt_property *prop; |
191 | int err = check_header_sw(fdt); | ||
192 | int nameoff; | 194 | int nameoff; |
193 | 195 | ||
194 | if (err) | 196 | FDT_SW_CHECK_HEADER(fdt); |
195 | return err; | ||
196 | 197 | ||
197 | nameoff = find_add_string(fdt, name); | 198 | nameoff = _fdt_find_add_string(fdt, name); |
198 | if (nameoff == 0) | 199 | if (nameoff == 0) |
199 | return -FDT_ERR_NOSPACE; | 200 | return -FDT_ERR_NOSPACE; |
200 | 201 | ||
201 | prop = grab_space(fdt, sizeof(*prop) + ALIGN(len, FDT_TAGSIZE)); | 202 | prop = _fdt_grab_space(fdt, sizeof(*prop) + FDT_TAGALIGN(len)); |
202 | if (! prop) | 203 | if (! prop) |
203 | return -FDT_ERR_NOSPACE; | 204 | return -FDT_ERR_NOSPACE; |
204 | 205 | ||
@@ -211,18 +212,16 @@ int fdt_property(void *fdt, const char *name, const void *val, int len) | |||
211 | 212 | ||
212 | int fdt_finish(void *fdt) | 213 | int fdt_finish(void *fdt) |
213 | { | 214 | { |
214 | int err = check_header_sw(fdt); | ||
215 | char *p = (char *)fdt; | 215 | char *p = (char *)fdt; |
216 | uint32_t *end; | 216 | uint32_t *end; |
217 | int oldstroffset, newstroffset; | 217 | int oldstroffset, newstroffset; |
218 | uint32_t tag; | 218 | uint32_t tag; |
219 | int offset, nextoffset; | 219 | int offset, nextoffset; |
220 | 220 | ||
221 | if (err) | 221 | FDT_SW_CHECK_HEADER(fdt); |
222 | return err; | ||
223 | 222 | ||
224 | /* Add terminator */ | 223 | /* Add terminator */ |
225 | end = grab_space(fdt, sizeof(*end)); | 224 | end = _fdt_grab_space(fdt, sizeof(*end)); |
226 | if (! end) | 225 | if (! end) |
227 | return -FDT_ERR_NOSPACE; | 226 | return -FDT_ERR_NOSPACE; |
228 | *end = cpu_to_fdt32(FDT_END); | 227 | *end = cpu_to_fdt32(FDT_END); |