]>
git.proxmox.com Git - qemu.git/blob - device_tree.c
2 * Functions to help device tree manipulation using libfdt.
3 * It also provides functions to read entries from device tree proc
6 * Copyright 2008 IBM Corporation.
7 * Authors: Jerone Young <jyoung5@us.ibm.com>
8 * Hollis Blanchard <hollisb@us.ibm.com>
10 * This work is licensed under the GNU GPL license version 2 or later.
15 #include <sys/types.h>
22 #include "qemu-common.h"
24 #include "device_tree.h"
28 void *load_device_tree(const char *filename_path
, int *sizep
)
31 int dt_file_load_size
;
36 dt_size
= get_image_size(filename_path
);
38 printf("Unable to get size of device tree file '%s'\n",
43 /* Expand to 2x size to give enough room for manipulation. */
45 /* First allocate space in qemu for device tree */
46 fdt
= qemu_mallocz(dt_size
);
48 dt_file_load_size
= load_image(filename_path
, fdt
);
49 if (dt_file_load_size
< 0) {
50 printf("Unable to open device tree file '%s'\n",
55 ret
= fdt_open_into(fdt
, fdt
, dt_size
);
57 printf("Unable to copy device tree in memory\n");
61 /* Check sanity of device tree */
62 if (fdt_check_header(fdt
)) {
63 printf ("Device tree file loaded into memory is invalid: %s\n",
75 int qemu_devtree_setprop(void *fdt
, const char *node_path
,
76 const char *property
, uint32_t *val_array
, int size
)
80 offset
= fdt_path_offset(fdt
, node_path
);
84 return fdt_setprop(fdt
, offset
, property
, val_array
, size
);
87 int qemu_devtree_setprop_cell(void *fdt
, const char *node_path
,
88 const char *property
, uint32_t val
)
92 offset
= fdt_path_offset(fdt
, node_path
);
96 return fdt_setprop_cell(fdt
, offset
, property
, val
);
99 int qemu_devtree_setprop_string(void *fdt
, const char *node_path
,
100 const char *property
, const char *string
)
104 offset
= fdt_path_offset(fdt
, node_path
);
108 return fdt_setprop_string(fdt
, offset
, property
, string
);