customize-outside-br.txt 16 KB

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