blob: 8a84018e7dd31990fa398431cd4dd60bfcfd51d1 [file] [log] [blame]
Louis Mayencourt3dea1a52019-10-14 14:09:40 +01001#!/usr/bin/env python3
2#
Louis Mayencourtc1c2bf72020-02-13 08:21:34 +00003# Copyright (c) 2019-2020, Arm Limited. All rights reserved.
Louis Mayencourt3dea1a52019-10-14 14:09:40 +01004#
5# SPDX-License-Identifier: BSD-3-Clause
6#
7
8import re
9import os
10import sys
11import operator
12
13# List of folder/map to parse
14bl_images = ['bl1', 'bl2', 'bl31']
15
16# List of symbols to search for
17blx_symbols = ['__BL1_RAM_START__', '__BL1_RAM_END__',
18 '__BL2_END__',
19 '__BL31_END__',
20 '__TEXT_START__', '__TEXT_END__',
21 '__RODATA_START__', '__RODATA_END__',
22 '__DATA_START__', '__DATA_END__',
23 '__STACKS_START__', '__STACKS_END__',
24 '__BSS_END',
Louis Mayencourtc1c2bf72020-02-13 08:21:34 +000025 '__COHERENT_RAM_START__', '__COHERENT_RAM_END__',
Louis Mayencourt3dea1a52019-10-14 14:09:40 +010026 ]
27
28# Regex to extract address from map file
29address_pattern = re.compile(r"\b0x\w*")
30
31# List of found element: [address, symbol, file]
32address_list = []
33
34# Get the directory from command line or use a default one
Louis Mayencourtc1c2bf72020-02-13 08:21:34 +000035inverted_print = True
Louis Mayencourt3dea1a52019-10-14 14:09:40 +010036if len(sys.argv) >= 2:
37 build_dir = sys.argv[1]
Louis Mayencourtc1c2bf72020-02-13 08:21:34 +000038 if len(sys.argv) >= 3:
39 inverted_print = sys.argv[2] == '0'
Louis Mayencourt3dea1a52019-10-14 14:09:40 +010040else:
41 build_dir = 'build/fvp/debug'
42
43# Extract all the required symbols from the map files
44for image in bl_images:
45 file_path = os.path.join(build_dir, image, '{}.map'.format(image))
46 if os.path.isfile(file_path):
47 with open (file_path, 'rt') as mapfile:
48 for line in mapfile:
49 for symbol in blx_symbols:
Louis Mayencourtc1c2bf72020-02-13 08:21:34 +000050 # Regex to find symbol definition
51 line_pattern = re.compile(r"\b0x\w*\s*" + symbol + "\s= .")
52 match = line_pattern.search(line)
53 if match:
Louis Mayencourt3dea1a52019-10-14 14:09:40 +010054 # Extract address from line
55 match = address_pattern.search(line)
56 if match:
57 address_list.append([match.group(0), symbol, image])
58
59# Sort by address
60address_list.sort(key=operator.itemgetter(0))
61
Louis Mayencourtc1c2bf72020-02-13 08:21:34 +000062# Invert list for lower address at bottom
63if inverted_print:
64 address_list = reversed(address_list)
65
Louis Mayencourt3dea1a52019-10-14 14:09:40 +010066# Generate memory view
Louis Mayencourtc1c2bf72020-02-13 08:21:34 +000067print('{:-^93}'.format('Memory Map from: ' + build_dir))
68for address in address_list:
Louis Mayencourt3dea1a52019-10-14 14:09:40 +010069 if "bl1" in address[2]:
Louis Mayencourtc1c2bf72020-02-13 08:21:34 +000070 print(address[0], '+{:-^22}+ |{:^22}| |{:^22}|'.format(address[1], '', ''))
Louis Mayencourt3dea1a52019-10-14 14:09:40 +010071 elif "bl2" in address[2]:
Louis Mayencourtc1c2bf72020-02-13 08:21:34 +000072 print(address[0], '|{:^22}| +{:-^22}+ |{:^22}|'.format('', address[1], ''))
Louis Mayencourt3dea1a52019-10-14 14:09:40 +010073 elif "bl31" in address[2]:
Louis Mayencourtc1c2bf72020-02-13 08:21:34 +000074 print(address[0], '|{:^22}| |{:^22}| +{:-^22}+'.format('', '', address[1]))
Louis Mayencourt3dea1a52019-10-14 14:09:40 +010075 else:
Louis Mayencourtc1c2bf72020-02-13 08:21:34 +000076 print(address[0], '|{:^22}| |{:^22}| +{:-^22}+'.format('', '', address[1]))
Louis Mayencourt3dea1a52019-10-14 14:09:40 +010077
Louis Mayencourtc1c2bf72020-02-13 08:21:34 +000078print('{:^20}{:_^22} {:_^22} {:_^22}'.format('', '', '', ''))
79print('{:^20}{:^22} {:^22} {:^22}'.format('address', 'bl1', 'bl2', 'bl31'))