]> rtime.felk.cvut.cz Git - coffee/buildroot.git/blob - docs/manual/customize-outside-br.txt
lrzsz: install symlinks for XMODEM and YMODEM
[coffee/buildroot.git] / docs / manual / customize-outside-br.txt
1 // -*- mode:doc -*- ;
2 // vim: set syntax=asciidoc:
3
4 [[outside-br-custom]]
5 === Keeping customizations outside of Buildroot
6
7 As already briefly mentioned in xref:customize-dir-structure[], you can
8 place project-specific customizations in two locations:
9
10  * directly within the Buildroot tree, typically maintaining them using
11    branches in a version control system so that upgrading to a newer
12    Buildroot release is easy.
13
14  * outside of the Buildroot tree, using the _br2-external_ mechanism.
15    This mechanism allows to keep package recipes, board support and
16    configuration files outside of the Buildroot tree, while still
17    having them nicely integrated in the build logic. We call this
18    location a _br2-external tree_. This section explains how to use
19    the br2-external mechanism and what to provide in a br2-external
20    tree.
21
22 One can tell Buildroot to use one or more br2-external trees by setting
23 the +BR2_EXTERNAL+ make variable set to the path(s) of the br2-external
24 tree(s) to use. It can be passed to any Buildroot +make+ invocation. It
25 is automatically saved in the hidden +.br-external.mk+ file in the output
26 directory. Thanks to this, there is no need to pass +BR2_EXTERNAL+ at
27 every +make+ invocation. It can however be changed at any time by
28 passing a new value, and can be removed by passing an empty value.
29
30 .Note
31 The path to a br2-external tree can be either absolute or relative.
32 If it is passed as a relative path, it is important to note that it is
33 interpreted relative to the main Buildroot source directory, *not* to
34 the Buildroot output directory.
35
36 .Note:
37 If using an br2-external tree from before Buildroot 2016.11, you need to
38 convert it before you can use it with Buildroot 2016.11 onward. See
39 xref:br2-external-converting[] for help on doing so.
40
41 Some examples:
42
43 -----
44 buildroot/ $ make BR2_EXTERNAL=/path/to/foo menuconfig
45 -----
46
47 From now on, definitions from the +/path/to/foo+ br2-external tree
48 will be used:
49
50 -----
51 buildroot/ $ make
52 buildroot/ $ make legal-info
53 -----
54
55 We can switch to another br2-external tree at any time:
56
57 -----
58 buildroot/ $ make BR2_EXTERNAL=/where/we/have/bar xconfig
59 -----
60
61 We can also use multiple br2-external trees:
62
63 ----
64 buildroot/ $ make BR2_EXTERNAL=/path/to/foo:/where/we/have/bar menuconfig
65 ----
66
67 Or disable the usage of any br2-external tree:
68
69 -----
70 buildroot/ $ make BR2_EXTERNAL= xconfig
71 -----
72
73 ==== Layout of a br2-external tree
74
75 A br2-external tree must contain at least those three files, described
76 in the following chapters:
77
78  * +external.desc+
79  * +external.mk+
80  * +Config.in+
81
82 Apart from those mandatory files, there may be additional and optional
83 content that may be present in a br2-external tree, like the +configs/+
84 directory. They are described in the following chapters as well.
85
86 A complete example br2-external tree layout is also described later.
87
88 ===== The +external.desc+ file
89
90 That file describes the br2-external tree: the _name_ and _description_
91 for that br2-external tree.
92
93 The format for this file is line based, with each line starting by a
94 keyword, followed by a colon and one or more spaces, followed by the
95 value assigned to that keyword. There are two keywords currently
96 recognised:
97
98  * +name+, mandatory, defines the name for that br2-external tree. That
99    name must only use ASCII characters in the set +[A-Za-z0-9_]+; any
100    other character is forbidden. Buildroot sets the variable
101    +BR2_EXTERNAL_$(NAME)_PATH+ to the absolute path of the br2-external
102    tree, so that you can use it to refer to your br2-external tree. This
103    variable is available both in Kconfig, so you can use it to source your
104    Kconfig files (see below) and in the Makefile, so that you can use it
105    to include other Makefiles (see below) or refer to other files (like
106    data files) from your br2-external tree.
107 +
108 .Note:
109 Since it is possible to use multiple br2-external trees at once, this
110   name is used by Buildroot to generate variables for each of those trees.
111   That name is used to identify your br2-external tree, so try to come up
112   with a name that really describes your br2-external tree, in order for
113   it to be relatively unique, so that it does not clash with another name
114   from another br2-external tree, especially if you are planning on
115   somehow sharing your br2-external tree with third parties or using
116   br2-external trees from third parties.
117
118  * +desc+, optional, provides a short description for that br2-external
119    tree. It shall fit on a single line, is mostly free-form (see below),
120    and is used when displaying information about a br2-external tree (e.g.
121    above the list of defconfig files, or as the prompt in the menuconfig);
122    as such, it should relatively brief (40 chars is probably a good upper
123    limit). The description is available in the +BR2_EXTERNAL_$(NAME)_DESC+
124    variable.
125
126 Examples of names and the corresponding +BR2_EXTERNAL_$(NAME)_PATH+
127 variables:
128
129   * +FOO+ -> +BR2_EXTERNAL_FOO_PATH+
130   * +BAR_42+ -> +BR2_EXTERNAL_BAR_42_PATH+
131
132 In the following examples, it is assumed the name to be set to +BAR_42+.
133
134 .Note:
135 Both +BR2_EXTERNAL_$(NAME)_PATH+ and `BR2_EXTERNAL_$(NAME)_DESC` are
136   available in the Kconfig files and the Makefiles. They are also
137   exported in the environment so are available in post-build, post-image
138   and in-fakeroot scripts.
139
140 ===== The +Config.in+ and +external.mk+ files
141
142 Those files (which may each be empty) can be used to define package
143 recipes (i.e. +foo/Config.in+ and +foo/foo.mk+ like for packages bundled
144 in Buildroot itself) or other custom configuration options or make logic.
145
146 Buildroot automatically includes the +Config.in+ from each br2-external
147 tree to make it appear in the top-level configuration menu, and includes
148 the +external.mk+ from each br2-external tree with the rest of the
149 makefile logic.
150
151 The main usage of this is to store package recipes. The recommended way
152 to do this is to write a +Config.in+ file that looks like:
153
154 ------
155 source "$BR2_EXTERNAL_BAR_42_PATH/package/package1/Config.in"
156 source "$BR2_EXTERNAL_BAR_42_PATH/package/package2/Config.in"
157 ------
158
159 Then, have an +external.mk+ file that looks like:
160
161 ------
162 include $(sort $(wildcard $(BR2_EXTERNAL_BAR_42_PATH)/package/*/*.mk))
163 ------
164
165 And then in +$(BR2_EXTERNAL_BAR_42_PATH)/package/package1+ and
166 +$(BR2_EXTERNAL_BAR_42_PATH)/package/package2+ create normal
167 Buildroot package recipes, as explained in xref:adding-packages[].
168 If you prefer, you can also group the packages in subdirectories
169 called <boardname> and adapt the above paths accordingly.
170
171 You can also define custom configuration options in +Config.in+ and
172 custom make logic in +external.mk+.
173
174 ===== The +configs/+ directory
175
176 One can store Buildroot defconfigs in the +configs+ subdirectory of
177 the br2-external tree. Buildroot will automatically show them in the
178 output of +make list-defconfigs+ and allow them to be loaded with the
179 normal +make <name>_defconfig+ command. They will be visible in the
180 'make list-defconfigs' output, below an +External configs+ label that
181 contains the name of the br2-external tree they are defined in.
182
183 .Note:
184 If a defconfig file is present in more than one br2-external tree, then
185 the one from the last br2-external tree is used. It is thus possible
186 to override a defconfig bundled in Buildroot or another br2-external
187 tree.
188
189 ===== Free-form content
190
191 One can store all the board-specific configuration files there, such
192 as the kernel configuration, the root filesystem overlay, or any other
193 configuration file for which Buildroot allows to set the location (by
194 using the +BR2_EXTERNAL_$(NAME)_PATH+ variable). For example, you
195 could set the paths to a global patch directory, to a rootfs overlay
196 and to the kernel configuration file as follows (e.g. by running
197 `make menuconfig` and filling in these options):
198
199 ----
200 BR2_GLOBAL_PATCH_DIR=$(BR2_EXTERNAL_BAR_42_PATH)/patches/
201 BR2_ROOTFS_OVERLAY=$(BR2_EXTERNAL_BAR_42_PATH)/board/<boardname>/overlay/
202 BR2_LINUX_KERNEL_CUSTOM_CONFIG_FILE=$(BR2_EXTERNAL_BAR_42_PATH)/board/<boardname>/kernel.config
203 ----
204
205 ===== Example layout
206
207 Here is an example layout using all features of br2-external (the sample
208 content is shown for the file above it, when it is relevant to explain
209 the br2-external tree; this is all entirely made up just for the sake of
210 illustration, of course):
211
212 ----
213 /path/to/br2-ext-tree/
214   |- external.desc
215   |     |name: BAR_42
216   |     |desc: Example br2-external tree
217   |     `----
218   |
219   |- Config.in
220   |     |source "$BR2_EXTERNAL_BAR_42_PATH/package/pkg-1/Config.in"
221   |     |source "$BR2_EXTERNAL_BAR_42_PATH/package/pkg-2/Config.in"
222   |     |
223   |     |config BAR_42_FLASH_ADDR
224   |     |    hex "my-board flash address"
225   |     |    default 0x10AD
226   |     `----
227   |
228   |- external.mk
229   |     |include $(sort $(wildcard $(BR2_EXTERNAL_BAR_42_PATH)/package/*/*.mk))
230   |     |
231   |     |flash-my-board:
232   |     |    $(BR2_EXTERNAL_BAR_42_PATH)/board/my-board/flash-image \
233   |     |        --image $(BINARIES_DIR)/image.bin \
234   |     |        --address $(BAR_42_FLASH_ADDR)
235   |     `----
236   |
237   |- package/pkg-1/Config.in
238   |     |config BR2_PACKAGE_PKG_1
239   |     |    bool "pkg-1"
240   |     |    help
241   |     |      Some help about pkg-1
242   |     `----
243   |- package/pkg-1/pkg-1.hash
244   |- package/pkg-1/pkg-1.mk
245   |     |PKG_1_VERSION = 1.2.3
246   |     |PKG_1_SITE = /some/where/to/get/pkg-1
247   |     |PKG_1_LICENSE = blabla
248   |     |
249   |     |define PKG_1_INSTALL_INIT_SYSV
250   |     |    $(INSTALL) -D -m 0755 $(PKG_1_PKGDIR)/S99my-daemon \
251   |     |                          $(TARGET_DIR)/etc/init.d/S99my-daemon
252   |     |endef
253   |     |
254   |     |$(eval $(autotools-package))
255   |     `----
256   |- package/pkg-1/S99my-daemon
257   |
258   |- package/pkg-2/Config.in
259   |- package/pkg-2/pkg-2.hash
260   |- package/pkg-2/pkg-2.mk
261   |
262   |- configs/my-board_defconfig
263   |     |BR2_GLOBAL_PATCH_DIR="$(BR2_EXTERNAL_BAR_42_PATH)/patches/"
264   |     |BR2_ROOTFS_OVERLAY="$(BR2_EXTERNAL_BAR_42_PATH)/board/my-board/overlay/"
265   |     |BR2_ROOTFS_POST_IMAGE_SCRIPT="$(BR2_EXTERNAL_BAR_42_PATH)/board/my-board/post-image.sh"
266   |     |BR2_LINUX_KERNEL_CUSTOM_CONFIG_FILE="$(BR2_EXTERNAL_BAR_42_PATH)/board/my-board/kernel.config"
267   |     `----
268   |
269   |- patches/linux/0001-some-change.patch
270   |- patches/linux/0002-some-other-change.patch
271   |- patches/busybox/0001-fix-something.patch
272   |
273   |- board/my-board/kernel.config
274   |- board/my-board/overlay/var/www/index.html
275   |- board/my-board/overlay/var/www/my.css
276   |- board/my-board/flash-image
277   `- board/my-board/post-image.sh
278         |#!/bin/sh
279         |generate-my-binary-image \
280         |    --root ${BINARIES_DIR}/rootfs.tar \
281         |    --kernel ${BINARIES_DIR}/zImage \
282         |    --dtb ${BINARIES_DIR}/my-board.dtb \
283         |    --output ${BINARIES_DIR}/image.bin
284         `----
285 ----
286
287 The br2-external tree will then be visible in the menuconfig (with
288 the layout expanded):
289
290 ----
291 External options  --->
292     *** Example br2-external tree (in /path/to/br2-ext-tree/)
293     [ ] pkg-1
294     [ ] pkg-2
295     (0x10AD) my-board flash address
296 ----
297
298 If you are using more than one br2-external tree, it would look like
299 (with the layout expanded and the second one with name +FOO_27+ but no
300 +desc:+ field in +external.desc+):
301
302 ----
303 External options  --->
304     Example br2-external tree  --->
305         *** Example br2-external tree (in /path/to/br2-ext-tree)
306         [ ] pkg-1
307         [ ] pkg-2
308         (0x10AD) my-board flash address
309     FOO_27  --->
310         *** FOO_27 (in /path/to/another-br2-ext)
311         [ ] foo
312         [ ] bar
313 ----