1# Build System
2
3## Overview
4
5The SCP/MCP Software build system is composed of a top-level Makefile and a
6collection of .mk files used to build and describe the building blocks and tools
7that create the final firmware binaries.
8
9This documentation covers the use of the build system when creating products,
10firmware, and modules.
11
12For details on how to build an existing product, please refer to the
13documentation using the build system's "help" parameter:
14
15    $> make help
16
17## Product and Firmware Hierarchy
18
19A product is a collection of firmware. All products are located under the
20__product__ directory and must adhere to the following hierarchy:
21
22    <root>
23     └─ product
24        └── <product>
25            ├── product.mk
26            │   ├── include
27            │   │   └── <product level header files...>
28            │   └── src
29            │       └── <product level source files...>
30            ├── <firmware_1>
31            │   └── <firmware 1 level configuration files...>
32            └── <firmware_2>
33                └── <firmware 2 level configuration files...>
34
35__Note:__ The names of the \<product\> and \<firmware\> directories must not
36contain spaces.
37
38The product.mk is described in the following sections.
39
40### The product.mk File
41
42The product.mk file describes a product to the build system listing all build
43images.
44
45The following parameters are mandatory:
46
47* __BS_PRODUCT_NAME__ - Human-friendly name for the product. The content of this
48  variable is exposed to the compilation units.
49* __BS_PRODUCT_FIRMWARE_LIST__ - List of firmware directories under the current
50  product.
51
52# Module
53
54Modules are the building blocks of a product firmware. Modules can be
55implemented under the modules/ directory at the root of the project, or they
56can be product-specific and implemented under the product/\<product\>/modules
57directory. In either case, modules have the following directory structure:
58
59    <module root>
60     └── <module>
61          ├── include
62          │   └── <header files...>
63          ├── src
64          │    ├── Makefile
65          │    └── <source files...>
66          ├── lib
67          │    └── mod_<module>.a
68          ├── test
69          │    └── <unit test files...>
70          ├── doc
71          │    └── <documentation files...>
72          ├── CMakeLists.txt
73          └── Module.cmake
74
75Only one of the 'src' or 'lib' directories is required. When building a
76firmware, if the 'src' directory is present then the module library is built
77from the module source code and the 'lib' directory, if present, is ignored.
78When only the 'lib' directory is supplied, the module's pre-built static library
79is used when building a firmware.
80
81__Note:__ The name of the \<module\> directory must not contain spaces.
82
83The name of the \<module\> directory is used in __SCP_MODULE__ by `cmake`
84
85The __doc__ directory is optional and may contain markdown (.md) based
86documentation.
87
88## Module Code Generation
89
90When a firmware is built there are two prerequisite files that will be generated
91by the build system, specifically by the __gen_module_code.py__ script:
92* fwk_module_idx.h: Contains an enumeration of the indices of the modules that
93    make up the firmware. The ordering of the module indices in the enumeration
94    within fwk_module_idx.h is guaranteed to follow the order of the module
95    names in the BS_FIRMWARE_MODULES list within the firmware's firmware.mk
96    file. This same ordering is used by the framework at runtime when performing
97    operations that involve iterating over all the modules that are present in
98    the firmware, such as the init_modules() function in fwk_module.c.
99* fwk_module_list.c: Contains a table of pointers to module descriptors, one
100    for each module that is being built as part of the firmware. This file and
101    its contents are used internally by the framework and should not normally
102    be used by other units such as modules.
103
104# Build Configurations
105
106It is possible to enable different build configurations for each build image,
107for more information please refer to [cmake_readme.md](doc/cmake_readme.md).
108
109## Notification Support
110
111When building a firmware and its dependencies, the
112`SCP_ENABLE_NOTIFICATIONS` parameter controls whether notification support
113is enabled or not.
114
115When notification support is enabled, the following applies:
116
117* The `BUILD_HAS_NOTIFICATION` definition is defined for the units being built.
118* Notification specific APIs are made available to the modules via the
119  framework components (see [framework.md](doc/framework.md)).
120
121## SCMI Perf Fast Channels Support
122
123When building a firmware and its dependencies, the
124`BUILD_HAS_SCMI_PERF_FAST_CHANNELS` parameter controls whether DVFS Fast channel
125support is enabled or not.
126
127## SCMI Notifications Support
128
129When building a firmware and its dependencies, the
130`BUILD_HAS_SCMI_NOTIFICATIONS` parameter controls whether SCMI notifications
131are enabled or not.
132
133## Debug Module Support
134
135When building a firmware and its dependencies, the `BUILD_HAS_DEBUG_UNIT`
136parameter controls whether the support for the Debug probe/trace unit is
137included.
138
139## SCMI Statistics Support
140
141When building a firmware and its dependencies, the
142`BUILD_HAS_STATISTICS` parameter controls whether statistics support is
143enabled or not.
144
145## SCMI Agent Resource Permissions
146
147When building a firmware and its dependencies, it is possible to enable a set
148of predefined access rules for protocols and agents via the
149BS_FIRMWARE_HAS_RESOURCE_PERMISSIONS parameter.
150
151## SCMI Reset Domain Protocol
152
153When building a firmware and its dependencies, the SCMI Reset protocol is
154enabled to control of reset-capable domains in the platform. This is possible
155via the BS_FIRMWARE_HAS_SCMI_RESET parameter.
156
157## SCMI Sensor Event Notifications
158
159When building a firmware and its dependencies, the
160`BUILD_HAS_SCMI_SENSOR_EVENTS` parameter controls if SCMI event notifications
161are enabled.
162
163## SCMI Sensor Protocol V2
164
165When building a firmware and its dependencies, the `BUILD_HAS_SCMI_SENSOR_V2`
166parameter controls if SCMI Sensor protocol V2 is enabled.
167
168## Clock Tree Management
169
170When building a firmware and its dependencies, the `BUILD_HAS_CLOCK_TREE_MGMT`
171parameter controls if Clock Tree Management is enabled.
172
173## Core Idle Suspend (WFE)
174
175WFE on ARM architecture makes processor suspends it's execution until it
176receives any interrupt. SCP firmware will execute this instruction when SCP
177firmware is in idle state, that is, when it has finished responding to all the
178internal events and external interrupts.
179
180Use `FMW_DISABLE_ARCH_SUSPEND` option to disable this execution of WFE. It
181can be defined in a platform specific fmw_arch.h file and adding this file
182in product/*/include directory.
183
184## Performance Plugin Handler
185
186/* TODO */
187
188Definitions
189===========
190
191The build system sets the following definitions during the compilation of C
192and assembly units:
193
194* __BUILD_HOST__ - Set when the CPU target is "host".
195* __BUILD_HAS_NOTIFICATION__ - Set when the build has notification support.
196* __BUILD_STRING__ - A string containing build information (date, time and git
197  commit). The string is assembled using the tool build_string.py.
198* __BUILD_TESTS__ - Set when building the framework unit tests.
199* __BUILD_MODE_DEBUG__ - Set when building in debug mode.
200* __NDEBUG__ - Set when building in release mode. This definition is used by the
201  standard C library to disable the assert() support.
202* __BUILD_VERSION_MAJOR__ - Major version number.
203* __BUILD_VERSION_MINOR__ - Minor version number.
204* __BUILD_VERSION_PATCH__ - Patch version number.
205* __BUILD_VERSION_STRING__ - String version using the format
206  "v<major>.<minor>.<patch>". Example: "v2.3.1".
207* __BUILD_VERSION_DESCRIBE_STRING__ - String containing version, date and git
208  commit description. If the source code is not under a git repository, the
209  string __unknown__ will be used instead.
210* __BUILD_HAS_MOD_<MODULE NAME>__ - Set for each module being part of the build.
211