⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 flashfslib.c

📁 flash驱动程序,Nor flash类型
💻 C
📖 第 1 页 / 共 3 页
字号:
                return 0;            /* is it the file we want ? */            if (strncmp(entry.name, name, sizeof entry.name) == 0)                file_addr = entry_addr;        } /* good link, read next file */        else            /* broken link in FLASH fixed file area */            return 0;    } /* walk down fixed file list */    /* did we find the file ? */    if (file_addr)    {        /* yes - set length and also get address of data portion of file.   */        *len       = entry.len;        file_addr += sizeof entry;    }    return file_addr;  /* start of data are of file, or zero if not found.  */} /* flashfs_find_file */#ifndef    BOOT_ROM/*** Provided externally in BOOT ROMs so that FLASHFS structures** in memory can be read.*//*** Name:	flashfs_read_data**** Purpose:	Read data from specified FLASH filing system address**** This function is used to read the data portion of a file found by the ** 'flashfs_find_file' function.  The length and destination pointer must** be specified as well as the read address (logical filing system address)**** Arguments:**	src		Data address**	pdest	Destination pointer**	len		Length of data to read (in bytes)**** Result:**	<None>***/void flashfs_read_data(U32 src, BYTE *dest, U32 len){    flash_read_fs_data(src, dest, len);}#endif/*** Name:	flashfs_write_data**** Purpose:	Write data to specified FLASH filing system address**** This function is used to write data directly to a loginal flash address**** Arguments:**	src		Data pointer**	dest	Destination address**	len		Length of data to write (in bytes)**** Result:**	0       Success***/int flashfs_write_data(BYTE *src, U32 dest, U32 len){#if !defined (BOOT_ROM) || !defined (NO_CONFIGINFO_FLASH)    return flash_write_fs_data(src, dest, len);#else    return  EIO;#endif}/*** Name:	flashfs_read_dir**** Purpose:	Read directory entry from flash**** This function allows iteration through the flashfs files.**** Arguments:**	token	Magic token, use 0 to start, or**          TOKEN_DYNAMIC_ONLY to only read dynamic files**	entry	Where to store DIRENT read, if any**** Result:**	0		No more files or error**	<>0		File entry read (next value of token)***/U32 flashfs_readdir (U32 token, FLASHFS_DIRENT *entry){    /*    ** Must be initialised before this is called    */    if ((NULL == entry) || (!initialised))    {        token = 0;    }    else    {        U32 fixedList = 0;        /*        ** Initialise: look for first file on list        */        if (0 == (token & ~TOKEN_DYNAMIC_ONLY))        {            flashfs_read_data(0, (BYTE *)&flashfs_root, sizeof flashfs_root); 			if (0 == token)			{				token = flashfs_root.first.fixed;				fixedList = TOKEN_FIXED_LIST;			}            if (0 == (token & ~TOKEN_DYNAMIC_ONLY))            {                /* No fixed files: try dynamic */                token = flashfs_root.first.dynamic;                fixedList = 0;            }        }        else        {            fixedList = token & TOKEN_FIXED_LIST;            token &= ~TOKEN_FIXED_LIST;        }        if (token)        {            U32 flashAddress = token;            flashfs_read_data (flashAddress, (BYTE *) entry, sizeof (FLASHFS_DIRENT));            if (0 == entry->next)            {                /* End of this list, see if another is available */                if (fixedList)                {                    flashfs_read_data(0, (BYTE *)&flashfs_root, sizeof flashfs_root);                     token = flashfs_root.first.dynamic;                }                else                {                    token = 0;                }            }            else            {                token = entry->next | fixedList;            }            /* Adjust "next" to point to start of file data */            entry->next = flashAddress + sizeof (FLASHFS_DIRENT);        }        else        {            entry->next = 0;        }    }    return    token;}void flash_read_fs_data (U32 s, BYTE *d, U32 n){    flash_read_data (s + flashStartOffset, d, n);    return;}#if !defined (BOOT_ROM) || !defined (NO_CONFIGINFO_FLASH)int flash_write_fs_data (BYTE *src, U32 dst, U32 num){    /* d is passed as an offset from the start of the file system, rather   */    /* than an flash address starting from the begining of flash (bootrom)  */    return flash_write_data (src, dst + flashStartOffset, num);}#endif#ifndef BOOT_ROM/*** Name:	flashfslib_PartitionErase**** Purpose:	Initialises all FLASH filing system area to 0xFF**** This function is invoked as the result of a console 'wipe' command** and is not used in normal operation.**** Arguments:**	partition**** Result:**	ESUCCESS    Wiped**  EINVAL      Invalid partition***/int  flashfslib_PartitionErase (U32 partition){    int     rc;    if (partition < NUM_PARTITIONS)    {        rc = check_flash_chips_writable ();        if (ESUCCESS == rc)        {            flash_erase (partitions [partition].actualStartOffset, partitions [partition].endOffset - partitions [partition].actualStartOffset);            partitions [partition].isValid = FALSE;        }    }    else    {        rc = EINVAL;    }    return  rc;}/*** Name:	flashfslib_PartitionCheckOffset**** Purpose:	Sets the file system area with regard to the FLASH chips**** The base of the file system area may change between updates (providing it** does not become so low as to overwrite the Boot ROM code).  The offset** must be checked to ensure that the Boot ROM code is not in the same sector** as the start of the file system.**** Arguments:**	partition**** Result:**	ESUCCESS    Offset checked**  EIO         Partition (now) invalid**  EINVAL      Invalid partition***/int  flashfslib_PartitionCheckOffset (U32 partition){    int     rc;    if (partition < NUM_PARTITIONS)    {        U32  newStartOffset, sectorEnd;        /*        ** Offset based on (compiled) request        */        rc = flash_sector_bounds (partitions [partition].startOffset, &newStartOffset, &sectorEnd);        if (ESUCCESS == rc)        {            /* Flash chips identified */            if (newStartOffset != partitions [partition].actualStartOffset)            {                /* new start position is the different from the last one */                TRACE1("Offset moved from 0x%x to 0x%x\n", partitions [partition].actualStartOffset, newStartOffset);                 /* set new global offset and size */                partitions [partition].actualStartOffset = newStartOffset;                 partitions [partition].isValid = FALSE;                 rc = EIO;            }             /* REVIEW: check for other partitions being destroyed */        }    }    else    {        rc = EINVAL;    }    return  rc;}/*** Name:    flash_program_root**** Program the FLASHFS root block, using the supplied values of ** first.fixed and first.dynamic.**** Result:**  0       Success**  <>0     Error*/int flashfs_program_root(U32 firstFixed, U32 firstDynamic){  FLASHFS_ROOT root;  int rc;  strcpy(root.volser, "ISFSV1");  root.first.fixed = firstFixed;  root.first.dynamic = firstDynamic;  root.limit = 0;  rc = flash_write_fs_data((char *)&root, 0, sizeof(FLASHFS_ROOT));  if (rc == ESUCCESS) program_sector();  return rc;}/*** Name:    flash_program_header**** Program the FLASHFS header, using the current value of** flashStartOffset. The checksum over the whole of the current** filing system is calculated automatically.**** Result:**  0       Success**  <>0     Error*/int flashfs_program_header(void){    FLASH_HEADER    header;    int             rc;    /*    ** Set header stucture up, use offset (possibly new)    */    header.flash_start_offset = flashStartOffset;    header.spare[0] =  0;    header.spare[1] =  0;    header.checksum = ~0; /* Saves a programing step for some chips */    rc = flash_write_fs_data ((BYTE *) &header, flashfsSize - sizeof (header), sizeof (header));    if (ESUCCESS == rc)    {        /* Flush last page into FLASH, guarantees stuff there for checksum  */        rc = program_sector ();        if (ESUCCESS == rc)        {            /* calculate checksum over flash memory */            header.checksum = flash_checksum (flashStartOffset, flashfsSize - sizeof (header.checksum));            rc = flash_write_fs_data ((BYTE *) &header, flashfsSize - sizeof (header), sizeof (header));            if (ESUCCESS == rc)            {                /* Flush last page into FLASH */                rc = program_sector ();            }        }    }    return  rc;}/***----------------------------------------------------------------------**** flashfslib_PartitionCheckErrorText**** Determine the number of partitions in the system**** Arguments:**  <None>**** Returns:**  U32         Number of partitions****----------------------------------------------------------------------*/const char *flashfslib_PartitionCheckErrorText (U32 err){    const char *    error;    static const char *errText [] =    {        "flash memory empty, no header detected\n",        "flash filing system start offset value out of bounds\n",        "bad checksum in flash chips, file system not valid\n",        "no 'volser' found in flash memory\n",        "overlength fixed file - bad flash\n",        "broken link in flash fixed file area\n",        "overlength dynamic file - bad flash\n",        "broken link in flash dynamic file area\n"    };    if (err < (sizeof (errText) / sizeof (const char *)))    {        error = errText [err];    }    else    {        error = "Unknown error";    }        return  error;}#endif/***----------------------------------------------------------------------**** flashfslib_PartitionCount**** Determine the number of partitions in the system**** Arguments:

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -