<p>&nbsp;</p>

<h2>1 Yaffs Direct Configuration</h2>

<p>Yaffs behaviour is dictated by compile time and run-time flags.</p>

<h3>1.1 Initialisation Parameters</h3>

<p>Each yaffs device is configured by a yaffs_DeviceParameterStruct structure which is part of the yaffs_DeviceStruct structure. This contains the following fields:</p>

<table>
	<colgroup>
		<col />
		<col />
	</colgroup>
	<tbody>
		<tr>
			<td>
			<p>name</p>
			</td>
			<td>
			<p>An optional name for the device</p>
			</td>
		</tr>
		<tr>
			<td>
			<p>totalBytesPerChunk</p>
			</td>
			<td>
			<p>The number of bytes in the data area of the flash page. If inbandTags is not set then this whole area will be used to store data and the tags will be stored in the spare area. If inbandTags is set then part of this area will be used to store tags and the rest will be used to store data.</p>
			</td>
		</tr>
		<tr>
			<td>
			<p>spareBytesPerChunk</p>
			</td>
			<td>
			<p>The number of available bytes in the spare area of the flash page. This excludes space used by ECC, bad block markers etc.</p>
			</td>
		</tr>
		<tr>
			<td>
			<p>startBlock</p>
			</td>
			<td>
			<p>The first block in the partition to be used. 0 for first block.</p>
			</td>
		</tr>
		<tr>
			<td>
			<p>endBlock</p>
			</td>
			<td>
			<p>The last block in the partition to be used.</p>
			</td>
		</tr>
		<tr>
			<td>
			<p>&nbsp;</p>
			</td>
			<td>
			<p>&nbsp;</p>
			</td>
		</tr>
		<tr>
			<td>
			<p>nReservedBlocks</p>
			</td>
			<td>
			<p>Number of good blocks blocks reserved for garbage collection etc. Needs to be at least 2, but 5 would be a more typical number.</p>
			</td>
		</tr>
		<tr>
			<td>
			<p>inbandTags</p>
			</td>
			<td>
			<p>Yaffs2 only:Flag indicating whether tags should be stored in the data area. If inbandTags is set then the short Op cache must be enabled (ie nShortOpCaches must be non-zero.</p>
			</td>
		</tr>
		<tr>
			<td>
			<p>useNANDECC</p>
			</td>
			<td>
			<p>Yaffs1 only: Flag indicating whether the driver performs ECC. If this is zero then Yaffs will perform ECC.</p>
			</td>
		</tr>
		<tr>
			<td>
			<p>noTagsECC</p>
			</td>
			<td>
			<p>Yaffs2 only: Flag indicating whether the tags have ECC attached to them.</p>
			</td>
		</tr>
		<tr>
			<td>
			<p>isYaffs2</p>
			</td>
			<td>
			<p>Flag indicating if this is using the Yaffs2 mechanism. If this is not set then Yaffs1 mode of operation is provided.</p>
			</td>
		</tr>
		<tr>
			<td>
			<p>&nbsp;</p>
			</td>
			<td>
			<p>&nbsp;</p>
			</td>
		</tr>
		<tr>
			<td>
			<p>nShortOpCaches</p>
			</td>
			<td>
			<p>Number of chunks to store in the short operation cache. Zero disables caching. Typical value is 10 to 20 or so. Caching is required for inband tags.</p>
			</td>
		</tr>
		<tr>
			<td>
			<p>emptyLostAndFound</p>
			</td>
			<td>
			<p>Flag to delete all files in lost and found on mount.</p>
			</td>
		</tr>
		<tr>
			<td>
			<p>skipCheckpointRead</p>
			</td>
			<td>
			<p>Yaffs2 only: Flag to skip reading checkpoint on mount. If set then a re-scan is forced.</p>
			</td>
		</tr>
		<tr>
			<td>
			<p>skipCheckpointWrite</p>
			</td>
			<td>
			<p>Yaffs2 only: Flag to skip writing checkpoint on sync or unmount.</p>
			</td>
		</tr>
		<tr>
			<td>
			<p>refreshPeriod</p>
			</td>
			<td>
			<p>Yaffs2 only: How often Yaffs should do a block refresh. Values less than 10 disable block refreshing. Typical values would be1000.</p>
			</td>
		</tr>
		<tr>
			<td>
			<p>&nbsp;</p>
			</td>
			<td>
			<p>&nbsp;</p>
			</td>
		</tr>
		<tr>
			<td>
			<p>initialiseNAND</p>
			</td>
			<td>
			<p>Pointer to function to initialise flash driver.</p>
			</td>
		</tr>
		<tr>
			<td>
			<p>deinitialiseNAND</p>
			</td>
			<td>
			<p>Pointer to function to de-initialise flash driver</p>
			</td>
		</tr>
		<tr>
			<td>
			<p>eraseBlockInNAND</p>
			</td>
			<td>
			<p>Pointer to function to erase a flash block</p>
			</td>
		</tr>
		<tr>
			<td>
			<p>&nbsp;</p>
			</td>
			<td>
			<p>&nbsp;</p>
			</td>
		</tr>
		<tr>
			<td>
			<p>writeChunkToNAND</p>
			</td>
			<td>
			<p>Yaffs1 only: Pointer to function to write a chunk</p>
			</td>
		</tr>
		<tr>
			<td>
			<p>readChunkFromNAND</p>
			</td>
			<td>
			<p>Yaffs1 only: Pointer to function to read a chunk.</p>
			</td>
		</tr>
		<tr>
			<td>
			<p>&nbsp;</p>
			</td>
			<td>
			<p>&nbsp;</p>
			</td>
		</tr>
		<tr>
			<td>
			<p>writeChunkWithTagsToNAND</p>
			</td>
			<td>
			<p>Yaffs2 only: Pointer to function to write a chunk plus tags</p>
			</td>
		</tr>
		<tr>
			<td>
			<p>readChunkWithTagsFromNAND</p>
			</td>
			<td>
			<p>Yaffs2 only: Pointer to function to read a chunk plus tags</p>
			</td>
		</tr>
		<tr>
			<td>
			<p>markNANDBlockBad</p>
			</td>
			<td>
			<p>Yaffs2 only: Function to mark a block bad</p>
			</td>
		</tr>
		<tr>
			<td>
			<p>queryNANDBlock</p>
			</td>
			<td>
			<p>Yaffs2 only: Function to query a block state</p>
			</td>
		</tr>
		<tr>
			<td>
			<p>&nbsp;</p>
			</td>
			<td>
			<p>&nbsp;</p>
			</td>
		</tr>
		<tr>
			<td>
			<p>gcControl</p>
			</td>
			<td>
			<p>Callback function that returns the garbage collector control flags. This is optional.</p>
			</td>
		</tr>
		<tr>
			<td>
			<p>removeObjectCallback</p>
			</td>
			<td>
			<p>Callback function called when an object is removed. This is set by the wrapper.</p>
			</td>
		</tr>
		<tr>
			<td>
			<p>markSuperBlockDirty</p>
			</td>
			<td>
			<p>Callback function that is called when a clean file system is first modified. This is set by the wrapper.</p>
			</td>
		</tr>
		<tr>
			<td>
			<p>&nbsp;</p>
			</td>
			<td>
			<p>&nbsp;</p>
			</td>
		</tr>
		<tr>
			<td>
			<p>disableSoftDelete</p>
			</td>
			<td>
			<p>Yaffs1 only. Debug only. Disables soft deletion if non-zero.</p>
			</td>
		</tr>
		<tr>
			<td>
			<p>&nbsp;</p>
			</td>
			<td>
			<p>&nbsp;</p>
			</td>
		</tr>
		<tr>
			<td>
			<p>useHeaderFileSize</p>
			</td>
			<td>
			<p>Debug only. Leave as zero</p>
			</td>
		</tr>
		<tr>
			<td>
			<p>disableLazyLoading</p>
			</td>
			<td>
			<p>Debug only. Leave as zero.</p>
			</td>
		</tr>
		<tr>
			<td>
			<p>wideTnodeDisabled</p>
			</td>
			<td>
			<p>Debug only. Leave as zero.</p>
			</td>
		</tr>
		<tr>
			<td>
			<p>&nbsp;</p>
			</td>
			<td>
			<p>&nbsp;</p>
			</td>
		</tr>
		<tr>
			<td>
			<p>deferDirectoryUpdate</p>
			</td>
			<td>
			<p>Used to defer directory updates.</p>
			</td>
		</tr>
	</tbody>
</table>

<p>&nbsp;</p>

<h3>1.2 Compile-time settings</h3>

<p>These setting are used to apply compile-time configurations.</p>

<p>CONFIG_YAFFS_ALWAYS_CHECK_CHUNK_ERASED</p>

<p>Normally Yaffs checks that chunks are erased only on the first chunk write to each block. This flag allows you to force all chunks to be checked. This is slower, but is worth using when doing early debugging.</p>

<p>CONFIG_YAFFS_CASE_INSENSITIVE</p>

<p>When selected case insensitive name comparisons are used. Note that this will not magically change Yaffs to be case insensitive in a case sensitive OS. This needs to be set according to the OS policy. Typically this is only used in Windows CE.</p>

<p>CONFIG_YAFFS_DIRECT</p>

<p>Used when compiling Yaffs Direct.</p>

<p>CONFIG_YAFFS_DISABLE_LAZY_LOAD</p>

<p>Lazy loading is used to defer loading up object details until the objects are accessed. This makes mount time faster. This flag can disable lazy loading. Debug only.</p>

<p>CONFIG_YAFFS_ECC_WRONG_ORDER</p>

<p>This flag should only be used with old Linux MTD code which had a bug in the ECC byte ordering.</p>

<p>CONFIG_YAFFS_NO_YAFFS1</p>

<p>Used to say that only Yaffs2 operation should be compiled in. Not currently supported.</p>

<p>CONFIG_YAFFS_SHORT_NAMES_IN_RAM</p>

<p>Set to configure Yaffs to store short object names in RAM. This is faster, but uses up more memory.</p>

<p>CONFIG_YAFFS_UNICODE</p>

<p>Set to configure Yaffs to use Unicode file names (eg. With WinCE).</p>

<p>CONFIG_YAFFS_USE_OWN_SORT</p>

<p>By default, Yaffs uses qsort for sorting blocks at mount scanning time. This is faster. Using this flag forces Yaffs to use a slow internal sort instead. Debug only.</p>

<p>CONFIG_YAFFS_UTIL</p>

<p>Used when compiling Yaffs for utilities.</p>

<p>CONFIG_YAFFS_WINCE</p>

<p>Set when compiling Yaffs for WinCE.</p>

<p>CONFIG_YAFFS_YAFFS2</p>

<p>Set when using Yaffs2 mode. At present this must always be set.</p>

<p>CONFIG_YAFFSFS_PROVIDE_VALUES</p>

<p>Used when compiling Yaffs Direct only.</p>

<h3>2 Tracing mechanism</h3>

<p>Yaffs has a lot of built in tracing to help debug and integrate. The tracing is controlled by yaffs_traceMask bitmask which allows various sets of tracing to be disabled or enabled at runtime.</p>

<p>The trace bits are specified in the yaffs_trace.h file.</p>

<p>The tracing mechanism has also been 'hijacked' to provide a control mask for extra verification code when the YAFFS_TRACE_VERIFYxxx trace bits are selected.</p>

<p>The tracing mechanism is readily integrated into the system via printf-like statements. Tracing is all done through macros which allow the strings to be converted into unicode or similar if need be.</p>

<h2>3 Linux</h2>

<h3>3.1 Linux compile-time flags</h3>

<p>The Linux compile time flags are documented in the Kconfig file and will not be duplicated here.</p>

<h3>3.2 Linux: /proc/yaffs trace adjustment</h3>

<p>Under Linux, the tracing mechanism is hooked up to both the /proc/yaffs and the sys interface. The /proc/yaffs interface is very user friendly.</p>

<p><code>#cat +os &gt; /proc/yaffs # Enables YAFFS_TRACE_OS<br />
#cat -all+gc &gt; /proc/yaffs # Disables everything then enable YAFFS_TRACE_GC<br />
#cat 0xf000 &gt; /proc/yaffs # Set trace mask to specified bitmask.</code></p>

<h3>3.3 Linux: /sys/ interface</h3>

<p>The Linux /sys/ interface is used by many Linux OS components to access the state of control variables. Some Yaffs variables are available via /sys/module/yaffs2/parameters/ *. Values can be read and modified using standard shell commands or from application programs.</p>

<p><code># ls /sys/module/yaffs2/parameters/ yaffs_auto_checkpoint yaffs_traceMask yaffs_wr_attempts<br />
# cat /sys/module/yaffs2/parameters/yaffs_auto_checkpoint 1<br />
# echo "2" &gt; /sys/module/yaffs2/parameters/yaffs_auto_checkpoint<br />
# cat /sys/module/yaffs2/parameters/yaffs_auto_checkpoint 2 </code></p>

<p>Yaffs currently supports the following variables:</p>

<p>yaffs_auto_checkpoint: Controls when checkpoints should be written.</p>

<p>yaffs_traceMask: An alternative, and less user friendly,interface to modify tracing.</p>

<p>yaffs_wr_attempts: The number of attempts that Yaffs will make to write a chunk.</p>

<p>yaffs_gc_control: Controls the garbage collector.</p>

<h3>3.4 Linux: /proc/yaffs state dumping</h3>

<p>Some of the state of Yaffs mounts can be determined by reading the /proc/yaffs entry.</p>

<p><code># cat /proc/yaffs<br />
charles@charles-laptop:/opt/y/cvs/yaffs2$ cat /proc/yaffs<br />
YAFFS built:Mar 16 2010 11:52:25<br />
$Id: yaffs_fs.c,v 1.101 2010-03-15 22:27:15 charles Exp $<br />
$Id: yaffs_guts.c,v 1.119 2010-03-12 02:48:34 charles Exp $<br />
<br />
Device 0 "NAND simulator partition 0" </code><br />
<code>startBlock......... 0<br />
endBlock........... 511<br />
totalBytesPerChunk. 2048<br />
useNANDECC......... 1<br />
noTagsECC.......... 0<br />
isYaffs2........... 1<br />
inbandTags......... 0<br />
emptyLostAndFound.. 1<br />
disableLazyLoad.... 0<br />
refreshPeriod...... 10000<br />
nShortOpCaches..... 10<br />
nReservedBlocks.... 5<br />
<br />
nDataBytesPerChunk. 2048<br />
chunkGroupBits..... 0<br />
chunkGroupSize..... 1<br />
nErasedBlocks...... 152<br />
blocksInCheckpoint. 0<br />
<br />
nTnodesCreated..... 2300<br />
nFreeTnodes........ 1852<br />
nObjectsCreated.... 2300<br />
nFreeObjects....... 1842<br />
nFreeChunks........ 27843<br />
<br />
nPageWrites........ 65993<br />
nPageReads......... 19631<br />
nBlockErasures..... 1133<br />
nGCCopies.......... 37<br />
garbageCollections. 161<br />
passiveGCs......... 137<br />
nRetriedWrites..... 0<br />
nRetireBlocks...... 0<br />
eccFixed........... 0<br />
eccUnfixed......... 0<br />
tagsEccFixed....... 0<br />
tagsEccUnfixed..... 0<br />
cacheHits.......... 44110<br />
nDeletedFiles...... 0<br />
nUnlinkedFiles..... 42917<br />
refreshCount....... 1<br />
nBackgroudDeletions 0</code></p>

<p>&nbsp;</p>

<h2>4 Conclusions</h2>

<p>Yaffs includes many options for changing speed or memory use, with specific flags for the Yaffs Direct Interface as well as Linux. Under Linux many of the control variables can be altered using standard Linux systems.</p>
