feat(debug): update print_memory_map.py

Add some entries in blx_symbols, that are used when the flag
SEPARATE_CODE_AND_RODATA is not enabled (__RO_* and __TEXT_RESIDENT_*).
Add all new symbols that were not yet present in the script.
Correct __BSS_END to __BSS_END__, and add __BSS_START__.
Add new *_XLAT_TABLE_* symbols.
As those strings are longer than 22, update display format string to
be dependent on the longest string.
The script also skips lines for which the _START__ and _END__
symbols have the same address (empty sections).

Signed-off-by: Yann Gautier <yann.gautier@foss.st.com>
Change-Id: I6c510ced6116b35d14ee2cb7a6711405604380d6
diff --git a/tools/memory/print_memory_map.py b/tools/memory/print_memory_map.py
index 8a84018..ef53f7e 100755
--- a/tools/memory/print_memory_map.py
+++ b/tools/memory/print_memory_map.py
@@ -1,6 +1,6 @@
 #!/usr/bin/env python3
 #
-# Copyright (c) 2019-2020, Arm Limited. All rights reserved.
+# Copyright (c) 2019-2022, Arm Limited and Contributors. All rights reserved.
 #
 # SPDX-License-Identifier: BSD-3-Clause
 #
@@ -17,12 +17,24 @@
 blx_symbols = ['__BL1_RAM_START__', '__BL1_RAM_END__',
                 '__BL2_END__',
                 '__BL31_END__',
+                '__RO_START__', '__RO_END_UNALIGNED__', '__RO_END__',
                 '__TEXT_START__', '__TEXT_END__',
+                '__TEXT_RESIDENT_START__', '__TEXT_RESIDENT_END__',
                 '__RODATA_START__', '__RODATA_END__',
                 '__DATA_START__', '__DATA_END__',
                 '__STACKS_START__', '__STACKS_END__',
-                '__BSS_END',
+                '__BSS_START__', '__BSS_END__',
                 '__COHERENT_RAM_START__', '__COHERENT_RAM_END__',
+                '__CPU_OPS_START__', '__CPU_OPS_END__',
+                '__FCONF_POPULATOR_START__', '__FCONF_POPULATOR_END__',
+                '__GOT_START__', '__GOT_END__',
+                '__PARSER_LIB_DESCS_START__', '__PARSER_LIB_DESCS_END__',
+                '__PMF_TIMESTAMP_START__', '__PMF_TIMESTAMP_END__',
+                '__PMF_SVC_DESCS_START__', '__PMF_SVC_DESCS_END__',
+                '__RELA_START__', '__RELA_END__',
+                '__RT_SVC_DESCS_START__', '__RT_SVC_DESCS_END__',
+                '__BASE_XLAT_TABLE_START__', '__BASE_XLAT_TABLE_END__',
+                '__XLAT_TABLE_START__', '__XLAT_TABLE_END__',
                ]
 
 # Regex to extract address from map file
@@ -40,6 +52,10 @@
 else:
     build_dir = 'build/fvp/debug'
 
+max_len = max(len(word) for word in blx_symbols) + 2
+if (max_len % 2) != 0:
+    max_len += 1
+
 # Extract all the required symbols from the map files
 for image in bl_images:
     file_path = os.path.join(build_dir, image, '{}.map'.format(image))
@@ -47,6 +63,7 @@
         with open (file_path, 'rt') as mapfile:
             for line in mapfile:
                 for symbol in blx_symbols:
+                    skip_symbol = 0
                     # Regex to find symbol definition
                     line_pattern = re.compile(r"\b0x\w*\s*" + symbol + "\s= .")
                     match = line_pattern.search(line)
@@ -54,7 +71,13 @@
                         # Extract address from line
                         match = address_pattern.search(line)
                         if match:
-                            address_list.append([match.group(0), symbol, image])
+                            if '_END__' in symbol:
+                                sym_start = symbol.replace('_END__', '_START__')
+                                if [match.group(0), sym_start, image] in address_list:
+                                    address_list.remove([match.group(0), sym_start, image])
+                                    skip_symbol = 1
+                            if skip_symbol == 0:
+                                address_list.append([match.group(0), symbol, image])
 
 # Sort by address
 address_list.sort(key=operator.itemgetter(0))
@@ -64,16 +87,16 @@
     address_list = reversed(address_list)
 
 # Generate memory view
-print('{:-^93}'.format('Memory Map from: ' + build_dir))
+print(('{:-^%d}' % (max_len * 3 + 20 + 7)).format('Memory Map from: ' + build_dir))
 for address in address_list:
     if "bl1" in address[2]:
-        print(address[0], '+{:-^22}+ |{:^22}| |{:^22}|'.format(address[1], '', ''))
+        print(address[0], ('+{:-^%d}+ |{:^%d}| |{:^%d}|' % (max_len, max_len, max_len)).format(address[1], '', ''))
     elif "bl2" in address[2]:
-        print(address[0], '|{:^22}| +{:-^22}+ |{:^22}|'.format('', address[1], ''))
+        print(address[0], ('|{:^%d}| +{:-^%d}+ |{:^%d}|' % (max_len, max_len, max_len)).format('', address[1], ''))
     elif "bl31" in address[2]:
-        print(address[0], '|{:^22}| |{:^22}| +{:-^22}+'.format('', '', address[1]))
+        print(address[0], ('|{:^%d}| |{:^%d}| +{:-^%d}+' % (max_len, max_len, max_len)).format('', '', address[1]))
     else:
-        print(address[0], '|{:^22}| |{:^22}| +{:-^22}+'.format('', '', address[1]))
+        print(address[0], ('|{:^%d}| |{:^%d}| +{:-^%d}+' % (max_len, max_len, max_len)).format('', '', address[1]))
 
-print('{:^20}{:_^22}   {:_^22}   {:_^22}'.format('', '', '', ''))
-print('{:^20}{:^22}   {:^22}   {:^22}'.format('address', 'bl1', 'bl2', 'bl31'))
+print(('{:^20}{:_^%d}   {:_^%d}   {:_^%d}' % (max_len, max_len, max_len)).format('', '', '', ''))
+print(('{:^20}{:^%d}   {:^%d}   {:^%d}' % (max_len, max_len, max_len)).format('address', 'bl1', 'bl2', 'bl31'))