aboutsummaryrefslogtreecommitdiff
path: root/findbase.pl
diff options
context:
space:
mode:
authorMark Rutland <mark.rutland@arm.com>2014-04-15 14:31:44 +0100
committerMark Rutland <mark.rutland@arm.com>2014-04-15 16:08:14 +0100
commit000a66b55f725918f55d40515bae5c400a969cad (patch)
tree23f1d6993b94ba36c7d948b5dcfd2ab862959294 /findbase.pl
parent0cb95d9d55b99b4b08f19b2349b2d5d1575b17a8 (diff)
Discover device base addresses from the DTB
The base addresses of various components can differ from one model to another. As these addresses are currently hard-coded in the bootwrapper, it is necessary to manually alter the bootwrapper for each variation. This patch adds scripting to extract the (absolute / CPU) addresses of various system components. With this change the bootwrapper build system will automatically discover the addresses that need to be used. Signed-off-by: Mark Rutland <mark.rutland@arm.com>
Diffstat (limited to 'findbase.pl')
-rwxr-xr-xfindbase.pl42
1 files changed, 42 insertions, 0 deletions
diff --git a/findbase.pl b/findbase.pl
new file mode 100755
index 0000000..1b6b93e
--- /dev/null
+++ b/findbase.pl
@@ -0,0 +1,42 @@
+#!/usr/bin/perl -w
+# Find device register base addresses.
+#
+# Usage: ./$0 <DTB> <index> <compatible ...>
+#
+# 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);
+
+my $idx = shift;
+die("no reg index provided") unless defined($idx);
+
+my @compats = shift;
+
+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();
+
+my @devs = ();
+for my $compat (@compats) {
+ push @devs, $root->find_compatible($compat);
+}
+
+# We only care about finding the first matching device
+my $dev = shift @devs;
+die("No matching devices found") if (not defined($dev));
+
+my ($addr, $size) = $dev->get_translated_reg($idx);
+die("Cannot find reg entry $idx") if (not defined($addr) or not defined($size));
+
+printf("0x%016x\n", $addr);