lib/nhlt: Use common function to set NHLT version
[coreboot.git] / Documentation / getting_started / build_system.md
blob787c833d2b506551dbfed393bad73673fb571f1e
1 # The coreboot build system
2 (this document is still incomplete and will be filled in over time)
4 ## General operation
5 The coreboot build system is based on GNU make but extends it significantly
6 to the point of providing its own custom language.
7 The overhead of learning this new syntax is (hopefully) offset by its lower
8 complexity.
10 The build system is defined in the toplevel `Makefile` and `toolchain.inc`
11 and is supposed to be generic (and is in fact used with a number of other
12 projects).  Project specific configuration should reside in files called
13 `Makefile.inc`.
15 In general, the build system provides a number of "classes" that describe
16 various parts of the build. These cover the various build targets in coreboot
17 such as the stages, subdirectories with more source code, and the general
18 addition of files.
20 Each class has a name (eg. `romstage`, `subdirs`, `cbfs-files`) and is used
21 by filling in a variable of that name followed by `-y` (eg. `romstage-y`,
22 `subdirs-y`, `cbfs-files-y`).
23 The `-y` suffix allows a simple interaction with our Kconfig build
24 configuration system: Kconfig options are available as variables starting
25 with a `CONFIG_` prefix and boolean options contain `y`, `n` or are empty.
27 This allows `class-$(CONFIG_FOO) += bar` to conditionally add `bar` to
28 `class` depending on the choice for `FOO`.
30 ## classes
31 Classes can be defined as required. `subdirs` is handled internally since
32 it's parsed per subdirectory to add further directories to the rule set.
34 TODO: explain how to create new classes and how to evaluate them.
36 ### subdirs
37 `subdirs` contains subdirectories (relative to the current directory) that
38 should also be handled by the build system. The build system expects these
39 directories to contain a file called `Makefile.inc`.
41 Subdirectories are not read at the point where the `subdirs` statement
42 resides but later, after the current directory is handled (and potentially
43 others, too).
45 ### cbfs-files
46 This class is used to add files to the final CBFS image. Since several more
47 options need to be maintained than can comfortably fit in that single
48 variable, additional variables are used.
50 `cbfs-files-y` contains the file name used in the CBFS image (called `foo`
51 here). Additional options are added in `foo-$(option)` variables. The
52 supported options are:
54 *  `file`: The on-disk file to add as `foo` (required)
55 *  `type`: The file type. Can be `raw`, `stage`, `payload`, and `flat-binary`
56    (required)
57 *  `compression`: Can be `none` or `lzma` (default: none)
58 *  `position`: An absolute position constraint for the placement of the file
59    (default: none)
60 *  `align`: Minimum alignment for the file (default: none)
61 *  `options`: Additional cbfstool options (default: none)
63 `position` and `align` are mutually exclusive.
65 #### FMAP region support
66 With the addition of FMAP flash partitioning support to coreboot, there was a
67 need to extend the specification of files to provide more precise control
68 which regions should contain which files, and even change some flags based on
69 the region.
71 Since FMAP policies depend on features using FMAP, that's kept separate from
72 the cbfs-files class.
74 The `position` and `align` options for file `foo` can be overwritten for a
75 region `REGION` using `foo-REGION-position` and `foo-REGION-align`.
77 The regions that each file should end in can be defined by overriding a
78 function called `regions-for-file` that's called as
79 `$(call regions-for-file,$(filename))` and should return a comma-separated
80 list of regions, such as `REGION1,REGION2,REGION3`.
82 The default implementation just returns `COREBOOT` (the default region) for
83 all files.
85 vboot provides its own implementation of `regions-for-file` that can be used
86 as reference in `src/vboot/Makefile.inc`.