cli: Add command "dts-check"

Validates the dts/dtb file for the selected board and outputs the validation logs to the user.
This can be used when adding a new board, developing or improving a dts file. Should lead to higher quality device trees and patches overall, if used.
Will show warnings/errors if patches patch in some functionalities to a devicetree file without patching in the dt-bindings .yaml at the same time.
This commit is contained in:
ColorfulRhino
2024-06-14 00:09:48 +02:00
committed by Igor
parent 663530dcf6
commit de81f10b0d
6 changed files with 71 additions and 13 deletions

View File

@@ -0,0 +1,22 @@
#!/usr/bin/env bash
#
# SPDX-License-Identifier: GPL-2.0
#
# Copyright (c) 2013-2024 Armbian
#
# This file is a part of the Armbian Build Framework
# https://github.com/armbian/build/
# Validate the dts/dtb file against dt bindings found in "linux/Documentation/devicetree/bindings/"
# See slide 15 in https://elinux.org/images/1/17/How_to_Get_Your_DT_Schema_Bindings_Accepted_in_Less_than_10_Iterations_-_Krzysztof_Kozlowski%2C_Linaro_-_ELCE_2023.pdf
function validate_dts() {
[[ -z "${BOOT_FDT_FILE}" ]] && exit_with_error "BOOT_FDT_FILE not set! No dts file to validate."
display_alert "Validating dts/dtb file for selected board" "${BOOT_FDT_FILE} ; see output below" "info"
# "make CHECK_DTBS=y" uses the pip modules "dtschema" and "yamllint"
prepare_python_and_pip
# Run "make CHECK_DTBS=y" for the selected board's dtb file
run_kernel_make "CHECK_DTBS=y ${BOOT_FDT_FILE}"
}

View File

@@ -18,12 +18,13 @@ function run_kernel_make_internal() {
prepare_distcc_compilation_config
common_make_envs=(
"CCACHE_BASEDIR=\"$(pwd)\"" # Base directory for ccache, for cache reuse # @TODO: experiment with this and the source path to maximize hit rate
"CCACHE_TEMPDIR=\"${CCACHE_TEMPDIR:?}\"" # Temporary directory for ccache, under WORKDIR
"PATH=\"${toolchain}:${PATH}\"" # Insert the toolchain first into the PATH.
"DPKG_COLORS=always" # Use colors for dpkg @TODO no dpkg is done anymore, remove?
"XZ_OPT='--threads=0'" # Use parallel XZ compression
"TERM='${TERM}'" # Pass the terminal type, so that 'make menuconfig' can work.
"CCACHE_BASEDIR=\"$(pwd)\"" # Base directory for ccache, for cache reuse # @TODO: experiment with this and the source path to maximize hit rate
"CCACHE_TEMPDIR=\"${CCACHE_TEMPDIR:?}\"" # Temporary directory for ccache, under WORKDIR
"PATH=\"${toolchain}:${PYTHON3_INFO[USERBASE]}/bin:${PATH}\"" # Insert the toolchain and the pip binaries into the PATH
"PYTHONPATH=\"${PYTHON3_INFO[MODULES_PATH]}:${PYTHONPATH}\"" # Insert the pip modules downloaded by Armbian into PYTHONPATH (needed for dtb checks)
"DPKG_COLORS=always" # Use colors for dpkg @TODO no dpkg is done anymore, remove?
"XZ_OPT='--threads=0'" # Use parallel XZ compression
"TERM='${TERM}'" # Pass the terminal type, so that 'make menuconfig' can work.
"COLUMNS='${COLUMNS:-160}'"
"COLORFGBG='${COLORFGBG}'"
)

View File

@@ -53,7 +53,7 @@ function compile_kernel() {
declare hash pre_patch_version
kernel_main_patching # has it's own logging sections inside
# Stop after patching;
# Stop after patching.
if [[ "${PATCH_ONLY}" == yes ]]; then
display_alert "PATCH_ONLY is set, stopping." "PATCH_ONLY=yes and patching success" "cachehit"
return 0
@@ -72,7 +72,6 @@ function compile_kernel() {
# re-read kernel version after patching
declare version
version=$(grab_version "$kernel_work_dir")
display_alert "Compiling $BRANCH kernel" "$version" "info"
# determine the toolchain
declare toolchain
@@ -80,6 +79,14 @@ function compile_kernel() {
kernel_config # has it's own logging sections inside
# Validate dts file if flag is set and stop after validation.
# Has to happen after kernel .config file was created
if [[ "${DTS_VALIDATE}" == yes ]]; then
LOG_SECTION="validate_dts" do_with_logging validate_dts
display_alert "DTS_VALIDATE is set, stopping." "DTS_VALIDATE=yes and dts sucessfully checked. See output above to fix your board's dts file." "cachehit"
return 0
fi
# Stop after configuring kernel, but only if using a specific CLI command ("kernel-config").
# Normal "KERNEL_CONFIGURE=yes" (during image build) is still allowed.
if [[ "${KERNEL_CONFIGURE}" == yes && "${ARMBIAN_COMMAND}" == *kernel-config ]]; then
@@ -87,6 +94,8 @@ function compile_kernel() {
return 0
fi
display_alert "Compiling $BRANCH kernel" "$version" "info"
# build via make and package .debs; they're separate sub-steps
kernel_prepare_build_and_package # has it's own logging sections inside