yaffscfg2k.c 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. /*
  2. * YAFFS: Yet Another Flash File System. A NAND-flash specific file system.
  3. *
  4. * Copyright (C) 2002-2007 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. /*
  14. * yaffscfg2k.c The configuration for the "direct" use of yaffs.
  15. *
  16. * This file is intended to be modified to your requirements.
  17. * There is no need to redistribute this file.
  18. */
  19. #include "yaffscfg.h"
  20. #include "yaffsfs.h"
  21. #include "yaffs_fileem2k.h"
  22. #include "yaffs_nandemul2k.h"
  23. #include <errno.h>
  24. unsigned yaffs_traceMask =
  25. YAFFS_TRACE_SCAN |
  26. YAFFS_TRACE_GC | YAFFS_TRACE_GC_DETAIL |
  27. YAFFS_TRACE_ERASE |
  28. YAFFS_TRACE_TRACING |
  29. YAFFS_TRACE_ALLOCATE |
  30. YAFFS_TRACE_CHECKPOINT |
  31. YAFFS_TRACE_BAD_BLOCKS |
  32. YAFFS_TRACE_VERIFY |
  33. YAFFS_TRACE_VERIFY_NAND |
  34. YAFFS_TRACE_VERIFY_FULL |
  35. // (~0) |
  36. 0;
  37. void yaffsfs_SetError(int err)
  38. {
  39. //Do whatever to set error
  40. errno = err;
  41. }
  42. void yaffsfs_Lock(void)
  43. {
  44. }
  45. void yaffsfs_Unlock(void)
  46. {
  47. }
  48. __u32 yaffsfs_CurrentTime(void)
  49. {
  50. return 0;
  51. }
  52. static int yaffs_kill_alloc = 0;
  53. static size_t total_malloced = 0;
  54. static size_t malloc_limit = 0 & 6000000;
  55. void *yaffs_malloc(size_t size)
  56. {
  57. size_t this;
  58. if(yaffs_kill_alloc)
  59. return NULL;
  60. if(malloc_limit && malloc_limit <(total_malloced + size) )
  61. return NULL;
  62. this = malloc(size);
  63. if(this)
  64. total_malloced += size;
  65. return this;
  66. }
  67. void yaffs_free(void *ptr)
  68. {
  69. free(ptr);
  70. }
  71. void yaffsfs_LocalInitialisation(void)
  72. {
  73. // Define locking semaphore.
  74. }
  75. // Configuration for:
  76. // /ram 2MB ramdisk
  77. // /boot 2MB boot disk (flash)
  78. // /flash 14MB flash disk (flash)
  79. // NB Though /boot and /flash occupy the same physical device they
  80. // are still disticnt "yaffs_Devices. You may think of these as "partitions"
  81. // using non-overlapping areas in the same device.
  82. //
  83. #include "yaffs_ramdisk.h"
  84. #include "yaffs_flashif.h"
  85. #include "yaffs_nandemul2k.h"
  86. static yaffs_Device ramDev;
  87. static yaffs_Device bootDev;
  88. static yaffs_Device flashDev;
  89. static yaffs_Device ram2kDev;
  90. static yaffsfs_DeviceConfiguration yaffsfs_config[] = {
  91. #if 0
  92. { "/ram", &ramDev},
  93. { "/boot", &bootDev},
  94. { "/flash/", &flashDev},
  95. { "/ram2k", &ram2kDev},
  96. {(void *)0,(void *)0}
  97. #else
  98. { "/", &ramDev},
  99. { "/flash/boot", &bootDev},
  100. { "/flash/flash", &flashDev},
  101. { "/ram2k", &ram2kDev},
  102. {(void *)0,(void *)0} /* Null entry to terminate list */
  103. #endif
  104. };
  105. int yaffs_StartUp(void)
  106. {
  107. // Stuff to configure YAFFS
  108. // Stuff to initialise anything special (eg lock semaphore).
  109. yaffsfs_LocalInitialisation();
  110. // Set up devices
  111. // /ram
  112. memset(&ramDev,0,sizeof(ramDev));
  113. ramDev.nDataBytesPerChunk = 512;
  114. ramDev.nChunksPerBlock = 32;
  115. ramDev.nReservedBlocks = 2; // Set this smaller for RAM
  116. ramDev.startBlock = 0; // Can use block 0
  117. ramDev.endBlock = 127; // Last block in 2MB.
  118. //ramDev.useNANDECC = 1;
  119. ramDev.nShortOpCaches = 0; // Disable caching on this device.
  120. ramDev.genericDevice = (void *) 0; // Used to identify the device in fstat.
  121. ramDev.writeChunkWithTagsToNAND = yramdisk_WriteChunkWithTagsToNAND;
  122. ramDev.readChunkWithTagsFromNAND = yramdisk_ReadChunkWithTagsFromNAND;
  123. ramDev.eraseBlockInNAND = yramdisk_EraseBlockInNAND;
  124. ramDev.initialiseNAND = yramdisk_InitialiseNAND;
  125. // /boot
  126. memset(&bootDev,0,sizeof(bootDev));
  127. bootDev.nDataBytesPerChunk = 512;
  128. bootDev.nChunksPerBlock = 32;
  129. bootDev.nReservedBlocks = 5;
  130. bootDev.startBlock = 0; // Can use block 0
  131. bootDev.endBlock = 63; // Last block
  132. //bootDev.useNANDECC = 0; // use YAFFS's ECC
  133. bootDev.nShortOpCaches = 10; // Use caches
  134. bootDev.genericDevice = (void *) 1; // Used to identify the device in fstat.
  135. bootDev.writeChunkWithTagsToNAND = yflash_WriteChunkWithTagsToNAND;
  136. bootDev.readChunkWithTagsFromNAND = yflash_ReadChunkWithTagsFromNAND;
  137. bootDev.eraseBlockInNAND = yflash_EraseBlockInNAND;
  138. bootDev.initialiseNAND = yflash_InitialiseNAND;
  139. bootDev.markNANDBlockBad = yflash_MarkNANDBlockBad;
  140. bootDev.queryNANDBlock = yflash_QueryNANDBlock;
  141. // /flash
  142. // Set this puppy up to use
  143. // the file emulation space as
  144. // 2kpage/64chunk per block/128MB device
  145. memset(&flashDev,0,sizeof(flashDev));
  146. flashDev.nDataBytesPerChunk = 2048;
  147. flashDev.nChunksPerBlock = 64;
  148. flashDev.nReservedBlocks = 5;
  149. flashDev.nCheckpointReservedBlocks = 5;
  150. //flashDev.checkpointStartBlock = 1;
  151. //flashDev.checkpointEndBlock = 20;
  152. flashDev.startBlock = 0;
  153. flashDev.endBlock = 200; // Make it smaller
  154. //flashDev.endBlock = yflash_GetNumberOfBlocks()-1;
  155. flashDev.isYaffs2 = 1;
  156. flashDev.wideTnodesDisabled=0;
  157. flashDev.nShortOpCaches = 10; // Use caches
  158. flashDev.genericDevice = (void *) 2; // Used to identify the device in fstat.
  159. flashDev.writeChunkWithTagsToNAND = yflash_WriteChunkWithTagsToNAND;
  160. flashDev.readChunkWithTagsFromNAND = yflash_ReadChunkWithTagsFromNAND;
  161. flashDev.eraseBlockInNAND = yflash_EraseBlockInNAND;
  162. flashDev.initialiseNAND = yflash_InitialiseNAND;
  163. flashDev.markNANDBlockBad = yflash_MarkNANDBlockBad;
  164. flashDev.queryNANDBlock = yflash_QueryNANDBlock;
  165. // /ram2k
  166. // Set this puppy up to use
  167. // the file emulation space as
  168. // 2kpage/64chunk per block/128MB device
  169. memset(&ram2kDev,0,sizeof(ram2kDev));
  170. ram2kDev.nDataBytesPerChunk = nandemul2k_GetBytesPerChunk();
  171. ram2kDev.nChunksPerBlock = nandemul2k_GetChunksPerBlock();
  172. ram2kDev.nReservedBlocks = 5;
  173. ram2kDev.startBlock = 0; // First block after /boot
  174. //ram2kDev.endBlock = 127; // Last block in 16MB
  175. ram2kDev.endBlock = nandemul2k_GetNumberOfBlocks() - 1; // Last block in 512MB
  176. ram2kDev.isYaffs2 = 1;
  177. ram2kDev.nShortOpCaches = 10; // Use caches
  178. ram2kDev.genericDevice = (void *) 3; // Used to identify the device in fstat.
  179. ram2kDev.writeChunkWithTagsToNAND = nandemul2k_WriteChunkWithTagsToNAND;
  180. ram2kDev.readChunkWithTagsFromNAND = nandemul2k_ReadChunkWithTagsFromNAND;
  181. ram2kDev.eraseBlockInNAND = nandemul2k_EraseBlockInNAND;
  182. ram2kDev.initialiseNAND = nandemul2k_InitialiseNAND;
  183. ram2kDev.markNANDBlockBad = nandemul2k_MarkNANDBlockBad;
  184. ram2kDev.queryNANDBlock = nandemul2k_QueryNANDBlock;
  185. yaffs_initialise(yaffsfs_config);
  186. return 0;
  187. }
  188. void SetCheckpointReservedBlocks(int n)
  189. {
  190. flashDev.nCheckpointReservedBlocks = n;
  191. }