Louis Mayencourt | 3dea1a5 | 2019-10-14 14:09:40 +0100 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
| 2 | # |
| 3 | # Copyright (c) 2019, Arm Limited. All rights reserved. |
| 4 | # |
| 5 | # SPDX-License-Identifier: BSD-3-Clause |
| 6 | # |
| 7 | |
| 8 | import re |
| 9 | import os |
| 10 | import sys |
| 11 | import operator |
| 12 | |
| 13 | # List of folder/map to parse |
| 14 | bl_images = ['bl1', 'bl2', 'bl31'] |
| 15 | |
| 16 | # List of symbols to search for |
| 17 | blx_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', |
| 25 | ] |
| 26 | |
| 27 | # Regex to extract address from map file |
| 28 | address_pattern = re.compile(r"\b0x\w*") |
| 29 | |
| 30 | # List of found element: [address, symbol, file] |
| 31 | address_list = [] |
| 32 | |
| 33 | # Get the directory from command line or use a default one |
| 34 | if len(sys.argv) >= 2: |
| 35 | build_dir = sys.argv[1] |
| 36 | else: |
| 37 | build_dir = 'build/fvp/debug' |
| 38 | |
| 39 | # Extract all the required symbols from the map files |
| 40 | for image in bl_images: |
| 41 | file_path = os.path.join(build_dir, image, '{}.map'.format(image)) |
| 42 | if os.path.isfile(file_path): |
| 43 | with open (file_path, 'rt') as mapfile: |
| 44 | for line in mapfile: |
| 45 | for symbol in blx_symbols: |
| 46 | if line.find(symbol) > 0 and line.find("ASSERT") < 0: |
| 47 | # Extract address from line |
| 48 | match = address_pattern.search(line) |
| 49 | if match: |
| 50 | address_list.append([match.group(0), symbol, image]) |
| 51 | |
| 52 | # Sort by address |
| 53 | address_list.sort(key=operator.itemgetter(0)) |
| 54 | |
| 55 | # Generate memory view |
| 56 | print('{:-^87}'.format('Memory Map from: ' + build_dir)) |
| 57 | for address in reversed(address_list): |
| 58 | if "bl1" in address[2]: |
| 59 | print(address[0], '+{:-^20}+ |{:^20}| |{:^20}|'.format(address[1], '', '')) |
| 60 | elif "bl2" in address[2]: |
| 61 | print(address[0], '|{:^20}| +{:-^20}+ |{:^20}|'.format('', address[1], '')) |
| 62 | elif "bl31" in address[2]: |
| 63 | print(address[0], '|{:^20}| |{:^20}| +{:-^20}+'.format('', '', address[1])) |
| 64 | else: |
| 65 | print(address[0], '|{:^20}| |{:^20}| +{:-^20}+'.format('', '', address[1])) |
| 66 | |
| 67 | print('{:^20}{:_^20} {:_^20} {:_^20}'.format('', '', '', '')) |
| 68 | print('{:^20}{:^20} {:^20} {:^20}'.format('address', 'bl1', 'bl2', 'bl31')) |