From mboxrd@z Thu Jan 1 00:00:00 1970 From: Scott Wood Date: Fri, 14 Jun 2013 17:19:45 -0500 Subject: [U-Boot] [PATCH] dfu, nand: before write a buffer to nand, erase the nand sectors In-Reply-To: <1371205443-27690-1-git-send-email-hs@denx.de> (from hs@denx.de on Fri Jun 14 05:24:03 2013) Message-ID: <1371248385.2996.19@snotra> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de On 06/14/2013 05:24:03 AM, Heiko Schocher wrote: > diff --git a/drivers/dfu/dfu_nand.c b/drivers/dfu/dfu_nand.c > index 7dc89b2..6f9a934 100644 > --- a/drivers/dfu/dfu_nand.c > +++ b/drivers/dfu/dfu_nand.c > @@ -63,12 +63,25 @@ static int nand_block_op(enum dfu_nand_op op, > struct dfu_entity *dfu, > > nand = &nand_info[nand_curr_device]; > > - if (op == DFU_OP_READ) > + if (op == DFU_OP_READ) { > ret = nand_read_skip_bad(nand, start, &count, &actual, > lim, buf); > - else > + } else { > + nand_erase_options_t opts; > + > + memset(&opts, 0, sizeof(opts)); > + opts.offset = start; > + opts.length = count; > + adjust_size_for_badblocks(&opts.length, offset, > + nand_curr_device); > + /* first erase */ > + ret = nand_erase_opts(nand, &opts); > + if (ret) > + return ret; You could use opts.spread instead of calling adjust_size_for_badblocks(). If you do want to use adjust_size_for_badblocks() -- say, to do bounds checking on the result -- please move it to nand_util.c, and pass in a pointer to nand_info_t instead of "int dev". -Scott