aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJon Medhurst <tixy@linaro.org>2012-10-09 14:34:27 +0100
committerPeter Maydell <peter.maydell@linaro.org>2012-10-09 14:34:27 +0100
commit7addd64ec2031aaf4b4e8899a197f28c94a24aff (patch)
tree9ee5a809c1c95c62836e5126afa1cd808d0e4cce
parent43b951490cd783e5c9823560ca1e682a7547209c (diff)
downloadboot-wrapper-7addd64ec2031aaf4b4e8899a197f28c94a24aff.tar.gz
bootwrapper: Factor out parsing of fdt #address-cells and #size-cells
A subsequent patch will also need to obtain address-cells and size-cells, so lets factor out this code into a handy function. Signed-off-by: Jon Medhurst <tixy@linaro.org> [PMM: fixed some minor style nits pointed out by Dave M] Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
-rw-r--r--semi_loader.c56
1 files changed, 34 insertions, 22 deletions
diff --git a/semi_loader.c b/semi_loader.c
index cbe911c..7bb0778 100644
--- a/semi_loader.c
+++ b/semi_loader.c
@@ -97,6 +97,39 @@ static int _fdt_make_node(void *fdt, int parentoffset, const char *name)
return fdt_add_subnode(fdt, parentoffset, name);
}
+static void _fdt_address_and_size_cells(void *fdt, int *addrcells, int *sizecells)
+{
+ int e;
+ uint32_t const *p;
+
+ if(!(p = fdt_getprop(fdt, 0, "#address-cells", &e)))
+ goto libfdt_error;
+ if(e != 4)
+ goto size_error;
+ *addrcells = fdt32_to_cpu(*p);
+ if(!(p = fdt_getprop(fdt, 0, "#size-cells", &e)))
+ goto libfdt_error;
+ if(e != 4)
+ goto size_error;
+ *sizecells = fdt32_to_cpu(*p);
+
+ /*
+ * Sanity-check address sizes, since addresses and sizes which do
+ * not take up exactly 4 or 8 bytes are not supported.
+ */
+ if ((*addrcells != 1 && *addrcells != 2) ||
+ (*sizecells != 1 && *sizecells != 2))
+ goto size_error;
+
+ return;
+
+libfdt_error:
+ fatal("libfdt: ", fdt_strerror(e), ", while looking for #address-cells/#size-cells\n");
+
+size_error:
+ fatal("Unexpected/invalid #address-cells/#size-cells in device tree\n");
+}
+
static void update_fdt(void **dest, struct loader_info *info)
{
int e;
@@ -112,25 +145,7 @@ static void update_fdt(void **dest, struct loader_info *info)
if((e = fdt_open_into((void *)info->fdt_start, fdt, FDT_SIZE_MAX)) < 0)
goto libfdt_error;
- /*
- * Sanity-check address sizes, since addresses and sizes which do
- * not take up exactly 4 or 8 bytes are not supported.
- */
- {
- if(!(p = fdt_getprop(fdt, 0, "#address-cells", &e)))
- goto libfdt_error;
- else if(e != 4)
- goto size_error;
- addrcells = fdt32_to_cpu(*p);
- if(!(p = fdt_getprop(fdt, 0, "#size-cells", &e)))
- goto libfdt_error;
- else if(e != 4)
- goto size_error;
- sizecells = fdt32_to_cpu(*p);
- if ((addrcells != 1 && addrcells != 2) ||
- (sizecells != 1 && sizecells != 2))
- goto size_error;
- }
+ _fdt_address_and_size_cells(fdt, &addrcells, &sizecells);
/*
* Add a memory node, but only if there isn't one already. If
@@ -225,9 +240,6 @@ no_add_memory:
libfdt_error:
fatal("libfdt: ", fdt_strerror(e), ", while updating device tree\n");
-
-size_error:
- fatal("Unexpected/invalid #address-cells/#size-cells in device tree\n");
}
static int is_space(char c)