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 ├── module 31 ├── <firmware_1> 32 │ └── <firmware 1 level configuration files...> 33 └── <firmware_2> 34 └── <firmware 2 level configuration files...> 35 36Different products that share similar files can be grouped into 37product_group. Shared files are located under __common__ directory, while 38all products' specific code are kept under product directory. The following 39hierarchy shows the grouped products under __product__ directory: 40 41 <root> 42 └─ product 43 └──<product_group> 44 ├── common 45 │ ├── include 46 │ │ └── <common header files for products...> 47 │ │── src 48 │ │ └── <common source files for products...> 49 │ └── module 50 └── <product> 51 ├── product.mk 52 │── include 53 │ └── <product level header files...> 54 │── src 55 │ └── <product level source files...> 56 │── module 57 ├── <firmware_1> 58 │ └── <firmware 1 level configuration files...> 59 └── <firmware_2> 60 └── <firmware 2 level configuration files...> 61 62__Note:__ The names of the \<product\> and \<firmware\> directories must not 63contain spaces. 64 65The product.mk is described in the following sections. 66 67### The product.mk File 68 69The product.mk file describes a product to the build system listing all build 70images. 71 72The following parameters are mandatory: 73 74* __BS_PRODUCT_NAME__ - Human-friendly name for the product. The content of this 75 variable is exposed to the compilation units. 76* __BS_FIRMWARE_LIST__ - List of firmware directories under the current 77 product. 78 79# Module 80 81Modules are the building blocks of a product firmware. Modules can be 82implemented under the modules/ directory at the root of the project, or they 83can be product-specific and implemented under the product/\<product\>/modules 84directory. In either case, modules have the following directory structure: 85 86 <module root> 87 └── <module> 88 ├── include 89 │ └── <header files...> 90 ├── src 91 │ ├── Makefile 92 │ └── <source files...> 93 ├── lib 94 │ └── mod_<module>.a 95 ├── test 96 │ └── <unit test files...> 97 ├── doc 98 │ └── <documentation files...> 99 ├── CMakeLists.txt 100 └── Module.cmake 101 102Only one of the 'src' or 'lib' directories is required. When building a 103firmware, if the 'src' directory is present then the module library is built 104from the module source code and the 'lib' directory, if present, is ignored. 105When only the 'lib' directory is supplied, the module's pre-built static library 106is used when building a firmware. 107 108__Note:__ The name of the \<module\> directory must not contain spaces. 109 110The name of the \<module\> directory is used in __SCP_MODULES__ by `cmake` 111 112The __doc__ directory is optional and may contain markdown (.md) based 113documentation. 114 115## Module Code Generation 116 117When a firmware is built there are two prerequisite files that will be generated 118by the build system. 119* fwk_module_idx.h: Contains an enumeration of the indices of the modules that 120 make up the firmware. The ordering of the module indices in the enumeration 121 within fwk_module_idx.h is guaranteed to follow the order of the module 122 names in the SCP_MODULES list within Firmware.cmake file. This same 123 ordering is used by the framework at runtime when performing operations 124 that involve iterating over all the modules that are present in the 125 firmware, such as the fwk_module_init_modules() function in fwk_module.c. 126* fwk_module_list.c: Contains a table of pointers to module descriptors, one 127 for each module that is being built as part of the firmware. This file and 128 its contents are used internally by the framework and should not normally 129 be used by other units such as modules. 130 131# Interface 132 133Interfaces provide a common set of abstractions and ensure consistent 134implementation across different modules. They define the APIs and data 135structures used by high-level modules, which do not need to be aware of the 136low-level module implementation details. This implies that low-level modules can 137be replaced without affecting the high-level ones. 138 139Each interface has its own directory within the interface folder, which contains 140header files in the main directory for including the interface's API. 141Additionally, the `doc` directory provides detailed documentation on how to use 142the interface effectively. 143 144## Folder Structure 145 146The `interface` folder follows a structure similar to the following: 147 148``` 149interface/ 150├── <interface name 1> 151│ ├── interface_<interface name 1>.h 152│ └── doc 153│ └── <documentation files...> 154├── <interface name 2> 155│ ├── interface_<interface name 2>.h 156│ └── doc 157│ └── <documentation files...> 158└── ... 159``` 160 161- Each interface is organized in its own subdirectory, following the naming 162convention `interface_<interface name>.h`. 163- The subdirectory within each interface contains the header files that 164define the interface's API. 165- The `doc` directory within each interface contains optional documentation 166specific to that interface. 167 168## Usage 169 170To use an interface it requires to add the `include` path in the respective 171module `CMakeLists.txt` file. 172 173```cmake 174target_include_directories(${SCP_MODULE_TARGET} PUBLIC 175 "${CMAKE_SOURCE_DIR}/interface/<interface name>") 176``` 177Then simply include `interface_<interface name>.h` file to use the interface API 178definitions. 179 180It is important to refer to the interface-specific documentation provided in the 181`doc` directory of each interface for detailed information on how to use the 182interface and any specific considerations or limitations. 183 184# Build Configurations 185 186It is possible to enable different build configurations for each build image, 187for more information please refer to [cmake_readme.md](doc/cmake_readme.md). 188 189## Notification Support 190 191When building a firmware and its dependencies, the 192`SCP_ENABLE_NOTIFICATIONS` parameter controls whether notification support 193is enabled or not. 194 195When notification support is enabled, the following applies: 196 197* The `BUILD_HAS_NOTIFICATION` definition is defined for the units being built. 198* Notification specific APIs are made available to the modules via the 199 framework components (see [framework.md](doc/framework.md)). 200 201## SCMI Perf Fast Channels Support 202 203When building a firmware and its dependencies, the 204`BUILD_HAS_SCMI_PERF_FAST_CHANNELS` parameter controls whether DVFS Fast channel 205support is enabled or not. 206 207## SCMI Notifications Support 208 209When building a firmware and its dependencies, the 210`BUILD_HAS_SCMI_NOTIFICATIONS` parameter controls whether SCMI notifications 211are enabled or not. 212 213## Debug Module Support 214 215When building a firmware and its dependencies, the `BUILD_HAS_DEBUG_UNIT` 216parameter controls whether the support for the Debug probe/trace unit is 217included. 218 219## SCMI Statistics Support 220 221When building a firmware and its dependencies, the 222`BUILD_HAS_STATISTICS` parameter controls whether statistics support is 223enabled or not. 224 225## SCMI Agent Resource Permissions 226 227When building a firmware and its dependencies, it is possible to enable a set 228of predefined access rules for protocols and agents via the 229BS_FIRMWARE_HAS_RESOURCE_PERMISSIONS parameter. 230 231## SCMI Reset Domain Protocol 232 233When building a firmware and its dependencies, the SCMI Reset protocol is 234enabled to control of reset-capable domains in the platform. This is possible 235via the BS_FIRMWARE_HAS_SCMI_RESET parameter. 236 237## SCMI Sensor Event Notifications 238 239When building a firmware and its dependencies, the 240`BUILD_HAS_SCMI_SENSOR_EVENTS` parameter controls if SCMI event notifications 241are enabled. 242 243## SCMI Sensor Protocol V2 244 245When building a firmware and its dependencies, the `BUILD_HAS_SCMI_SENSOR_V2` 246parameter controls if SCMI Sensor protocol V2 is enabled. 247 248## Clock Tree Management 249 250When building a firmware and its dependencies, the `BUILD_HAS_CLOCK_TREE_MGMT` 251parameter controls if Clock Tree Management is enabled. 252 253## Transport based fast channel 254 255When building a firmware and its dependencies, the `BUILD_HAS_MOD_TRANSPORT_FC` 256parameter controls if generic transport module implemented fast channel 257interface to be used. 258 259## Core Idle Suspend (WFE) 260 261WFE on ARM architecture makes processor suspends it's execution until it 262receives any interrupt. SCP firmware will execute this instruction when SCP 263firmware is in idle state, that is, when it has finished responding to all the 264internal events and external interrupts. 265 266Use `FMW_DISABLE_ARCH_SUSPEND` option to disable this execution of WFE. It 267can be defined in a platform specific fmw_arch.h file and adding this file 268in product/*/include directory. 269 270## Agent Logical Domain 271 272When building a firmware and its dependencies, the 273`BUILD_HAS_AGENT_LOGICAL_DOMAIN` parameter controls whether SCMI agents can have 274their relative view on system resources exposed by SCMI protocols. 275 276 277## Performance Plugin Handler 278 279/* TODO */ 280 281Definitions 282=========== 283 284The build system sets the following definitions during the compilation of C 285and assembly units: 286 287* __BUILD_HOST__ - Set when the CPU target is "host". 288* __BUILD_HAS_NOTIFICATION__ - Set when the build has notification support. 289* __BUILD_STRING__ - A string containing build information (date, time and git 290 commit). The string is assembled using the tool build_string.py. 291* __BUILD_TESTS__ - Set when building the framework unit tests. 292* __BUILD_MODE_DEBUG__ - Set when building in debug mode. 293* __NDEBUG__ - Set when building in release mode. This definition is used by the 294 standard C library to disable the assert() support. 295* __BUILD_VERSION_MAJOR__ - Major version number. 296* __BUILD_VERSION_MINOR__ - Minor version number. 297* __BUILD_VERSION_PATCH__ - Patch version number. 298* __BUILD_VERSION_STRING__ - String version using the format 299 "v<major>.<minor>.<patch>". Example: "v2.3.1". 300* __BUILD_VERSION_DESCRIBE_STRING__ - String containing version, date and git 301 commit description. If the source code is not under a git repository, the 302 string __unknown__ will be used instead. 303* __BUILD_HAS_MOD_<MODULE NAME>__ - Set for each module being part of the build. 304