Skip to contentSkip to conversation

difference between fdtdec and fdt_support ?

DISCUSSION Marek Behún 3 participants 7 messages Jan 6, 2022 – Jan 27, 2022

lore
Share & tools
lore
#0 lore raw

Hi Simon,

I am a little confused.

We have
common/fdt_support.c
and
lib/fdtdec.c

The second one implements for example fdtdec_get_is_enabled(), which I would rather expect in fdt_support by name fdt_node_is_available(), or something like that.

Also fdtdec does a strange thing with compatible strings: it declares an enum for compatible strings and then a map which maps this enum values to compatible strings... Why not just use the compatible strings?

What is the purpose of having two files implementing fdt stuff?

Marek

#1 lore raw
Quoted 5 lines · Marek Behún

Also fdtdec does a strange thing with compatible strings: it declares an enum for compatible strings and then a map which maps this enum values to compatible strings... Why not just use the compatible strings?

What is the purpose of having two files implementing fdt stuff?

AFAIK, the primary purpose is to ensure powerpc binaries are bloated with useless string literals.</sarcasm>

https://lore.kernel.org/u-boot/[email protected]/

Rasmus

#2 lore raw
In reply to Marek Behún

Hi Marek,

Quoted 5 lines · Marek Behún

Hi Simon,

I am a little confused.

Quoted 8 lines

We have
common/fdt_support.c
and
lib/fdtdec.c

The second one implements for example fdtdec_get_is_enabled(), which I would rather expect in fdt_support by name fdt_node_is_available(), or something like that.

Should be moved to ofnode

Quoted 4 lines

Also fdtdec does a strange thing with compatible strings: it declares an enum for compatible strings and then a map which maps this enum values to compatible strings... Why not just use the compatible strings?

Did you see the comment?

* NOTE: This list is basically a TODO list for things that need to be
* converted to driver model. So don't add new things here unless there is a
* good reason why driver-model conversion is infeasible. Examples include
* things which are used before driver model is available.

This is effectively a list of things that should be converted to driver model. The list should then go away.

Quoted 2 lines

What is the purpose of having two files implementing fdt stuff?

fdtdec - for reading from the DT. Should go away and be replaced with the ofnode API, and fdtaddr.c
fdt_support - for updating the DT, e.g. for fixups before booting an OS

Regards,
Simon

#3 lore raw
Quoted 13 lines · On Thu, 6 Jan 2022 08:48:48 -0700 Simon Glass <[email protected]> wrote:

Hi Marek,

Quoted 10 lines · Marek Behún

Hi Simon,

I am a little confused.

We have
common/fdt_support.c
and
lib/fdtdec.c

Quoted 5 lines
Quoted 3 lines

The second one implements for example fdtdec_get_is_enabled(), which I would rather expect in fdt_support by name fdt_node_is_available(), or something like that.

Should be moved to ofnode

?? But this function is needed for example when fixing device tree for Linux.

Quoted 7 lines
Quoted 4 lines

Also fdtdec does a strange thing with compatible strings: it declares an enum for compatible strings and then a map which maps this enum values to compatible strings... Why not just use the compatible strings?

Did you see the comment?

Quoted 7 lines

* NOTE: This list is basically a TODO list for things that need to be
* converted to driver model. So don't add new things here unless there is a
* good reason why driver-model conversion is infeasible. Examples include
* things which are used before driver model is available.

This is effectively a list of things that should be converted to driver model. The list should then go away.

Hmm. But can't that be simply made into a list in a comment? Because currently this is compiled in for every board that uses any such function from fdtdec, even if they don't use any string from those compatible strings.

Quoted 6 lines
Quoted 2 lines

What is the purpose of having two files implementing fdt stuff?

fdtdec - for reading from the DT. Should go away and be replaced with the ofnode API, and fdtaddr.c
fdt_support - for updating the DT, e.g. for fixups before booting an OS

Thanks! Okay that makes sense. This means that we should also have fdt_node_is_available() in fdt_support.c which does the same thing. (For now this can be made a static inline function that calls
fdtdec_get_is_enabled().)

Marek

#4 lore raw

Hi Marek,

Quoted 38 lines · Marek Behún
Quoted 13 lines · On Thu, 6 Jan 2022 08:48:48 -0700 Simon Glass <[email protected]> wrote:

Hi Marek,

Quoted 10 lines · Marek Behún

Hi Simon,

I am a little confused.

We have
common/fdt_support.c
and
lib/fdtdec.c

Quoted 5 lines
Quoted 3 lines

The second one implements for example fdtdec_get_is_enabled(), which I would rather expect in fdt_support by name fdt_node_is_available(), or something like that.

Should be moved to ofnode

?? But this function is needed for example when fixing device tree for Linux.

Quoted 12 lines
Quoted 4 lines

Also fdtdec does a strange thing with compatible strings: it declares an enum for compatible strings and then a map which maps this enum values to compatible strings... Why not just use the compatible strings?

Did you see the comment?

* NOTE: This list is basically a TODO list for things that need to be
* converted to driver model. So don't add new things here unless there is a
* good reason why driver-model conversion is infeasible. Examples include
* things which are used before driver model is available.

Quoted 7 lines
Quoted 2 lines

This is effectively a list of things that should be converted to driver model. The list should then go away.

Hmm. But can't that be simply made into a list in a comment? Because currently this is compiled in for every board that uses any such function from fdtdec, even if they don't use any string from those compatible strings.

Well another option would be to delete the boards that need it, since no one has seen fit to resolve this all these years. Or create some drivers for them.

Quoted 4 lines
Quoted 4 lines
Quoted 3 lines

What is the purpose of having two files implementing fdt stuff?

Quoted 8 lines
Quoted 3 lines

fdtdec - for reading from the DT. Should go away and be replaced with the ofnode API, and fdtaddr.c
fdt_support - for updating the DT, e.g. for fixups before booting an OS

Thanks! Okay that makes sense. This means that we should also have fdt_node_is_available() in fdt_support.c which does the same thing. (For now this can be made a static inline function that calls
fdtdec_get_is_enabled().)

OK.

BTW fdt_support.c should really move to use ofnode. There are few ofnode 'write' functions at present, but we should fill those out so we don't need to use flattree for anything, with OF_LIVE is enabled.

Regards,
Simon

#5 lore raw
Quoted 44 lines · On Thu, 6 Jan 2022 09:15:17 -0700 Simon Glass <[email protected]> wrote:

Hi Marek,

Quoted 41 lines · Marek Behún
Quoted 13 lines · On Thu, 6 Jan 2022 08:48:48 -0700 Simon Glass <[email protected]> wrote:

Hi Marek,

Quoted 10 lines · Marek Behún

Hi Simon,

I am a little confused.

We have
common/fdt_support.c
and
lib/fdtdec.c

Quoted 5 lines
Quoted 3 lines

The second one implements for example fdtdec_get_is_enabled(), which I would rather expect in fdt_support by name fdt_node_is_available(), or something like that.

Should be moved to ofnode

?? But this function is needed for example when fixing device tree for Linux.

Quoted 14 lines
Quoted 4 lines

Also fdtdec does a strange thing with compatible strings: it declares an enum for compatible strings and then a map which maps this enum values to compatible strings... Why not just use the compatible strings?

Did you see the comment?

* NOTE: This list is basically a TODO list for things that need to be
* converted to driver model. So don't add new things here unless there is a
* good reason why driver-model conversion is infeasible. Examples include
* things which are used before driver model is available.

This is effectively a list of things that should be converted to driver model. The list should then go away.

Quoted 8 lines
Quoted 4 lines

Hmm. But can't that be simply made into a list in a comment? Because currently this is compiled in for every board that uses any such function from fdtdec, even if they don't use any string from those compatible strings.

Well another option would be to delete the boards that need it, since no one has seen fit to resolve this all these years. Or create some drivers for them.

I still don't quite understand why the compatible strings have to be in this fdtdec.c file.

For example in
arch/arm/mach-socfpga/clock_manager_arria10.c
we call
node = fdtdec_next_compatible(blob, 0,

                       COMPAT_ALTERA_SOCFPGA_CLK_INIT);

This constant, COMPAT_ALTERA_SOCFPGA_CLK_INIT, is an enum constant, which is then in fdtdec.c translated to string compatible with
compat_names[id]
for which fdt_node_offset_by_compatible() is used.

So why not simply put this string constant into
arch/arm/mach-socfpga/clock_manager_arria10.c
by calling
node = fdt_node_offset_by_compatible(blob, node,

                        "altr,socfpga-a10-clk-init");

??

That way at least the string literals won't be compiled in into every u-boot binary, even those that don't need those literals at all.

Quoted 13 lines
Quoted 4 lines
Quoted 4 lines
Quoted 3 lines

What is the purpose of having two files implementing fdt stuff?

Quoted 8 lines
Quoted 3 lines

fdtdec - for reading from the DT. Should go away and be replaced with the ofnode API, and fdtaddr.c
fdt_support - for updating the DT, e.g. for fixups before booting an OS

Thanks! Okay that makes sense. This means that we should also have fdt_node_is_available() in fdt_support.c which does the same thing. (For now this can be made a static inline function that calls
fdtdec_get_is_enabled().)

Quoted 5 lines

OK.

BTW fdt_support.c should really move to use ofnode. There are few ofnode 'write' functions at present, but we should fill those out so we don't need to use flattree for anything, with OF_LIVE is enabled.

Can OF_LIVE then generate dtb for kernel?

Marek

#6 lore raw

Hi Marek,

Quoted 74 lines · Marek Behún
Quoted 44 lines · On Thu, 6 Jan 2022 09:15:17 -0700 Simon Glass <[email protected]> wrote:

Hi Marek,

Quoted 41 lines · Marek Behún
Quoted 13 lines · On Thu, 6 Jan 2022 08:48:48 -0700 Simon Glass <[email protected]> wrote:

Hi Marek,

Quoted 10 lines · Marek Behún

Hi Simon,

I am a little confused.

We have
common/fdt_support.c
and
lib/fdtdec.c

Quoted 5 lines
Quoted 3 lines

The second one implements for example fdtdec_get_is_enabled(), which I would rather expect in fdt_support by name fdt_node_is_available(), or something like that.

Should be moved to ofnode

?? But this function is needed for example when fixing device tree for Linux.

Quoted 14 lines
Quoted 4 lines

Also fdtdec does a strange thing with compatible strings: it declares an enum for compatible strings and then a map which maps this enum values to compatible strings... Why not just use the compatible strings?

Did you see the comment?

* NOTE: This list is basically a TODO list for things that need to be
* converted to driver model. So don't add new things here unless there is a
* good reason why driver-model conversion is infeasible. Examples include
* things which are used before driver model is available.

This is effectively a list of things that should be converted to driver model. The list should then go away.

Quoted 8 lines
Quoted 4 lines

Hmm. But can't that be simply made into a list in a comment? Because currently this is compiled in for every board that uses any such function from fdtdec, even if they don't use any string from those compatible strings.

Well another option would be to delete the boards that need it, since no one has seen fit to resolve this all these years. Or create some drivers for them.

I still don't quite understand why the compatible strings have to be in this fdtdec.c file.

For example in
arch/arm/mach-socfpga/clock_manager_arria10.c
we call
node = fdtdec_next_compatible(blob, 0,

                       COMPAT_ALTERA_SOCFPGA_CLK_INIT);

This constant, COMPAT_ALTERA_SOCFPGA_CLK_INIT, is an enum constant, which is then in fdtdec.c translated to string compatible with
compat_names[id]
for which fdt_node_offset_by_compatible() is used.

So why not simply put this string constant into
arch/arm/mach-socfpga/clock_manager_arria10.c
by calling
node = fdt_node_offset_by_compatible(blob, node,

Quoted 5 lines
                        "altr,socfpga-a10-clk-init");

??

That way at least the string literals won't be compiled in into every u-boot binary, even those that don't need those literals at all.

Yes, indeed, but really these uses should be dropped and converted to driver model.

Quoted 14 lines
Quoted 14 lines
Quoted 13 lines
Quoted 8 lines
Quoted 4 lines

What is the purpose of having two files implementing fdt stuff?

fdtdec - for reading from the DT. Should go away and be replaced with the ofnode API, and fdtaddr.c
fdt_support - for updating the DT, e.g. for fixups before booting an OS

Thanks! Okay that makes sense. This means that we should also have fdt_node_is_available() in fdt_support.c which does the same thing. (For now this can be made a static inline function that calls
fdtdec_get_is_enabled().)

Quoted 7 lines
Quoted 5 lines

OK.

BTW fdt_support.c should really move to use ofnode. There are few ofnode 'write' functions at present, but we should fill those out so we don't need to use flattree for anything, with OF_LIVE is enabled.

Can OF_LIVE then generate dtb for kernel?

It isn't implemented, but we should add it. It is a simple piece of code to flatten the tree.

Regards,
Simon