yaffs_nand.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /*
  2. * YAFFS: Yet Another Flash File System. A NAND-flash specific file system.
  3. *
  4. * Copyright (C) 2002-2010 Aleph One Ltd.
  5. * for Toby Churchill Ltd and Brightstar Engineering
  6. *
  7. * Created by Charles Manning <charles@aleph1.co.uk>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2 as
  11. * published by the Free Software Foundation.
  12. */
  13. #include "yaffs_nand.h"
  14. #include "yaffs_tagscompat.h"
  15. #include "yaffs_tagsvalidity.h"
  16. #include "yaffs_getblockinfo.h"
  17. int yaffs_rd_chunk_tags_nand(struct yaffs_dev *dev, int nand_chunk,
  18. u8 * buffer, struct yaffs_ext_tags *tags)
  19. {
  20. int result;
  21. struct yaffs_ext_tags local_tags;
  22. int realigned_chunk = nand_chunk - dev->chunk_offset;
  23. dev->n_page_reads++;
  24. /* If there are no tags provided, use local tags to get prioritised gc working */
  25. if (!tags)
  26. tags = &local_tags;
  27. if (dev->param.read_chunk_tags_fn)
  28. result =
  29. dev->param.read_chunk_tags_fn(dev, realigned_chunk, buffer,
  30. tags);
  31. else
  32. result = yaffs_tags_compat_rd(dev,
  33. realigned_chunk, buffer, tags);
  34. if (tags && tags->ecc_result > YAFFS_ECC_RESULT_NO_ERROR) {
  35. struct yaffs_block_info *bi;
  36. bi = yaffs_get_block_info(dev,
  37. nand_chunk /
  38. dev->param.chunks_per_block);
  39. yaffs_handle_chunk_error(dev, bi);
  40. }
  41. return result;
  42. }
  43. int yaffs_wr_chunk_tags_nand(struct yaffs_dev *dev,
  44. int nand_chunk,
  45. const u8 * buffer, struct yaffs_ext_tags *tags)
  46. {
  47. dev->n_page_writes++;
  48. nand_chunk -= dev->chunk_offset;
  49. if (tags) {
  50. tags->seq_number = dev->seq_number;
  51. tags->chunk_used = 1;
  52. if (!yaffs_validate_tags(tags)) {
  53. yaffs_trace(YAFFS_TRACE_ERROR, "Writing uninitialised tags");
  54. YBUG();
  55. }
  56. yaffs_trace(YAFFS_TRACE_WRITE,
  57. "Writing chunk %d tags %d %d",
  58. nand_chunk, tags->obj_id, tags->chunk_id);
  59. } else {
  60. yaffs_trace(YAFFS_TRACE_ERROR, "Writing with no tags");
  61. YBUG();
  62. }
  63. if (dev->param.write_chunk_tags_fn)
  64. return dev->param.write_chunk_tags_fn(dev, nand_chunk, buffer,
  65. tags);
  66. else
  67. return yaffs_tags_compat_wr(dev, nand_chunk, buffer, tags);
  68. }
  69. int yaffs_mark_bad(struct yaffs_dev *dev, int block_no)
  70. {
  71. block_no -= dev->block_offset;
  72. if (dev->param.bad_block_fn)
  73. return dev->param.bad_block_fn(dev, block_no);
  74. else
  75. return yaffs_tags_compat_mark_bad(dev, block_no);
  76. }
  77. int yaffs_query_init_block_state(struct yaffs_dev *dev,
  78. int block_no,
  79. enum yaffs_block_state *state,
  80. u32 * seq_number)
  81. {
  82. block_no -= dev->block_offset;
  83. if (dev->param.query_block_fn)
  84. return dev->param.query_block_fn(dev, block_no, state,
  85. seq_number);
  86. else
  87. return yaffs_tags_compat_query_block(dev, block_no,
  88. state, seq_number);
  89. }
  90. int yaffs_erase_block(struct yaffs_dev *dev, int flash_block)
  91. {
  92. int result;
  93. flash_block -= dev->block_offset;
  94. dev->n_erasures++;
  95. result = dev->param.erase_fn(dev, flash_block);
  96. return result;
  97. }
  98. int yaffs_init_nand(struct yaffs_dev *dev)
  99. {
  100. if (dev->param.initialise_flash_fn)
  101. return dev->param.initialise_flash_fn(dev);
  102. return YAFFS_OK;
  103. }