diff mbox

[v2,1/2] fdt: additions required for arm64 Linux loader

Message ID 1387486735-13461-1-git-send-email-leif.lindholm@linaro.org
State New
Headers show

Commit Message

Leif Lindholm Dec. 19, 2013, 8:58 p.m. UTC
- Add grub_fdt_create_empty_tree() function.
- Add 64-bit setprop.
---
 grub-core/lib/fdt.c |   29 +++++++++++++++++++++++++++++
 include/grub/fdt.h  |   20 ++++++++++++++++++++
 2 files changed, 49 insertions(+)
diff mbox

Patch

diff --git a/grub-core/lib/fdt.c b/grub-core/lib/fdt.c
index 9f34dc7..57d6f30 100644
--- a/grub-core/lib/fdt.c
+++ b/grub-core/lib/fdt.c
@@ -423,3 +423,32 @@  int grub_fdt_set_prop (void *fdt, unsigned int nodeoffset, const char *name,
   grub_memcpy (prop + 3, val, len);
   return 0;
 }
+
+int
+grub_fdt_create_empty_tree (void *fdt, unsigned int size)
+{
+  struct grub_fdt_empty_tree *et;
+
+  if (size < GRUB_FDT_EMPTY_TREE_SZ)
+    return -1;
+
+  grub_memset (fdt, 0, size);
+  et = fdt;
+
+  et->empty_node.tree_end = grub_cpu_to_be32_compile_time (FDT_END);
+  et->empty_node.node_end = grub_cpu_to_be32_compile_time (FDT_END_NODE);
+  et->empty_node.node_start = grub_cpu_to_be32_compile_time (FDT_BEGIN_NODE);
+  ((struct grub_fdt_empty_tree *) fdt)->header.off_mem_rsvmap =
+    grub_cpu_to_be32 (ALIGN_UP (sizeof (grub_fdt_header_t), 8));
+
+  grub_fdt_set_off_dt_strings (fdt, sizeof (*et));
+  grub_fdt_set_off_dt_struct (fdt,
+			      sizeof (et->header) + sizeof (et->empty_rsvmap));
+  grub_fdt_set_version (fdt, FDT_SUPPORTED_VERSION);
+  grub_fdt_set_last_comp_version (fdt, FDT_SUPPORTED_VERSION);
+  grub_fdt_set_size_dt_struct (fdt, sizeof (et->empty_node));
+  grub_fdt_set_totalsize (fdt, size);
+  grub_fdt_set_magic (fdt, FDT_MAGIC);
+
+  return 0;
+}
diff --git a/include/grub/fdt.h b/include/grub/fdt.h
index 2ad0536..fae322e 100644
--- a/include/grub/fdt.h
+++ b/include/grub/fdt.h
@@ -36,6 +36,19 @@  typedef struct {
 	grub_uint32_t size_dt_struct;
 } grub_fdt_header_t;
 
+struct grub_fdt_empty_tree {
+  grub_fdt_header_t header;
+  grub_uint64_t empty_rsvmap[2];
+  struct {
+    grub_uint32_t node_start;
+    grub_uint8_t name[1];
+    grub_uint32_t node_end;
+    grub_uint32_t tree_end;
+  } empty_node;
+};
+
+#define GRUB_FDT_EMPTY_TREE_SZ  sizeof (struct grub_fdt_empty_tree)
+
 #define grub_fdt_get_header(fdt, field)	\
 	grub_be_to_cpu32(((const grub_fdt_header_t *)(fdt))->field)
 #define grub_fdt_set_header(fdt, field, value)	\
@@ -82,6 +95,7 @@  typedef struct {
 #define grub_fdt_set_size_dt_struct(fdt, value)	\
 	grub_fdt_set_header(fdt, size_dt_struct, value)
 
+int grub_fdt_create_empty_tree (void *fdt, unsigned int size);
 int grub_fdt_check_header (void *fdt, unsigned int size);
 int grub_fdt_find_subnode (const void *fdt, unsigned int parentoffset,
 			   const char *name);
@@ -96,4 +110,10 @@  int grub_fdt_set_prop (void *fdt, unsigned int nodeoffset, const char *name,
   grub_fdt_set_prop ((fdt), (nodeoffset), (name), &_val, 4);	\
 })
 
+#define grub_fdt_set_prop64(fdt, nodeoffset, name, val)        \
+({ \
+  grub_uint64_t _val = grub_cpu_to_be64(val); \
+  grub_fdt_set_prop ((fdt), (nodeoffset), (name), &_val, 8);   \
+})
+
 #endif	/* ! GRUB_FDT_HEADER */