High-Level Details

The following details assume a basic system: CPU, I/O, RAM, and one flash device. The system flash memory includes three defined sections: flash space used by the MicroMonitor code itself, the flash space used to store the files, and the space dedicated to interruptible defragmentation (the spare sector). The flash memory used by TFS for file storage begins on a sector boundary, and the spare sector is located immediately after the last sector in which files are stored. The spare sector must be at least as large as any other sector in the device, and the sector prior to the spare is assumed to be of equal size (refer to Figure 7.1).

image from book
Figure 7.1: TFS Overlayed on a Flash Device.

TFS organizes the files within the flash memory in a contiguous, one-way linked list. The initial portion of the file is a file header (see Figure 7.2), which contains information about the file, a pointer to the next file, and a 32-bit cyclic redundancy check (CRC) of the header and data portion of the file. Maintaining unique CRC checks for header and data allows TFS to detect corruption. File size is limited only by the amount of flash memory allocated to TFS. There is no restriction with regard to sector boundaries. The header structure is shown in Listing 7.2.

Listing 7.2: TFS Header Structure.
image from book
 struct tfshdr {     ushort  hdrsize;               /* Size of this header.              */     ushort  hdrvrsn;               /* Header version #.                 */     long    filsize;               /* Size of the file.                 */     long    flags;                 /* Flags describing the file.        */     ulong   filcrc;                /* 32 bit CRC of file.               */     ulong   hdrcrc;                /* 32 bit CRC of the header.         */     ulong   modtime;               /* Time when file was last modified. */     struct  tfshdr  *next;         /* Pointer to next file in list.     */     char    name[TFSNAMESIZE+1];   /* Name of file.                     */     char    info[TFSINFOSIZE+1];   /* Miscellaneous info field.         */ #if TFS_RESERVED     ulong   rsvd[TFS_RESERVED]; #endif }; 
image from book
 
image from book
Figure 7.2: Files (Data and Header) Within Flash Space.

TFS must be initialized when the system is first built. The flash space allocated to TFS must therefore be erased. From that point on, as a file is created it is appended to the end of the linked list of files. If a file is deleted from the list, the file is simply marked as deleted. At some point, after several files have been deleted, it becomes necessary to clean up the TFS flash space by running a defragmentation process. This defragmentation process requires a spare sector plus some space that grows downward from the top of the last TFS sector and whose size is dependent on the number of active files.

Note that the spare sector cannot reside within the space used by TFS. The spare sector must be at the end of the space because TFS assumes that all files are contiguous within the flash space. Contiguous data is a very nice feature for extremely time-critical applications. You can store a data file in flash and access the file by name to retrieve the starting point of the data. From that point on, you can use simple (and more efficient) memory accesses to read data from the memory space.



Embedded Systems Firmware Demystified
Embedded Systems Firmware Demystified (With CD-ROM)
ISBN: 1578200997
EAN: 2147483647
Year: 2002
Pages: 118
Authors: Ed Sutter

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net