xref: /rk3399_ARM-atf/docs/tools/memory-layout-tool.rst (revision d9d5eb138ded8d4abeaf0cd1341ddf451aa299b8)
1af5b49e9SHarrison MutaiTF-A Memory Layout Tool
2af5b49e9SHarrison Mutai=======================
3af5b49e9SHarrison Mutai
4af5b49e9SHarrison MutaiTF-A's memory layout tool is a Python script for analyzing the virtual
5af5b49e9SHarrison Mutaimemory layout of TF-A builds.
6af5b49e9SHarrison Mutai
7af5b49e9SHarrison MutaiPrerequisites
8af5b49e9SHarrison Mutai~~~~~~~~~~~~~
9af5b49e9SHarrison Mutai
10af5b49e9SHarrison Mutai#. Python (3.8 or later)
11af5b49e9SHarrison Mutai#. `Poetry`_ Python package manager
12af5b49e9SHarrison Mutai
13af5b49e9SHarrison MutaiGetting Started
14af5b49e9SHarrison Mutai~~~~~~~~~~~~~~~
15af5b49e9SHarrison Mutai
16af5b49e9SHarrison Mutai#. Install Poetry
17af5b49e9SHarrison Mutai
18af5b49e9SHarrison Mutai    .. code:: shell
19af5b49e9SHarrison Mutai
20af5b49e9SHarrison Mutai        curl -sSL https://install.python-poetry.org | python3 -
21af5b49e9SHarrison Mutai
22af5b49e9SHarrison Mutai#. Install the required packages
23af5b49e9SHarrison Mutai
24af5b49e9SHarrison Mutai    .. code:: shell
25af5b49e9SHarrison Mutai
26af5b49e9SHarrison Mutai        poetry install --with memory
27af5b49e9SHarrison Mutai
28af5b49e9SHarrison Mutai#. Verify that the tool runs in the installed virtual environment
29af5b49e9SHarrison Mutai
30af5b49e9SHarrison Mutai    .. code:: shell
31af5b49e9SHarrison Mutai
32af5b49e9SHarrison Mutai        poetry run memory --help
33af5b49e9SHarrison Mutai
34af5b49e9SHarrison MutaiSymbol Virtual Map
35af5b49e9SHarrison Mutai~~~~~~~~~~~~~~~~~~
36af5b49e9SHarrison Mutai
37af5b49e9SHarrison MutaiThe tool can be used to generate a visualisation of the symbol table. By
38af5b49e9SHarrison Mutaidefault, it prints the symbols representing the start and end address of the
39af5b49e9SHarrison Mutaimain memory regions in an ELF file (i.e. text, bss, rodata) but can be modified
40af5b49e9SHarrison Mutaito print any set of symbols.
41af5b49e9SHarrison Mutai
42af5b49e9SHarrison Mutai.. code:: shell
43af5b49e9SHarrison Mutai
44af5b49e9SHarrison Mutai    $ poetry run memory -s
45af5b49e9SHarrison Mutai    build-path: build/fvp/release
46af5b49e9SHarrison Mutai    Virtual Address Map:
47af5b49e9SHarrison Mutai               +------------__BL1_RAM_END__------------+---------------------------------------+
48af5b49e9SHarrison Mutai               +---------__COHERENT_RAM_END__----------+                                       |
49af5b49e9SHarrison Mutai               +--------__COHERENT_RAM_START__---------+                                       |
50af5b49e9SHarrison Mutai    0x0403b000 +----------__XLAT_TABLE_END__-----------+                                       |
51af5b49e9SHarrison Mutai    0x04036000 +---------__XLAT_TABLE_START__----------+                                       |
52af5b49e9SHarrison Mutai               +--------__BASE_XLAT_TABLE_END__--------+                                       |
53af5b49e9SHarrison Mutai    0x04035600 +--------------__BSS_END__--------------+                                       |
54af5b49e9SHarrison Mutai               +-------__BASE_XLAT_TABLE_START__-------+                                       |
55af5b49e9SHarrison Mutai               +-----__PMF_PERCPU_TIMESTAMP_END__------+                                       |
56af5b49e9SHarrison Mutai               +---------__PMF_TIMESTAMP_END__---------+                                       |
57af5b49e9SHarrison Mutai    0x04035400 +--------__PMF_TIMESTAMP_START__--------+                                       |
58af5b49e9SHarrison Mutai               +-------------__BSS_START__-------------+                                       |
59af5b49e9SHarrison Mutai    0x04034a00 +------------__STACKS_END__-------------+                                       |
60af5b49e9SHarrison Mutai    0x04034500 +-----------__STACKS_START__------------+                                       |
61af5b49e9SHarrison Mutai    0x040344c5 +-----------__DATA_RAM_END__------------+                                       |
62af5b49e9SHarrison Mutai               +-----------__BL1_RAM_START__-----------+                                       |
63af5b49e9SHarrison Mutai    0x04034000 +----------__DATA_RAM_START__-----------+                                       |
64af5b49e9SHarrison Mutai               |                                       +---------__COHERENT_RAM_END__----------+
65af5b49e9SHarrison Mutai               |                                       +--------__COHERENT_RAM_START__---------+
66af5b49e9SHarrison Mutai    0x0402e000 |                                       +----------__XLAT_TABLE_END__-----------+
67af5b49e9SHarrison Mutai    0x04029000 |                                       +---------__XLAT_TABLE_START__----------+
68af5b49e9SHarrison Mutai               |                                       +--------__BASE_XLAT_TABLE_END__--------+
69af5b49e9SHarrison Mutai    0x04028800 |                                       +--------------__BSS_END__--------------+
70af5b49e9SHarrison Mutai               |                                       +-------__BASE_XLAT_TABLE_START__-------+
71af5b49e9SHarrison Mutai               |                                       +-----__PMF_PERCPU_TIMESTAMP_END__------+
72af5b49e9SHarrison Mutai               |                                       +---------__PMF_TIMESTAMP_END__---------+
73af5b49e9SHarrison Mutai    0x04028580 |                                       +--------__PMF_TIMESTAMP_START__--------+
74af5b49e9SHarrison Mutai    0x04028000 |                                       +-------------__BSS_START__-------------+
75af5b49e9SHarrison Mutai    0x04027e40 |                                       +------------__STACKS_END__-------------+
76af5b49e9SHarrison Mutai    0x04027840 |                                       +-----------__STACKS_START__------------+
77af5b49e9SHarrison Mutai    0x04027000 |                                       +------------__RODATA_END__-------------+
78af5b49e9SHarrison Mutai               |                                       +------------__CPU_OPS_END__------------+
79af5b49e9SHarrison Mutai               |                                       +-----------__CPU_OPS_START__-----------+
80af5b49e9SHarrison Mutai               |                                       +--------__FCONF_POPULATOR_END__--------+
81af5b49e9SHarrison Mutai               |                                       +--------------__GOT_END__--------------+
82af5b49e9SHarrison Mutai               |                                       +-------------__GOT_START__-------------+
83af5b49e9SHarrison Mutai               |                                       +---------__PMF_SVC_DESCS_END__---------+
84af5b49e9SHarrison Mutai    0x04026c10 |                                       +--------__PMF_SVC_DESCS_START__--------+
85af5b49e9SHarrison Mutai    0x04026bf8 |                                       +-------__FCONF_POPULATOR_START__-------+
86af5b49e9SHarrison Mutai               |                                       +-----------__RODATA_START__------------+
87af5b49e9SHarrison Mutai    0x04026000 |                                       +-------------__TEXT_END__--------------+
88af5b49e9SHarrison Mutai    0x04021000 |                                       +------------__TEXT_START__-------------+
89af5b49e9SHarrison Mutai    0x000062b5 +------------__BL1_ROM_END__------------+                                       |
90af5b49e9SHarrison Mutai    0x00005df0 +----------__DATA_ROM_START__-----------+                                       |
91af5b49e9SHarrison Mutai               +------------__CPU_OPS_END__------------+                                       |
92af5b49e9SHarrison Mutai               +--------------__GOT_END__--------------+                                       |
93af5b49e9SHarrison Mutai               +-------------__GOT_START__-------------+                                       |
94af5b49e9SHarrison Mutai    0x00005de8 +------------__RODATA_END__-------------+                                       |
95af5b49e9SHarrison Mutai               +-----------__CPU_OPS_START__-----------+                                       |
96af5b49e9SHarrison Mutai               +--------__FCONF_POPULATOR_END__--------+                                       |
97af5b49e9SHarrison Mutai               +---------__PMF_SVC_DESCS_END__---------+                                       |
98af5b49e9SHarrison Mutai    0x00005c98 +--------__PMF_SVC_DESCS_START__--------+                                       |
99af5b49e9SHarrison Mutai    0x00005c80 +-------__FCONF_POPULATOR_START__-------+                                       |
100af5b49e9SHarrison Mutai               +-----------__RODATA_START__------------+                                       |
101af5b49e9SHarrison Mutai    0x00005000 +-------------__TEXT_END__--------------+                                       |
102af5b49e9SHarrison Mutai    0x00000000 +------------__TEXT_START__-------------+---------------------------------------+
103af5b49e9SHarrison Mutai
104af5b49e9SHarrison MutaiAddresses are displayed in hexadecimal by default but can be printed in decimal
105af5b49e9SHarrison Mutaiinstead with the ``-d`` option.
106af5b49e9SHarrison Mutai
107af5b49e9SHarrison MutaiBecause of the length of many of the symbols, the tool defaults to a text width
108af5b49e9SHarrison Mutaiof 120 chars. This can be increased if needed with the ``-w`` option.
109af5b49e9SHarrison Mutai
110af5b49e9SHarrison MutaiFor more detailed help instructions, run:
111af5b49e9SHarrison Mutai
112af5b49e9SHarrison Mutai.. code:: shell
113af5b49e9SHarrison Mutai
114af5b49e9SHarrison Mutai    poetry run memory --help
115af5b49e9SHarrison Mutai
116*d9d5eb13SHarrison MutaiMemory Footprint
117*d9d5eb13SHarrison Mutai~~~~~~~~~~~~~~~~
118*d9d5eb13SHarrison Mutai
119*d9d5eb13SHarrison MutaiThe tool enables users to view static memory consumption. When the options
120*d9d5eb13SHarrison Mutai``-f``, or ``--footprint`` are provided, the script analyses the ELF binaries in
121*d9d5eb13SHarrison Mutaithe build path to generate a table (per memory type), showing memory allocation
122*d9d5eb13SHarrison Mutaiand usage. This is the default output generated by the tool.
123*d9d5eb13SHarrison Mutai
124*d9d5eb13SHarrison Mutai.. code:: shell
125*d9d5eb13SHarrison Mutai
126*d9d5eb13SHarrison Mutai    $ poetry run memory -f
127*d9d5eb13SHarrison Mutai    build-path: build/fvp/release
128*d9d5eb13SHarrison Mutai    +----------------------------------------------------------------------------+
129*d9d5eb13SHarrison Mutai    |                         Memory Usage (bytes) [RAM]                         |
130*d9d5eb13SHarrison Mutai    +-----------+------------+------------+------------+------------+------------+
131*d9d5eb13SHarrison Mutai    | Component |   Start    |   Limit    |    Size    |    Free    |   Total    |
132*d9d5eb13SHarrison Mutai    +-----------+------------+------------+------------+------------+------------+
133*d9d5eb13SHarrison Mutai    |    BL1    |    4034000 |    4040000 |       7000 |       5000 |       c000 |
134*d9d5eb13SHarrison Mutai    |    BL2    |    4021000 |    4034000 |       d000 |       6000 |      13000 |
135*d9d5eb13SHarrison Mutai    |    BL2U   |    4021000 |    4034000 |       a000 |       9000 |      13000 |
136*d9d5eb13SHarrison Mutai    |    BL31   |    4003000 |    4040000 |      1e000 |      1f000 |      3d000 |
137*d9d5eb13SHarrison Mutai    +-----------+------------+------------+------------+------------+------------+
138*d9d5eb13SHarrison Mutai
139*d9d5eb13SHarrison Mutai    +----------------------------------------------------------------------------+
140*d9d5eb13SHarrison Mutai    |                         Memory Usage (bytes) [ROM]                         |
141*d9d5eb13SHarrison Mutai    +-----------+------------+------------+------------+------------+------------+
142*d9d5eb13SHarrison Mutai    | Component |   Start    |   Limit    |    Size    |    Free    |   Total    |
143*d9d5eb13SHarrison Mutai    +-----------+------------+------------+------------+------------+------------+
144*d9d5eb13SHarrison Mutai    |    BL1    |          0 |    4000000 |       5df0 |    3ffa210 |    4000000 |
145*d9d5eb13SHarrison Mutai    +-----------+------------+------------+------------+------------+------------+
146*d9d5eb13SHarrison Mutai
147*d9d5eb13SHarrison MutaiThe script relies on symbols in the symbol table to determine the start, end,
148*d9d5eb13SHarrison Mutaiand limit addresses of each bootloader stage.
149*d9d5eb13SHarrison Mutai
150af5b49e9SHarrison Mutai--------------
151af5b49e9SHarrison Mutai
152af5b49e9SHarrison Mutai*Copyright (c) 2023, Arm Limited. All rights reserved.*
153af5b49e9SHarrison Mutai
154af5b49e9SHarrison Mutai.. _Poetry: https://python-poetry.org/docs/
155