fit: prefer the default configuration on best-match ties
PATCH 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 ++++++++++++-- include/image.h | 4 +++ test/boot/image.c | 68 +++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 92 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,
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 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 5 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.
Signed-off-by Carlo Caione <[email protected]>
This seems appropriate, so:
Did you look around under doc/ to see if anything there needs a note as well? Thanks.
Signature · 1 line
Tom
Quoted 2 lines · Tom Rini
Did you look around under doc/ to see if anything there needs a note as well? Thanks.
mmh, probably I can add something to doc/usage/fit/overlay-fdt-boot.rst to make this explicit. Let me send a V2 with that, I'll add your Reviewed-by.
Cheers,
--
Carlo Caione
Hi,
Quoted 16 lines · Carlo Caione
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.
Quoted 7 lines
Signed-off-by Carlo Caione <[email protected]>boot/Kconfig | 2 ++
boot/image-fit.c | 20 ++++++++++++++-- include/image.h | 4 ++++ test/boot/image.c | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 92 insertions(+), 2 deletions(-)
This could use a spec tweak, perhaps?
Regards,
Simon
Quoted 1 line · Simon Glass
This could use a spec tweak, perhaps?
Why not, let me prepare a PR for that as well.
Thanks,
--
Carlo Caione