📄 flashfslib.c
字号:
** <None>**** Returns:** U32 Number of partitions****----------------------------------------------------------------------*/U32 flashfslib_PartitionCount (void){ return NUM_PARTITIONS;}/***----------------------------------------------------------------------**** flashfslib_PartitionCheck**** Determine the number of partitions in the system**** Arguments:** partition Partition number** fullCheck TRUE: check name details, FALSE: basic partition check** errorCode Further detail on errored partition**** Returns:** ESUCCESS Good filing system detected.** EIO Bad filing system (error details in errorCode)** EINVAL Invalid argument****----------------------------------------------------------------------*/int flashfslib_PartitionCheck (U32 partition, BOOL fullCheck, U32 *errorCode){ int rc = EIO; flashfslib_initialise (); if (partition < NUM_PARTITIONS) { FLASH_HEADER flashfsHeader; Partition * partitionPtr = & partitions [partition]; /* Read header from top of flash memory. */ flash_read_data (partitionPtr->endOffset - sizeof flashfsHeader, (BYTE *)&flashfsHeader, sizeof flashfsHeader); if ((flashfsHeader.spare [0] != 0) || (flashfsHeader.spare [1] != 0)) { /* Two fields in the header are reserved and 0. Test for this. */ *errorCode = 0; } else if (flashfsHeader.flash_start_offset > TOTAL_FLASH_SIZE) { /* sanity check start offset value read from flash, ignore large values. */ *errorCode = 1; } else { U32 sum; /* recalculate offset and size from value read from flash */ partitionPtr->actualStartOffset = flashfsHeader.flash_start_offset; /* calculate checksum of the memory (less the last word) */ sum = flash_checksum (partitionPtr->actualStartOffset, partitionPtr->endOffset - partitionPtr->actualStartOffset - sizeof (flashfsHeader.checksum)); /* check calculated sum against that recovered from the header */ if (sum != flashfsHeader.checksum) { *errorCode = 2; } else { FLASHFS_ROOT flashfsRoot; /* read the flash volroot structure from start of file area */ flash_read_data (partitionPtr->actualStartOffset, (BYTE *)&flashfsRoot, sizeof flashfsRoot); /* check for file system id */ if (strncmp (flashfsRoot.volser, "ISFSV1", sizeof flashfsRoot.volser) != 0) { *errorCode = 3; } else if (!fullCheck) { /* ** Stop if names are not to be checked */ rc = ESUCCESS; } else { U32 maxFileAddr; U32 next; FLASHFS_DIRENT entry; int i; /* ** maximum address to be reached by a file */ maxFileAddr = partitionPtr->endOffset - sizeof (FLASH_HEADER); rc = ESUCCESS; i = 0; /* ** Walk fixed, then dynamic, file lists */ next = flashfsRoot.first.fixed; do { /* ** Leaf down list checking all the links are within range. */ while (next && (ESUCCESS == rc)) { /* ** Check next address is 'sensible' and will fit. */ if ((next + sizeof (entry)) < maxFileAddr) { /* ** Read the file entry */ flash_read_data (partitionPtr->actualStartOffset + next, (BYTE *)&entry, sizeof entry); /* ** If length field not sensible, error. */ if ((next + sizeof (entry) + entry.len) > maxFileAddr) { /* ** Distinguish between fixed and dynamic files */ *errorCode = 4 + i; rc = EIO; } } else { *errorCode = 5 + i; rc = EIO; } next = entry.next; } i += 2; next = flashfsRoot.first.dynamic; } while ((ESUCCESS == rc) && (i <= 2)); } } } /* ** Update partition validity: if it failed then it won't be valid. */ partitions [partition].isValid = (ESUCCESS == rc); partitions [partition].checked = TRUE; } else { rc = EINVAL; } return rc;}/***----------------------------------------------------------------------**** flashfslib_PartitionDetails**** Get definitions of partition**** Arguments:** partition Partition number** start Start address of partition (absolute flash address)** end End address of partition + 1 (absolute flash address)**** Returns:** ESUCCESS Partition details valid** EINVAL Invalid argument****----------------------------------------------------------------------*/int flashfslib_PartitionDetails (U32 partition, U32 *start, U32 *end){ int rc; flashfslib_initialise (); if (partition < NUM_PARTITIONS) { *end = partitions [partition].endOffset; if (partitions [partition].isValid) { *start = partitions [partition].actualStartOffset; } else { *start = partitions [partition].startOffset; } rc = ESUCCESS; } else { rc = EINVAL; } return rc;}/***----------------------------------------------------------------------**** flashfslib_PartitionFormat**** Format a partition ready for use.**** Arguments:** partition**** Returns:** ESUCCESS Partition created** EINVAL Illegal argument** EIO Error writing flash****----------------------------------------------------------------------*/int flashfslib_PartitionFormat (U32 partition){ int rc;#ifdef BOOT_ROM rc = EIO; UNUSED (partition);#else flashfslib_initialise (); if (partition < NUM_PARTITIONS) { /* ** Save current partition details while formatting the partition */ U32 savedSize = flashfsSize; U32 savedOffset = flashStartOffset; /* ** Ensure that the partition lines up with sector boundaries (enforces ** robustness). */ flashfslib_PartitionCheckOffset (partition); flashfsSize = partitions [partition].endOffset - partitions [partition].actualStartOffset; flashStartOffset = partitions [partition].actualStartOffset; /* ** Program empty root structure and rewrite the header */ rc = flashfs_program_root (0, 0); if (ESUCCESS == rc) { rc = flashfs_program_header (); } /* ** Restore original partition details */ flashfsSize = savedSize; flashStartOffset = savedOffset; /* ** Update partition validity: if formatting failed then it won't be valid. */ partitions [partition].isValid = (ESUCCESS == rc); partitions [partition].checked = TRUE; } else { rc = EINVAL; }#endif return rc;}/***----------------------------------------------------------------------**** flashfslib_PartitionActivate**** Make a partition active: this says nothing about the validity of** the partition.**** Arguments:** partition**** Returns:** ESUCCESS Partition created** EINVAL Illegal argument** EIO Error writing flash****----------------------------------------------------------------------*/int flashfslib_PartitionActivate (U32 partition){ int rc; if (partition < NUM_PARTITIONS) { rc = flashfslib_PartitionDetails (partition, &flashStartOffset, &flashfsSize); assert (ESUCCESS == rc); flashfsSize -= flashStartOffset; } else { rc = EINVAL; } return rc;}/***----------------------------------------------------------------------**** flashfslib_PartitionValid**** Determine whether or not a partition is valid.**** Arguments:** partition**** Returns:** ESUCCESS Partition created** EINVAL Illegal argument** EIO Error writing flash****----------------------------------------------------------------------*/int flashfslib_PartitionValid (U32 partition){ int rc; if (partition < NUM_PARTITIONS) { /* ** Force checking of partition if un-checked. */ if (!partitions [partition].checked) { U32 err; rc = flashfslib_PartitionCheck (partition, TRUE, &err); } if (partitions [partition].isValid) { rc = ESUCCESS; } else { rc = EIO; } } else { rc = EINVAL; } return rc;}/***----------------------------------------------------------------------**** flashfslib_PartitionInvalidate**** Invalidate a partition**** Arguments:** partition**** Returns:** ESUCCESS Partition created** EINVAL Illegal argument****----------------------------------------------------------------------*/int flashfslib_PartitionInvalidate (U32 partition){ int rc; if (partition < NUM_PARTITIONS) { /* ** Say that the partition has been checked but that it is ** invalid. */ partitions [partition].isValid = FALSE; partitions [partition].checked = TRUE; rc = ESUCCESS; } else { rc = EINVAL; } return rc;}/* flashfslib.c */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -