[U-Boot] [PATCH 3/4] [v3] nand_util: drop trailing all-0xff pages if requested

Scott Wood scottwood at freescale.com
Mon Jun 6 22:58:29 CEST 2011


On Tue, May 24, 2011 at 10:18:36AM -0400, Ben Gardiner wrote:
> +#ifdef CONFIG_CMD_NAND_TRIMFFS
> +static size_t drop_ffs(const nand_info_t *nand, const u_char *buf,
> +			const size_t *len)
> +{
> +	size_t i, l = *len;
> +
> +	for (i = l - 1; i >= 0; i--)
> +		if (((const uint8_t *)buf)[i] != 0xFF)
> +			break;

This cast looks unnecessary.

> +	/* The resulting length must be aligned to the minimum flash I/O size */
> +	l = i + 1;
> +	l = (l + nand->writesize - 1) / nand->writesize;
> +	l *=  nand->writesize;
> +	return l;

We allow unaligned lengths (the rest of the page gets padded with 0xff,
see nand_do_page_write-ops).  The input length might be unaligned --
this adjustment could cause you to read beyond the end of the supplied
buffer.

> +}
> +#endif
> +
>  /**
>   * nand_write_skip_bad:
>   *
> @@ -499,7 +520,7 @@ int nand_write_skip_bad(nand_info_t *nand, loff_t offset, size_t *length,
>  		return -EINVAL;
>  	}
>  
> -	if (!need_skip) {
> +	if (!need_skip && !(flags & WITH_DROP_FFS)) {
>  		rval = nand_write (nand, offset, length, buffer);
>  		if (rval == 0)
>  			return 0;

Why not call drop_ffs before this point?

> @@ -512,7 +533,7 @@ int nand_write_skip_bad(nand_info_t *nand, loff_t offset, size_t *length,
>  
>  	while (left_to_write > 0) {
>  		size_t block_offset = offset & (nand->erasesize - 1);
> -		size_t write_size;
> +		size_t write_size, truncated_write_size;
>  
>  		WATCHDOG_RESET ();
>  
> @@ -558,7 +579,15 @@ int nand_write_skip_bad(nand_info_t *nand, loff_t offset, size_t *length,
>  		else
>  #endif
>  		{
> -			rval = nand_write (nand, offset, &write_size, p_buffer);
> +			truncated_write_size = write_size;
> +#ifdef CONFIG_CMD_NAND_TRIMFFS
> +			if (flags & WITH_DROP_FFS)
> +				truncated_write_size = drop_ffs(nand, p_buffer,
> +						&write_size);
> +#endif

What if both WITH_DROP_FFS and WITH_YAFFS_OOB are specified?

-Scott



More information about the U-Boot mailing list