customize-outside-br.txt 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  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 +.br-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. directory. They are described in the following chapters as well.
  64. A complete example br2-external tree layout is also described later.
  65. ===== The +external.desc+ file
  66. That file describes the br2-external tree: the _name_ and _description_
  67. for that br2-external tree.
  68. The format for this file is line based, with each line starting by a
  69. keyword, followed by a colon and one or more spaces, followed by the
  70. value assigned to that keyword. There are two keywords currently
  71. recognised:
  72. * +name+, mandatory, defines the name for that br2-external tree. That
  73. name must only use ASCII characters in the set +[A-Za-z0-9_]+; any
  74. other character is forbidden. Buildroot sets the variable
  75. +BR2_EXTERNAL_$(NAME)_PATH+ to the absolute path of the br2-external
  76. tree, so that you can use it to refer to your br2-external tree. This
  77. variable is available both in Kconfig, so you can use it to source your
  78. Kconfig files (see below) and in the Makefile, so that you can use it
  79. to include other Makefiles (see below) or refer to other files (like
  80. data files) from your br2-external tree.
  81. +
  82. .Note:
  83. Since it is possible to use multiple br2-external trees at once, this
  84. name is used by Buildroot to generate variables for each of those trees.
  85. That name is used to identify your br2-external tree, so try to come up
  86. with a name that really describes your br2-external tree, in order for
  87. it to be relatively unique, so that it does not clash with another name
  88. from another br2-external tree, especially if you are planning on
  89. somehow sharing your br2-external tree with third parties or using
  90. br2-external trees from third parties.
  91. * +desc+, optional, provides a short description for that br2-external
  92. tree. It shall fit on a single line, is mostly free-form (see below),
  93. and is used when displaying information about a br2-external tree (e.g.
  94. above the list of defconfig files, or as the prompt in the menuconfig);
  95. as such, it should relatively brief (40 chars is probably a good upper
  96. limit). The description is available in the +BR2_EXTERNAL_$(NAME)_DESC+
  97. variable.
  98. Examples of names and the corresponding +BR2_EXTERNAL_$(NAME)_PATH+
  99. variables:
  100. * +FOO+ -> +BR2_EXTERNAL_FOO_PATH+
  101. * +BAR_42+ -> +BR2_EXTERNAL_BAR_42_PATH+
  102. In the following examples, it is assumed the name to be set to +BAR_42+.
  103. .Note:
  104. Both +BR2_EXTERNAL_$(NAME)_PATH+ and `BR2_EXTERNAL_$(NAME)_DESC` are
  105. available in the Kconfig files and the Makefiles. They are also
  106. exported in the environment so are available in post-build, post-image
  107. and in-fakeroot scripts.
  108. ===== The +Config.in+ and +external.mk+ files
  109. Those files (which may each be empty) can be used to define package
  110. recipes (i.e. +foo/Config.in+ and +foo/foo.mk+ like for packages bundled
  111. in Buildroot itself) or other custom configuration options or make logic.
  112. Buildroot automatically includes the +Config.in+ from each br2-external
  113. tree to make it appear in the top-level configuration menu, and includes
  114. the +external.mk+ from each br2-external tree with the rest of the
  115. makefile logic.
  116. The main usage of this is to store package recipes. The recommended way
  117. to do this is to write a +Config.in+ file that looks like:
  118. ------
  119. source "$BR2_EXTERNAL_BAR_42_PATH/package/package1/Config.in"
  120. source "$BR2_EXTERNAL_BAR_42_PATH/package/package2/Config.in"
  121. ------
  122. Then, have an +external.mk+ file that looks like:
  123. ------
  124. include $(sort $(wildcard $(BR2_EXTERNAL_BAR_42_PATH)/package/*/*.mk))
  125. ------
  126. And then in +$(BR2_EXTERNAL_BAR_42_PATH)/package/package1+ and
  127. +$(BR2_EXTERNAL_BAR_42_PATH)/package/package2+ create normal
  128. Buildroot package recipes, as explained in xref:adding-packages[].
  129. If you prefer, you can also group the packages in subdirectories
  130. called <boardname> and adapt the above paths accordingly.
  131. You can also define custom configuration options in +Config.in+ and
  132. custom make logic in +external.mk+.
  133. ===== The +configs/+ directory
  134. One can store Buildroot defconfigs in the +configs+ subdirectory of
  135. the br2-external tree. Buildroot will automatically show them in the
  136. output of +make list-defconfigs+ and allow them to be loaded with the
  137. normal +make <name>_defconfig+ command. They will be visible in the
  138. 'make list-defconfigs' output, below an +External configs+ label that
  139. contains the name of the br2-external tree they are defined in.
  140. .Note:
  141. If a defconfig file is present in more than one br2-external tree, then
  142. the one from the last br2-external tree is used. It is thus possible
  143. to override a defconfig bundled in Buildroot or another br2-external
  144. tree.
  145. ===== Free-form content
  146. One can store all the board-specific configuration files there, such
  147. as the kernel configuration, the root filesystem overlay, or any other
  148. configuration file for which Buildroot allows to set the location (by
  149. using the +BR2_EXTERNAL_$(NAME)_PATH+ variable). For example, you
  150. could set the paths to a global patch directory, to a rootfs overlay
  151. and to the kernel configuration file as follows (e.g. by running
  152. `make menuconfig` and filling in these options):
  153. ----
  154. BR2_GLOBAL_PATCH_DIR=$(BR2_EXTERNAL_BAR_42_PATH)/patches/
  155. BR2_ROOTFS_OVERLAY=$(BR2_EXTERNAL_BAR_42_PATH)/board/<boardname>/overlay/
  156. BR2_LINUX_KERNEL_CUSTOM_CONFIG_FILE=$(BR2_EXTERNAL_BAR_42_PATH)/board/<boardname>/kernel.config
  157. ----
  158. ===== Example layout
  159. Here is an example layout using all features of br2-external (the sample
  160. content is shown for the file above it, when it is relevant to explain
  161. the br2-external tree; this is all entirely made up just for the sake of
  162. illustration, of course):
  163. ----
  164. /path/to/br2-ext-tree/
  165. |- external.desc
  166. | |name: BAR_42
  167. | |desc: Example br2-external tree
  168. | `----
  169. |
  170. |- Config.in
  171. | |source "$BR2_EXTERNAL_BAR_42_PATH/package/pkg-1/Config.in"
  172. | |source "$BR2_EXTERNAL_BAR_42_PATH/package/pkg-2/Config.in"
  173. | |
  174. | |config BAR_42_FLASH_ADDR
  175. | | hex "my-board flash address"
  176. | | default 0x10AD
  177. | `----
  178. |
  179. |- external.mk
  180. | |include $(sort $(wildcard $(BR2_EXTERNAL_BAR_42_PATH)/package/*/*.mk))
  181. | |
  182. | |flash-my-board:
  183. | | $(BR2_EXTERNAL_BAR_42_PATH)/board/my-board/flash-image \
  184. | | --image $(BINARIES_DIR)/image.bin \
  185. | | --address $(BAR_42_FLASH_ADDR)
  186. | `----
  187. |
  188. |- package/pkg-1/Config.in
  189. | |config BR2_PACKAGE_PKG_1
  190. | | bool "pkg-1"
  191. | | help
  192. | | Some help about pkg-1
  193. | `----
  194. |- package/pkg-1/pkg-1.hash
  195. |- package/pkg-1/pkg-1.mk
  196. | |PKG_1_VERSION = 1.2.3
  197. | |PKG_1_SITE = /some/where/to/get/pkg-1
  198. | |PKG_1_LICENSE = blabla
  199. | |
  200. | |define PKG_1_INSTALL_INIT_SYSV
  201. | | $(INSTALL) -D -m 0755 $(PKG_1_PKGDIR)/S99my-daemon \
  202. | | $(TARGET_DIR)/etc/init.d/S99my-daemon
  203. | |endef
  204. | |
  205. | |$(eval $(autotools-package))
  206. | `----
  207. |- package/pkg-1/S99my-daemon
  208. |
  209. |- package/pkg-2/Config.in
  210. |- package/pkg-2/pkg-2.hash
  211. |- package/pkg-2/pkg-2.mk
  212. |
  213. |- configs/my-board_defconfig
  214. | |BR2_GLOBAL_PATCH_DIR="$(BR2_EXTERNAL_BAR_42_PATH)/patches/"
  215. | |BR2_ROOTFS_OVERLAY="$(BR2_EXTERNAL_BAR_42_PATH)/board/my-board/overlay/"
  216. | |BR2_ROOTFS_POST_IMAGE_SCRIPT="$(BR2_EXTERNAL_BAR_42_PATH)/board/my-board/post-image.sh"
  217. | |BR2_LINUX_KERNEL_CUSTOM_CONFIG_FILE="$(BR2_EXTERNAL_BAR_42_PATH)/board/my-board/kernel.config"
  218. | `----
  219. |
  220. |- patches/linux/0001-some-change.patch
  221. |- patches/linux/0002-some-other-change.patch
  222. |- patches/busybox/0001-fix-something.patch
  223. |
  224. |- board/my-board/kernel.config
  225. |- board/my-board/overlay/var/www/index.html
  226. |- board/my-board/overlay/var/www/my.css
  227. |- board/my-board/flash-image
  228. `- board/my-board/post-image.sh
  229. |#!/bin/sh
  230. |generate-my-binary-image \
  231. | --root ${BINARIES_DIR}/rootfs.tar \
  232. | --kernel ${BINARIES_DIR}/zImage \
  233. | --dtb ${BINARIES_DIR}/my-board.dtb \
  234. | --output ${BINARIES_DIR}/image.bin
  235. `----
  236. ----
  237. The br2-external tree will then be visible in the menuconfig (with
  238. the layout expanded):
  239. ----
  240. External options --->
  241. *** Example br2-external tree (in /path/to/br2-ext-tree/)
  242. [ ] pkg-1
  243. [ ] pkg-2
  244. (0x10AD) my-board flash address
  245. ----
  246. If you are using more than one br2-external tree, it would look like
  247. (with the layout expanded and the second one with name +FOO_27+ but no
  248. +desc:+ field in +external.desc+):
  249. ----
  250. External options --->
  251. Example br2-external tree --->
  252. *** Example br2-external tree (in /path/to/br2-ext-tree)
  253. [ ] pkg-1
  254. [ ] pkg-2
  255. (0x10AD) my-board flash address
  256. FOO_27 --->
  257. *** FOO_27 (in /path/to/another-br2-ext)
  258. [ ] foo
  259. [ ] bar
  260. ----