drivers/mtd/nand/nand_util.c
- 472 int nand_write_skip_bad(nand_info_t *nand, loff_t offset, size_t *length_i,
-
473 u_char *buffer)
-
474 {
-
475 int rval;
-
476 //size_t left_to_write = *length;
-
477 size_t len_incl_bad;
-
478 u_char *p_buffer = buffer;
-
479
-
480 #if 1 //ABING Fixed NOT align filesize
-
481
-
482 size_t *length;
-
483 size_t page_size = nand->writesize;
-
484 size_t page_num = *length_i/page_size;
-
485 size_t n = *length_i;
-
486 size_t left_to_write;
-
487
-
488 if (*length_i % (page_size) != 0) {
-
489 printf("Not align, modified\n");
-
490 n = (page_num + 1) * page_size;
-
491 }
-
492
-
493 length = &n;
-
494 left_to_write = n;
-
495 #endif
-
496
-
497 /* Reject writes, which are not page aligned */
-
498 if ((offset & (nand->writesize - 1)) != 0 ||
-
499 (*length & (nand->writesize - 1)) != 0) {
-
500 printf ("Attempt to write non page aligned data\n");
-
501 return -EINVAL;
-
502 }
其实还可以用更简单的办法,就是如果长度不对齐,则将长度或上页大小即可:
- 497 if (*length % (page_size) != 0) {
-
498 left_to_write = *length | nand->writesize;
- left_to_write += 1;
-
499 }
用这种方法无需改动函数原型的参数名称,也更简洁。
(function(w, d, g, J) { var e = J.stringify || J.encode; d[g] = d[g] || {}; d[g]['showValidImages'] = d[g]['showValidImages'] || function() { w.postMessage(e({'msg': {'g': g, 'm':'s'}}), location.href); } })(window, document, '__huaban', JSON); (function(w, d, g, J) { var e = J.stringify || J.encode; d[g] = d[g] || {}; d[g]['showValidImages'] = d[g]['showValidImages'] || function() { w.postMessage(e({'msg': {'g': g, 'm':'s'}}), location.href); } })(window, document, '__huaban', JSON);
阅读(2922) | 评论(0) | 转发(0) |