fit: prefer the default configuration on best-match ties
PATCH v2 1/1 fit: prefer the default configuration on best-match ties
With CONFIG_FIT_BEST_MATCH, fit_conf_find_compat() selects the configuration matching the most specific U-Boot compatible string; on equal matches the first listed configuration wins and the configurations node 'default' property is never consulted.
A FIT whose configurations all share the same base devicetree compatible (e.g. one manifest carrying a base tree plus overlay combinations for a single board) therefore always boots the first configuration, silently ignoring the default chosen by the manifest author.
Break score ties in favour of the default configuration. A strictly better compatible match still wins over it, and FITs without a default keep the current first-listed behaviour.
--- boot/Kconfig | 2 + boot/image-fit.c | 20 ++++++++- doc/usage/fit/overlay-fdt-boot.rst | 6 +++ include/image.h | 4 ++ test/boot/image.c | 68 ++++++++++++++++++++++++++++++ 5 files changed, 98 insertions(+), 2 deletions(-)
boot/Kconfig +2 -0
@@ -191,6 +191,8 @@ config FIT_BEST_MATCH U-Boot itself. A match is considered "best" if it matches the most specific compatibility entry of U-Boot's fdt's root node. The order of entries in the configuration's fdt is ignored. + If several configurations match equally well, the one named by + the configurations node 'default' property is preferred. config FIT_IMAGE_POST_PROCESS bool "Enable post-processing of FIT artifacts after loading by U-Boot"
boot/image-fit.c +18 -2
@@ -1799,6 +1799,8 @@ int fit_conf_find_compat(const void *fit, const void *fdt)int fdt_compat_len;int best_match_offset =0 ;int best_match_pos =0 ; +const char *default_name; +int default_noffset =-1 ; confs_noffset =fdt_path_offset (fit,FIT_CONFS_PATH ); images_noffset =fdt_path_offset (fit,FIT_IMAGES_PATH );
@@ -1813,6 +1815,15 @@ int fit_conf_find_compat(const void *fit, const void *fdt)return -ENXIO ; } +/* the default configuration breaks ties between equal matches */ + default_name =fdt_getprop (fit, confs_noffset,FIT_DEFAULT_PROP ,NULL ); +if (default_name) { + default_noffset =fdt_subnode_offset (fit, confs_noffset, + default_name); +if (default_noffset <0 ) + default_noffset =-1 ; + } +/* * Loop over the configurations in the FIT image. */
@@ -1863,10 +1874,15 @@ int fit_conf_find_compat(const void *fit, const void *fdt) cur_fdt_compat = fdt_compat;/* * Look for a match for each U-Boot compatibility string in -* turn in the compat string property. +* turn in the compat string property. A configuration only +* replaces the current best match on a strictly better +* position, or on an equal position if it is the default +* configuration. */ for (i = 0; len > 0 && - (!best_match_offset || best_match_pos > i); i++) { + (!best_match_offset || best_match_pos > i || + (best_match_pos == i && noffset == default_noffset)); + i++) { int cur_len = strlen(cur_fdt_compat) + 1; if (!fdt_node_check_compatible(fdt, compat_noffset,
doc/usage/fit/overlay-fdt-boot.rst +6 -0
@@ -111,6 +111,12 @@ Where config is one of:: This selects the DTB to use when booting. +If no configuration is given, U-Boot picks one automatically: with +``CONFIG_FIT_BEST_MATCH`` it selects the configuration whose fdt is the most +compatible with U-Boot's own control devicetree, and falls back to the +``default`` configuration otherwise. When several configurations match +equally well, the ``default`` one is preferred. + .. _fit_configuration_using_overlays: Configuration using overlays
include/image.h +4 -0
@@ -1526,6 +1526,10 @@ int fit_check_format(const void *fit, ulong size);* compatible list, "foo,bar", matches a compatible string in the root of fdt1. * "bim,bam" in fdt2 matches the second string which isn't as good as fdt1. * +* If several configurations match at the same position, the one named by the +* 'default' property of the configurations node is preferred, then the first +* one listed. +* * As an optimization, the compatible property from the FDT's root node can be * copied into the configuration node in the FIT image. This is required to * match configurations with compressed FDTs.
test/boot/image.c +68 -0
76 lines not on this page · raw message
Signature · 1 line
2.55.0
Quoted 17 lines · Carlo Caione
With
CONFIG_FIT_BEST_MATCH,fit_conf_find_compat()selects the configuration matching the most specific U-Boot compatible string; on equal matches the first listed configuration wins and the configurations node 'default' property is never consulted.A FIT whose configurations all share the same base devicetree compatible (e.g. one manifest carrying a base tree plus overlay combinations for a single board) therefore always boots the first configuration, silently ignoring the default chosen by the manifest author.
Break score ties in favour of the default configuration. A strictly better compatible match still wins over it, and FITs without a default keep the current first-listed behaviour.
Reviewed-by Simon Glass <[email protected]>Reviewed-by Tom Rini <[email protected]>Signed-off-by Carlo Caione <[email protected]>
Quoted 7 lines
--- boot/Kconfig | 2 + boot/image-fit.c | 20 ++++++++- doc/usage/fit/overlay-fdt-boot.rst | 6 +++ include/image.h | 4 ++ test/boot/image.c | 68 ++++++++++++++++++++++++++++++ 5 files changed, 98 insertions(+), 2 deletions(-)
FWIW this is the link to the PR changing the spec [0]
[0] https://github.com/open-source-firmware/flat-image-tree/pull/59
Cheers,
--
Carlo Caione
Quoted 10 lines · Carlo Caione
With
CONFIG_FIT_BEST_MATCH,fit_conf_find_compat()selects the configuration matching the most specific U-Boot compatible string; on equal matches the first listed configuration wins and the configurations node 'default' property is never consulted.A FIT whose configurations all share the same base devicetree compatible (e.g. one manifest carrying a base tree plus overlay combinations for a single board) therefore always boots the first configuration, silently ignoring the default chosen by the manifest author.
Quoted 7 lines
Break score ties in favour of the default configuration. A strictly better compatible match still wins over it, and FITs without a default keep the current first-listed behaviour.
Reviewed-by Simon Glass <[email protected]>Reviewed-by Tom Rini <[email protected]>Signed-off-by Carlo Caione <[email protected]>
Hi Simon and Tom,
any chance you can pick this up for the next release?
Thanks,
--
Carlo Caione
Quoted 15 lines · Carlo Caione
Quoted 14 lines · Carlo Caione
With
CONFIG_FIT_BEST_MATCH,fit_conf_find_compat()selects the configuration matching the most specific U-Boot compatible string; on equal matches the first listed configuration wins and the configurations node 'default' property is never consulted.A FIT whose configurations all share the same base devicetree compatible (e.g. one manifest carrying a base tree plus overlay combinations for a single board) therefore always boots the first configuration, silently ignoring the default chosen by the manifest author.
Break score ties in favour of the default configuration. A strictly better compatible match still wins over it, and FITs without a default keep the current first-listed behaviour.
Quoted 6 lines
Quoted 3 lines
Reviewed-by Simon Glass <[email protected]>Reviewed-by Tom Rini <[email protected]>Signed-off-by Carlo Caione <[email protected]>Hi Simon and Tom,
any chance you can pick this up for the next release?
Ah, so I had read
https://github.com/open-source-firmware/flat-image-tree/pull/59#pullrequestreview-4663326599
as requesting a change in wording, but I guess it was acknowledging a change in wording you had done, so I should grab this soon then, yes, thanks for the reminder.
Signature · 1 line
Tom
Quoted 11 lines · Carlo Caione
With
CONFIG_FIT_BEST_MATCH,fit_conf_find_compat()selects the configuration matching the most specific U-Boot compatible string; on equal matches the first listed configuration wins and the configurations node 'default' property is never consulted.A FIT whose configurations all share the same base devicetree compatible (e.g. one manifest carrying a base tree plus overlay combinations for a single board) therefore always boots the first configuration, silently ignoring the default chosen by the manifest author.
[...]
Applied to u-boot/main, thanks!
[1/1] fit: prefer the default configuration on best-match ties
commit: 574b1adad70a19d95c65e0f37f9c36d94fb5418f
Signature · 1 line
Tom