 yaffs for vxworks yaffs for vxworks admin 11 january 2016 328pm the source and the definitive version of this document can be found in our git repository  together with other yaffs documents  1 background the purpose of this document is to describe the yaffsforvxworks wrapper as well as provide sufficient information to port yaffs to the vxworks bsp this document assumes a working knowledge of vxworks this document does not describe the inner workings of yaffs and a study of other yaffs documents is recommended documents shown below in italics are available at http wwwyaffsnet documents   2 licensing yaffs was originally released for linux under the gnu public license gpl various embedded developers soon identified that yaffs would be ideal for their applications but were not able to use gpl based code in their systems aleph one ltd has alternative licensing arrangements to support such applications since vxworks is proprietary code that is incompatible with gpl alternative licensing arrangements must be sought to use yaffs with vxworks or most other embedded rtoss 3 what are yaffs and yaffs direct interface  yaffs stands for yet another flash file system and was the first file system designed from the ground up for nand flash storage in 2002 aleph one set out to identify file system options for using nand flash as a file system various file systems available at the time were evaluated and all were found lacking in one way or another the need for a suitable nand storage file system was identified and yaffs was designed to fill that need although yaffs was originally designed for nand flash it has been used successfully with nor flash systems and even as a ram file system this allows high reliability file systems to be constructed using nor flash with a future migration path to nand flash for higher density and performance yaffs was originally designed for use with the linux operating system but was designed in a very modular way the operatingsystemspecific code was kept separate from the main yaffs file system code this allows yaffs to be ported quite cleanly to other operating systems through operating system personality modules one such personality module is the yaffs direct interface ydi which allows yaffs to be simply integrated with embedded systems with or without an rtos see http wwwyaffsnet documents yaffsdirectinterface the current version is yaffs2 which supports a wider range of nand flash components including 2k 4k 8k or even 16k page devices and devices with multilevel cells mlc and produces equivalent or better performance yaffs2 include yaffs1 compatibility code so yaffs1 images still work and migration is quite simple yaffs1 or yaffs2 mode of operation are simply selected by a runtime parameter as well as providing a nand file system ydi also provides a ram emulation layer to allow yaffs to operate as a ram file system too while the ram emulation is perhaps not as efficient as a dedicated ram file system this does allow one well proven file system to use both ram and flash yaffs has been used for many products using various operating systems including windows embedded compact previously called windows ce and various rtoss including threadx vxworks psos to name just a few note that there is a native port of yaffs to ecos that does not use ydi this is supported and distributed by ecoccentric  http wwwecoscentriccom    4 why use yaffs  for an in depth understanding of the advantages of yaffs please read http wwwyaffsnet documents considerationschoosingflashfilesystem for a brief overview yaffs is the first and perhaps only file system designed specifically for nand flash this means that yaffs has been designed to work around the various limitations and quirks of nand flash as well as exploit the various features of nand to achieve an effective file system some features to consider yaffs has been well proven and has been used to ship in large volumes in several products using many different operating systems compilers and processors yaffs is written in portable c and is endian neutral yaffs provides bad block handling and ecc algorithms to handle deficiencies in nand flash yaffs is a logstructured file system which makes it very robust to corruptions caused by power failures etc yaffs has highly optimised and predictable garbage collection strategies this makes it high performance and very deterministic when compared with similar file systems yaffs has a lower memory footprint than most other logstructured flash file systems yaffs provides a wide range of posixstyle file system support including directories symbolic and hard links etc through standard file system interface calls yaffs is highly configurable to work with various flash geometries various ecc options caching options etc yaffs direct interface is simple to integrate in a system only a few interface functions are required yaffs can be used with a wide range of memory technologies 5 what is yaffs forvxworks  many organizations have used yaffs on vxworks with just yaffs direct interface ydi so what benefit does yaffsforvxworks offer ydi provides a posixlike api but with yaffs specific names for example yaffsopen yaffsread yaffsclose etc while ydi provides a solution for many systems and is very well proven it has one major drawback it is not a native file system that means existing code that calls open read write etc cannot be immediately used with ydi the code needs to be rewritten to call the ydi functions yaffsopen yaffsread this porting is costly and error prone code written for ydi is then locked to yaffs and makes portability testability problems tools such as the vxworks console shell cannot be used to access yaffs files via ydi yaffsforvxworks fixes these limitations yaffsforvxworks is a wrapper around ydi that plugs ydi in as a native file system ie yaffs becomes a file system that is accessed no different from any of the other file systems on system this makes it really easy to migrate existing vxworks software or develop new vxworks software to get the benefits of yaffs yaffsforvxworks follows the vxworks operating system model used by other vxworks file systems so it is easy for vxworks developers to integrate yaffs and integrate it with their normal workflow as mentioned above yaffsforvxworks is a wrapped version of ydi that means all the testing and experience of using ydi since 2002 is incorporated into yaffsforvxworks yaffs is already supported in uboot so if you re using uboot as a boot loader then there is already seamless support for yaffs file system access between the boot loader and vxworks some organizations have developed their own vxworks wrappers for yaffs but using the yaffsforvxworks wrapper saves a lot of integration and testing effort once the yaffsforvxworks file system code is loaded into the kernel flash devices are added using yaffsdevadd they are then available in the vxworks file system for access just like any other files in the system  6 yaffsforvxworks code yaffsforvxworks is supplied as a vxworks downloadable kernel module dkm project with full source code this can then be modifies into a bsp layer or library and compiled directly into the kernel the code comprises yaffs direct interface ydi plus two wrapper files yaffsdrvc this file does all the ioslib interfacing ie plugs yaffs in as a vxworks file system and plugs in the flash devices as file system devices this file provides one externally visible function call yaffsdevadd which allows yaffs devices ie flash drivers to be plugged in yaffxvxgluec this file provides all the os resources that yaffs needs from vxworks for example it initialises a semaphore and does any error code routing in addition if the yaffs filesystem driver is build as a dkm a file called yaffsdkmc provides the dummy dkm start function the code is provided as a dkm project this includes the specification of the defines needed to compile yaffs under vxworks if the code is moved out of the dkm then it is important to make sure the correct defines are set up 7 example simulated flash driver the yaffsforvxworks package provides an example yaffs device that runs on a ram simulator this allows the file system to be tested in a simulation target without flash memory eg the vxworks simulator this also provides an example for how to develop a flash driver and plug it in to yaffs 8 example real time process rtp  an example rtp is provided that performs some basic file system operations and demonstrates a working filesystem this rtp uses standard file system calls open read write demonstrating that the yaffsforvxworks layer is operating as a native file system 9 integrating a flash device integrating a flash device is a relatively straightforward process the device is set up as a yaffsdevice structure which is then installed into yaffs by calling the yaffsdevadd function the nand simulator can serve as an example for how to do this the following snippet outlines the requirements for a better description of the params and drv substructures refer to http wwwyaffsnet yaffstuningandconfiguration  struct yaffsdev yramsimcreateramsim dev malloc sizeof dev first set everything to null memset dev  sizeof dev there are three sections to the yaffsdev structure that needs to be initialised the params substructure which are all the control parameters the drv substructure which holds the driver functions the context which holds a private pointer used to hold a driver context p dev param p name strdup name p startblock startblock p endblock endblock p totalbytesperchunk datasize p sparebytesperchunk sparesize p chunksperblock pagesperblock p nreservedblocks 2 p usenandecc 1 p inbandtags  p isyaffs2 1 d dev drv d drvinitialisefn yramsiminitialise d drvdeinitialisefn yramsimdeinitialise d drvreadchunkfn yramsimrdchunk d drvwritechunkfn yramsimwrchunk d drverasefn yramsimerase d drvcheckbadfn yramsimcheckblockbad d drvmarkbadfn yramsimmarkblockbad dev drivercontext void sim return dev void start void int result struct yaffsdev dev printf yaffs ramsim started n create and add a ram simulator device to add a different sort of device set up the device and call yaffsdevadd dev yramsimcreateramsim yramsim  400  399 printf device is p n dev if dev result yaffsdevadd dev printf yaffsdevadd returned d n result printf yaffs ram simulator now available in file system as s dev paramname  10 appendix running the examples on the vxworks simulator once you have built the yaffsfilesystemdriver and yaffsramsimdevice projects you can start up yaffs on the simulator as follows start the simulator load the yaffsfilesystemdriver dkm by right clicking on the yaffsfilesystemdriver project then selecting run debug kernel task load the yaffsramsimdevice dkm by right clicking on the yaffsfilesystemdriver project then selecting run debug kernel task at this stage the vxworks console should look something like 77777777 77777777 77777777 77777777 77777777 77777777 77777777 77777777 77777777 7777777 77777777 77777 vxworks 7 77777777 777 77777777 7 core kernel version 10102 77777777 build date oct 13 2015 121053 77777777 7777777 copyright wind river systems inc 77777 19842015 777 7 7 777 board simlinux board os memory size 511mb ed r policy mode deployed debug agent started always stop mode agent not started loading symbol table from charlesqcore home charles windriver workspace vip1 default vxworkssym done yaffs file system dkm started yaffs flash devices can now be added by calling yaffsdevadd yaffs ramsim started device is 0x8829e010 adding yaffs device 0x8829e010 yramsim yaffsdevadd returned  yaffs ram simulator now available in file system as yramsim at this stage you should be able to see the yaffs file system is running ls yramsim yramsim lost found value  0x0 if you have built the yaffstest project then try running that this should show something like start running yaffs test dump directory from pwd lost found inode 2 length 2048 mode 41b6 directory fs size 52297728 51072k free 51642368 50432k n files 4 writechecktest opening a open of a returned 3 writestufftofile returned 100000 finished running yaffs test do a file listing again will show the file system state after running the test llr yramsim listing directory yramsim drwxrwxrw 1   2048 nov 25 1407 level1 rwrwrw 1   50505 nov 25 1407 seektrunc rwrwrw 1   123000 nov 25 1407 s drwrwrw 1   2048 nov 25 1406 lost found listing directory yramsim level1 drwxrwxrw 1   2048 nov 25 1407 level2 listing directory yramsim level1 level2 drwxrwxrw 1   2048 nov 25 1407 level3 listing directory yramsim level1 level2 level3 drwxrwxrw 1   2048 nov 25 1407 level4 listing directory yramsim level1 level2 level3 level4 listing directory yramsim lost found value  0x0  