Skip to content

Commit

Permalink
dt: add helper for empty dt creation
Browse files Browse the repository at this point in the history
We want to get rid of the concept of loading an external device tree and instead
generate our own. However, to do this we need to also create a device tree
template programatically.

This patch adds a helper to create an empty device tree in memory.

Signed-off-by: Alexander Graf <[email protected]>
Reviewed-by: Peter Crosthwaite <[email protected]>
  • Loading branch information
agraf committed Jun 23, 2012
1 parent 7d5fd10 commit ce36252
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
37 changes: 37 additions & 0 deletions device_tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,43 @@

#include <libfdt.h>

#define FDT_MAX_SIZE 0x10000

void *create_device_tree(int *sizep)
{
void *fdt;
int ret;

*sizep = FDT_MAX_SIZE;
fdt = g_malloc0(FDT_MAX_SIZE);
ret = fdt_create(fdt, FDT_MAX_SIZE);
if (ret < 0) {
goto fail;
}
ret = fdt_begin_node(fdt, "");
if (ret < 0) {
goto fail;
}
ret = fdt_end_node(fdt);
if (ret < 0) {
goto fail;
}
ret = fdt_finish(fdt);
if (ret < 0) {
goto fail;
}
ret = fdt_open_into(fdt, fdt, *sizep);
if (ret) {
fprintf(stderr, "Unable to copy device tree in memory\n");
exit(1);
}

return fdt;
fail:
fprintf(stderr, "%s Couldn't create dt: %s\n", __func__, fdt_strerror(ret));
exit(1);
}

void *load_device_tree(const char *filename_path, int *sizep)
{
int dt_size;
Expand Down
1 change: 1 addition & 0 deletions device_tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#ifndef __DEVICE_TREE_H__
#define __DEVICE_TREE_H__

void *create_device_tree(int *sizep);
void *load_device_tree(const char *filename_path, int *sizep);

int qemu_devtree_setprop(void *fdt, const char *node_path,
Expand Down

0 comments on commit ce36252

Please sign in to comment.