True FFS Kernel Programming
1. Format Flash
Even if Flash is not bound to a block device driver, it can be formatted.
Tffsdevformat (int tffsdriveno, int formatarg);
typedef struct
{
tffsformatparams Formatparams;
unsigned formatflags;
} tffsdevformatparams;
2. Create the boot image area2.1 Creating the boot image area
Create the boot image area by formatting Flash so that the tffs segment starts at an offset position.
Tffsformatparams
typedef struct {
long int bootimagelen; Keep to boot image space size
unsigned percentuse;
unsigned noofspareunits;
unsigned long vmaddressinglimit;
Int (*progresscallback) (int totalunitstoformat, int totalunitsformattedsofar);
char * VOLUMELABEL;
unsigned nooffatcopies;
unsigned embeddedcislength;
char * EMBEDDEDCIS;
} tffsformatparams;
STATUS Systffsformat (void)
{
Status status;
Tffsdevformatparams params =
{
#define HALF_FORMAT/* Lower 0.5MB for bootimage, Upper 1.5MB for tffs */
#ifdef Half_format
{0x80000l, 1, 0x10000l, NULL, {0,0,0,0}, NULL, 2, 0, null},
#else
{0x000000l, 1, 0x10000l, NULL, {0,0,0,0}, NULL, 2, 0, null},
#endif/* Half_format */
ftl_format_if_needed
};
/* We assume the drive number 0 is RFA */
Status = Tffsdevformat (0, (int) ¶ms);
return (status);
}
2.2 Write boot image to flash
Implemented with the function tffsbootimageput (), the function relies on tffsrawio (), so it cannot be used after the tffs volume is loaded.
Tffsbootimageput () can directly manipulate any area of the flash.
function definition:
STATUS Tffsbootimageput
(
int Driveno,/* tffs Drive number */
int offset,/* offset in the flash Chip/card */
char * filename/* binary format of the bootimage */
)
3 Mounting the driver
The function usrtffsconfig () loads the Dosfile file system onto the Tffs flash driver.
STATUS Usrtffsconfig
(
int drive,/* Drive number of tffs */
int removable,/* 0 for nonremovable Flash media */
char * fileName/* mount point */
)
STATUS usrtffsconfig (int drive, int removable, char * fileName)
{
int dosfscachesizedefault = 128 * 1024;
CBIO_DEV_ID Pcbio;
Blk_dev * PBLKDEV;
Char devname [Boot_file_len];
if (UINT) drive >= noofdrives) {
Printerr ("Drive was out of range (0-%d)./n", noOfDrives-1);
return (ERROR);
}
/* Create a block device spanning entire disk (non-distructive!) */
if (Pblkdev = tffsdevcreate (drive, removable)= = = NULL) {
Printerr ("Tffsdevcreate failed./n");
return (ERROR);
}
/* split off boot device from boot file */
Devsplit (FileName, devname);
/* Initialize the block device as a DOSFS device named */
/* Create e.g. Kbytes disk cache */
if (Pcbio = dcachedevcreate ((cbio_dev_id) Pblkdev, NULL,
Dosfscachesizedefault, Devname)) = = NULL)
return (ERROR);
if (dosfsdevcreate (devname, Pcbio, 0, NONE) ! = OK)
return (ERROR);
return (OK);
}
4 tffs Shell command
Formats Flash, but retains the boot image area.
Systffsformat
Load RFA medium as drive 0
Usrtffsconfig 0,0, "/rfa/"
Transferred from: http://m.blog.csdn.net/blog/da895/6033647
Tffs formatting to the success process of creation