memory-layout-tool.rst 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. TF-A Memory Layout Tool
  2. =======================
  3. TF-A's memory layout tool is a Python script for analyzing the virtual
  4. memory layout of TF-A builds.
  5. Prerequisites
  6. ~~~~~~~~~~~~~
  7. #. Python (3.8 or later)
  8. #. `Poetry`_ Python package manager
  9. Getting Started
  10. ~~~~~~~~~~~~~~~
  11. #. Install Poetry
  12. .. code:: shell
  13. curl -sSL https://install.python-poetry.org | python3 -
  14. #. Install the required packages
  15. .. code:: shell
  16. poetry install --with memory
  17. #. Verify that the tool runs in the installed virtual environment
  18. .. code:: shell
  19. poetry run memory --help
  20. Symbol Virtual Map
  21. ~~~~~~~~~~~~~~~~~~
  22. The tool can be used to generate a visualisation of the symbol table. By
  23. default, it prints the symbols representing the start and end address of the
  24. main memory regions in an ELF file (i.e. text, bss, rodata) but can be modified
  25. to print any set of symbols.
  26. .. code:: shell
  27. $ poetry run memory -s
  28. build-path: build/fvp/release
  29. Virtual Address Map:
  30. +------------__BL1_RAM_END__------------+---------------------------------------+
  31. +---------__COHERENT_RAM_END__----------+ |
  32. +--------__COHERENT_RAM_START__---------+ |
  33. 0x0403b000 +----------__XLAT_TABLE_END__-----------+ |
  34. 0x04036000 +---------__XLAT_TABLE_START__----------+ |
  35. +--------__BASE_XLAT_TABLE_END__--------+ |
  36. 0x04035600 +--------------__BSS_END__--------------+ |
  37. +-------__BASE_XLAT_TABLE_START__-------+ |
  38. +-----__PMF_PERCPU_TIMESTAMP_END__------+ |
  39. +---------__PMF_TIMESTAMP_END__---------+ |
  40. 0x04035400 +--------__PMF_TIMESTAMP_START__--------+ |
  41. +-------------__BSS_START__-------------+ |
  42. 0x04034a00 +------------__STACKS_END__-------------+ |
  43. 0x04034500 +-----------__STACKS_START__------------+ |
  44. 0x040344c5 +-----------__DATA_RAM_END__------------+ |
  45. +-----------__BL1_RAM_START__-----------+ |
  46. 0x04034000 +----------__DATA_RAM_START__-----------+ |
  47. | +---------__COHERENT_RAM_END__----------+
  48. | +--------__COHERENT_RAM_START__---------+
  49. 0x0402e000 | +----------__XLAT_TABLE_END__-----------+
  50. 0x04029000 | +---------__XLAT_TABLE_START__----------+
  51. | +--------__BASE_XLAT_TABLE_END__--------+
  52. 0x04028800 | +--------------__BSS_END__--------------+
  53. | +-------__BASE_XLAT_TABLE_START__-------+
  54. | +-----__PMF_PERCPU_TIMESTAMP_END__------+
  55. | +---------__PMF_TIMESTAMP_END__---------+
  56. 0x04028580 | +--------__PMF_TIMESTAMP_START__--------+
  57. 0x04028000 | +-------------__BSS_START__-------------+
  58. 0x04027e40 | +------------__STACKS_END__-------------+
  59. 0x04027840 | +-----------__STACKS_START__------------+
  60. 0x04027000 | +------------__RODATA_END__-------------+
  61. | +------------__CPU_OPS_END__------------+
  62. | +-----------__CPU_OPS_START__-----------+
  63. | +--------__FCONF_POPULATOR_END__--------+
  64. | +--------------__GOT_END__--------------+
  65. | +-------------__GOT_START__-------------+
  66. | +---------__PMF_SVC_DESCS_END__---------+
  67. 0x04026c10 | +--------__PMF_SVC_DESCS_START__--------+
  68. 0x04026bf8 | +-------__FCONF_POPULATOR_START__-------+
  69. | +-----------__RODATA_START__------------+
  70. 0x04026000 | +-------------__TEXT_END__--------------+
  71. 0x04021000 | +------------__TEXT_START__-------------+
  72. 0x000062b5 +------------__BL1_ROM_END__------------+ |
  73. 0x00005df0 +----------__DATA_ROM_START__-----------+ |
  74. +------------__CPU_OPS_END__------------+ |
  75. +--------------__GOT_END__--------------+ |
  76. +-------------__GOT_START__-------------+ |
  77. 0x00005de8 +------------__RODATA_END__-------------+ |
  78. +-----------__CPU_OPS_START__-----------+ |
  79. +--------__FCONF_POPULATOR_END__--------+ |
  80. +---------__PMF_SVC_DESCS_END__---------+ |
  81. 0x00005c98 +--------__PMF_SVC_DESCS_START__--------+ |
  82. 0x00005c80 +-------__FCONF_POPULATOR_START__-------+ |
  83. +-----------__RODATA_START__------------+ |
  84. 0x00005000 +-------------__TEXT_END__--------------+ |
  85. 0x00000000 +------------__TEXT_START__-------------+---------------------------------------+
  86. Addresses are displayed in hexadecimal by default but can be printed in decimal
  87. instead with the ``-d`` option.
  88. Because of the length of many of the symbols, the tool defaults to a text width
  89. of 120 chars. This can be increased if needed with the ``-w`` option.
  90. For more detailed help instructions, run:
  91. .. code:: shell
  92. poetry run memory --help
  93. Memory Footprint
  94. ~~~~~~~~~~~~~~~~
  95. The tool enables users to view static memory consumption. When the options
  96. ``-f``, or ``--footprint`` are provided, the script analyses the ELF binaries in
  97. the build path to generate a table (per memory type), showing memory allocation
  98. and usage. This is the default output generated by the tool.
  99. .. code:: shell
  100. $ poetry run memory -f
  101. build-path: build/fvp/release
  102. +----------------------------------------------------------------------------+
  103. | Memory Usage (bytes) [RAM] |
  104. +-----------+------------+------------+------------+------------+------------+
  105. | Component | Start | Limit | Size | Free | Total |
  106. +-----------+------------+------------+------------+------------+------------+
  107. | BL1 | 4034000 | 4040000 | 7000 | 5000 | c000 |
  108. | BL2 | 4021000 | 4034000 | d000 | 6000 | 13000 |
  109. | BL2U | 4021000 | 4034000 | a000 | 9000 | 13000 |
  110. | BL31 | 4003000 | 4040000 | 1e000 | 1f000 | 3d000 |
  111. +-----------+------------+------------+------------+------------+------------+
  112. +----------------------------------------------------------------------------+
  113. | Memory Usage (bytes) [ROM] |
  114. +-----------+------------+------------+------------+------------+------------+
  115. | Component | Start | Limit | Size | Free | Total |
  116. +-----------+------------+------------+------------+------------+------------+
  117. | BL1 | 0 | 4000000 | 5df0 | 3ffa210 | 4000000 |
  118. +-----------+------------+------------+------------+------------+------------+
  119. The script relies on symbols in the symbol table to determine the start, end,
  120. and limit addresses of each bootloader stage.
  121. Memory Tree
  122. ~~~~~~~~~~~
  123. A hierarchical view of the memory layout can be produced by passing the option
  124. ``-t`` or ``--tree`` to the tool. This gives the start, end, and size of each
  125. module, their ELF segments as well as sections.
  126. .. code:: shell
  127. $ poetry run memory -t
  128. build-path: build/fvp/release
  129. name start end size
  130. bl1 0 400c000 400c000
  131. ├── 00 0 5de0 5de0
  132. │ ├── .text 0 5000 5000
  133. │ └── .rodata 5000 5de0 de0
  134. ├── 01 4034000 40344c5 4c5
  135. │ └── .data 4034000 40344c5 4c5
  136. ├── 02 4034500 4034a00 500
  137. │ └── .stacks 4034500 4034a00 500
  138. ├── 04 4034a00 4035600 c00
  139. │ └── .bss 4034a00 4035600 c00
  140. └── 03 4036000 403b000 5000
  141. └── .xlat_table 4036000 403b000 5000
  142. bl2 4021000 4034000 13000
  143. ├── 00 4021000 4027000 6000
  144. │ ├── .text 4021000 4026000 5000
  145. │ └── .rodata 4026000 4027000 1000
  146. └── 01 4027000 402e000 7000
  147. ├── .data 4027000 4027809 809
  148. ├── .stacks 4027840 4027e40 600
  149. ├── .bss 4028000 4028800 800
  150. └── .xlat_table 4029000 402e000 5000
  151. bl2u 4021000 4034000 13000
  152. ├── 00 4021000 4025000 4000
  153. │ ├── .text 4021000 4024000 3000
  154. │ └── .rodata 4024000 4025000 1000
  155. └── 01 4025000 402b000 6000
  156. ├── .data 4025000 4025065 65
  157. ├── .stacks 4025080 4025480 400
  158. ├── .bss 4025600 4025c00 600
  159. └── .xlat_table 4026000 402b000 5000
  160. bl31 4003000 4040000 3d000
  161. ├── 02 ffe00000 ffe03000 3000
  162. │ └── .el3_tzc_dram ffe00000 ffe03000 3000
  163. ├── 00 4003000 4010000 d000
  164. │ └── .text 4003000 4010000 d000
  165. └── 01 4010000 4021000 11000
  166. ├── .rodata 4010000 4012000 2000
  167. ├── .data 4012000 401219d 19d
  168. ├── .stacks 40121c0 40161c0 4000
  169. ├── .bss 4016200 4018c00 2a00
  170. ├── .xlat_table 4019000 4020000 7000
  171. └── .coherent_ram 4020000 4021000 1000
  172. The granularity of this view can be modified with the ``--depth`` option. For
  173. instance, if you only require the tree up to the level showing segment data,
  174. you can specify the depth with:
  175. .. code::
  176. $ poetry run memory -t --depth 2
  177. build-path: build/fvp/release
  178. name start end size
  179. bl1 0 400c000 400c000
  180. ├── 00 0 5df0 5df0
  181. ├── 01 4034000 40344c5 4c5
  182. ├── 02 4034500 4034a00 500
  183. ├── 04 4034a00 4035600 c00
  184. └── 03 4036000 403b000 5000
  185. bl2 4021000 4034000 13000
  186. ├── 00 4021000 4027000 6000
  187. └── 01 4027000 402e000 7000
  188. bl2u 4021000 4034000 13000
  189. ├── 00 4021000 4025000 4000
  190. └── 01 4025000 402b000 6000
  191. bl31 4003000 4040000 3d000
  192. ├── 02 ffe00000 ffe03000 3000
  193. ├── 00 4003000 4010000 d000
  194. └── 01 4010000 4021000 11000
  195. --------------
  196. *Copyright (c) 2023, Arm Limited. All rights reserved.*
  197. .. _Poetry: https://python-poetry.org/docs/