Louis Mayencourt | 3dea1a5 | 2019-10-14 14:09:40 +0100 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
| 2 | # |
Louis Mayencourt | c1c2bf7 | 2020-02-13 08:21:34 +0000 | [diff] [blame] | 3 | # Copyright (c) 2019-2020, Arm Limited. All rights reserved. |
Louis Mayencourt | 3dea1a5 | 2019-10-14 14:09:40 +0100 | [diff] [blame] | 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', |
Louis Mayencourt | c1c2bf7 | 2020-02-13 08:21:34 +0000 | [diff] [blame] | 25 | '__COHERENT_RAM_START__', '__COHERENT_RAM_END__', |
Louis Mayencourt | 3dea1a5 | 2019-10-14 14:09:40 +0100 | [diff] [blame] | 26 | ] |
| 27 | |
| 28 | # Regex to extract address from map file |
| 29 | address_pattern = re.compile(r"\b0x\w*") |
| 30 | |
| 31 | # List of found element: [address, symbol, file] |
| 32 | address_list = [] |
| 33 | |
| 34 | # Get the directory from command line or use a default one |
Louis Mayencourt | c1c2bf7 | 2020-02-13 08:21:34 +0000 | [diff] [blame] | 35 | inverted_print = True |
Louis Mayencourt | 3dea1a5 | 2019-10-14 14:09:40 +0100 | [diff] [blame] | 36 | if len(sys.argv) >= 2: |
| 37 | build_dir = sys.argv[1] |
Louis Mayencourt | c1c2bf7 | 2020-02-13 08:21:34 +0000 | [diff] [blame] | 38 | if len(sys.argv) >= 3: |
| 39 | inverted_print = sys.argv[2] == '0' |
Louis Mayencourt | 3dea1a5 | 2019-10-14 14:09:40 +0100 | [diff] [blame] | 40 | else: |
| 41 | build_dir = 'build/fvp/debug' |
| 42 | |
| 43 | # Extract all the required symbols from the map files |
| 44 | for 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 Mayencourt | c1c2bf7 | 2020-02-13 08:21:34 +0000 | [diff] [blame] | 50 | # 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 Mayencourt | 3dea1a5 | 2019-10-14 14:09:40 +0100 | [diff] [blame] | 54 | # 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 |
| 60 | address_list.sort(key=operator.itemgetter(0)) |
| 61 | |
Louis Mayencourt | c1c2bf7 | 2020-02-13 08:21:34 +0000 | [diff] [blame] | 62 | # Invert list for lower address at bottom |
| 63 | if inverted_print: |
| 64 | address_list = reversed(address_list) |
| 65 | |
Louis Mayencourt | 3dea1a5 | 2019-10-14 14:09:40 +0100 | [diff] [blame] | 66 | # Generate memory view |
Louis Mayencourt | c1c2bf7 | 2020-02-13 08:21:34 +0000 | [diff] [blame] | 67 | print('{:-^93}'.format('Memory Map from: ' + build_dir)) |
| 68 | for address in address_list: |
Louis Mayencourt | 3dea1a5 | 2019-10-14 14:09:40 +0100 | [diff] [blame] | 69 | if "bl1" in address[2]: |
Louis Mayencourt | c1c2bf7 | 2020-02-13 08:21:34 +0000 | [diff] [blame] | 70 | print(address[0], '+{:-^22}+ |{:^22}| |{:^22}|'.format(address[1], '', '')) |
Louis Mayencourt | 3dea1a5 | 2019-10-14 14:09:40 +0100 | [diff] [blame] | 71 | elif "bl2" in address[2]: |
Louis Mayencourt | c1c2bf7 | 2020-02-13 08:21:34 +0000 | [diff] [blame] | 72 | print(address[0], '|{:^22}| +{:-^22}+ |{:^22}|'.format('', address[1], '')) |
Louis Mayencourt | 3dea1a5 | 2019-10-14 14:09:40 +0100 | [diff] [blame] | 73 | elif "bl31" in address[2]: |
Louis Mayencourt | c1c2bf7 | 2020-02-13 08:21:34 +0000 | [diff] [blame] | 74 | print(address[0], '|{:^22}| |{:^22}| +{:-^22}+'.format('', '', address[1])) |
Louis Mayencourt | 3dea1a5 | 2019-10-14 14:09:40 +0100 | [diff] [blame] | 75 | else: |
Louis Mayencourt | c1c2bf7 | 2020-02-13 08:21:34 +0000 | [diff] [blame] | 76 | print(address[0], '|{:^22}| |{:^22}| +{:-^22}+'.format('', '', address[1])) |
Louis Mayencourt | 3dea1a5 | 2019-10-14 14:09:40 +0100 | [diff] [blame] | 77 | |
Louis Mayencourt | c1c2bf7 | 2020-02-13 08:21:34 +0000 | [diff] [blame] | 78 | print('{:^20}{:_^22} {:_^22} {:_^22}'.format('', '', '', '')) |
| 79 | print('{:^20}{:^22} {:^22} {:^22}'.format('address', 'bl1', 'bl2', 'bl31')) |