From 70edbd1cf5b51bf0b4a2135ab58c68a40969fb7b Mon Sep 17 00:00:00 2001 From: Grzegorz Swiderski Date: Thu, 9 May 2024 12:31:23 +0200 Subject: [PATCH] soc: nordic: Add system for validating DT headers against MDK Hardware-specific properties should stay in sync with the definitions provided by MDK. Existing measures for this include: * The `validate_base_addresses.c` file included in every build; * The `nordic-nrf-ficr-nrf54h20.h` header generated from SVD. If there's information that cannot be extracted from SVD, it may have to be validated against C types. Add `validate_binding_headers.c` for this purpose, which automagically includes all `dt-bindings` headers included by DTS in a given build. Signed-off-by: Grzegorz Swiderski --- soc/nordic/CMakeLists.txt | 13 ++++++++ soc/nordic/validate_binding_headers.c | 48 +++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 soc/nordic/validate_binding_headers.c diff --git a/soc/nordic/CMakeLists.txt b/soc/nordic/CMakeLists.txt index 9797d2e717a..f1ad19476f0 100644 --- a/soc/nordic/CMakeLists.txt +++ b/soc/nordic/CMakeLists.txt @@ -8,9 +8,22 @@ endif() zephyr_library_sources( validate_base_addresses.c + validate_binding_headers.c validate_enabled_instances.c ) +# Include dt-bindings headers into the build. This lets us validate all required +# DT values against the MDK, without having to conditionally include different +# headers for different SoCs. +set(dt_binding_includes ${DTS_INCLUDE_FILES}) +list(FILTER dt_binding_includes INCLUDE REGEX "/dt-bindings/.*\.h$") +list(TRANSFORM dt_binding_includes PREPEND "-include;") +set_source_files_properties( + validate_binding_headers.c + DIRECTORY ${CMAKE_CURRENT_LIST_DIR} + PROPERTIES COMPILE_OPTIONS "${dt_binding_includes}" +) + if(CONFIG_SOC_HAS_TIMING_FUNCTIONS AND NOT CONFIG_BOARD_HAS_TIMING_FUNCTIONS) if(CONFIG_TIMING_FUNCTIONS) # Use nRF-specific timing calculations only if DWT is not present diff --git a/soc/nordic/validate_binding_headers.c b/soc/nordic/validate_binding_headers.c new file mode 100644 index 00000000000..98ffffe8670 --- /dev/null +++ b/soc/nordic/validate_binding_headers.c @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2024 Nordic Semiconductor ASA + * SPDX-License-Identifier: Apache-2.0 + */ + +/** + * This file validates definitions found in dt-bindings headers against their + * expected values from MDK, which may be provided in the form of C types. + * + * Note: all dt-bindings headers which have been included by DTS in this build + * are automagically included in this file as well. See CMakeLists.txt. + */ + +#include +#include + +#include + +/** + * Domain IDs. See: + * - dt-bindings/misc/nordic-domain-id-nrf54h20.h + */ +#if defined(NRF_DOMAIN_ID_APPLICATION) +BUILD_ASSERT(NRF_DOMAIN_ID_APPLICATION == NRF_DOMAIN_APPLICATION); +#endif +#if defined(NRF_DOMAIN_ID_RADIOCORE) +BUILD_ASSERT(NRF_DOMAIN_ID_RADIOCORE == NRF_DOMAIN_RADIOCORE); +#endif +#if defined(NRF_DOMAIN_ID_GLOBALFAST) +BUILD_ASSERT(NRF_DOMAIN_ID_GLOBALFAST == NRF_DOMAIN_GLOBALFAST); +#endif +#if defined(NRF_DOMAIN_ID_GLOBALSLOW) +BUILD_ASSERT(NRF_DOMAIN_ID_GLOBALSLOW == NRF_DOMAIN_GLOBALSLOW); +#endif + +/** + * Owner IDs. See: + * - dt-bindings/misc/nordic-owner-id-nrf54h20.h + */ +#if defined(NRF_OWNER_ID_NONE) +BUILD_ASSERT(NRF_OWNER_ID_NONE == NRF_OWNER_NONE); +#endif +#if defined(NRF_OWNER_ID_APPLICATION) +BUILD_ASSERT(NRF_OWNER_ID_APPLICATION == NRF_OWNER_APPLICATION); +#endif +#if defined(NRF_OWNER_ID_RADIOCORE) +BUILD_ASSERT(NRF_OWNER_ID_RADIOCORE == NRF_OWNER_RADIOCORE); +#endif