2
1

customize-directory-structure.adoc 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. // -*- mode:doc; -*-
  2. // vim: set syntax=asciidoc:
  3. [[customize-dir-structure]]
  4. === Recommended directory structure
  5. When customizing Buildroot for your project, you will be creating one or
  6. more project-specific files that need to be stored somewhere. While most
  7. of these files could be placed in _any_ location as their path is to be
  8. specified in the Buildroot configuration, the Buildroot developers
  9. recommend a specific directory structure which is described in this
  10. section.
  11. Orthogonal to this directory structure, you can choose _where_ you place
  12. this structure itself: either inside the Buildroot tree, or outside of
  13. it using a br2-external tree. Both options are valid, the choice is up
  14. to you.
  15. ----
  16. +-- board/
  17. | +-- <company>/
  18. | +-- <boardname>/
  19. | +-- linux.config
  20. | +-- busybox.config
  21. | +-- <other configuration files>
  22. | +-- post_build.sh
  23. | +-- post_image.sh
  24. | +-- rootfs_overlay/
  25. | | +-- etc/
  26. | | +-- <some files>
  27. | +-- patches/
  28. | +-- foo/
  29. | | +-- <some patches>
  30. | +-- libbar/
  31. | +-- <some other patches>
  32. |
  33. +-- configs/
  34. | +-- <boardname>_defconfig
  35. |
  36. +-- package/
  37. | +-- <company>/
  38. | +-- Config.in (if not using a br2-external tree)
  39. | +-- <company>.mk (if not using a br2-external tree)
  40. | +-- package1/
  41. | | +-- Config.in
  42. | | +-- package1.mk
  43. | +-- package2/
  44. | +-- Config.in
  45. | +-- package2.mk
  46. |
  47. +-- Config.in (if using a br2-external tree)
  48. +-- Makefile (if using a custom top makefile)
  49. +-- external.mk (if using a br2-external tree)
  50. +-- external.desc (if using a br2-external tree)
  51. ----
  52. Details on the files shown above are given further in this chapter.
  53. Note: if you choose to place this structure outside of the Buildroot
  54. tree but in a br2-external tree, the <company> and possibly <boardname>
  55. components may be superfluous and can be left out.
  56. ==== Implementing layered customizations
  57. It is quite common for a user to have several related projects that partly
  58. need the same customizations. Instead of duplicating these
  59. customizations for each project, it is recommended to use a layered
  60. customization approach, as explained in this section.
  61. Almost all of the customization methods available in Buildroot, like
  62. post-build scripts and root filesystem overlays, accept a
  63. space-separated list of items. The specified items are always treated in
  64. order, from left to right. By creating more than one such item, one for
  65. the common customizations and another one for the really
  66. project-specific customizations, you can avoid unnecessary duplication.
  67. Each layer is typically embodied by a separate directory inside
  68. +board/<company>/+. Depending on your projects, you could even introduce
  69. more than two layers.
  70. An example directory structure for where a user has two customization
  71. layers 'common' and 'fooboard' is:
  72. ----
  73. +-- board/
  74. +-- <company>/
  75. +-- common/
  76. | +-- post_build.sh
  77. | +-- rootfs_overlay/
  78. | | +-- ...
  79. | +-- patches/
  80. | +-- ...
  81. |
  82. +-- fooboard/
  83. +-- linux.config
  84. +-- busybox.config
  85. +-- <other configuration files>
  86. +-- post_build.sh
  87. +-- rootfs_overlay/
  88. | +-- ...
  89. +-- patches/
  90. +-- ...
  91. ----
  92. For example, if the user has the +BR2_GLOBAL_PATCH_DIR+ configuration
  93. option set as:
  94. ----
  95. BR2_GLOBAL_PATCH_DIR="board/<company>/common/patches board/<company>/fooboard/patches"
  96. ----
  97. then first the patches from the 'common' layer would be applied,
  98. followed by the patches from the 'fooboard' layer.
  99. ==== Custom top Makefile
  100. You normally launch Buildroot from the buildroot source directory, pointing
  101. +BR2_EXTERNAL+ and +O+ to the right places for the build you want to make.
  102. You can simplify this by adding a Makefile to your br2-external that sets
  103. these variables and calls into buildroot.
  104. You can add additional, custom rules to this Makefile for various tasks you
  105. need to perform, e.g. integrate multiple configurations into a single image,
  106. upload to a release server or to a test device, include multiple
  107. br2-external configurations, etc.
  108. A basic Makefile looks like this. It assumes the buildroot source is available
  109. (e.g. as a git submodule) in the +buildroot+ subdirectory. It makes sure that
  110. the download directory is shared between different builds, and it organizes
  111. the output directories in a structure under +outputs/+.
  112. ----
  113. # SPDX-License-Identifier: GPL-2.0
  114. # Avoid surprises by disabling default rules
  115. MAKEFLAGS += --no-builtin-rules
  116. .SUFFIXES:
  117. THIS_EXTERNAL_PATH := $(abspath $(dir $(lastword $(MAKEFILE_LIST))))
  118. # Put downloads in this directory instead of in the Buildroot directory
  119. ifeq ($(BR2_DL_DIR),)
  120. BR2_DL_DIR = $(THIS_EXTERNAL_PATH)/dl
  121. endif
  122. OUTPUT_BASEDIR = $(THIS_EXTERNAL_PATH)/output
  123. OUTPUT_DIR = $(OUTPUT_BASEDIR)/$(patsubst %_defconfig,%,$@)
  124. MAKE_BUILDROOT = $(MAKE) -C $(THIS_EXTERNAL_PATH)/buildroot BR2_EXTERNAL=$(THIS_EXTERNAL_PATH)
  125. %: $(THIS_EXTERNAL_PATH)/configs/%
  126. $(MAKE_BUILDROOT) O=$(OUTPUT_DIR) $@
  127. sed -i /^BR2_DL_DIR=.*/s%%BR2_DL_DIR=$(BR2_DL_DIR)% $(OUTPUT_DIR)/.config
  128. ----