]>
Commit | Line | Data |
---|---|---|
1e57a462 | 1 | /*\r |
2 | * libfdt - Flat Device Tree manipulation\r | |
3 | * Copyright (C) 2006 David Gibson, IBM Corporation.\r | |
4 | *\r | |
5 | * libfdt is dual licensed: you can use it either under the terms of\r | |
6 | * the GPL, or the BSD license, at your option.\r | |
7 | *\r | |
8 | * a) This library is free software; you can redistribute it and/or\r | |
9 | * modify it under the terms of the GNU General Public License as\r | |
10 | * published by the Free Software Foundation; either version 2 of the\r | |
11 | * License, or (at your option) any later version.\r | |
12 | *\r | |
13 | * This library is distributed in the hope that it will be useful,\r | |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of\r | |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r | |
16 | * GNU General Public License for more details.\r | |
17 | *\r | |
18 | * You should have received a copy of the GNU General Public\r | |
19 | * License along with this library; if not, write to the Free\r | |
20 | * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,\r | |
21 | * MA 02110-1301 USA\r | |
22 | *\r | |
23 | * Alternatively,\r | |
24 | *\r | |
25 | * b) Redistribution and use in source and binary forms, with or\r | |
26 | * without modification, are permitted provided that the following\r | |
27 | * conditions are met:\r | |
28 | *\r | |
29 | * 1. Redistributions of source code must retain the above\r | |
30 | * copyright notice, this list of conditions and the following\r | |
31 | * disclaimer.\r | |
32 | * 2. Redistributions in binary form must reproduce the above\r | |
33 | * copyright notice, this list of conditions and the following\r | |
34 | * disclaimer in the documentation and/or other materials\r | |
35 | * provided with the distribution.\r | |
36 | *\r | |
37 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND\r | |
38 | * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,\r | |
39 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF\r | |
40 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE\r | |
41 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR\r | |
42 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\r | |
43 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\r | |
44 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\r | |
45 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r | |
46 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\r | |
47 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR\r | |
48 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,\r | |
49 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r | |
50 | */\r | |
51 | #include "libfdt_env.h"\r | |
52 | \r | |
53 | #include <fdt.h>\r | |
54 | #include <libfdt.h>\r | |
55 | \r | |
56 | #include "libfdt_internal.h"\r | |
57 | \r | |
e7108d0e MK |
58 | int\r |
59 | fdt_setprop_inplace_namelen_partial (\r | |
60 | void *fdt,\r | |
61 | int nodeoffset,\r | |
62 | const char *name,\r | |
63 | int namelen,\r | |
64 | uint32_t idx,\r | |
65 | const void *val,\r | |
66 | int len\r | |
67 | )\r | |
a0992390 | 68 | {\r |
e7108d0e MK |
69 | void *propval;\r |
70 | int proplen;\r | |
71 | \r | |
72 | propval = fdt_getprop_namelen_w (\r | |
73 | fdt,\r | |
74 | nodeoffset,\r | |
75 | name,\r | |
76 | namelen,\r | |
77 | &proplen\r | |
78 | );\r | |
79 | if (!propval) {\r | |
80 | return proplen;\r | |
81 | }\r | |
82 | \r | |
83 | if (proplen < (len + idx)) {\r | |
84 | return -FDT_ERR_NOSPACE;\r | |
85 | }\r | |
86 | \r | |
87 | memcpy ((char *)propval + idx, val, len);\r | |
88 | return 0;\r | |
a0992390 PB |
89 | }\r |
90 | \r | |
e7108d0e MK |
91 | int\r |
92 | fdt_setprop_inplace (\r | |
93 | void *fdt,\r | |
94 | int nodeoffset,\r | |
95 | const char *name,\r | |
96 | const void *val,\r | |
97 | int len\r | |
98 | )\r | |
1e57a462 | 99 | {\r |
e7108d0e MK |
100 | const void *propval;\r |
101 | int proplen;\r | |
102 | \r | |
103 | propval = fdt_getprop (fdt, nodeoffset, name, &proplen);\r | |
104 | if (!propval) {\r | |
105 | return proplen;\r | |
106 | }\r | |
107 | \r | |
108 | if (proplen != len) {\r | |
109 | return -FDT_ERR_NOSPACE;\r | |
110 | }\r | |
111 | \r | |
112 | return fdt_setprop_inplace_namelen_partial (\r | |
113 | fdt,\r | |
114 | nodeoffset,\r | |
115 | name,\r | |
116 | strlen (name),\r | |
117 | 0,\r | |
118 | val,\r | |
119 | len\r | |
120 | );\r | |
1e57a462 | 121 | }\r |
122 | \r | |
e7108d0e MK |
123 | static void\r |
124 | _fdt_nop_region (\r | |
125 | void *start,\r | |
126 | int len\r | |
127 | )\r | |
1e57a462 | 128 | {\r |
e7108d0e | 129 | fdt32_t *p;\r |
1e57a462 | 130 | \r |
e7108d0e MK |
131 | for (p = start; (char *)p < ((char *)start + len); p++) {\r |
132 | *p = cpu_to_fdt32 (FDT_NOP);\r | |
133 | }\r | |
1e57a462 | 134 | }\r |
135 | \r | |
e7108d0e MK |
136 | int\r |
137 | fdt_nop_property (\r | |
138 | void *fdt,\r | |
139 | int nodeoffset,\r | |
140 | const char *name\r | |
141 | )\r | |
1e57a462 | 142 | {\r |
e7108d0e MK |
143 | struct fdt_property *prop;\r |
144 | int len;\r | |
1e57a462 | 145 | \r |
e7108d0e MK |
146 | prop = fdt_get_property_w (fdt, nodeoffset, name, &len);\r |
147 | if (!prop) {\r | |
148 | return len;\r | |
149 | }\r | |
1e57a462 | 150 | \r |
e7108d0e | 151 | _fdt_nop_region (prop, len + sizeof (*prop));\r |
1e57a462 | 152 | \r |
e7108d0e | 153 | return 0;\r |
1e57a462 | 154 | }\r |
155 | \r | |
e7108d0e MK |
156 | int\r |
157 | _fdt_node_end_offset (\r | |
158 | void *fdt,\r | |
159 | int offset\r | |
160 | )\r | |
1e57a462 | 161 | {\r |
e7108d0e | 162 | int depth = 0;\r |
1e57a462 | 163 | \r |
e7108d0e MK |
164 | while ((offset >= 0) && (depth >= 0)) {\r |
165 | offset = fdt_next_node (fdt, offset, &depth);\r | |
166 | }\r | |
1e57a462 | 167 | \r |
e7108d0e | 168 | return offset;\r |
1e57a462 | 169 | }\r |
170 | \r | |
e7108d0e MK |
171 | int\r |
172 | fdt_nop_node (\r | |
173 | void *fdt,\r | |
174 | int nodeoffset\r | |
175 | )\r | |
1e57a462 | 176 | {\r |
e7108d0e MK |
177 | int endoffset;\r |
178 | \r | |
179 | endoffset = _fdt_node_end_offset (fdt, nodeoffset);\r | |
180 | if (endoffset < 0) {\r | |
181 | return endoffset;\r | |
182 | }\r | |
183 | \r | |
184 | _fdt_nop_region (\r | |
185 | fdt_offset_ptr_w (fdt, nodeoffset, 0),\r | |
186 | endoffset - nodeoffset\r | |
187 | );\r | |
188 | return 0;\r | |
1e57a462 | 189 | }\r |