mirror of
https://source.denx.de/u-boot/u-boot.git
synced 2026-06-13 15:03:58 +03:00
Merge patch series "mkimage: validate default configuration reference"
Aristo Chen <jj251510319013@gmail.com> says: This patch series introduces a validation step in `mkimage` to ensure that the `default` property under the `/configurations` node in a FIT image references a valid subnode. If the referenced node does not exist, mkimage now prints an error and fails early. This helps prevent runtime failures when U-Boot attempts to boot using an undefined configuration. The first patch implements the validation logic in `fit_image.c`. The second patch fixes an invalid default configuration reference exposed by this new check in the `k3-am65-iot2050-boot-image.dtsi`. The final patch adds a test case to verify that mkimage correctly fails when an invalid default configuration is present in the ITS file. This series improves the robustness of FIT image generation and helps catch malformed image trees during build time. Link: https://lore.kernel.org/r/20250715130317.3886-1-aristo.chen@canonical.com
This commit is contained in:
@@ -208,7 +208,7 @@
|
||||
fit,fdt-list-val = "ti/k3-am6528-iot2050-basic", "ti/k3-am6548-iot2050-advanced";
|
||||
|
||||
configurations {
|
||||
default = "ti/k3-am6528-iot2050-basic";
|
||||
default = "config-1";
|
||||
@config-SEQ {
|
||||
loadables =
|
||||
#ifdef CONFIG_WDT_K3_RTI_FW_FILE
|
||||
@@ -265,7 +265,7 @@
|
||||
};
|
||||
|
||||
configurations {
|
||||
default = "ti/k3-am6528-iot2050-basic-pg2";
|
||||
default = "config-1";
|
||||
@config-SEQ {
|
||||
loadables =
|
||||
#ifdef CONFIG_WDT_K3_RTI_FW_FILE
|
||||
|
||||
@@ -7,6 +7,7 @@ import os
|
||||
import subprocess
|
||||
import pytest
|
||||
import fit_util
|
||||
import re
|
||||
|
||||
@pytest.mark.boardspec('sandbox')
|
||||
@pytest.mark.requiredtool('dtc')
|
||||
@@ -56,3 +57,47 @@ def test_fit_invalid_image_reference(ubman):
|
||||
assert result.returncode != 0, "mkimage should fail due to missing image reference"
|
||||
assert "references undefined image 'notexist'" in result.stderr
|
||||
|
||||
def test_fit_invalid_default_config(ubman):
|
||||
"""Test that mkimage fails when default config is missing"""
|
||||
|
||||
its_fname = fit_util.make_fname(ubman, "invalid.its")
|
||||
itb_fname = fit_util.make_fname(ubman, "invalid.itb")
|
||||
kernel = fit_util.make_kernel(ubman, 'kernel.bin', 'kernel')
|
||||
|
||||
# Write ITS with an invalid reference to a nonexistent default config
|
||||
its_text = '''
|
||||
/dts-v1/;
|
||||
|
||||
/ {
|
||||
images {
|
||||
kernel@1 {
|
||||
description = "Test Kernel";
|
||||
data = /incbin/("kernel.bin");
|
||||
type = "kernel";
|
||||
arch = "sandbox";
|
||||
os = "linux";
|
||||
compression = "none";
|
||||
load = <0x40000>;
|
||||
entry = <0x40000>;
|
||||
};
|
||||
};
|
||||
|
||||
configurations {
|
||||
default = "conf@1";
|
||||
conf@2 {
|
||||
kernel = "kernel@1";
|
||||
};
|
||||
};
|
||||
};
|
||||
'''
|
||||
|
||||
with open(its_fname, 'w') as f:
|
||||
f.write(its_text)
|
||||
|
||||
mkimage = os.path.join(ubman.config.build_dir, 'tools/mkimage')
|
||||
cmd = [mkimage, '-f', its_fname, itb_fname]
|
||||
|
||||
result = subprocess.run(cmd, capture_output=True, text=True)
|
||||
|
||||
assert result.returncode != 0, "mkimage should fail due to missing default config"
|
||||
assert re.search(r"Default configuration '.*' not found under /configurations", result.stderr)
|
||||
|
||||
@@ -756,6 +756,8 @@ static int fit_import_data(struct image_tool_params *params, const char *fname)
|
||||
}
|
||||
|
||||
confs = fdt_path_offset(fdt, FIT_CONFS_PATH);
|
||||
const char *default_conf =
|
||||
(char *)fdt_getprop(fdt, confs, FIT_DEFAULT_PROP, NULL);
|
||||
static const char * const props[] = { FIT_KERNEL_PROP,
|
||||
FIT_RAMDISK_PROP,
|
||||
FIT_FDT_PROP,
|
||||
@@ -764,6 +766,14 @@ static int fit_import_data(struct image_tool_params *params, const char *fname)
|
||||
FIT_FIRMWARE_PROP,
|
||||
FIT_SCRIPT_PROP};
|
||||
|
||||
if (default_conf && fdt_subnode_offset(fdt, confs, default_conf) < 0) {
|
||||
fprintf(stderr,
|
||||
"Error: Default configuration '%s' not found under /configurations\n",
|
||||
default_conf);
|
||||
ret = FDT_ERR_NOTFOUND;
|
||||
goto err_munmap;
|
||||
}
|
||||
|
||||
fdt_for_each_subnode(node, fdt, confs) {
|
||||
const char *conf_name = fdt_get_name(fdt, node, NULL);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user