[PATCH v1] mtd: parsers: ofpart: Fix parsing when size-cells is 0
Miquel Raynal
miquel.raynal at bootlin.com
Fri Dec 2 01:14:18 PST 2022
Hi Francesco,
francesco at dolcini.it wrote on Fri, 2 Dec 2022 08:19:00 +0100:
> From: Francesco Dolcini <francesco.dolcini at toradex.com>
>
> Add a fallback mechanism to handle the case in which #size-cells is set
> to <0>. According to the DT binding the nand controller node should have
> set it to 0 and this is not compatible with the legacy way of
> specifying partitions directly as child nodes of the nand-controller node.
I understand the problem, I understand the fix, but I have to say, I
strongly dislike it :) Touching an mtd core driver to fix a single
broken use case like that is... problematic, for the least.
I am sorry but if a 6.0 kernel breaks because:
- a legacy scheme is used in the description
- u-boot still does not conform to the DT standard
- a patch tries to make a tool happy
Then the solution is clearly not an 'mtd core' mainline patch.
If you really want to workaround U-Boot, either you revert that patch
or you just fix the DT description instead. The parent/child/partitions
scheme has been enforced for maybe 5 years now and for a good reason: a
NAND controller with partitions does not make _any_ sense. There are
plenty of examples out there, imx7-colibri.dtsi has received many
updates since its introduction (for the best), so why not this one?
Cheers,
Miquèl
> This fixes a boot failure on colibri-imx7 and potentially other boards.
>
> Cc: stable at vger.kernel.org
> Fixes: 753395ea1e45 ("ARM: dts: imx7: Fix NAND controller size-cells")
> Link: https://lore.kernel.org/all/Y4dgBTGNWpM6SQXI@francesco-nb.int.toradex.com/
> Signed-off-by: Francesco Dolcini <francesco.dolcini at toradex.com>
> ---
> drivers/mtd/parsers/ofpart_core.c | 11 +++++++++++
> 1 file changed, 11 insertions(+)
>
> diff --git a/drivers/mtd/parsers/ofpart_core.c b/drivers/mtd/parsers/ofpart_core.c
> index 192190c42fc8..aa3b7fa61e50 100644
> --- a/drivers/mtd/parsers/ofpart_core.c
> +++ b/drivers/mtd/parsers/ofpart_core.c
> @@ -122,6 +122,17 @@ static int parse_fixed_partitions(struct mtd_info *master,
>
> a_cells = of_n_addr_cells(pp);
> s_cells = of_n_size_cells(pp);
> + if (s_cells == 0) {
> + /*
> + * Use #size-cells = <1> for backward compatibility
> + * in case #size-cells is set to <0> and firmware adds
> + * OF partitions without setting it.
> + */
> + pr_warn_once("%s: ofpart partition %pOF (%pOF) #size-cells is <0>, using <1> for backward compatibility.\n",
> + master->name, pp,
> + mtd_node);
> + s_cells = 1;
> + }
> if (len / 4 != a_cells + s_cells) {
> pr_debug("%s: ofpart partition %pOF (%pOF) error parsing reg property.\n",
> master->name, pp,
More information about the linux-mtd
mailing list