blob: d8bc89ceae9130301180c627872e79e7b84eb008 [file] [log] [blame]
Sathees Balya17d8eed2019-01-30 15:56:44 +00001Library at ROM
2==============
3
Sathees Balya17d8eed2019-01-30 15:56:44 +00004This document provides an overview of the "library at ROM" implementation in
5Trusted Firmware-A (TF-A).
6
7Introduction
8~~~~~~~~~~~~
9
10The "library at ROM" feature allows platforms to build a library of functions to
11be placed in ROM. This reduces SRAM usage by utilising the available space in
12ROM. The "library at ROM" contains a jump table with the list of functions that
13are placed in ROM. The capabilities of the "library at ROM" are:
14
151. Functions can be from one or several libraries.
16
172. Functions can be patched after they have been programmed into ROM.
18
193. Platform-specific libraries can be placed in ROM.
20
214. Functions can be accessed by one or more BL images.
22
23Index file
24~~~~~~~~~~
25
Paul Beesley814f8c02019-03-13 15:49:27 +000026.. image:: ../resources/diagrams/romlib_design.png
Sathees Balya17d8eed2019-01-30 15:56:44 +000027 :width: 600
28
29Library at ROM is described by an index file with the list of functions to be
30placed in ROM. The index file is platform specific and its format is:
31
32::
33
34 lib function [patch]
35
36 lib -- Name of the library the function belongs to
37 function -- Name of the function to be placed in library at ROM
38 [patch] -- Option to patch the function
39
40It is also possible to insert reserved spaces in the list by using the keyword
41"reserved" rather than the "lib" and "function" names as shown below:
42
43::
44
Imre Kis2d137c52019-07-09 18:30:58 +020045 reserved
Sathees Balya17d8eed2019-01-30 15:56:44 +000046
47The reserved spaces can be used to add more functions in the future without
48affecting the order and location of functions already existing in the jump
49table. Also, for additional flexibility and modularity, the index file can
50include other index files.
51
52For an index file example, refer to ``lib/romlib/jmptbl.i``.
53
54Wrapper functions
55~~~~~~~~~~~~~~~~~
56
Paul Beesley814f8c02019-03-13 15:49:27 +000057.. image:: ../resources/diagrams/romlib_wrapper.png
Sathees Balya17d8eed2019-01-30 15:56:44 +000058 :width: 600
59
60When invoking a function of the "library at ROM", the calling sequence is as
61follows:
62
63BL image --> wrapper function --> jump table entry --> library at ROM
64
65The index file is used to create a jump table which is placed in ROM. Then, the
66wrappers refer to the jump table to call the "library at ROM" functions. The
67wrappers essentially contain a branch instruction to the jump table entry
68corresponding to the original function. Finally, the original function in the BL
69image(s) is replaced with the wrapper function.
70
71The "library at ROM" contains a necessary init function that initialises the
72global variables defined by the functions inside "library at ROM".
73
Imre Kis2d137c52019-07-09 18:30:58 +020074Script
75~~~~~~
Sathees Balya17d8eed2019-01-30 15:56:44 +000076
Imre Kis2d137c52019-07-09 18:30:58 +020077There is a ``romlib_generate.py`` Python script that generates the necessary
78files for the "library at ROM" to work. It implements multiple functions:
Sathees Balya17d8eed2019-01-30 15:56:44 +000079
Imre Kis2d137c52019-07-09 18:30:58 +0200801. ``romlib_generate.py gentbl [args]`` - Generates the jump table by parsing
81 the index file.
Sathees Balya17d8eed2019-01-30 15:56:44 +000082
Imre Kis2d137c52019-07-09 18:30:58 +0200832. ``romlib_generator.py genvar [args]`` - Generates the jump table global
84 variable (**not** the jump table itself) with the absolute address in ROM.
85 This global variable is, basically, a pointer to the jump table.
Sathees Balya17d8eed2019-01-30 15:56:44 +000086
Imre Kis2d137c52019-07-09 18:30:58 +0200873. ``romlib_generator.py genwrappers [args]`` - Generates a wrapper function for
88 each entry in the index file except for the ones that contain the keyword
89 ``patch``. The generated wrapper file is called ``<fn_name>.s``.
90
914. ``romlib_generator.py pre [args]`` - Preprocesses the index file which means
92 it resolves all the include commands in the file recursively. It can also
93 generate a dependency file of the included index files which can be directly
94 used in makefiles.
95
96Each ``romlib_generate.py`` function has its own manual which is accessible by
97runing ``romlib_generator.py [function] --help``.
98
99``romlib_generate.py`` requires Python 3 environment.
100
Sathees Balya17d8eed2019-01-30 15:56:44 +0000101
102Patching of functions in library at ROM
103~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
104
Imre Kis2d137c52019-07-09 18:30:58 +0200105The ``romlib_generator.py genwrappers`` does not generate wrappers for the
106entries in the index file that contain the keyword ``patch``. Thus, it allows
107calling the function from the actual library by breaking the link to the
108"library at ROM" version of this function.
Sathees Balya17d8eed2019-01-30 15:56:44 +0000109
110The calling sequence for a patched function is as follows:
111
112BL image --> function
113
114Build library at ROM
115~~~~~~~~~~~~~~~~~~~~~
116
117The environment variable ``CROSS_COMPILE`` must be set as per the user guide.
John Tsichritzisaec19d32019-03-08 16:54:13 +0000118In the below example the usage of ROMLIB together with mbed TLS is demonstrated
119to showcase the benefits of library at ROM - it's not mandatory.
Sathees Balya17d8eed2019-01-30 15:56:44 +0000120
Paul Beesley493e3492019-03-13 15:11:04 +0000121.. code:: shell
Sathees Balya17d8eed2019-01-30 15:56:44 +0000122
123 make PLAT=fvp \
124 MBEDTLS_DIR=</path/to/mbedtls/> \
125 TRUSTED_BOARD_BOOT=1 GENERATE_COT=1 \
126 ARM_ROTPK_LOCATION=devel_rsa \
127 ROT_KEY=plat/arm/board/common/rotpk/arm_rotprivk_rsa.pem \
128 BL33=</path/to/bl33.bin> \
129 USE_ROMLIB=1 \
130 all fip
131
Sathees Balya17d8eed2019-01-30 15:56:44 +0000132--------------
133
134*Copyright (c) 2019, Arm Limited. All rights reserved.*