blob: 3d41c4434bb385b9b7bcdf4a504b110ab74386d0 [file] [log] [blame]
aurel32f652e6a2008-12-16 10:43:48 +00001/*
2 * Functions to help device tree manipulation using libfdt.
3 * It also provides functions to read entries from device tree proc
4 * interface.
5 *
6 * Copyright 2008 IBM Corporation.
7 * Authors: Jerone Young <jyoung5@us.ibm.com>
8 * Hollis Blanchard <hollisb@us.ibm.com>
9 *
10 * This work is licensed under the GNU GPL license version 2 or later.
11 *
12 */
13
Peter Maydelld38ea872016-01-29 17:50:05 +000014#include "qemu/osdep.h"
aurel32f652e6a2008-12-16 10:43:48 +000015
Eric Auger60e43e92016-02-19 09:42:29 -070016#ifdef CONFIG_LINUX
17#include <dirent.h>
18#endif
19
aurel32f652e6a2008-12-16 10:43:48 +000020#include "qemu-common.h"
Li Liudb013f82014-08-26 14:38:02 +080021#include "qemu/error-report.h"
Paolo Bonzini9c17d612012-12-17 18:20:04 +010022#include "sysemu/device_tree.h"
Markus Armbruster2ff3de62013-07-04 15:09:22 +020023#include "sysemu/sysemu.h"
Blue Swirl39b7f202009-09-22 17:51:36 +000024#include "hw/loader.h"
Marcel Apfelbaum6cabe7f2015-02-04 17:43:53 +020025#include "hw/boards.h"
Paolo Bonzini1de7afc2012-12-17 18:20:00 +010026#include "qemu/config-file.h"
aurel32f652e6a2008-12-16 10:43:48 +000027
28#include <libfdt.h>
29
Alexander Grafce362522012-05-17 15:33:54 +020030#define FDT_MAX_SIZE 0x10000
31
32void *create_device_tree(int *sizep)
33{
34 void *fdt;
35 int ret;
36
37 *sizep = FDT_MAX_SIZE;
38 fdt = g_malloc0(FDT_MAX_SIZE);
39 ret = fdt_create(fdt, FDT_MAX_SIZE);
40 if (ret < 0) {
41 goto fail;
42 }
Peter Maydellef6de702013-11-22 17:17:09 +000043 ret = fdt_finish_reservemap(fdt);
44 if (ret < 0) {
45 goto fail;
46 }
Alexander Grafce362522012-05-17 15:33:54 +020047 ret = fdt_begin_node(fdt, "");
48 if (ret < 0) {
49 goto fail;
50 }
51 ret = fdt_end_node(fdt);
52 if (ret < 0) {
53 goto fail;
54 }
55 ret = fdt_finish(fdt);
56 if (ret < 0) {
57 goto fail;
58 }
59 ret = fdt_open_into(fdt, fdt, *sizep);
60 if (ret) {
Li Liu508e2212014-08-26 14:38:03 +080061 error_report("Unable to copy device tree in memory");
Alexander Grafce362522012-05-17 15:33:54 +020062 exit(1);
63 }
64
65 return fdt;
66fail:
Li Liu508e2212014-08-26 14:38:03 +080067 error_report("%s Couldn't create dt: %s", __func__, fdt_strerror(ret));
Alexander Grafce362522012-05-17 15:33:54 +020068 exit(1);
69}
70
pbrook7ec632b2009-04-10 16:23:59 +000071void *load_device_tree(const char *filename_path, int *sizep)
aurel32f652e6a2008-12-16 10:43:48 +000072{
pbrook7ec632b2009-04-10 16:23:59 +000073 int dt_size;
aurel32f652e6a2008-12-16 10:43:48 +000074 int dt_file_load_size;
aurel32f652e6a2008-12-16 10:43:48 +000075 int ret;
pbrook7ec632b2009-04-10 16:23:59 +000076 void *fdt = NULL;
aurel32f652e6a2008-12-16 10:43:48 +000077
pbrook7ec632b2009-04-10 16:23:59 +000078 *sizep = 0;
79 dt_size = get_image_size(filename_path);
80 if (dt_size < 0) {
Li Liudb013f82014-08-26 14:38:02 +080081 error_report("Unable to get size of device tree file '%s'",
82 filename_path);
aurel32f652e6a2008-12-16 10:43:48 +000083 goto fail;
84 }
85
pbrook7ec632b2009-04-10 16:23:59 +000086 /* Expand to 2x size to give enough room for manipulation. */
Alexander Grafded57c52011-07-23 10:54:11 +020087 dt_size += 10000;
pbrook7ec632b2009-04-10 16:23:59 +000088 dt_size *= 2;
aurel32f652e6a2008-12-16 10:43:48 +000089 /* First allocate space in qemu for device tree */
Anthony Liguori7267c092011-08-20 22:09:37 -050090 fdt = g_malloc0(dt_size);
aurel32f652e6a2008-12-16 10:43:48 +000091
pbrook7ec632b2009-04-10 16:23:59 +000092 dt_file_load_size = load_image(filename_path, fdt);
93 if (dt_file_load_size < 0) {
Li Liudb013f82014-08-26 14:38:02 +080094 error_report("Unable to open device tree file '%s'",
95 filename_path);
pbrook7ec632b2009-04-10 16:23:59 +000096 goto fail;
97 }
aurel32f652e6a2008-12-16 10:43:48 +000098
pbrook7ec632b2009-04-10 16:23:59 +000099 ret = fdt_open_into(fdt, fdt, dt_size);
aurel32f652e6a2008-12-16 10:43:48 +0000100 if (ret) {
Li Liudb013f82014-08-26 14:38:02 +0800101 error_report("Unable to copy device tree in memory");
aurel32f652e6a2008-12-16 10:43:48 +0000102 goto fail;
103 }
104
105 /* Check sanity of device tree */
106 if (fdt_check_header(fdt)) {
Li Liudb013f82014-08-26 14:38:02 +0800107 error_report("Device tree file loaded into memory is invalid: %s",
108 filename_path);
aurel32f652e6a2008-12-16 10:43:48 +0000109 goto fail;
110 }
pbrook7ec632b2009-04-10 16:23:59 +0000111 *sizep = dt_size;
aurel32f652e6a2008-12-16 10:43:48 +0000112 return fdt;
113
114fail:
Anthony Liguori7267c092011-08-20 22:09:37 -0500115 g_free(fdt);
aurel32f652e6a2008-12-16 10:43:48 +0000116 return NULL;
117}
118
Eric Auger60e43e92016-02-19 09:42:29 -0700119#ifdef CONFIG_LINUX
120
121#define SYSFS_DT_BASEDIR "/proc/device-tree"
122
123/**
124 * read_fstree: this function is inspired from dtc read_fstree
125 * @fdt: preallocated fdt blob buffer, to be populated
126 * @dirname: directory to scan under SYSFS_DT_BASEDIR
127 * the search is recursive and the tree is searched down to the
128 * leaves (property files).
129 *
130 * the function asserts in case of error
131 */
132static void read_fstree(void *fdt, const char *dirname)
133{
134 DIR *d;
135 struct dirent *de;
136 struct stat st;
137 const char *root_dir = SYSFS_DT_BASEDIR;
138 const char *parent_node;
139
140 if (strstr(dirname, root_dir) != dirname) {
141 error_setg(&error_fatal, "%s: %s must be searched within %s",
142 __func__, dirname, root_dir);
143 }
144 parent_node = &dirname[strlen(SYSFS_DT_BASEDIR)];
145
146 d = opendir(dirname);
147 if (!d) {
148 error_setg(&error_fatal, "%s cannot open %s", __func__, dirname);
149 }
150
151 while ((de = readdir(d)) != NULL) {
152 char *tmpnam;
153
154 if (!g_strcmp0(de->d_name, ".")
155 || !g_strcmp0(de->d_name, "..")) {
156 continue;
157 }
158
159 tmpnam = g_strdup_printf("%s/%s", dirname, de->d_name);
160
161 if (lstat(tmpnam, &st) < 0) {
162 error_setg(&error_fatal, "%s cannot lstat %s", __func__, tmpnam);
163 }
164
165 if (S_ISREG(st.st_mode)) {
166 gchar *val;
167 gsize len;
168
169 if (!g_file_get_contents(tmpnam, &val, &len, NULL)) {
170 error_setg(&error_fatal, "%s not able to extract info from %s",
171 __func__, tmpnam);
172 }
173
174 if (strlen(parent_node) > 0) {
175 qemu_fdt_setprop(fdt, parent_node,
176 de->d_name, val, len);
177 } else {
178 qemu_fdt_setprop(fdt, "/", de->d_name, val, len);
179 }
180 g_free(val);
181 } else if (S_ISDIR(st.st_mode)) {
182 char *node_name;
183
184 node_name = g_strdup_printf("%s/%s",
185 parent_node, de->d_name);
186 qemu_fdt_add_subnode(fdt, node_name);
187 g_free(node_name);
188 read_fstree(fdt, tmpnam);
189 }
190
191 g_free(tmpnam);
192 }
193
194 closedir(d);
195}
196
197/* load_device_tree_from_sysfs: extract the dt blob from host sysfs */
198void *load_device_tree_from_sysfs(void)
199{
200 void *host_fdt;
201 int host_fdt_size;
202
203 host_fdt = create_device_tree(&host_fdt_size);
204 read_fstree(host_fdt, SYSFS_DT_BASEDIR);
205 if (fdt_check_header(host_fdt)) {
206 error_setg(&error_fatal,
207 "%s host device tree extracted into memory is invalid",
208 __func__);
209 }
210 return host_fdt;
211}
212
213#endif /* CONFIG_LINUX */
214
Alexander Grafccbcfed2011-07-23 10:52:00 +0200215static int findnode_nofail(void *fdt, const char *node_path)
aurel32f652e6a2008-12-16 10:43:48 +0000216{
217 int offset;
218
219 offset = fdt_path_offset(fdt, node_path);
Alexander Grafccbcfed2011-07-23 10:52:00 +0200220 if (offset < 0) {
Li Liu508e2212014-08-26 14:38:03 +0800221 error_report("%s Couldn't find node %s: %s", __func__, node_path,
222 fdt_strerror(offset));
Alexander Grafccbcfed2011-07-23 10:52:00 +0200223 exit(1);
224 }
aurel32f652e6a2008-12-16 10:43:48 +0000225
Alexander Grafccbcfed2011-07-23 10:52:00 +0200226 return offset;
227}
228
Eric Auger6d795662016-02-19 09:42:30 -0700229char **qemu_fdt_node_path(void *fdt, const char *name, char *compat,
230 Error **errp)
231{
232 int offset, len, ret;
233 const char *iter_name;
234 unsigned int path_len = 16, n = 0;
235 GSList *path_list = NULL, *iter;
236 char **path_array;
237
238 offset = fdt_node_offset_by_compatible(fdt, -1, compat);
239
240 while (offset >= 0) {
241 iter_name = fdt_get_name(fdt, offset, &len);
242 if (!iter_name) {
243 offset = len;
244 break;
245 }
246 if (!strcmp(iter_name, name)) {
247 char *path;
248
249 path = g_malloc(path_len);
250 while ((ret = fdt_get_path(fdt, offset, path, path_len))
251 == -FDT_ERR_NOSPACE) {
252 path_len += 16;
253 path = g_realloc(path, path_len);
254 }
255 path_list = g_slist_prepend(path_list, path);
256 n++;
257 }
258 offset = fdt_node_offset_by_compatible(fdt, offset, compat);
259 }
260
261 if (offset < 0 && offset != -FDT_ERR_NOTFOUND) {
262 error_setg(errp, "%s: abort parsing dt for %s/%s: %s",
263 __func__, name, compat, fdt_strerror(offset));
264 for (iter = path_list; iter; iter = iter->next) {
265 g_free(iter->data);
266 }
267 g_slist_free(path_list);
268 return NULL;
269 }
270
271 path_array = g_new(char *, n + 1);
272 path_array[n--] = NULL;
273
274 for (iter = path_list; iter; iter = iter->next) {
275 path_array[n--] = iter->data;
276 }
277
278 g_slist_free(path_list);
279
280 return path_array;
281}
282
Peter Crosthwaite5a4348d2013-11-11 18:14:41 +1000283int qemu_fdt_setprop(void *fdt, const char *node_path,
Peter Crosthwaitebe5907f2013-11-11 18:15:21 +1000284 const char *property, const void *val, int size)
Alexander Grafccbcfed2011-07-23 10:52:00 +0200285{
286 int r;
287
Peter Crosthwaitebe5907f2013-11-11 18:15:21 +1000288 r = fdt_setprop(fdt, findnode_nofail(fdt, node_path), property, val, size);
Alexander Grafccbcfed2011-07-23 10:52:00 +0200289 if (r < 0) {
Li Liu508e2212014-08-26 14:38:03 +0800290 error_report("%s: Couldn't set %s/%s: %s", __func__, node_path,
291 property, fdt_strerror(r));
Alexander Grafccbcfed2011-07-23 10:52:00 +0200292 exit(1);
293 }
294
295 return r;
aurel32f652e6a2008-12-16 10:43:48 +0000296}
297
Peter Crosthwaite5a4348d2013-11-11 18:14:41 +1000298int qemu_fdt_setprop_cell(void *fdt, const char *node_path,
299 const char *property, uint32_t val)
aurel32f652e6a2008-12-16 10:43:48 +0000300{
Alexander Grafccbcfed2011-07-23 10:52:00 +0200301 int r;
aurel32f652e6a2008-12-16 10:43:48 +0000302
Alexander Grafccbcfed2011-07-23 10:52:00 +0200303 r = fdt_setprop_cell(fdt, findnode_nofail(fdt, node_path), property, val);
304 if (r < 0) {
Li Liu508e2212014-08-26 14:38:03 +0800305 error_report("%s: Couldn't set %s/%s = %#08x: %s", __func__,
306 node_path, property, val, fdt_strerror(r));
Alexander Grafccbcfed2011-07-23 10:52:00 +0200307 exit(1);
308 }
aurel32f652e6a2008-12-16 10:43:48 +0000309
Alexander Grafccbcfed2011-07-23 10:52:00 +0200310 return r;
aurel32f652e6a2008-12-16 10:43:48 +0000311}
312
Peter Crosthwaite5a4348d2013-11-11 18:14:41 +1000313int qemu_fdt_setprop_u64(void *fdt, const char *node_path,
314 const char *property, uint64_t val)
Alexander Grafbb28eb32012-05-18 01:53:01 +0200315{
316 val = cpu_to_be64(val);
Peter Crosthwaite5a4348d2013-11-11 18:14:41 +1000317 return qemu_fdt_setprop(fdt, node_path, property, &val, sizeof(val));
Alexander Grafbb28eb32012-05-18 01:53:01 +0200318}
319
Peter Crosthwaite5a4348d2013-11-11 18:14:41 +1000320int qemu_fdt_setprop_string(void *fdt, const char *node_path,
321 const char *property, const char *string)
aurel32f652e6a2008-12-16 10:43:48 +0000322{
Alexander Grafccbcfed2011-07-23 10:52:00 +0200323 int r;
aurel32f652e6a2008-12-16 10:43:48 +0000324
Alexander Grafccbcfed2011-07-23 10:52:00 +0200325 r = fdt_setprop_string(fdt, findnode_nofail(fdt, node_path), property, string);
326 if (r < 0) {
Li Liu508e2212014-08-26 14:38:03 +0800327 error_report("%s: Couldn't set %s/%s = %s: %s", __func__,
328 node_path, property, string, fdt_strerror(r));
Alexander Grafccbcfed2011-07-23 10:52:00 +0200329 exit(1);
330 }
aurel32f652e6a2008-12-16 10:43:48 +0000331
Alexander Grafccbcfed2011-07-23 10:52:00 +0200332 return r;
aurel32f652e6a2008-12-16 10:43:48 +0000333}
Alexander Grafd69a8e62011-07-21 01:52:57 +0200334
Peter Crosthwaite5a4348d2013-11-11 18:14:41 +1000335const void *qemu_fdt_getprop(void *fdt, const char *node_path,
Eric Auger78e24f22016-02-19 09:42:30 -0700336 const char *property, int *lenp, Error **errp)
Peter Maydellf0aa7132012-07-20 13:34:50 +0100337{
338 int len;
339 const void *r;
Eric Auger78e24f22016-02-19 09:42:30 -0700340
Peter Maydellf0aa7132012-07-20 13:34:50 +0100341 if (!lenp) {
342 lenp = &len;
343 }
344 r = fdt_getprop(fdt, findnode_nofail(fdt, node_path), property, lenp);
345 if (!r) {
Eric Auger78e24f22016-02-19 09:42:30 -0700346 error_setg(errp, "%s: Couldn't get %s/%s: %s", __func__,
347 node_path, property, fdt_strerror(*lenp));
Peter Maydellf0aa7132012-07-20 13:34:50 +0100348 }
349 return r;
350}
351
Peter Crosthwaite5a4348d2013-11-11 18:14:41 +1000352uint32_t qemu_fdt_getprop_cell(void *fdt, const char *node_path,
353 const char *property)
Peter Maydellf0aa7132012-07-20 13:34:50 +0100354{
355 int len;
Eric Auger78e24f22016-02-19 09:42:30 -0700356 const uint32_t *p = qemu_fdt_getprop(fdt, node_path, property, &len,
357 &error_fatal);
Peter Maydellf0aa7132012-07-20 13:34:50 +0100358 if (len != 4) {
Li Liu508e2212014-08-26 14:38:03 +0800359 error_report("%s: %s/%s not 4 bytes long (not a cell?)",
360 __func__, node_path, property);
Peter Maydellf0aa7132012-07-20 13:34:50 +0100361 exit(1);
362 }
363 return be32_to_cpu(*p);
364}
365
Peter Crosthwaite5a4348d2013-11-11 18:14:41 +1000366uint32_t qemu_fdt_get_phandle(void *fdt, const char *path)
Alexander Graf7d5fd102012-05-17 15:23:39 +0200367{
368 uint32_t r;
369
370 r = fdt_get_phandle(fdt, findnode_nofail(fdt, path));
Stefan Weil909a1962013-06-10 22:12:25 +0200371 if (r == 0) {
Li Liu508e2212014-08-26 14:38:03 +0800372 error_report("%s: Couldn't get phandle for %s: %s", __func__,
373 path, fdt_strerror(r));
Alexander Graf7d5fd102012-05-17 15:23:39 +0200374 exit(1);
375 }
376
377 return r;
378}
379
Peter Crosthwaite5a4348d2013-11-11 18:14:41 +1000380int qemu_fdt_setprop_phandle(void *fdt, const char *node_path,
381 const char *property,
382 const char *target_node_path)
Alexander Graf8535ab12012-05-17 14:11:52 +0200383{
Peter Crosthwaite5a4348d2013-11-11 18:14:41 +1000384 uint32_t phandle = qemu_fdt_get_phandle(fdt, target_node_path);
385 return qemu_fdt_setprop_cell(fdt, node_path, property, phandle);
Alexander Graf8535ab12012-05-17 14:11:52 +0200386}
387
Peter Crosthwaite5a4348d2013-11-11 18:14:41 +1000388uint32_t qemu_fdt_alloc_phandle(void *fdt)
Alexander Graf3601b572012-05-17 16:58:55 +0200389{
Alexander Graf4b1b1c82012-06-06 01:01:23 +0200390 static int phandle = 0x0;
391
392 /*
393 * We need to find out if the user gave us special instruction at
Kamalesh Babulalcc47a162015-07-24 13:48:13 +0530394 * which phandle id to start allocating phandles.
Alexander Graf4b1b1c82012-06-06 01:01:23 +0200395 */
396 if (!phandle) {
Marcel Apfelbaum6cabe7f2015-02-04 17:43:53 +0200397 phandle = machine_phandle_start(current_machine);
Alexander Graf4b1b1c82012-06-06 01:01:23 +0200398 }
399
400 if (!phandle) {
401 /*
402 * None or invalid phandle given on the command line, so fall back to
403 * default starting point.
404 */
405 phandle = 0x8000;
406 }
Alexander Graf3601b572012-05-17 16:58:55 +0200407
408 return phandle++;
409}
410
Peter Crosthwaite5a4348d2013-11-11 18:14:41 +1000411int qemu_fdt_nop_node(void *fdt, const char *node_path)
Alexander Grafd69a8e62011-07-21 01:52:57 +0200412{
Alexander Grafccbcfed2011-07-23 10:52:00 +0200413 int r;
Alexander Grafd69a8e62011-07-21 01:52:57 +0200414
Alexander Grafccbcfed2011-07-23 10:52:00 +0200415 r = fdt_nop_node(fdt, findnode_nofail(fdt, node_path));
416 if (r < 0) {
Li Liu508e2212014-08-26 14:38:03 +0800417 error_report("%s: Couldn't nop node %s: %s", __func__, node_path,
418 fdt_strerror(r));
Alexander Grafccbcfed2011-07-23 10:52:00 +0200419 exit(1);
420 }
Alexander Grafd69a8e62011-07-21 01:52:57 +0200421
Alexander Grafccbcfed2011-07-23 10:52:00 +0200422 return r;
Alexander Grafd69a8e62011-07-21 01:52:57 +0200423}
Alexander Graf80ad7812011-07-22 13:55:37 +0200424
Peter Crosthwaite5a4348d2013-11-11 18:14:41 +1000425int qemu_fdt_add_subnode(void *fdt, const char *name)
Alexander Graf80ad7812011-07-22 13:55:37 +0200426{
Alexander Graf80ad7812011-07-22 13:55:37 +0200427 char *dupname = g_strdup(name);
428 char *basename = strrchr(dupname, '/');
429 int retval;
Alexander Grafc640d082012-05-17 11:40:42 +0200430 int parent = 0;
Alexander Graf80ad7812011-07-22 13:55:37 +0200431
432 if (!basename) {
Stefan Weilbff39b62011-10-17 22:12:09 +0200433 g_free(dupname);
Alexander Graf80ad7812011-07-22 13:55:37 +0200434 return -1;
435 }
436
437 basename[0] = '\0';
438 basename++;
439
Alexander Grafc640d082012-05-17 11:40:42 +0200440 if (dupname[0]) {
441 parent = findnode_nofail(fdt, dupname);
442 }
443
444 retval = fdt_add_subnode(fdt, parent, basename);
Alexander Grafccbcfed2011-07-23 10:52:00 +0200445 if (retval < 0) {
Li Liu508e2212014-08-26 14:38:03 +0800446 error_report("FDT: Failed to create subnode %s: %s", name,
447 fdt_strerror(retval));
Alexander Grafccbcfed2011-07-23 10:52:00 +0200448 exit(1);
Alexander Graf80ad7812011-07-22 13:55:37 +0200449 }
450
Alexander Graf80ad7812011-07-22 13:55:37 +0200451 g_free(dupname);
452 return retval;
453}
Alexander Graf71193432012-09-23 08:37:59 +0200454
Peter Crosthwaite5a4348d2013-11-11 18:14:41 +1000455void qemu_fdt_dumpdtb(void *fdt, int size)
Alexander Graf71193432012-09-23 08:37:59 +0200456{
Markus Armbruster2ff3de62013-07-04 15:09:22 +0200457 const char *dumpdtb = qemu_opt_get(qemu_get_machine_opts(), "dumpdtb");
Alexander Graf71193432012-09-23 08:37:59 +0200458
Markus Armbruster2ff3de62013-07-04 15:09:22 +0200459 if (dumpdtb) {
460 /* Dump the dtb to a file and quit */
461 exit(g_file_set_contents(dumpdtb, fdt, size, NULL) ? 0 : 1);
Alexander Graf71193432012-09-23 08:37:59 +0200462 }
Alexander Graf71193432012-09-23 08:37:59 +0200463}
Peter Maydell97c38f82013-07-16 13:25:05 +0100464
Peter Crosthwaite5a4348d2013-11-11 18:14:41 +1000465int qemu_fdt_setprop_sized_cells_from_array(void *fdt,
466 const char *node_path,
467 const char *property,
468 int numvalues,
469 uint64_t *values)
Peter Maydell97c38f82013-07-16 13:25:05 +0100470{
471 uint32_t *propcells;
472 uint64_t value;
473 int cellnum, vnum, ncells;
474 uint32_t hival;
Sergey Fedorov2bf9feb2014-12-11 18:45:05 +0300475 int ret;
Peter Maydell97c38f82013-07-16 13:25:05 +0100476
477 propcells = g_new0(uint32_t, numvalues * 2);
478
479 cellnum = 0;
480 for (vnum = 0; vnum < numvalues; vnum++) {
481 ncells = values[vnum * 2];
482 if (ncells != 1 && ncells != 2) {
Sergey Fedorov2bf9feb2014-12-11 18:45:05 +0300483 ret = -1;
484 goto out;
Peter Maydell97c38f82013-07-16 13:25:05 +0100485 }
486 value = values[vnum * 2 + 1];
487 hival = cpu_to_be32(value >> 32);
488 if (ncells > 1) {
489 propcells[cellnum++] = hival;
490 } else if (hival != 0) {
Sergey Fedorov2bf9feb2014-12-11 18:45:05 +0300491 ret = -1;
492 goto out;
Peter Maydell97c38f82013-07-16 13:25:05 +0100493 }
494 propcells[cellnum++] = cpu_to_be32(value);
495 }
496
Sergey Fedorov2bf9feb2014-12-11 18:45:05 +0300497 ret = qemu_fdt_setprop(fdt, node_path, property, propcells,
498 cellnum * sizeof(uint32_t));
499out:
500 g_free(propcells);
501 return ret;
Peter Maydell97c38f82013-07-16 13:25:05 +0100502}