lib/devicetree: Support 64 bit addresses for the initrd
The "linux,initrd-start" and "linux,initrd-end" properties encode the start
and end address of the initrd. The size of the address is encoded in the
root node #address-cells property and can be 1 cell (32 bits) or 2 cells
(64 bits). Add support for parsing a 64 bit address.
Signed-off-by: Alexandru Elisei <alexandru.elisei@arm.com>
[Fixed compilation for 32-bit arm with another cast.]
Signed-off-by: Andrew Jones <drjones@redhat.com>
diff --git a/lib/devicetree.c b/lib/devicetree.c
index 409d18b..fa8399a 100644
--- a/lib/devicetree.c
+++ b/lib/devicetree.c
@@ -288,7 +288,7 @@
int dt_get_initrd(const char **initrd, u32 *size)
{
const struct fdt_property *prop;
- const char *start, *end;
+ u64 start, end;
int node, len;
u32 *data;
@@ -303,7 +303,12 @@
if (!prop)
return len;
data = (u32 *)prop->data;
- start = (const char *)(unsigned long)fdt32_to_cpu(*data);
+ start = fdt32_to_cpu(*data);
+ if (len == 8) {
+ assert(sizeof(long) == 8);
+ data++;
+ start = (start << 32) | fdt32_to_cpu(*data);
+ }
prop = fdt_get_property(fdt, node, "linux,initrd-end", &len);
if (!prop) {
@@ -311,10 +316,14 @@
return len;
}
data = (u32 *)prop->data;
- end = (const char *)(unsigned long)fdt32_to_cpu(*data);
+ end = fdt32_to_cpu(*data);
+ if (len == 8) {
+ data++;
+ end = (end << 32) | fdt32_to_cpu(*data);
+ }
- *initrd = start;
- *size = (unsigned long)end - (unsigned long)start;
+ *initrd = (char *)(unsigned long)start;
+ *size = end - start;
return 0;
}