From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: Sascha Hauer <s.hauer@pengutronix.de>
Cc: barebox@lists.infradead.org
Subject: Re: [PATCH 2/4] of: fdt: implement fdt_machine_is_compatible
Date: Mon, 4 Mar 2024 10:50:01 +0100 [thread overview]
Message-ID: <56a2ac27-2619-4f2e-8997-70ef77d86644@pengutronix.de> (raw)
In-Reply-To: <ZeWWQpxQeTM9vrw_@pengutronix.de>
On 04.03.24 10:37, Sascha Hauer wrote:
> On Fri, Mar 01, 2024 at 02:04:43PM +0100, Ahmad Fatoum wrote:
>> When finding compatible bootloader spec files, barebox will unflatten
>> each DTB in turn, allocating objects for each property and node, only to
>> compare a single property and then free all the allocations again.
>>
>> Given that this operation is repeated for every device tree until a
>> match is found, it's a good idea to be able to compare machine
>> (top-level) compatibles without having to unflatten the whole FDT.
>>
>> Implemnt fdt_machine_is_compatible() that does just that. This
>> intentionally opencodes the device tree iteration as to minimize
>> code and runtime size. Using libfdt without LTO would be slower
>> and bigger.
>>
>> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
>> ---
>> drivers/of/fdt.c | 95 ++++++++++++++++++++++++++++++++++++++++++++++++
>> include/of.h | 3 ++
>> 2 files changed, 98 insertions(+)
>>
>> diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
>> index 676b8a5535bf..aa3d2e967acd 100644
>> --- a/drivers/of/fdt.c
>> +++ b/drivers/of/fdt.c
>> @@ -668,3 +668,98 @@ void fdt_print_reserve_map(const void *__fdt)
>> return;
>> }
>> }
>> +
>> +static int fdt_string_is_compatible(const char *haystack, int haystack_len,
>> + const char *needle, int needle_len)
>> +{
>> + const char *p;
>> + int index = 0;
>> +
>> + while (haystack_len >= needle_len) {
>> + if (memcmp(needle, haystack, needle_len + 1) == 0)
>> + return OF_DEVICE_COMPATIBLE_MAX_SCORE - (index << 2);
>> +
>> + p = memchr(haystack, '\0', haystack_len);
>> + if (!p)
>> + return 0;
>> + haystack_len -= (p - haystack) + 1;
>> + haystack = p + 1;
>> + index++;
>> + }
>> +
>> + return 0;
>> +}
>> +
>> +bool fdt_machine_is_compatible(const struct fdt_header *fdt, size_t fdt_size, const char *compat)
>> +{
>> + uint32_t tag;
>> + const struct fdt_property *fdt_prop;
>> + const char *name;
>> + uint32_t dt_struct;
>> + const struct fdt_node_header *fnh;
>> + const void *dt_strings;
>> + struct fdt_header f;
>> + int ret, len;
>> + int expect = FDT_BEGIN_NODE;
>> + int compat_len = strlen(compat);
>> +
>> + ret = fdt_parse_header(fdt, fdt_size, &f);
>> + if (ret < 0)
>> + return ERR_PTR(ret);
>
> return false here
Ouch. Thanks for fixing!
>
> Sascha
>
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
next prev parent reply other threads:[~2024-03-04 10:30 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-01 13:04 [PATCH 0/4] of: fdt: read blspec/FIT DT compat without unflattening Ahmad Fatoum
2024-03-01 13:04 ` [PATCH 1/4] of: fdt: factor out FDT header parsing Ahmad Fatoum
2024-03-01 13:04 ` [PATCH 2/4] of: fdt: implement fdt_machine_is_compatible Ahmad Fatoum
2024-03-04 9:37 ` Sascha Hauer
2024-03-04 9:49 ` Sascha Hauer
2024-03-04 9:50 ` Ahmad Fatoum [this message]
2024-03-01 13:04 ` [PATCH 3/4] blspec: don't parse whole device tree to compare compatibles Ahmad Fatoum
2024-03-01 13:04 ` [PATCH 4/4] FIT: support finding compatible configuration by FDT compatible Ahmad Fatoum
2024-03-04 9:49 ` [PATCH 0/4] of: fdt: read blspec/FIT DT compat without unflattening Sascha Hauer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=56a2ac27-2619-4f2e-8997-70ef77d86644@pengutronix.de \
--to=a.fatoum@pengutronix.de \
--cc=barebox@lists.infradead.org \
--cc=s.hauer@pengutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox