| # Copyright 2022 Google LLC |
| # |
| # Licensed under the Apache License, Version 2.0 (the "License"); |
| # you may not use this file except in compliance with the License. |
| # You may obtain a copy of the License at |
| # |
| # https://www.apache.org/licenses/LICENSE-2.0 |
| # |
| # Unless required by applicable law or agreed to in writing, software |
| # distributed under the License is distributed on an "AS IS" BASIS, |
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| # See the License for the specific language governing permissions and |
| # limitations under the License. |
| |
| # Builds CHERIoT firmware. |
| # The source for cheriot-rtos is in $(CHERIOT_SRC_DIR) |
| # The source for the application is in $(CHERIOT_FIRMWARE_SRC_DIR), defined |
| # according to ${CHERIOT_FIRMWARE} in ${PLATFORM}/platform.mk |
| # The outputs are placed in $(CHERIOT_FIRMWARE_DEBUG) or $(CHERIOT_FIRMWARE_RELEASE) |
| |
| # Drivers for each platform and platform-specific make targets are stored in |
| # platform/$PLATFORM/platform.mk make files. Everything in this file must be |
| # made platform-agnostic. As such, we use phony targets that can be extended in |
| # the platform.mk files as double-colon (::) aggregate targets. These phony |
| # targets are explicitly grouped and have notes in their doccomments. |
| |
| CHERIOT_SRC_DIR := $(ROOTDIR)/sw/cheriot-rtos |
| |
| # CHERIOT_OUT_DIR is defined in build/setup.sh |
| CHERIOT_OUT_DEBUG := $(CHERIOT_OUT_DIR)/debug |
| CHERIOT_OUT_RELEASE := $(CHERIOT_OUT_DIR)/release |
| |
| CHERIOT_FIRMWARE_DEBUG := $(CHERIOT_OUT_DEBUG)/cheriot/cheriot/release/${CHERIOT_FIRMWARE}-firmware |
| # XXX debug builds don't work atm |
| #CHERIOT_FIRMWARE_DEBUG := $(CHERIOT_OUT_DEBUG)/cheriot/cheriot/debug/${CHERIOT_FIRMWARE}-firmware |
| CHERIOT_FIRMWARE_RELEASE := $(CHERIOT_OUT_RELEASE)/cheriot/cheriot/release/${CHERIOT_FIRMWARE}-firmware |
| |
| # TODO: add CHERIOT_FIRMWARE_SRC_DIR (not currently defined in time to use here) |
| CHERIOT_SOURCES := $(shell find $(CHERIOT_SRC_DIR) \(\ |
| -name \*.rs -or \ |
| -name \*.c -or \ |
| -name \*.h -or \ |
| -name \*.cpp \ |
| \) -type f) |
| |
| # Platform-specific aggregate targets |
| |
| ## Builds auto-generated include files for the CHERIoT system |
| # |
| # In the generic case, this is a noop. But it's an aggregate target, |
| # so that platform-specific headers may also be generated from other |
| # parts of the project. |
| # |
| # Note: this is a platform-specific aggregate phony target, and additional rules |
| # for each platform are defined in build/$PLATFORM/platform.mk |
| cheriot-gen-headers:: |
| |
| ## Cleans the auto-generated CHERIoT include files |
| # |
| # Note: this is a platform-specific aggregate phony target, and additional rules |
| # for each platform are defined in build/$PLATFORM/platform.mk |
| cheriot-clean-headers:: |
| |
| ## CHERIoT debug build-tree preparation target |
| # |
| # Prepares the output directory tree for building. In the generic case, this |
| # just makes our target directory tree, but each specific platform may also need |
| # to link in source files or modify the target tree somewhat. This aggregate |
| # target provides that functionality for a debug build. |
| # |
| # Note: this is a platform-specific aggregate phony target, and additional rules |
| # for each platform are defined in build/$PLATFORM/platform.mk |
| cheriot-build-debug-prepare:: | $(CHERIOT_OUT_DEBUG) |
| |
| ## CHERIoT release build-tree preparation target |
| # |
| # Prepares the output directory tree for building. In the generic case, this |
| # just makes our target directory tree, but each specific platform may also need |
| # to link in source files or modify the target tree somewhat. This aggregate |
| # target provides that functionality for a release build. |
| # |
| # Note: this is a platform-specific aggregate phony target, and additional rules |
| # for each platform are defined in build/$PLATFORM/platform.mk |
| cheriot-build-release-prepare:: | $(CHERIOT_OUT_RELEASE) |
| |
| # CHERIoT-generic targets |
| |
| ## Cleans all CHERIoT build artifacts for the current platform |
| # TODO(sleffler): cheriot-clean-headers once they are per-platform |
| cheriot-clean: |
| rm -rf $(CHERIOT_OUT_DIR) |
| |
| $(CHERIOT_OUT_DEBUG): |
| mkdir -p $(CHERIOT_OUT_DEBUG) |
| |
| $(CHERIOT_OUT_RELEASE): |
| mkdir -p $(CHERIOT_OUT_RELEASE) |
| |
| # Update submodules to track any changes in the .gitmodules. Alternatively |
| # the submodules could be mirrored and spliced by the manifest but any |
| # pinned sha's would then need to be tracked. |
| cheriot_check: |
| echo Updating $(CHERIOT_SRC_DIR) submodules...; \ |
| git -C $(CHERIOT_SRC_DIR) submodule sync && \ |
| git -C $(CHERIOT_SRC_DIR) submodule update --init --jobs=8 --depth=10; \ |
| |
| |
| # Build CHERIoT firmware image. |
| |
| $(CHERIOT_FIRMWARE_DEBUG): $(CHERIOT_SOURCES) cheriot-gen-headers cheriot-build-debug-prepare | cheriot_check $(CHERIOT_OUT_DEBUG) |
| export XMAKE_CONFIGDIR=${CHERIOT_OUT_DEBUG}; \ |
| cd ${CHERIOT_FIRMWARE_SRC_DIR} && \ |
| xmake config \ |
| -o ${CHERIOT_OUT_DEBUG} \ |
| --sdk=${ROOTDIR}/cache/cheriot-tools \ |
| --board=${PLATFORM} \ |
| ${CHERIOT_DEBUG_CONFIG_OPTIONS} && \ |
| xmake build |
| |
| ## Generates CHERIoT build artifacts with debugging suport |
| cheriot-bundle-debug: $(CHERIOT_FIRMWARE_DEBUG) |
| |
| $(CHERIOT_FIRMWARE_RELEASE): $(CHERIOT_SOURCES) cheriot-gen-headers cheriot-build-release-prepare | cheriot_check $(CHERIOT_OUT_RELEASE) |
| export XMAKE_CONFIGDIR=${CHERIOT_OUT_RELEASE}; \ |
| cd ${CHERIOT_FIRMWARE_SRC_DIR} && \ |
| xmake config \ |
| -o ${CHERIOT_OUT_RELEASE} \ |
| --sdk=${ROOTDIR}/cache/cheriot-tools \ |
| --board=${PLATFORM} \ |
| ${CHERIOT_RELEASE_CONFIG_OPTIONS} && \ |
| xmake build |
| |
| ## Generates CHERIoT build artifacts setup for release |
| cheriot-bundle-release: $(CHERIOT_FIRMWARE_RELEASE) |
| |
| ## Generates both debug & release CHERIoT build artifacts |
| cheriot: cheriot-bundle-debug cheriot-bundle-release |
| |
| .PHONY:: cheriot cheriot_check cheriot-clean |
| .PHONY:: cheriot-bundle-debug cheriot-bundle-release |
| .PHONY:: cheriot-builtins-debug cheriot-builtins-release |
| .PHONY:: cheriot-gen-headers cheriot-clean-headers |
| .PHONY:: cheriot-build-debug-prepare cheriot-build-release-prepare |
| .PHONY:: $(CHERIOT_OUT_DEBUG) $(CHERIOT_OUT_RELEASE) |