- do {
- /* write 512 bytes */
- davinci_read_block_data(nand, data, 512);
- data += 512;
- data_size -= 512;
-
- /* read this "out-of-band" data -- infix */
- davinci_read_block_data(nand, oob, 16);
- oob += 16;
- oob_size -= 16;
- } while (data_size);
-
+ want_col = 0;
+ at_col = 0;
+ while ((data && data_size) || (oob && oob_size)) {
+
+ if (data && data_size) {
+ if (want_col != at_col) {
+ /* Reads are slow, so seek past them when we can */
+ ret = davinci_seek_column(nand, want_col);
+ if (ret != ERROR_OK)
+ return ret;
+ at_col = want_col;
+ }
+ /* read 512 bytes or data_size, whichever is smaller*/
+ read_size = data_size > 512 ? 512 : data_size;
+ davinci_read_block_data(nand, data, read_size);
+ data += read_size;
+ data_size -= read_size;
+ at_col += read_size;
+ }
+ want_col += 512;
+
+ if (oob && oob_size) {
+ if (want_col != at_col) {
+ ret = davinci_seek_column(nand, want_col);
+ if (ret != ERROR_OK)
+ return ret;
+ at_col = want_col;
+ }
+ /* read this "out-of-band" data -- infix */
+ read_size = oob_size > 16 ? 16 : oob_size;
+ davinci_read_block_data(nand, oob, read_size);
+ oob += read_size;
+ oob_size -= read_size;
+ at_col += read_size;
+ }
+ want_col += 16;
+ }