Heinrich Schuchardt | 16327a2 | 2020-09-05 10:58:53 +0200 | [diff] [blame] | 1 | Building with GCC |
| 2 | ================= |
| 3 | |
| 4 | Dependencies |
| 5 | ------------ |
| 6 | |
| 7 | For building U-Boot you need a GCC compiler for your host platform. If you |
| 8 | are not building on the target platform you further need a GCC cross compiler. |
| 9 | |
| 10 | Debian based |
| 11 | ~~~~~~~~~~~~ |
| 12 | |
| 13 | On Debian based systems the cross compiler packages are named |
| 14 | gcc-<architecture>-linux-gnu. |
| 15 | |
| 16 | You could install GCC and the GCC cross compiler for the ARMv8 architecture with |
| 17 | |
| 18 | .. code-block:: bash |
| 19 | |
Heinrich Schuchardt | c78ffd1 | 2020-09-20 12:31:47 +0200 | [diff] [blame] | 20 | sudo apt-get install gcc gcc-aarch64-linux-gnu |
Heinrich Schuchardt | 16327a2 | 2020-09-05 10:58:53 +0200 | [diff] [blame] | 21 | |
| 22 | Depending on the build targets further packages maybe needed |
| 23 | |
| 24 | .. code-block:: bash |
| 25 | |
| 26 | sudo apt-get install bc bison build-essential coccinelle \ |
Heinrich Schuchardt | bc2ed7f | 2021-08-01 23:29:20 +0200 | [diff] [blame] | 27 | device-tree-compiler dfu-util efitools flex gdisk graphviz imagemagick \ |
Heinrich Schuchardt | a5469ac | 2022-03-12 11:56:23 +0100 | [diff] [blame] | 28 | liblz4-tool libgnutls28-dev libguestfs-tools libncurses-dev \ |
| 29 | libpython3-dev libsdl2-dev libssl-dev lz4 lzma lzma-alone openssl \ |
Heinrich Schuchardt | 9b97d12 | 2022-10-08 00:46:35 +0200 | [diff] [blame] | 30 | pkg-config python3 python3-asteval python3-coverage python3-filelock \ |
Heinrich Schuchardt | 566cd94 | 2022-05-26 10:15:58 +0200 | [diff] [blame] | 31 | python3-pkg-resources python3-pycryptodome python3-pyelftools \ |
Heinrich Schuchardt | 9b97d12 | 2022-10-08 00:46:35 +0200 | [diff] [blame] | 32 | python3-pytest python3-pytest-xdist python3-sphinxcontrib.apidoc \ |
| 33 | python3-sphinx-rtd-theme python3-subunit python3-testtools \ |
| 34 | python3-virtualenv swig uuid-dev |
Heinrich Schuchardt | 16327a2 | 2020-09-05 10:58:53 +0200 | [diff] [blame] | 35 | |
Heinrich Schuchardt | 0a79392 | 2020-09-20 12:01:30 +0200 | [diff] [blame] | 36 | SUSE based |
| 37 | ~~~~~~~~~~ |
| 38 | |
| 39 | On suse based systems the cross compiler packages are named |
| 40 | cross-<architecture>-gcc<version>. |
| 41 | |
| 42 | You could install GCC and the GCC 10 cross compiler for the ARMv8 architecture |
| 43 | with |
| 44 | |
| 45 | .. code-block:: bash |
| 46 | |
| 47 | sudo zypper install gcc cross-aarch64-gcc10 |
| 48 | |
| 49 | Depending on the build targets further packages maybe needed. |
| 50 | |
| 51 | .. code-block:: bash |
| 52 | |
| 53 | zypper install bc bison flex gcc libopenssl-devel libSDL2-devel make \ |
| 54 | ncurses-devel python3-devel python3-pytest swig |
| 55 | |
Heinrich Schuchardt | 81050ef | 2022-01-11 01:37:01 +0100 | [diff] [blame] | 56 | Alpine Linux |
| 57 | ~~~~~~~~~~~~ |
| 58 | |
| 59 | For building U-Boot on Alpine Linux at least the following packages are needed: |
| 60 | |
| 61 | .. code-block:: bash |
| 62 | |
Milan P. Stanić | 9a9e480 | 2023-10-17 21:46:58 +0200 | [diff] [blame] | 63 | apk add alpine-sdk bc bison dtc flex gnutls-dev linux-headers ncurses-dev \ |
| 64 | openssl-dev py3-elftools py3-setuptools python3-dev swig util-linux-dev |
| 65 | |
| 66 | Depending on the build target further packages may be needed: |
| 67 | |
| 68 | * sandbox with lcd: sdl2-dev |
Milan P. Stanić | 1bfd473 | 2023-11-04 15:38:15 +0100 | [diff] [blame] | 69 | * riscv64 S-mode targets: opensbi |
Milan P. Stanić | 9a9e480 | 2023-10-17 21:46:58 +0200 | [diff] [blame] | 70 | * some arm64 targets: arm-trusted-firmware |
Heinrich Schuchardt | 81050ef | 2022-01-11 01:37:01 +0100 | [diff] [blame] | 71 | |
Heinrich Schuchardt | 16327a2 | 2020-09-05 10:58:53 +0200 | [diff] [blame] | 72 | Prerequisites |
| 73 | ------------- |
| 74 | |
| 75 | For some boards you have to build prerequisite files before you can build |
| 76 | U-Boot, e.g. for the some boards you will need to build the ARM Trusted Firmware |
| 77 | beforehand. Please, refer to the board specific documentation |
| 78 | :doc:`../board/index`. |
| 79 | |
| 80 | Configuration |
| 81 | ------------- |
| 82 | |
| 83 | Directory configs/ contains the template configuration files for the maintained |
| 84 | boards following the naming scheme:: |
| 85 | |
| 86 | <board name>_defconfig |
| 87 | |
| 88 | These files have been stripped of default settings. So you cannot use them |
| 89 | directly. Instead their name serves as a make target to generate the actual |
| 90 | configuration file .config. For instance the configuration template for the |
| 91 | Odroid C2 board is called odroid-c2_defconfig. The corresponding .config file |
| 92 | is generated by |
| 93 | |
| 94 | .. code-block:: bash |
| 95 | |
| 96 | make odroid-c2_defconfig |
| 97 | |
| 98 | You can adjust the configuration using |
| 99 | |
| 100 | .. code-block:: bash |
| 101 | |
| 102 | make menuconfig |
| 103 | |
| 104 | Building |
| 105 | -------- |
| 106 | |
| 107 | When cross compiling you will have to specify the prefix of the cross-compiler. |
| 108 | You can either specify the value of the CROSS_COMPILE variable on the make |
| 109 | command line or export it beforehand. |
| 110 | |
| 111 | .. code-block:: bash |
| 112 | |
| 113 | CROSS_COMPILE=<compiler-prefix> make |
| 114 | |
| 115 | Assuming cross compiling on Debian for ARMv8 this would be |
| 116 | |
| 117 | .. code-block:: bash |
| 118 | |
| 119 | CROSS_COMPILE=aarch64-linux-gnu- make |
| 120 | |
Heinrich Schuchardt | 68c367d | 2024-07-14 09:18:04 +0200 | [diff] [blame] | 121 | Out-of-tree building |
| 122 | ~~~~~~~~~~~~~~~~~~~~ |
| 123 | |
| 124 | By default building is performed locally and the objects are saved in the source |
| 125 | directory. To build out-out-tree use one of the two methods below: |
| 126 | |
| 127 | Add O= parameter to the make command line: |
| 128 | |
| 129 | .. code-block:: bash |
| 130 | |
| 131 | make O=/tmp/build distclean |
| 132 | make O=/tmp/build NAME_defconfig |
| 133 | make O=/tmp/build |
| 134 | |
| 135 | Use environment variable KBUILD_OUTPUT: |
| 136 | |
| 137 | .. code-block:: bash |
| 138 | |
| 139 | export KBUILD_OUTPUT=/tmp/build |
| 140 | make distclean |
| 141 | make NAME_defconfig |
| 142 | make |
| 143 | |
| 144 | .. note:: |
| 145 | |
| 146 | The command line "O=" parameter overrides the KBUILD_OUTPUT environment |
| 147 | variable. |
| 148 | |
Heinrich Schuchardt | 16327a2 | 2020-09-05 10:58:53 +0200 | [diff] [blame] | 149 | Build parameters |
| 150 | ~~~~~~~~~~~~~~~~ |
| 151 | |
| 152 | A list of available parameters for the make command can be obtained via |
| 153 | |
| 154 | .. code-block:: bash |
| 155 | |
| 156 | make help |
| 157 | |
| 158 | You can speed up compilation by parallelization using the -j parameter, e.g. |
| 159 | |
| 160 | .. code-block:: bash |
| 161 | |
| 162 | CROSS_COMPILE=aarch64-linux-gnu- make -j$(nproc) |
| 163 | |
| 164 | Further important build parameters are |
| 165 | |
| 166 | * O=<dir> - generate all output files in directory <dir>, including .config |
| 167 | * V=1 - verbose build |
| 168 | |
Simon Glass | 90619e7 | 2021-09-22 11:34:44 -0600 | [diff] [blame] | 169 | Devicetree compiler |
| 170 | ~~~~~~~~~~~~~~~~~~~ |
| 171 | |
| 172 | Boards that use `CONFIG_OF_CONTROL` (i.e. almost all of them) need the |
| 173 | devicetree compiler (dtc). Those with `CONFIG_PYLIBFDT` need pylibfdt, a Python |
| 174 | library for accessing devicetree data. Suitable versions of these are included |
| 175 | in the U-Boot tree in `scripts/dtc` and built automatically as needed. |
| 176 | |
| 177 | To use the system versions of these, use the DTC parameter, for example |
| 178 | |
| 179 | .. code-block:: bash |
| 180 | |
| 181 | DTC=/usr/bin/dtc make |
| 182 | |
| 183 | In this case, dtc and pylibfdt are not built. The build checks that the version |
| 184 | of dtc is new enough. It also makes sure that pylibfdt is present, if needed |
| 185 | (see `scripts_dtc` in the Makefile). |
| 186 | |
| 187 | Note that the :doc:`tools` are always built with the included version of libfdt |
| 188 | so it is not possible to build U-Boot tools with a system libfdt, at present. |
| 189 | |
Simon Glass | 6c8ec91 | 2022-08-03 12:13:08 -0600 | [diff] [blame] | 190 | Link-time optimisation (LTO) |
| 191 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 192 | |
| 193 | U-Boot supports link-time optimisation which can reduce the size of the final |
| 194 | U-Boot binaries, particularly with SPL. |
| 195 | |
| 196 | At present this can be enabled by ARM boards by adding `CONFIG_LTO=y` into the |
| 197 | defconfig file. Other architectures are not supported. LTO is enabled by default |
| 198 | for sandbox. |
| 199 | |
| 200 | This does incur a link-time penalty of several seconds. For faster incremental |
| 201 | builds during development, you can disable it by setting `NO_LTO` to `1`. |
| 202 | |
| 203 | .. code-block:: bash |
| 204 | |
| 205 | NO_LTO=1 make |
| 206 | |
Heinrich Schuchardt | 16327a2 | 2020-09-05 10:58:53 +0200 | [diff] [blame] | 207 | Other build targets |
| 208 | ~~~~~~~~~~~~~~~~~~~ |
| 209 | |
| 210 | A list of all make targets can be obtained via |
| 211 | |
| 212 | .. code-block:: bash |
| 213 | |
| 214 | make help |
| 215 | |
| 216 | Important ones are |
| 217 | |
| 218 | * clean - remove most generated files but keep the configuration |
| 219 | * mrproper - remove all generated files + config + various backup files |
| 220 | |
| 221 | Installation |
| 222 | ------------ |
| 223 | |
| 224 | The process for installing U-Boot on the target device is device specific. |
| 225 | Please, refer to the board specific documentation :doc:`../board/index`. |