aboutsummaryrefslogtreecommitdiffstats
path: root/findmem.pl
blob: ae75a8c932514887a64aa5f0347c4a4fa96fa0dc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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);