2 // vim: set syntax=asciidoc:
5 === Keeping customizations outside of Buildroot
7 As already briefly mentioned in xref:customize-dir-structure[], you can
8 place project-specific customizations in two locations:
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.
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
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.
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.
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.
44 buildroot/ $ make BR2_EXTERNAL=/path/to/foo menuconfig
47 From now on, definitions from the +/path/to/foo+ br2-external tree
52 buildroot/ $ make legal-info
55 We can switch to another br2-external tree at any time:
58 buildroot/ $ make BR2_EXTERNAL=/where/we/have/bar xconfig
61 We can also use multiple br2-external trees:
64 buildroot/ $ make BR2_EXTERNAL=/path/to/foo:/where/we/have/bar menuconfig
67 Or disable the usage of any br2-external tree:
70 buildroot/ $ make BR2_EXTERNAL= xconfig
73 ==== Layout of a br2-external tree
75 A br2-external tree must contain at least those three files, described
76 in the following chapters:
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.
86 A complete example br2-external tree layout is also described later.
88 ===== The +external.desc+ file
90 That file describes the br2-external tree: the _name_ and _description_
91 for that br2-external tree.
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
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.
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.
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+
126 Examples of names and the corresponding +BR2_EXTERNAL_$(NAME)_PATH+
129 * +FOO+ -> +BR2_EXTERNAL_FOO_PATH+
130 * +BAR_42+ -> +BR2_EXTERNAL_BAR_42_PATH+
132 In the following examples, it is assumed the name to be set to +BAR_42+.
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.
140 ===== The +Config.in+ and +external.mk+ files
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.
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
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:
155 source "$BR2_EXTERNAL_BAR_42_PATH/package/package1/Config.in"
156 source "$BR2_EXTERNAL_BAR_42_PATH/package/package2/Config.in"
159 Then, have an +external.mk+ file that looks like:
162 include $(sort $(wildcard $(BR2_EXTERNAL_BAR_42_PATH)/package/*/*.mk))
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.
171 You can also define custom configuration options in +Config.in+ and
172 custom make logic in +external.mk+.
174 ===== The +configs/+ directory
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.
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
189 ===== Free-form content
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):
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_FOO)/board/<boardname>/kernel.config
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):
213 /path/to/br2-ext-tree/
216 | |desc: Example br2-external tree
220 | |source "$BR2_EXTERNAL_BAR_42_PATH/package/pkg-1/Config.in"
221 | |source "$BR2_EXTERNAL_BAR_42_PATH/package/pkg-2/Config.in"
223 | |config BAR_42_FLASH_ADDR
224 | | hex "my-board flash address"
229 | |include $(sort $(wildcard $(BR2_EXTERNAL_BAR_42_PATH)/package/*/*.mk))
232 | | $(BR2_EXTERNAL_BAR_42_PATH)/board/my-board/flash-image \
233 | | --image $(BINARIES_DIR)/image.bin \
234 | | --address $(BAR_42_FLASH_ADDR)
237 |- package/pkg-1/Config.in
238 | |config BR2_PACKAGE_PKG_1
241 | | Some help about pkg-1
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
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
254 | |$(eval $(autotools-package))
256 |- package/pkg-1/S99my-daemon
258 |- package/pkg-2/Config.in
259 |- package/pkg-2/pkg-2.hash
260 |- package/pkg-2/pkg-2.mk
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_FOO)/board/my-board/kernel.config"
269 |- patches/linux/0001-some-change.patch
270 |- patches/linux/0002-some-other-change.patch
271 |- patches/busybox/0001-fix-something.patch
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
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
287 The br2-external tree will then be visible in the menuconfig (with
288 the layout expanded):
291 External options --->
292 *** Example br2-external tree (in /path/to/br2-ext-tree/)
295 (0x10AD) my-board flash address
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+):
303 External options --->
304 Example br2-external tree --->
305 *** Example br2-external tree (in /path/to/br2-ext-tree)
308 (0x10AD) my-board flash address
310 *** FOO_27 (in /path/to/another-br2-ext)