Louis Mayencourt | 3dea1a5 | 2019-10-14 14:09:40 +0100 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
| 2 | # |
Yann Gautier | 522acd2 | 2022-04-04 18:22:45 +0200 | [diff] [blame] | 3 | # Copyright (c) 2019-2022, Arm Limited and Contributors. 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__', |
Yann Gautier | 522acd2 | 2022-04-04 18:22:45 +0200 | [diff] [blame] | 20 | '__RO_START__', '__RO_END_UNALIGNED__', '__RO_END__', |
Louis Mayencourt | 3dea1a5 | 2019-10-14 14:09:40 +0100 | [diff] [blame] | 21 | '__TEXT_START__', '__TEXT_END__', |
Yann Gautier | 522acd2 | 2022-04-04 18:22:45 +0200 | [diff] [blame] | 22 | '__TEXT_RESIDENT_START__', '__TEXT_RESIDENT_END__', |
Louis Mayencourt | 3dea1a5 | 2019-10-14 14:09:40 +0100 | [diff] [blame] | 23 | '__RODATA_START__', '__RODATA_END__', |
| 24 | '__DATA_START__', '__DATA_END__', |
| 25 | '__STACKS_START__', '__STACKS_END__', |
Yann Gautier | 522acd2 | 2022-04-04 18:22:45 +0200 | [diff] [blame] | 26 | '__BSS_START__', '__BSS_END__', |
Louis Mayencourt | c1c2bf7 | 2020-02-13 08:21:34 +0000 | [diff] [blame] | 27 | '__COHERENT_RAM_START__', '__COHERENT_RAM_END__', |
Yann Gautier | 522acd2 | 2022-04-04 18:22:45 +0200 | [diff] [blame] | 28 | '__CPU_OPS_START__', '__CPU_OPS_END__', |
| 29 | '__FCONF_POPULATOR_START__', '__FCONF_POPULATOR_END__', |
| 30 | '__GOT_START__', '__GOT_END__', |
| 31 | '__PARSER_LIB_DESCS_START__', '__PARSER_LIB_DESCS_END__', |
| 32 | '__PMF_TIMESTAMP_START__', '__PMF_TIMESTAMP_END__', |
| 33 | '__PMF_SVC_DESCS_START__', '__PMF_SVC_DESCS_END__', |
| 34 | '__RELA_START__', '__RELA_END__', |
| 35 | '__RT_SVC_DESCS_START__', '__RT_SVC_DESCS_END__', |
| 36 | '__BASE_XLAT_TABLE_START__', '__BASE_XLAT_TABLE_END__', |
| 37 | '__XLAT_TABLE_START__', '__XLAT_TABLE_END__', |
Louis Mayencourt | 3dea1a5 | 2019-10-14 14:09:40 +0100 | [diff] [blame] | 38 | ] |
| 39 | |
| 40 | # Regex to extract address from map file |
| 41 | address_pattern = re.compile(r"\b0x\w*") |
| 42 | |
| 43 | # List of found element: [address, symbol, file] |
| 44 | address_list = [] |
| 45 | |
| 46 | # Get the directory from command line or use a default one |
Louis Mayencourt | c1c2bf7 | 2020-02-13 08:21:34 +0000 | [diff] [blame] | 47 | inverted_print = True |
Louis Mayencourt | 3dea1a5 | 2019-10-14 14:09:40 +0100 | [diff] [blame] | 48 | if len(sys.argv) >= 2: |
| 49 | build_dir = sys.argv[1] |
Louis Mayencourt | c1c2bf7 | 2020-02-13 08:21:34 +0000 | [diff] [blame] | 50 | if len(sys.argv) >= 3: |
| 51 | inverted_print = sys.argv[2] == '0' |
Louis Mayencourt | 3dea1a5 | 2019-10-14 14:09:40 +0100 | [diff] [blame] | 52 | else: |
| 53 | build_dir = 'build/fvp/debug' |
| 54 | |
Yann Gautier | 522acd2 | 2022-04-04 18:22:45 +0200 | [diff] [blame] | 55 | max_len = max(len(word) for word in blx_symbols) + 2 |
| 56 | if (max_len % 2) != 0: |
| 57 | max_len += 1 |
| 58 | |
Louis Mayencourt | 3dea1a5 | 2019-10-14 14:09:40 +0100 | [diff] [blame] | 59 | # Extract all the required symbols from the map files |
| 60 | for image in bl_images: |
| 61 | file_path = os.path.join(build_dir, image, '{}.map'.format(image)) |
| 62 | if os.path.isfile(file_path): |
| 63 | with open (file_path, 'rt') as mapfile: |
| 64 | for line in mapfile: |
| 65 | for symbol in blx_symbols: |
Yann Gautier | 522acd2 | 2022-04-04 18:22:45 +0200 | [diff] [blame] | 66 | skip_symbol = 0 |
Louis Mayencourt | c1c2bf7 | 2020-02-13 08:21:34 +0000 | [diff] [blame] | 67 | # Regex to find symbol definition |
| 68 | line_pattern = re.compile(r"\b0x\w*\s*" + symbol + "\s= .") |
| 69 | match = line_pattern.search(line) |
| 70 | if match: |
Louis Mayencourt | 3dea1a5 | 2019-10-14 14:09:40 +0100 | [diff] [blame] | 71 | # Extract address from line |
| 72 | match = address_pattern.search(line) |
| 73 | if match: |
Yann Gautier | 522acd2 | 2022-04-04 18:22:45 +0200 | [diff] [blame] | 74 | if '_END__' in symbol: |
| 75 | sym_start = symbol.replace('_END__', '_START__') |
| 76 | if [match.group(0), sym_start, image] in address_list: |
| 77 | address_list.remove([match.group(0), sym_start, image]) |
| 78 | skip_symbol = 1 |
| 79 | if skip_symbol == 0: |
| 80 | address_list.append([match.group(0), symbol, image]) |
Louis Mayencourt | 3dea1a5 | 2019-10-14 14:09:40 +0100 | [diff] [blame] | 81 | |
| 82 | # Sort by address |
| 83 | address_list.sort(key=operator.itemgetter(0)) |
| 84 | |
Louis Mayencourt | c1c2bf7 | 2020-02-13 08:21:34 +0000 | [diff] [blame] | 85 | # Invert list for lower address at bottom |
| 86 | if inverted_print: |
| 87 | address_list = reversed(address_list) |
| 88 | |
Louis Mayencourt | 3dea1a5 | 2019-10-14 14:09:40 +0100 | [diff] [blame] | 89 | # Generate memory view |
Yann Gautier | 522acd2 | 2022-04-04 18:22:45 +0200 | [diff] [blame] | 90 | print(('{:-^%d}' % (max_len * 3 + 20 + 7)).format('Memory Map from: ' + build_dir)) |
Louis Mayencourt | c1c2bf7 | 2020-02-13 08:21:34 +0000 | [diff] [blame] | 91 | for address in address_list: |
Louis Mayencourt | 3dea1a5 | 2019-10-14 14:09:40 +0100 | [diff] [blame] | 92 | if "bl1" in address[2]: |
Yann Gautier | 522acd2 | 2022-04-04 18:22:45 +0200 | [diff] [blame] | 93 | print(address[0], ('+{:-^%d}+ |{:^%d}| |{:^%d}|' % (max_len, max_len, max_len)).format(address[1], '', '')) |
Louis Mayencourt | 3dea1a5 | 2019-10-14 14:09:40 +0100 | [diff] [blame] | 94 | elif "bl2" in address[2]: |
Yann Gautier | 522acd2 | 2022-04-04 18:22:45 +0200 | [diff] [blame] | 95 | print(address[0], ('|{:^%d}| +{:-^%d}+ |{:^%d}|' % (max_len, max_len, max_len)).format('', address[1], '')) |
Louis Mayencourt | 3dea1a5 | 2019-10-14 14:09:40 +0100 | [diff] [blame] | 96 | elif "bl31" in address[2]: |
Yann Gautier | 522acd2 | 2022-04-04 18:22:45 +0200 | [diff] [blame] | 97 | print(address[0], ('|{:^%d}| |{:^%d}| +{:-^%d}+' % (max_len, max_len, max_len)).format('', '', address[1])) |
Louis Mayencourt | 3dea1a5 | 2019-10-14 14:09:40 +0100 | [diff] [blame] | 98 | else: |
Yann Gautier | 522acd2 | 2022-04-04 18:22:45 +0200 | [diff] [blame] | 99 | print(address[0], ('|{:^%d}| |{:^%d}| +{:-^%d}+' % (max_len, max_len, max_len)).format('', '', address[1])) |
Louis Mayencourt | 3dea1a5 | 2019-10-14 14:09:40 +0100 | [diff] [blame] | 100 | |
Yann Gautier | 522acd2 | 2022-04-04 18:22:45 +0200 | [diff] [blame] | 101 | print(('{:^20}{:_^%d} {:_^%d} {:_^%d}' % (max_len, max_len, max_len)).format('', '', '', '')) |
| 102 | print(('{:^20}{:^%d} {:^%d} {:^%d}' % (max_len, max_len, max_len)).format('address', 'bl1', 'bl2', 'bl31')) |