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 <grzegorz.swiderski@nordicsemi.no>
This commit is contained in:
Grzegorz Swiderski 2024-05-09 12:31:23 +02:00 committed by Johan Hedberg
commit 70edbd1cf5
2 changed files with 61 additions and 0 deletions

View file

@ -8,9 +8,22 @@ endif()
zephyr_library_sources( zephyr_library_sources(
validate_base_addresses.c validate_base_addresses.c
validate_binding_headers.c
validate_enabled_instances.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_SOC_HAS_TIMING_FUNCTIONS AND NOT CONFIG_BOARD_HAS_TIMING_FUNCTIONS)
if(CONFIG_TIMING_FUNCTIONS) if(CONFIG_TIMING_FUNCTIONS)
# Use nRF-specific timing calculations only if DWT is not present # Use nRF-specific timing calculations only if DWT is not present

View file

@ -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 <zephyr/sys/util_macro.h>
#include <zephyr/toolchain.h>
#include <nrf.h>
/**
* 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