[U-Boot] [PATCH v2 20/21] cmd: mtd: add 'mtd' command

Miquel Raynal miquel.raynal at bootlin.com
Thu Jul 12 13:12:37 UTC 2018


Hi Boris,

> > > +
> > > +		if (full_erase) {
> > > +			off = 0;
> > > +			len = mtd->size;
> > > +		}
> > > +
> > > +		if ((u32)off % mtd->erasesize) {    
> > 
> > Sounds dangerous. We have 8GB NANDs on sunxi platforms...  
> 
> [...]
> 
> > > +
> > > +		if ((u32)len % mtd->erasesize) {    
> > 
> > Same here. I guess there's a do_div() in uboot.  
> 
> In both cases I take the less significant bytes of a 64-bit value. The
> modulo operation is safe as long as mtd->erasesize is a 32-bit value
> too. I don't think there is any danger?

As discussed out of this thread, this works because mtd->erasesize is
always a power of 2. Erase sizes not being a power of 2 do not exist
but it will be safer to switch to do_div().

Thanks,
Miquèl


More information about the U-Boot mailing list