[PATCH] mtd-utils: flash_erase: Adjust jffs2 cleanmarker size for min_io_size

Tudor Ambarus tudor.ambarus at linaro.org
Tue Mar 21 20:56:58 PDT 2023


Hi!

On 3/15/23 08:33, tkuw584924 at gmail.com wrote:
> From: Takahiro Kuwano <Takahiro.Kuwano at infineon.com>
> 
> JFFS2 supports buffer mode for ECC'd NOR Flash and the size of cleanmarker
> is rounded up to mtd->writesize. The flash_erase utility should do the
> same when it writes JFFS2 cleanmarker.
> 
> Signed-off-by: Takahiro Kuwano <Takahiro.Kuwano at infineon.com>
> ---
>  include/common.h         | 1 +
>  misc-utils/flash_erase.c | 2 +-
>  2 files changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/include/common.h b/include/common.h
> index 31b6cd1..4b9b661 100644
> --- a/include/common.h
> +++ b/include/common.h
> @@ -46,6 +46,7 @@ extern "C" {
>  #define MAX(a, b) ((a) > (b) ? (a) : (b))
>  #endif
>  #define min(a, b) MIN(a, b) /* glue for linux kernel source */
> +#define max(a, b) MAX(a, b)
>  #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
>  
>  #define ALIGN(x,a) __ALIGN_MASK(x,(typeof(x))(a)-1)
> diff --git a/misc-utils/flash_erase.c b/misc-utils/flash_erase.c
> index 49a880f..6ff4b93 100644
> --- a/misc-utils/flash_erase.c
> +++ b/misc-utils/flash_erase.c
> @@ -212,7 +212,7 @@ int main(int argc, char *argv[])
>  		cleanmarker.magic = cpu_to_je16 (JFFS2_MAGIC_BITMASK);
>  		cleanmarker.nodetype = cpu_to_je16 (JFFS2_NODETYPE_CLEANMARKER);
>  		if (!isNAND) {
> -			cleanmarker.totlen = cpu_to_je32(sizeof(cleanmarker));
> +			cleanmarker.totlen = cpu_to_je32(max(sizeof(cleanmarker), mtd.min_io_size));

If we really want to match what's in kernel, we should set it to
max(16u, c->mtd->writesize);

And you'll have to update clear_marker() as well.

Now while the change is fair, when looking into the kernel I see that
there's no magic value defined for the NOR cleanmarker and there are no
methods to check the value of the cleanmarker for NORs. Is this patch
part of a larger effort that adds cleanmarker support for NORs in kernel?

What motivated you to do this change?

Cheers,
ta

>  		} else {
>  			cleanmarker.totlen = cpu_to_je32(8);
>  			cmlen = min(mtd.oobavail, 8);



More information about the linux-mtd mailing list