mbox series

[v5,0/3] Add support for unprotected spare data page

Message ID 20220608001030.18813-1-ansuelsmth@gmail.com
Headers show
Series Add support for unprotected spare data page | expand

Message

Christian Marangi June 8, 2022, 12:10 a.m. UTC
Some background about this.
On original qsdk ipq8064 based firmware there was a big separation from
boot partition and user partition. With boot partition we refer to
partition used to init the router (bootloader, spm firmware and other
internal stuff) With user partition we refer to linux partition and data
partition not used to init the router.
When someone had to write to these boot partition a special mode was
needed, to switch the nand driver to this special configuration.

Upstream version of the nandc driver totally dropped this and the result
is that if someone try to read data from these partition a CRC warning
is printed and if someone try to write that (if for example someone
wants to replace the bootloader) result is a broken system as the data
is badly written.

This series comes to fix this.

A user can declare offset and size of these special partition using the
qcom,boot-pages binding.

An initial implementation of this assumed that the boot-pages started
from the start of the nand but we discover that some device have backup
of these special partition and we can have situation where we have this
partition scheme
- APPSBL (require special mode)
- APPSBLENV (doesn't require special mode)
- ART
- APPSBLBK (back of APPSBL require special mode)
- APPSBLENVBK (back of APPSBLENV doesn't require special mode)
With this configuration we need to declare sparse boot page and we can't
assume boot-pages always starts from the start of the nand.

A user can use this form to declare sparse boot pages
qcom,boot-pages = <0x0 0x0c80000 0x0c80000 0x0500000>;

The driver internally will parse this array, convert it to nand pages
and check internally on every read/write if this special configuration
should used for that page or the normal one.

The reason for all of this is that qcom FOR SOME REASON, disable ECC for
spare data only for these boot partition and we need to reflect this
special configuration to mute these warning and to permit actually
writing to these pages.

v5:
- Rename boot-pages to boot-partitions
- Add additional check to parsing function
- Rename unprotect_spare_data to codeword_fixup
- Add additional info from Manivannan
- Add patch to remove holes in qcom_nand_host struct
v4:
- Fix wrong compatible set for boot-pages (ipq8074 instead of ipq806x)
v3:
- Fix typo in Docmunetation commit desription
- Add items description for uint32-matrix
v2:
- Add fixes from Krzysztof in Documentation

Ansuel Smith (3):
  mtd: nand: raw: qcom_nandc: add support for unprotected spare data
    pages
  dt-bindings: mtd: qcom_nandc: document qcom,boot-partitions binding
  mtd: nand: raw: qcom_nandc: reorder qcom_nand_host struct

 .../devicetree/bindings/mtd/qcom,nandc.yaml   |  26 +++
 drivers/mtd/nand/raw/qcom_nandc.c             | 179 +++++++++++++++++-
 2 files changed, 198 insertions(+), 7 deletions(-)

Comments

Christian Marangi June 9, 2022, 10:25 a.m. UTC | #1
On Thu, Jun 09, 2022 at 12:50:29PM +0530, Manivannan Sadhasivam wrote:
> On Wed, Jun 08, 2022 at 02:10:29AM +0200, Ansuel Smith wrote:
> > Document new qcom,boot-partition binding used to apply special
> > read/write layout to boot partitions.
> > 
> > QCOM apply a special layout where spare data is not protected
> > by ECC for some special pages (used for boot partition). Add
> > Documentation on how to declare these special pages.
> > 
> > Signed-off-by: Ansuel Smith <ansuelsmth@gmail.com>
> > ---
> >  .../devicetree/bindings/mtd/qcom,nandc.yaml   | 26 +++++++++++++++++++
> >  1 file changed, 26 insertions(+)
> > 
> > diff --git a/Documentation/devicetree/bindings/mtd/qcom,nandc.yaml b/Documentation/devicetree/bindings/mtd/qcom,nandc.yaml
> > index 84ad7ff30121..a0914ccb95b0 100644
> > --- a/Documentation/devicetree/bindings/mtd/qcom,nandc.yaml
> > +++ b/Documentation/devicetree/bindings/mtd/qcom,nandc.yaml
> > @@ -102,6 +102,30 @@ allOf:
> >              - const: rx
> >              - const: cmd
> >  
> > +  - if:
> > +      properties:
> > +        compatible:
> > +          contains:
> > +            enum:
> > +              - qcom,ipq806x-nand
> > +
> > +    then:
> > +      properties:
> > +        qcom,boot-partitions:
> > +          $ref: /schemas/types.yaml#/definitions/uint32-matrix
> 
> Wondering if u32 is enough for covering all ranges? Other than this,
> 
> Reviewed-by: Manivannan Sadhasivam <mani@kernel.org>
> 
> Thanks,
> Mani
>

I mean they are offset and sizes... Considering it's an old SoC and max
nand mounted is 1g we should be safe with u32.

> > +          items:
> > +            items:
> > +              - description: offset
> > +              - description: size
> > +          description:
> > +            Boot partition use a different layout where the 4 bytes of spare
> > +            data are not protected by ECC. Use this to declare these special
> > +            partitions by defining first the offset and then the size.
> > +
> > +            It's in the form of <offset1 size1 offset2 size2 offset3 ...>
> > +
> > +            Refer to the ipq8064 example on how to use this special binding.
> > +
> >  required:
> >    - compatible
> >    - reg
> > @@ -135,6 +159,8 @@ examples:
> >          nand-ecc-strength = <4>;
> >          nand-bus-width = <8>;
> >  
> > +        qcom,boot-partitions = <0x0 0x58a0000>;
> > +
> >          partitions {
> >            compatible = "fixed-partitions";
> >            #address-cells = <1>;
> > -- 
> > 2.36.1
> > 
> 
> -- 
> மணிவண்ணன் சதாசிவம்
Manivannan Sadhasivam June 9, 2022, 10:39 a.m. UTC | #2
On Thu, Jun 09, 2022 at 12:25:27PM +0200, Ansuel Smith wrote:
> On Thu, Jun 09, 2022 at 12:50:29PM +0530, Manivannan Sadhasivam wrote:
> > On Wed, Jun 08, 2022 at 02:10:29AM +0200, Ansuel Smith wrote:
> > > Document new qcom,boot-partition binding used to apply special
> > > read/write layout to boot partitions.
> > > 
> > > QCOM apply a special layout where spare data is not protected
> > > by ECC for some special pages (used for boot partition). Add
> > > Documentation on how to declare these special pages.
> > > 
> > > Signed-off-by: Ansuel Smith <ansuelsmth@gmail.com>
> > > ---
> > >  .../devicetree/bindings/mtd/qcom,nandc.yaml   | 26 +++++++++++++++++++
> > >  1 file changed, 26 insertions(+)
> > > 
> > > diff --git a/Documentation/devicetree/bindings/mtd/qcom,nandc.yaml b/Documentation/devicetree/bindings/mtd/qcom,nandc.yaml
> > > index 84ad7ff30121..a0914ccb95b0 100644
> > > --- a/Documentation/devicetree/bindings/mtd/qcom,nandc.yaml
> > > +++ b/Documentation/devicetree/bindings/mtd/qcom,nandc.yaml
> > > @@ -102,6 +102,30 @@ allOf:
> > >              - const: rx
> > >              - const: cmd
> > >  
> > > +  - if:
> > > +      properties:
> > > +        compatible:
> > > +          contains:
> > > +            enum:
> > > +              - qcom,ipq806x-nand
> > > +
> > > +    then:
> > > +      properties:
> > > +        qcom,boot-partitions:
> > > +          $ref: /schemas/types.yaml#/definitions/uint32-matrix
> > 
> > Wondering if u32 is enough for covering all ranges? Other than this,
> > 
> > Reviewed-by: Manivannan Sadhasivam <mani@kernel.org>
> > 
> > Thanks,
> > Mani
> >
> 
> I mean they are offset and sizes... Considering it's an old SoC and max
> nand mounted is 1g we should be safe with u32.
> 

I thought so but wanted to confirm...

Thanks,
Mani

> > > +          items:
> > > +            items:
> > > +              - description: offset
> > > +              - description: size
> > > +          description:
> > > +            Boot partition use a different layout where the 4 bytes of spare
> > > +            data are not protected by ECC. Use this to declare these special
> > > +            partitions by defining first the offset and then the size.
> > > +
> > > +            It's in the form of <offset1 size1 offset2 size2 offset3 ...>
> > > +
> > > +            Refer to the ipq8064 example on how to use this special binding.
> > > +
> > >  required:
> > >    - compatible
> > >    - reg
> > > @@ -135,6 +159,8 @@ examples:
> > >          nand-ecc-strength = <4>;
> > >          nand-bus-width = <8>;
> > >  
> > > +        qcom,boot-partitions = <0x0 0x58a0000>;
> > > +
> > >          partitions {
> > >            compatible = "fixed-partitions";
> > >            #address-cells = <1>;
> > > -- 
> > > 2.36.1
> > > 
> > 
> > -- 
> > மணிவண்ணன் சதாசிவம்
> 
> -- 
> 	Ansuel