doc: describe building with GCC
[platform/kernel/u-boot.git] / doc / build / gcc.rst
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
20     sudo apt-get gcc gcc-aarch64-linux-gnu
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 \
27       device-tree-compiler dfu-util efitools flex gdisk liblz4-tool \
28       libguestfs-tools libncurses-dev libpython3-dev libsdl2-dev libssl-dev \
29       lzma-alone openssl python3 python3-coverage python3-pyelftools \
30       python3-pytest python3-sphinxcontrib.apidoc python3-sphinx-rtd-theme swig
31
32 Prerequisites
33 -------------
34
35 For some boards you have to build prerequisite files before you can build
36 U-Boot, e.g. for the some boards you will need to build the ARM Trusted Firmware
37 beforehand. Please, refer to the board specific documentation
38 :doc:`../board/index`.
39
40 Configuration
41 -------------
42
43 Directory configs/ contains the template configuration files for the maintained
44 boards following the naming scheme::
45
46     <board name>_defconfig
47
48 These files have been stripped of default settings. So you cannot use them
49 directly. Instead their name serves as a make target to generate the actual
50 configuration file .config. For instance the configuration template for the
51 Odroid C2 board is called odroid-c2_defconfig. The corresponding .config file
52 is generated by
53
54 .. code-block:: bash
55
56     make odroid-c2_defconfig
57
58 You can adjust the configuration using
59
60 .. code-block:: bash
61
62     make menuconfig
63
64 Building
65 --------
66
67 When cross compiling you will have to specify the prefix of the cross-compiler.
68 You can either specify the value of the CROSS_COMPILE variable on the make
69 command line or export it beforehand.
70
71 .. code-block:: bash
72
73     CROSS_COMPILE=<compiler-prefix> make
74
75 Assuming cross compiling on Debian for ARMv8 this would be
76
77 .. code-block:: bash
78
79     CROSS_COMPILE=aarch64-linux-gnu- make
80
81 Build parameters
82 ~~~~~~~~~~~~~~~~
83
84 A list of available parameters for the make command can be obtained via
85
86 .. code-block:: bash
87
88     make help
89
90 You can speed up compilation by parallelization using the -j parameter, e.g.
91
92 .. code-block:: bash
93
94     CROSS_COMPILE=aarch64-linux-gnu- make -j$(nproc)
95
96 Further important build parameters are
97
98 * O=<dir> - generate all output files in directory <dir>, including .config
99 * V=1 - verbose build
100
101 Other build targets
102 ~~~~~~~~~~~~~~~~~~~
103
104 A list of all make targets can be obtained via
105
106 .. code-block:: bash
107
108     make help
109
110 Important ones are
111
112 * clean - remove most generated files but keep the configuration
113 * mrproper - remove all generated files + config + various backup files
114
115 Installation
116 ------------
117
118 The process for installing U-Boot on the target device is device specific.
119 Please, refer to the board specific documentation :doc:`../board/index`.