Sathees Balya | 17d8eed | 2019-01-30 15:56:44 +0000 | [diff] [blame] | 1 | Library at ROM |
| 2 | ============== |
| 3 | |
| 4 | .. section-numbering:: |
| 5 | :suffix: . |
| 6 | |
| 7 | .. contents:: |
| 8 | |
| 9 | This document provides an overview of the "library at ROM" implementation in |
| 10 | Trusted Firmware-A (TF-A). |
| 11 | |
| 12 | Introduction |
| 13 | ~~~~~~~~~~~~ |
| 14 | |
| 15 | The "library at ROM" feature allows platforms to build a library of functions to |
| 16 | be placed in ROM. This reduces SRAM usage by utilising the available space in |
| 17 | ROM. The "library at ROM" contains a jump table with the list of functions that |
| 18 | are placed in ROM. The capabilities of the "library at ROM" are: |
| 19 | |
| 20 | 1. Functions can be from one or several libraries. |
| 21 | |
| 22 | 2. Functions can be patched after they have been programmed into ROM. |
| 23 | |
| 24 | 3. Platform-specific libraries can be placed in ROM. |
| 25 | |
| 26 | 4. Functions can be accessed by one or more BL images. |
| 27 | |
| 28 | Index file |
| 29 | ~~~~~~~~~~ |
| 30 | |
| 31 | .. image:: diagrams/romlib_design.png |
| 32 | :width: 600 |
| 33 | |
| 34 | Library at ROM is described by an index file with the list of functions to be |
| 35 | placed in ROM. The index file is platform specific and its format is: |
| 36 | |
| 37 | :: |
| 38 | |
| 39 | lib function [patch] |
| 40 | |
| 41 | lib -- Name of the library the function belongs to |
| 42 | function -- Name of the function to be placed in library at ROM |
| 43 | [patch] -- Option to patch the function |
| 44 | |
| 45 | It is also possible to insert reserved spaces in the list by using the keyword |
| 46 | "reserved" rather than the "lib" and "function" names as shown below: |
| 47 | |
| 48 | :: |
| 49 | |
| 50 | reserved reserved |
| 51 | |
| 52 | The reserved spaces can be used to add more functions in the future without |
| 53 | affecting the order and location of functions already existing in the jump |
| 54 | table. Also, for additional flexibility and modularity, the index file can |
| 55 | include other index files. |
| 56 | |
| 57 | For an index file example, refer to ``lib/romlib/jmptbl.i``. |
| 58 | |
| 59 | Wrapper functions |
| 60 | ~~~~~~~~~~~~~~~~~ |
| 61 | |
| 62 | .. image:: diagrams/romlib_wrapper.png |
| 63 | :width: 600 |
| 64 | |
| 65 | When invoking a function of the "library at ROM", the calling sequence is as |
| 66 | follows: |
| 67 | |
| 68 | BL image --> wrapper function --> jump table entry --> library at ROM |
| 69 | |
| 70 | The index file is used to create a jump table which is placed in ROM. Then, the |
| 71 | wrappers refer to the jump table to call the "library at ROM" functions. The |
| 72 | wrappers essentially contain a branch instruction to the jump table entry |
| 73 | corresponding to the original function. Finally, the original function in the BL |
| 74 | image(s) is replaced with the wrapper function. |
| 75 | |
| 76 | The "library at ROM" contains a necessary init function that initialises the |
| 77 | global variables defined by the functions inside "library at ROM". |
| 78 | |
| 79 | Scripts |
| 80 | ~~~~~~~ |
| 81 | |
| 82 | There are several scripts that generate the necessary files for the "library at |
| 83 | ROM" to work: |
| 84 | |
| 85 | 1. ``gentbl.sh`` - Generates the jump table by parsing the index file. |
| 86 | |
| 87 | 2. ``genvar.sh`` - Generates the jump table global variable (**not** the jump |
| 88 | table itself) with the absolute address in ROM. This global variable is, |
| 89 | basically, a pointer to the jump table. |
| 90 | |
| 91 | 3. ``genwrappers.sh`` - Generates a wrapper function for each entry in the index |
| 92 | file except for the ones that contain the keyword ``patch``. The generated |
| 93 | wrapper file is called ``<lib>_<fn_name>.S``. |
| 94 | |
| 95 | Patching of functions in library at ROM |
| 96 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 97 | |
| 98 | The ``genwrappers.sh`` script does not generate wrappers for the entries in the |
| 99 | index file that contain the keyword ``patch``. Thus, it allows calling the |
| 100 | function from the actual library by breaking the link to the "library at ROM" |
| 101 | version of this function. |
| 102 | |
| 103 | The calling sequence for a patched function is as follows: |
| 104 | |
| 105 | BL image --> function |
| 106 | |
| 107 | Build library at ROM |
| 108 | ~~~~~~~~~~~~~~~~~~~~~ |
| 109 | |
| 110 | The environment variable ``CROSS_COMPILE`` must be set as per the user guide. |
| 111 | |
| 112 | :: |
| 113 | |
| 114 | make PLAT=fvp \ |
| 115 | MBEDTLS_DIR=</path/to/mbedtls/> \ |
| 116 | TRUSTED_BOARD_BOOT=1 GENERATE_COT=1 \ |
| 117 | ARM_ROTPK_LOCATION=devel_rsa \ |
| 118 | ROT_KEY=plat/arm/board/common/rotpk/arm_rotprivk_rsa.pem \ |
| 119 | BL33=</path/to/bl33.bin> \ |
| 120 | USE_ROMLIB=1 \ |
| 121 | all fip |
| 122 | |
| 123 | -------------- |
| 124 | |
| 125 | *Copyright (c) 2019, Arm Limited. All rights reserved.* |