summaryrefslogtreecommitdiff
path: root/libfdt
diff options
context:
space:
mode:
authorWolfgang Denk <wd@denx.de>2007-04-18 17:47:39 +0200
committerWolfgang Denk <wd@denx.de>2007-04-18 17:47:39 +0200
commit5cca4092bd23d255ed304b8f76cd18ac11adb785 (patch)
tree0159b09bbed29dab7b44fc76fd54f8ce7906fec6 /libfdt
parentfd094c6379e2ef8a4d0ceb5640b24cb0c8d04449 (diff)
parentf35a53fc7b0c79fcfe7bdc01163c4b34aaba1460 (diff)
downloadu-boot-imx-5cca4092bd23d255ed304b8f76cd18ac11adb785.zip
u-boot-imx-5cca4092bd23d255ed304b8f76cd18ac11adb785.tar.gz
u-boot-imx-5cca4092bd23d255ed304b8f76cd18ac11adb785.tar.bz2
Merge with /home/wd/git/u-boot/custodian/u-boot-fdt
Diffstat (limited to 'libfdt')
-rw-r--r--libfdt/fdt.c4
-rw-r--r--libfdt/fdt_ro.c76
-rw-r--r--libfdt/fdt_rw.c2
-rw-r--r--libfdt/fdt_wip.c26
4 files changed, 103 insertions, 5 deletions
diff --git a/libfdt/fdt.c b/libfdt/fdt.c
index 4b1c8ab..212b838 100644
--- a/libfdt/fdt.c
+++ b/libfdt/fdt.c
@@ -23,7 +23,7 @@
#include "libfdt_internal.h"
-int _fdt_check_header(const void *fdt)
+int fdt_check_header(const void *fdt)
{
if (fdt_magic(fdt) == FDT_MAGIC) {
/* Complete tree */
@@ -72,7 +72,7 @@ const char *_fdt_find_string(const char *strtab, int tabsize, const char *s)
int fdt_move(const void *fdt, void *buf, int bufsize)
{
- int err = _fdt_check_header(fdt);
+ int err = fdt_check_header(fdt);
if (err)
return err;
diff --git a/libfdt/fdt_ro.c b/libfdt/fdt_ro.c
index ce01dc7..af33336 100644
--- a/libfdt/fdt_ro.c
+++ b/libfdt/fdt_ro.c
@@ -25,7 +25,7 @@
#define CHECK_HEADER(fdt) { \
int err; \
- if ((err = _fdt_check_header(fdt)) != 0) \
+ if ((err = fdt_check_header(fdt)) != 0) \
return err; \
}
@@ -188,7 +188,7 @@ struct fdt_property *fdt_get_property(const void *fdt,
int offset, nextoffset;
int err;
- if ((err = _fdt_check_header(fdt)) != 0)
+ if ((err = fdt_check_header(fdt)) != 0)
goto fail;
err = -FDT_ERR_BADOFFSET;
@@ -329,3 +329,75 @@ uint32_t fdt_next_tag(const void *fdt, int offset, int *nextoffset, char **namep
return tag;
}
+
+/*
+ * Return the number of used reserve map entries and total slots available.
+ */
+int fdt_num_reservemap(void *fdt, int *used, int *total)
+{
+ struct fdt_reserve_entry *re;
+ int start;
+ int end;
+ int err = fdt_check_header(fdt);
+
+ if (err != 0)
+ return err;
+
+ start = fdt_off_mem_rsvmap(fdt);
+
+ /*
+ * Convention is that the reserve map is before the dt_struct,
+ * but it does not have to be.
+ */
+ end = fdt_totalsize(fdt);
+ if (end > fdt_off_dt_struct(fdt))
+ end = fdt_off_dt_struct(fdt);
+ if (end > fdt_off_dt_strings(fdt))
+ end = fdt_off_dt_strings(fdt);
+
+ /*
+ * Since the reserved area list is zero terminated, you get one fewer.
+ */
+ if (total)
+ *total = ((end - start) / sizeof(struct fdt_reserve_entry)) - 1;
+
+ if (used) {
+ *used = 0;
+ while (start < end) {
+ re = (struct fdt_reserve_entry *)(fdt + start);
+ if (re->size == 0)
+ return 0; /* zero size terminates the list */
+
+ *used += 1;
+ start += sizeof(struct fdt_reserve_entry);
+ }
+ /*
+ * If we get here, there was no zero size termination.
+ */
+ return -FDT_ERR_BADLAYOUT;
+ }
+ return 0;
+}
+
+/*
+ * Return the nth reserve map entry.
+ */
+int fdt_get_reservemap(void *fdt, int n, struct fdt_reserve_entry *re)
+{
+ int used;
+ int total;
+ int err;
+
+ err = fdt_num_reservemap(fdt, &used, &total);
+ if (err != 0)
+ return err;
+
+ if (n >= total)
+ return -FDT_ERR_NOSPACE;
+ if (re) {
+ *re = *(struct fdt_reserve_entry *)
+ _fdt_offset_ptr(fdt, n * sizeof(struct fdt_reserve_entry));
+ }
+ return 0;
+}
+
diff --git a/libfdt/fdt_rw.c b/libfdt/fdt_rw.c
index b33fbf4..aaafc53 100644
--- a/libfdt/fdt_rw.c
+++ b/libfdt/fdt_rw.c
@@ -27,7 +27,7 @@ static int rw_check_header(void *fdt)
{
int err;
- if ((err = _fdt_check_header(fdt)))
+ if ((err = fdt_check_header(fdt)))
return err;
if (fdt_version(fdt) < 0x11)
return -FDT_ERR_BADVERSION;
diff --git a/libfdt/fdt_wip.c b/libfdt/fdt_wip.c
index 261b9b0..cf81183 100644
--- a/libfdt/fdt_wip.c
+++ b/libfdt/fdt_wip.c
@@ -110,3 +110,29 @@ int fdt_nop_node(void *fdt, int nodeoffset)
nop_region(fdt_offset_ptr(fdt, nodeoffset, 0), endoffset - nodeoffset);
return 0;
}
+
+/*
+ * Replace a reserve map entry in the nth slot.
+ */
+int fdt_replace_reservemap_entry(void *fdt, int n, uint64_t addr, uint64_t size)
+{
+ struct fdt_reserve_entry *re;
+ int used;
+ int total;
+ int err;
+
+ err = fdt_num_reservemap(fdt, &used, &total);
+ if (err != 0)
+ return err;
+
+ if (n >= total)
+ return -FDT_ERR_NOSPACE;
+ re = (struct fdt_reserve_entry *)
+ (fdt + fdt_off_mem_rsvmap(fdt) +
+ (n * sizeof(struct fdt_reserve_entry)));
+ re->address = cpu_to_fdt64(addr);
+ re->size = cpu_to_fdt64(size);
+
+ return 0;
+}
+