~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/scripts/dtc/libfdt/fdt_sw.c

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /scripts/dtc/libfdt/fdt_sw.c (Architecture ppc) and /scripts/dtc/libfdt/fdt_sw.c (Architecture alpha)


  1 // SPDX-License-Identifier: (GPL-2.0-or-later       1 // SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause)
  2 /*                                                  2 /*
  3  * libfdt - Flat Device Tree manipulation           3  * libfdt - Flat Device Tree manipulation
  4  * Copyright (C) 2006 David Gibson, IBM Corpor      4  * Copyright (C) 2006 David Gibson, IBM Corporation.
  5  */                                                 5  */
  6 #include "libfdt_env.h"                             6 #include "libfdt_env.h"
  7                                                     7 
  8 #include <fdt.h>                                    8 #include <fdt.h>
  9 #include <libfdt.h>                                 9 #include <libfdt.h>
 10                                                    10 
 11 #include "libfdt_internal.h"                       11 #include "libfdt_internal.h"
 12                                                    12 
 13 static int fdt_sw_probe_(void *fdt)                13 static int fdt_sw_probe_(void *fdt)
 14 {                                                  14 {
 15         if (!can_assume(VALID_INPUT)) {            15         if (!can_assume(VALID_INPUT)) {
 16                 if (fdt_magic(fdt) == FDT_MAGI     16                 if (fdt_magic(fdt) == FDT_MAGIC)
 17                         return -FDT_ERR_BADSTA     17                         return -FDT_ERR_BADSTATE;
 18                 else if (fdt_magic(fdt) != FDT     18                 else if (fdt_magic(fdt) != FDT_SW_MAGIC)
 19                         return -FDT_ERR_BADMAG     19                         return -FDT_ERR_BADMAGIC;
 20         }                                          20         }
 21                                                    21 
 22         return 0;                                  22         return 0;
 23 }                                                  23 }
 24                                                    24 
 25 #define FDT_SW_PROBE(fdt) \                        25 #define FDT_SW_PROBE(fdt) \
 26         { \                                        26         { \
 27                 int err; \                         27                 int err; \
 28                 if ((err = fdt_sw_probe_(fdt))     28                 if ((err = fdt_sw_probe_(fdt)) != 0) \
 29                         return err; \              29                         return err; \
 30         }                                          30         }
 31                                                    31 
 32 /* 'memrsv' state:      Initial state after fd     32 /* 'memrsv' state:      Initial state after fdt_create()
 33  *                                                 33  *
 34  * Allowed functions:                              34  * Allowed functions:
 35  *      fdt_add_reservemap_entry()                 35  *      fdt_add_reservemap_entry()
 36  *      fdt_finish_reservemap()         [moves     36  *      fdt_finish_reservemap()         [moves to 'struct' state]
 37  */                                                37  */
 38 static int fdt_sw_probe_memrsv_(void *fdt)         38 static int fdt_sw_probe_memrsv_(void *fdt)
 39 {                                                  39 {
 40         int err = fdt_sw_probe_(fdt);              40         int err = fdt_sw_probe_(fdt);
 41         if (err)                                   41         if (err)
 42                 return err;                        42                 return err;
 43                                                    43 
 44         if (!can_assume(VALID_INPUT) && fdt_of     44         if (!can_assume(VALID_INPUT) && fdt_off_dt_strings(fdt) != 0)
 45                 return -FDT_ERR_BADSTATE;          45                 return -FDT_ERR_BADSTATE;
 46         return 0;                                  46         return 0;
 47 }                                                  47 }
 48                                                    48 
 49 #define FDT_SW_PROBE_MEMRSV(fdt) \                 49 #define FDT_SW_PROBE_MEMRSV(fdt) \
 50         { \                                        50         { \
 51                 int err; \                         51                 int err; \
 52                 if ((err = fdt_sw_probe_memrsv     52                 if ((err = fdt_sw_probe_memrsv_(fdt)) != 0) \
 53                         return err; \              53                         return err; \
 54         }                                          54         }
 55                                                    55 
 56 /* 'struct' state:      Enter this state after     56 /* 'struct' state:      Enter this state after fdt_finish_reservemap()
 57  *                                                 57  *
 58  * Allowed functions:                              58  * Allowed functions:
 59  *      fdt_begin_node()                           59  *      fdt_begin_node()
 60  *      fdt_end_node()                             60  *      fdt_end_node()
 61  *      fdt_property*()                            61  *      fdt_property*()
 62  *      fdt_finish()                    [moves     62  *      fdt_finish()                    [moves to 'complete' state]
 63  */                                                63  */
 64 static int fdt_sw_probe_struct_(void *fdt)         64 static int fdt_sw_probe_struct_(void *fdt)
 65 {                                                  65 {
 66         int err = fdt_sw_probe_(fdt);              66         int err = fdt_sw_probe_(fdt);
 67         if (err)                                   67         if (err)
 68                 return err;                        68                 return err;
 69                                                    69 
 70         if (!can_assume(VALID_INPUT) &&            70         if (!can_assume(VALID_INPUT) &&
 71             fdt_off_dt_strings(fdt) != fdt_tot     71             fdt_off_dt_strings(fdt) != fdt_totalsize(fdt))
 72                 return -FDT_ERR_BADSTATE;          72                 return -FDT_ERR_BADSTATE;
 73         return 0;                                  73         return 0;
 74 }                                                  74 }
 75                                                    75 
 76 #define FDT_SW_PROBE_STRUCT(fdt) \                 76 #define FDT_SW_PROBE_STRUCT(fdt) \
 77         { \                                        77         { \
 78                 int err; \                         78                 int err; \
 79                 if ((err = fdt_sw_probe_struct     79                 if ((err = fdt_sw_probe_struct_(fdt)) != 0) \
 80                         return err; \              80                         return err; \
 81         }                                          81         }
 82                                                    82 
 83 static inline uint32_t sw_flags(void *fdt)         83 static inline uint32_t sw_flags(void *fdt)
 84 {                                                  84 {
 85         /* assert: (fdt_magic(fdt) == FDT_SW_M     85         /* assert: (fdt_magic(fdt) == FDT_SW_MAGIC) */
 86         return fdt_last_comp_version(fdt);         86         return fdt_last_comp_version(fdt);
 87 }                                                  87 }
 88                                                    88 
 89 /* 'complete' state:    Enter this state after     89 /* 'complete' state:    Enter this state after fdt_finish()
 90  *                                                 90  *
 91  * Allowed functions: none                         91  * Allowed functions: none
 92  */                                                92  */
 93                                                    93 
 94 static void *fdt_grab_space_(void *fdt, size_t     94 static void *fdt_grab_space_(void *fdt, size_t len)
 95 {                                                  95 {
 96         unsigned int offset = fdt_size_dt_stru     96         unsigned int offset = fdt_size_dt_struct(fdt);
 97         unsigned int spaceleft;                    97         unsigned int spaceleft;
 98                                                    98 
 99         spaceleft = fdt_totalsize(fdt) - fdt_o     99         spaceleft = fdt_totalsize(fdt) - fdt_off_dt_struct(fdt)
100                 - fdt_size_dt_strings(fdt);       100                 - fdt_size_dt_strings(fdt);
101                                                   101 
102         if ((offset + len < offset) || (offset    102         if ((offset + len < offset) || (offset + len > spaceleft))
103                 return NULL;                      103                 return NULL;
104                                                   104 
105         fdt_set_size_dt_struct(fdt, offset + l    105         fdt_set_size_dt_struct(fdt, offset + len);
106         return fdt_offset_ptr_w_(fdt, offset);    106         return fdt_offset_ptr_w_(fdt, offset);
107 }                                                 107 }
108                                                   108 
109 int fdt_create_with_flags(void *buf, int bufsi    109 int fdt_create_with_flags(void *buf, int bufsize, uint32_t flags)
110 {                                                 110 {
111         const int hdrsize = FDT_ALIGN(sizeof(s    111         const int hdrsize = FDT_ALIGN(sizeof(struct fdt_header),
112                                       sizeof(s    112                                       sizeof(struct fdt_reserve_entry));
113         void *fdt = buf;                          113         void *fdt = buf;
114                                                   114 
115         if (bufsize < hdrsize)                    115         if (bufsize < hdrsize)
116                 return -FDT_ERR_NOSPACE;          116                 return -FDT_ERR_NOSPACE;
117                                                   117 
118         if (flags & ~FDT_CREATE_FLAGS_ALL)        118         if (flags & ~FDT_CREATE_FLAGS_ALL)
119                 return -FDT_ERR_BADFLAGS;         119                 return -FDT_ERR_BADFLAGS;
120                                                   120 
121         memset(buf, 0, bufsize);                  121         memset(buf, 0, bufsize);
122                                                   122 
123         /*                                        123         /*
124          * magic and last_comp_version keep in    124          * magic and last_comp_version keep intermediate state during the fdt
125          * creation process, which is replaced    125          * creation process, which is replaced with the proper FDT format by
126          * fdt_finish().                          126          * fdt_finish().
127          *                                        127          *
128          * flags should be accessed with sw_fl    128          * flags should be accessed with sw_flags().
129          */                                       129          */
130         fdt_set_magic(fdt, FDT_SW_MAGIC);         130         fdt_set_magic(fdt, FDT_SW_MAGIC);
131         fdt_set_version(fdt, FDT_LAST_SUPPORTE    131         fdt_set_version(fdt, FDT_LAST_SUPPORTED_VERSION);
132         fdt_set_last_comp_version(fdt, flags);    132         fdt_set_last_comp_version(fdt, flags);
133                                                   133 
134         fdt_set_totalsize(fdt,  bufsize);         134         fdt_set_totalsize(fdt,  bufsize);
135                                                   135 
136         fdt_set_off_mem_rsvmap(fdt, hdrsize);     136         fdt_set_off_mem_rsvmap(fdt, hdrsize);
137         fdt_set_off_dt_struct(fdt, fdt_off_mem    137         fdt_set_off_dt_struct(fdt, fdt_off_mem_rsvmap(fdt));
138         fdt_set_off_dt_strings(fdt, 0);           138         fdt_set_off_dt_strings(fdt, 0);
139                                                   139 
140         return 0;                                 140         return 0;
141 }                                                 141 }
142                                                   142 
143 int fdt_create(void *buf, int bufsize)            143 int fdt_create(void *buf, int bufsize)
144 {                                                 144 {
145         return fdt_create_with_flags(buf, bufs    145         return fdt_create_with_flags(buf, bufsize, 0);
146 }                                                 146 }
147                                                   147 
148 int fdt_resize(void *fdt, void *buf, int bufsi    148 int fdt_resize(void *fdt, void *buf, int bufsize)
149 {                                                 149 {
150         size_t headsize, tailsize;                150         size_t headsize, tailsize;
151         char *oldtail, *newtail;                  151         char *oldtail, *newtail;
152                                                   152 
153         FDT_SW_PROBE(fdt);                        153         FDT_SW_PROBE(fdt);
154                                                   154 
155         if (bufsize < 0)                          155         if (bufsize < 0)
156                 return -FDT_ERR_NOSPACE;          156                 return -FDT_ERR_NOSPACE;
157                                                   157 
158         headsize = fdt_off_dt_struct(fdt) + fd    158         headsize = fdt_off_dt_struct(fdt) + fdt_size_dt_struct(fdt);
159         tailsize = fdt_size_dt_strings(fdt);      159         tailsize = fdt_size_dt_strings(fdt);
160                                                   160 
161         if (!can_assume(VALID_DTB) &&             161         if (!can_assume(VALID_DTB) &&
162             headsize + tailsize > fdt_totalsiz    162             headsize + tailsize > fdt_totalsize(fdt))
163                 return -FDT_ERR_INTERNAL;         163                 return -FDT_ERR_INTERNAL;
164                                                   164 
165         if ((headsize + tailsize) > (unsigned)    165         if ((headsize + tailsize) > (unsigned)bufsize)
166                 return -FDT_ERR_NOSPACE;          166                 return -FDT_ERR_NOSPACE;
167                                                   167 
168         oldtail = (char *)fdt + fdt_totalsize(    168         oldtail = (char *)fdt + fdt_totalsize(fdt) - tailsize;
169         newtail = (char *)buf + bufsize - tail    169         newtail = (char *)buf + bufsize - tailsize;
170                                                   170 
171         /* Two cases to avoid clobbering data     171         /* Two cases to avoid clobbering data if the old and new
172          * buffers partially overlap */           172          * buffers partially overlap */
173         if (buf <= fdt) {                         173         if (buf <= fdt) {
174                 memmove(buf, fdt, headsize);      174                 memmove(buf, fdt, headsize);
175                 memmove(newtail, oldtail, tail    175                 memmove(newtail, oldtail, tailsize);
176         } else {                                  176         } else {
177                 memmove(newtail, oldtail, tail    177                 memmove(newtail, oldtail, tailsize);
178                 memmove(buf, fdt, headsize);      178                 memmove(buf, fdt, headsize);
179         }                                         179         }
180                                                   180 
181         fdt_set_totalsize(buf, bufsize);          181         fdt_set_totalsize(buf, bufsize);
182         if (fdt_off_dt_strings(buf))              182         if (fdt_off_dt_strings(buf))
183                 fdt_set_off_dt_strings(buf, bu    183                 fdt_set_off_dt_strings(buf, bufsize);
184                                                   184 
185         return 0;                                 185         return 0;
186 }                                                 186 }
187                                                   187 
188 int fdt_add_reservemap_entry(void *fdt, uint64    188 int fdt_add_reservemap_entry(void *fdt, uint64_t addr, uint64_t size)
189 {                                                 189 {
190         struct fdt_reserve_entry *re;             190         struct fdt_reserve_entry *re;
191         int offset;                               191         int offset;
192                                                   192 
193         FDT_SW_PROBE_MEMRSV(fdt);                 193         FDT_SW_PROBE_MEMRSV(fdt);
194                                                   194 
195         offset = fdt_off_dt_struct(fdt);          195         offset = fdt_off_dt_struct(fdt);
196         if ((offset + sizeof(*re)) > fdt_total    196         if ((offset + sizeof(*re)) > fdt_totalsize(fdt))
197                 return -FDT_ERR_NOSPACE;          197                 return -FDT_ERR_NOSPACE;
198                                                   198 
199         re = (struct fdt_reserve_entry *)((cha    199         re = (struct fdt_reserve_entry *)((char *)fdt + offset);
200         re->address = cpu_to_fdt64(addr);         200         re->address = cpu_to_fdt64(addr);
201         re->size = cpu_to_fdt64(size);            201         re->size = cpu_to_fdt64(size);
202                                                   202 
203         fdt_set_off_dt_struct(fdt, offset + si    203         fdt_set_off_dt_struct(fdt, offset + sizeof(*re));
204                                                   204 
205         return 0;                                 205         return 0;
206 }                                                 206 }
207                                                   207 
208 int fdt_finish_reservemap(void *fdt)              208 int fdt_finish_reservemap(void *fdt)
209 {                                                 209 {
210         int err = fdt_add_reservemap_entry(fdt    210         int err = fdt_add_reservemap_entry(fdt, 0, 0);
211                                                   211 
212         if (err)                                  212         if (err)
213                 return err;                       213                 return err;
214                                                   214 
215         fdt_set_off_dt_strings(fdt, fdt_totals    215         fdt_set_off_dt_strings(fdt, fdt_totalsize(fdt));
216         return 0;                                 216         return 0;
217 }                                                 217 }
218                                                   218 
219 int fdt_begin_node(void *fdt, const char *name    219 int fdt_begin_node(void *fdt, const char *name)
220 {                                                 220 {
221         struct fdt_node_header *nh;               221         struct fdt_node_header *nh;
222         int namelen;                              222         int namelen;
223                                                   223 
224         FDT_SW_PROBE_STRUCT(fdt);                 224         FDT_SW_PROBE_STRUCT(fdt);
225                                                   225 
226         namelen = strlen(name) + 1;               226         namelen = strlen(name) + 1;
227         nh = fdt_grab_space_(fdt, sizeof(*nh)     227         nh = fdt_grab_space_(fdt, sizeof(*nh) + FDT_TAGALIGN(namelen));
228         if (! nh)                                 228         if (! nh)
229                 return -FDT_ERR_NOSPACE;          229                 return -FDT_ERR_NOSPACE;
230                                                   230 
231         nh->tag = cpu_to_fdt32(FDT_BEGIN_NODE)    231         nh->tag = cpu_to_fdt32(FDT_BEGIN_NODE);
232         memcpy(nh->name, name, namelen);          232         memcpy(nh->name, name, namelen);
233         return 0;                                 233         return 0;
234 }                                                 234 }
235                                                   235 
236 int fdt_end_node(void *fdt)                       236 int fdt_end_node(void *fdt)
237 {                                                 237 {
238         fdt32_t *en;                              238         fdt32_t *en;
239                                                   239 
240         FDT_SW_PROBE_STRUCT(fdt);                 240         FDT_SW_PROBE_STRUCT(fdt);
241                                                   241 
242         en = fdt_grab_space_(fdt, FDT_TAGSIZE)    242         en = fdt_grab_space_(fdt, FDT_TAGSIZE);
243         if (! en)                                 243         if (! en)
244                 return -FDT_ERR_NOSPACE;          244                 return -FDT_ERR_NOSPACE;
245                                                   245 
246         *en = cpu_to_fdt32(FDT_END_NODE);         246         *en = cpu_to_fdt32(FDT_END_NODE);
247         return 0;                                 247         return 0;
248 }                                                 248 }
249                                                   249 
250 static int fdt_add_string_(void *fdt, const ch    250 static int fdt_add_string_(void *fdt, const char *s)
251 {                                                 251 {
252         char *strtab = (char *)fdt + fdt_total    252         char *strtab = (char *)fdt + fdt_totalsize(fdt);
253         unsigned int strtabsize = fdt_size_dt_    253         unsigned int strtabsize = fdt_size_dt_strings(fdt);
254         unsigned int len = strlen(s) + 1;         254         unsigned int len = strlen(s) + 1;
255         unsigned int struct_top, offset;          255         unsigned int struct_top, offset;
256                                                   256 
257         offset = strtabsize + len;                257         offset = strtabsize + len;
258         struct_top = fdt_off_dt_struct(fdt) +     258         struct_top = fdt_off_dt_struct(fdt) + fdt_size_dt_struct(fdt);
259         if (fdt_totalsize(fdt) - offset < stru    259         if (fdt_totalsize(fdt) - offset < struct_top)
260                 return 0; /* no more room :( *    260                 return 0; /* no more room :( */
261                                                   261 
262         memcpy(strtab - offset, s, len);          262         memcpy(strtab - offset, s, len);
263         fdt_set_size_dt_strings(fdt, strtabsiz    263         fdt_set_size_dt_strings(fdt, strtabsize + len);
264         return -offset;                           264         return -offset;
265 }                                                 265 }
266                                                   266 
267 /* Must only be used to roll back in case of e    267 /* Must only be used to roll back in case of error */
268 static void fdt_del_last_string_(void *fdt, co    268 static void fdt_del_last_string_(void *fdt, const char *s)
269 {                                                 269 {
270         int strtabsize = fdt_size_dt_strings(f    270         int strtabsize = fdt_size_dt_strings(fdt);
271         int len = strlen(s) + 1;                  271         int len = strlen(s) + 1;
272                                                   272 
273         fdt_set_size_dt_strings(fdt, strtabsiz    273         fdt_set_size_dt_strings(fdt, strtabsize - len);
274 }                                                 274 }
275                                                   275 
276 static int fdt_find_add_string_(void *fdt, con    276 static int fdt_find_add_string_(void *fdt, const char *s, int *allocated)
277 {                                                 277 {
278         char *strtab = (char *)fdt + fdt_total    278         char *strtab = (char *)fdt + fdt_totalsize(fdt);
279         int strtabsize = fdt_size_dt_strings(f    279         int strtabsize = fdt_size_dt_strings(fdt);
280         const char *p;                            280         const char *p;
281                                                   281 
282         *allocated = 0;                           282         *allocated = 0;
283                                                   283 
284         p = fdt_find_string_(strtab - strtabsi    284         p = fdt_find_string_(strtab - strtabsize, strtabsize, s);
285         if (p)                                    285         if (p)
286                 return p - strtab;                286                 return p - strtab;
287                                                   287 
288         *allocated = 1;                           288         *allocated = 1;
289                                                   289 
290         return fdt_add_string_(fdt, s);           290         return fdt_add_string_(fdt, s);
291 }                                                 291 }
292                                                   292 
293 int fdt_property_placeholder(void *fdt, const     293 int fdt_property_placeholder(void *fdt, const char *name, int len, void **valp)
294 {                                                 294 {
295         struct fdt_property *prop;                295         struct fdt_property *prop;
296         int nameoff;                              296         int nameoff;
297         int allocated;                            297         int allocated;
298                                                   298 
299         FDT_SW_PROBE_STRUCT(fdt);                 299         FDT_SW_PROBE_STRUCT(fdt);
300                                                   300 
301         /* String de-duplication can be slow,     301         /* String de-duplication can be slow, _NO_NAME_DEDUP skips it */
302         if (sw_flags(fdt) & FDT_CREATE_FLAG_NO    302         if (sw_flags(fdt) & FDT_CREATE_FLAG_NO_NAME_DEDUP) {
303                 allocated = 1;                    303                 allocated = 1;
304                 nameoff = fdt_add_string_(fdt,    304                 nameoff = fdt_add_string_(fdt, name);
305         } else {                                  305         } else {
306                 nameoff = fdt_find_add_string_    306                 nameoff = fdt_find_add_string_(fdt, name, &allocated);
307         }                                         307         }
308         if (nameoff == 0)                         308         if (nameoff == 0)
309                 return -FDT_ERR_NOSPACE;          309                 return -FDT_ERR_NOSPACE;
310                                                   310 
311         prop = fdt_grab_space_(fdt, sizeof(*pr    311         prop = fdt_grab_space_(fdt, sizeof(*prop) + FDT_TAGALIGN(len));
312         if (! prop) {                             312         if (! prop) {
313                 if (allocated)                    313                 if (allocated)
314                         fdt_del_last_string_(f    314                         fdt_del_last_string_(fdt, name);
315                 return -FDT_ERR_NOSPACE;          315                 return -FDT_ERR_NOSPACE;
316         }                                         316         }
317                                                   317 
318         prop->tag = cpu_to_fdt32(FDT_PROP);       318         prop->tag = cpu_to_fdt32(FDT_PROP);
319         prop->nameoff = cpu_to_fdt32(nameoff);    319         prop->nameoff = cpu_to_fdt32(nameoff);
320         prop->len = cpu_to_fdt32(len);            320         prop->len = cpu_to_fdt32(len);
321         *valp = prop->data;                       321         *valp = prop->data;
322         return 0;                                 322         return 0;
323 }                                                 323 }
324                                                   324 
325 int fdt_property(void *fdt, const char *name,     325 int fdt_property(void *fdt, const char *name, const void *val, int len)
326 {                                                 326 {
327         void *ptr;                                327         void *ptr;
328         int ret;                                  328         int ret;
329                                                   329 
330         ret = fdt_property_placeholder(fdt, na    330         ret = fdt_property_placeholder(fdt, name, len, &ptr);
331         if (ret)                                  331         if (ret)
332                 return ret;                       332                 return ret;
333         memcpy(ptr, val, len);                    333         memcpy(ptr, val, len);
334         return 0;                                 334         return 0;
335 }                                                 335 }
336                                                   336 
337 int fdt_finish(void *fdt)                         337 int fdt_finish(void *fdt)
338 {                                                 338 {
339         char *p = (char *)fdt;                    339         char *p = (char *)fdt;
340         fdt32_t *end;                             340         fdt32_t *end;
341         int oldstroffset, newstroffset;           341         int oldstroffset, newstroffset;
342         uint32_t tag;                             342         uint32_t tag;
343         int offset, nextoffset;                   343         int offset, nextoffset;
344                                                   344 
345         FDT_SW_PROBE_STRUCT(fdt);                 345         FDT_SW_PROBE_STRUCT(fdt);
346                                                   346 
347         /* Add terminator */                      347         /* Add terminator */
348         end = fdt_grab_space_(fdt, sizeof(*end    348         end = fdt_grab_space_(fdt, sizeof(*end));
349         if (! end)                                349         if (! end)
350                 return -FDT_ERR_NOSPACE;          350                 return -FDT_ERR_NOSPACE;
351         *end = cpu_to_fdt32(FDT_END);             351         *end = cpu_to_fdt32(FDT_END);
352                                                   352 
353         /* Relocate the string table */           353         /* Relocate the string table */
354         oldstroffset = fdt_totalsize(fdt) - fd    354         oldstroffset = fdt_totalsize(fdt) - fdt_size_dt_strings(fdt);
355         newstroffset = fdt_off_dt_struct(fdt)     355         newstroffset = fdt_off_dt_struct(fdt) + fdt_size_dt_struct(fdt);
356         memmove(p + newstroffset, p + oldstrof    356         memmove(p + newstroffset, p + oldstroffset, fdt_size_dt_strings(fdt));
357         fdt_set_off_dt_strings(fdt, newstroffs    357         fdt_set_off_dt_strings(fdt, newstroffset);
358                                                   358 
359         /* Walk the structure, correcting stri    359         /* Walk the structure, correcting string offsets */
360         offset = 0;                               360         offset = 0;
361         while ((tag = fdt_next_tag(fdt, offset    361         while ((tag = fdt_next_tag(fdt, offset, &nextoffset)) != FDT_END) {
362                 if (tag == FDT_PROP) {            362                 if (tag == FDT_PROP) {
363                         struct fdt_property *p    363                         struct fdt_property *prop =
364                                 fdt_offset_ptr    364                                 fdt_offset_ptr_w_(fdt, offset);
365                         int nameoff;              365                         int nameoff;
366                                                   366 
367                         nameoff = fdt32_to_cpu    367                         nameoff = fdt32_to_cpu(prop->nameoff);
368                         nameoff += fdt_size_dt    368                         nameoff += fdt_size_dt_strings(fdt);
369                         prop->nameoff = cpu_to    369                         prop->nameoff = cpu_to_fdt32(nameoff);
370                 }                                 370                 }
371                 offset = nextoffset;              371                 offset = nextoffset;
372         }                                         372         }
373         if (nextoffset < 0)                       373         if (nextoffset < 0)
374                 return nextoffset;                374                 return nextoffset;
375                                                   375 
376         /* Finally, adjust the header */          376         /* Finally, adjust the header */
377         fdt_set_totalsize(fdt, newstroffset +     377         fdt_set_totalsize(fdt, newstroffset + fdt_size_dt_strings(fdt));
378                                                   378 
379         /* And fix up fields that were keeping    379         /* And fix up fields that were keeping intermediate state. */
380         fdt_set_last_comp_version(fdt, FDT_LAS    380         fdt_set_last_comp_version(fdt, FDT_LAST_COMPATIBLE_VERSION);
381         fdt_set_magic(fdt, FDT_MAGIC);            381         fdt_set_magic(fdt, FDT_MAGIC);
382                                                   382 
383         return 0;                                 383         return 0;
384 }                                                 384 }
385                                                   385 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php