]> xenbits.xensource.com Git - people/julieng/boot-wrapper-aarch64.git/commitdiff
Discover memory from the DTB
authorMark Rutland <mark.rutland@arm.com>
Tue, 15 Apr 2014 15:02:02 +0000 (16:02 +0100)
committerMark Rutland <mark.rutland@arm.com>
Tue, 15 Apr 2014 15:08:19 +0000 (16:08 +0100)
In case the start of physical memory happens to be different on some
model variant, this patch adds the necessary tooling to detect the base
address of said memory and ensure that the kernel and wrapper get loaded
at appropriate addresses.

Signed-off-by: Mark Rutland <mark.rutland@arm.com>
Makefile.am
findmem.pl [new file with mode: 0755]

index 41adf14cfff4035b98c97c35d53d42db3582f074..2f69061f7a1abdac00302cd4078904e1c2c2cb70 100644 (file)
@@ -8,7 +8,7 @@
 # found in the LICENSE.txt file.
 
 # VE
-PHYS_OFFSET    := 0x80000000
+PHYS_OFFSET    := $(shell $(top_srcdir)/findmem.pl $(KERNEL_DTB))
 UART_BASE      := $(shell $(top_srcdir)/findbase.pl $(KERNEL_DTB) 0 'arm,pl011')
 SYSREGS_BASE   := $(shell $(top_srcdir)/findbase.pl $(KERNEL_DTB) 0 'arm,vexpress-sysreg')
 GIC_DIST_BASE  := $(shell $(top_srcdir)/findbase.pl $(KERNEL_DTB) 0 'arm,cortex-a15-gic')
diff --git a/findmem.pl b/findmem.pl
new file mode 100755 (executable)
index 0000000..ae75a8c
--- /dev/null
@@ -0,0 +1,33 @@
+#!/usr/bin/perl -w
+# Find the start of physical memory
+#
+# Usage: ./$0 <DTB> 
+#
+# Copyright (C) 2014 ARM Limited. All rights reserved.
+#
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE.txt file.
+
+use warnings;
+use strict;
+
+use FDT;
+
+my $filename = shift;
+die("No filename provided") unless defined($filename);
+
+open (my $fh, "<:raw", $filename) or die("Unable to open file '$filename'");
+
+my $fdt = FDT->parse($fh) or die("Unable to parse DTB");
+
+my $root = $fdt->get_root();
+
+# We assume the memory nodes and their reg entries are ordered by address.
+my @mems = $root->find_by_device_type("memory");
+my $mem = shift @mems;
+die("Unable to find memory") unless defined($mem);
+
+my ($addr, $size) = $mem->get_translated_reg(0);
+die("Cannot find first memory bank") unless (defined($addr) && defined($size));
+
+printf("0x%016x\n", $addr);