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, void *load_addr)
31
int dt_file_load_size;
37
dt_file_size = get_image_size(filename_path);
38
if (dt_file_size < 0) {
39
printf("Unable to get size of device tree file '%s'\n",
44
/* First allocate space in qemu for device tree */
45
dt_file = qemu_mallocz(dt_file_size);
47
dt_file_load_size = load_image(filename_path, dt_file);
49
/* Second we place new copy of 2x size in guest memory
50
* This give us enough room for manipulation.
52
new_dt_size = dt_file_size * 2;
55
ret = fdt_open_into(dt_file, fdt, new_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",
67
/* free qemu memory with old device tree */
76
int qemu_devtree_setprop(void *fdt, const char *node_path,
77
const char *property, uint32_t *val_array, int size)
81
offset = fdt_path_offset(fdt, node_path);
85
return fdt_setprop(fdt, offset, property, val_array, size);
88
int qemu_devtree_setprop_cell(void *fdt, const char *node_path,
89
const char *property, uint32_t val)
93
offset = fdt_path_offset(fdt, node_path);
97
return fdt_setprop_cell(fdt, offset, property, val);
100
int qemu_devtree_setprop_string(void *fdt, const char *node_path,
101
const char *property, const char *string)
105
offset = fdt_path_offset(fdt, node_path);
109
return fdt_setprop_string(fdt, offset, property, string);