Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix typos in documentation #254

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ Otherwise, configure the `builddir` variable towards the top of `makefile` as so
## FEATURES

What spiffs does:
- Specifically designed for low ram usage
- Uses statically sized ram buffers, independent of number of files
- Posix-like api: open, close, read, write, seek, stat, etc
- Specifically designed for low RAM usage
- Uses statically sized RAM buffers, independent of number of files
- Posix-like API: open, close, read, write, seek, stat, etc
- It can run on any NOR flash, not only SPI flash - theoretically also on embedded flash of a microprocessor
- Multiple spiffs configurations can run on same target - and even on same SPI flash device
- Implements static wear leveling
Expand All @@ -45,7 +45,7 @@ What spiffs does:
What spiffs does not:
- Presently, spiffs does not support directories. It produces a flat structure. Creating a file with path *tmp/myfile.txt* will create a file called *tmp/myfile.txt* instead of a *myfile.txt* under directory *tmp*.
- It is not a realtime stack. One write operation might last much longer than another.
- Poor scalability. Spiffs is intended for small memory devices - the normal sizes for SPI flashes. Going beyond ~128Mbyte is probably a bad idea. This is a side effect of the design goal to use as little ram as possible.
- Poor scalability. Spiffs is intended for small memory devices - the normal sizes for SPI flashes. Going beyond ~128Mbyte is probably a bad idea. This is a side effect of the design goal to use as little RAM as possible.
- Presently, it does not detect or handle bad blocks.
- One configuration, one binary. There's no generic spiffs binary that handles all types of configurations.

Expand All @@ -59,7 +59,7 @@ See the [wiki](https://github.com/pellepl/spiffs/wiki) for [configuring](https:/

For design, see [docs/TECH_SPEC](https://github.com/pellepl/spiffs/blob/master/docs/TECH_SPEC).

For a generic spi flash driver, see [this](https://github.com/pellepl/spiflash_driver).
For a generic SPI flash driver, see [this](https://github.com/pellepl/spiflash_driver).

## HISTORY

Expand Down Expand Up @@ -132,7 +132,7 @@ New config defines:

New API functions:
- `SPIFFS_set_file_callback_func` - register a callback informing about file events
- `SPIFFS_probe_fs` - probe a spi flash trying to figure out size of fs
- `SPIFFS_probe_fs` - probe a SPI flash trying to figure out size of fs
- `SPIFFS_open_by_page` - open a file by page index
- `SPIFFS_eof` - checks if end of file is reached
- `SPIFFS_tell` - returns current file offset
Expand Down
24 changes: 12 additions & 12 deletions docs/TECH_SPEC
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ TODO
* SPIFFS DESIGN

Spiffs is inspired by YAFFS. However, YAFFS is designed for NAND flashes, and
for bigger targets with much more ram. Nevertheless, many wise thoughts have
for bigger targets with much more RAM. Nevertheless, many wise thoughts have
been borrowed from YAFFS when writing spiffs. Kudos!

The main complication writing spiffs was that it cannot be assumed the target
has a heap. Spiffs must go along only with the work ram buffer given to it.
has a heap. Spiffs must go along only with the work RAM buffer given to it.
This forces extra implementation on many areas of spiffs.


Expand All @@ -23,7 +23,7 @@ SPI flash devices are physically divided in blocks. On some SPI flash devices,
blocks are further divided into sectors. Datasheets sometimes name blocks as
sectors and vice versa.

Common memory capacaties for SPI flashes are 512kB up to 8MB of data, where
Common memory capacities for SPI flashes are 512kB up to 8MB of data, where
blocks may be 64kB. Sectors can be e.g. 4kB, if supported. Many SPI flashes
have uniform block sizes, whereas others have non-uniform - the latter meaning
that e.g. the first 16 blocks are 4kB big, and the rest are 64kB.
Expand Down Expand Up @@ -99,7 +99,7 @@ small page size will make metadata occupy a lot of the memory on the flash. A
page size of 64 bytes will waste 8-14% on metadata, while 256 bytes 2-4%.
So it seems it is good to select a big page size.

Also, spiffs uses a ram buffer being two times the page size. This ram buffer
Also, spiffs uses a RAM buffer being two times the page size. This RAM buffer
is used for loading and manipulating pages, but it is also used for algorithms
to find free file ids, scanning the file system, etc. Having too small a page
size means less work buffer for spiffs, ending up in more reads operations and
Expand All @@ -108,12 +108,12 @@ eventually gives a slower file system.
Choosing the page size for the system involves many factors:
- How big is the logical block size
- What is the normal size of most files
- How much ram can be spent
- How much RAM can be spent
- How much data (vs metadata) must be crammed into the file system
- How fast must spiffs be
- Other things impossible to find out

So, chosing the Optimal Page Size (tm) seems tricky, to say the least. Don't
So, choosing the Optimal Page Size (tm) seems tricky, to say the least. Don't
fret - there is no optimal page size. This varies from how the target will use
spiffs. Use the golden rule:

Expand Down Expand Up @@ -179,23 +179,23 @@ object index array correlates with the data page span index.
PAGE 4, DATA, SPAN_IX 2 --------/

Things to be unveiled in page 0 - well.. Spiffs is designed for systems low on
ram. We cannot keep a dynamic list on the whereabouts of each object index
RAM. We cannot keep a dynamic list on the whereabouts of each object index
header so we can find a file fast. There might not even be a heap! But, we do
not want to scan all page headers on the flash to find the object index header.

The first page(s) of each block contains the so called object look-up. These
are not normal pages, they do not have a header. Instead, they are arrays
pointing out what object-id the rest of all pages in the block belongs to.

By this look-up, only the first page(s) in each block must to scanned to find
By this look-up, only the first page(s) in each block must be scanned to find
the actual page which contains the object index header of the desired object.

The object lookup is redundant metadata. The assumption is that it presents
less overhead reading a full page of data to memory from each block and search
that, instead of reading a small amount of data from each page (i.e. the page
header) in all blocks. Each read operation from SPI flash normally contains
extra data as the read command itself and the flash address. Also, depending on
the underlying implementation, other criterions may need to be passed for each
the underlying implementation, other criteria may need to be passed for each
read transaction, like mutexes and such.

The veiled example unveiled would look like this, with some extra pages:
Expand All @@ -217,7 +217,7 @@ PAGE 12 page header: [obj_id:23 span_ix:2 flags:DELETED|DATA] ...

Ok, so why are page 9 to 12 marked as 0 when they belong to object id 23? These
pages are deleted, so this is marked both in page header flags and in the look
up. This is an example where spiffs uses NOR flashes "nand-way" of writing.
up. This is an example where spiffs uses NOR flash's "nand-way" of writing.

As a matter of fact, there are two object id's which are special:

Expand All @@ -231,9 +231,9 @@ would look like this:

PAGE 0 [ 12 12 545 12 *12 34 34 *4 0 0 0 0 ...]

where the asterisk means the msb of the object id is set.
where the asterisk means the MSB of the object id is set.

This is another way to speed up the searches when looking for object indices.
By looking on the object id's msb in the object lookup, it is also possible
By looking on the object id's MSB in the object lookup, it is also possible
to find out whether the page is an object index page or a data page.

2 changes: 1 addition & 1 deletion docs/TODO
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ SPIFFS2 thoughts

* Instead of exact object id:s in the object lookup tables, use a hash of span index and object id.
Eg. object id xor:ed with bit-reversed span index.
This should decrease number of actual pages that needs to be visited when looking thru the obj lut.
This should decrease number of actual pages that needs to be visited when looking through the obj lut.

* Logical number of each block. When moving stuff in a garbage collected page, the free
page is assigned the same number as the garbage collected. Thus, object index pages do not have to
Expand Down
4 changes: 2 additions & 2 deletions py/python_ops.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ void *my_spiffs_mount(int phys_size,
spiffs *pfs = &d->fs;

spiffs_config cfg;
cfg.phys_size = phys_size; // use all spi flash
cfg.phys_addr = phys_addr; // start spiffs at start of spi flash
cfg.phys_size = phys_size; // use all SPI flash
cfg.phys_addr = phys_addr; // start spiffs at start of SPI flash
cfg.phys_erase_block = phys_erase_block; // according to datasheet
cfg.log_block_size = log_block_size; // let us not complicate things
cfg.log_page_size = log_page_size; // as we said
Expand Down
18 changes: 9 additions & 9 deletions src/default/spiffs_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#define SPIFFS_CONFIG_H_

// ----------- 8< ------------
// Following includes are for the linux test build of spiffs
// Following includes are for the Linux test build of spiffs
// These may/should/must be removed/altered/replaced in your target
#include "params_test.h"
#include <stdio.h>
Expand Down Expand Up @@ -40,7 +40,7 @@
#ifndef SPIFFS_CHECK_DBG
#define SPIFFS_CHECK_DBG(_f, ...) //printf(_f, ## __VA_ARGS__)
#endif
// Set spiffs debug output call for all api invocations.
// Set spiffs debug output call for all API invocations.
#ifndef SPIFFS_API_DBG
#define SPIFFS_API_DBG(_f, ...) //printf(_f, ## __VA_ARGS__)
#endif
Expand Down Expand Up @@ -127,7 +127,7 @@
// used pages normally gives a negative score (as these must be moved).
// To have a fair wear-leveling, the erase age is also included in score,
// whose factor normally is the most positive.
// The larger the score, the more likely it is that the block will
// The larger the score, the more likely it is that the block will be
// picked for garbage collection.

// Garbage collecting heuristics - weight used for deleted pages.
Expand All @@ -144,7 +144,7 @@
#define SPIFFS_GC_HEUR_W_ERASE_AGE (50)
#endif

// Object name maximum length. Note that this length include the
// Object name maximum length. Note that this length includes the
// zero-termination character, meaning maximum string of characters
// can at most be SPIFFS_OBJ_NAME_LEN - 1.
#ifndef SPIFFS_OBJ_NAME_LEN
Expand Down Expand Up @@ -191,7 +191,7 @@
#endif
#endif

// SPIFFS_LOCK and SPIFFS_UNLOCK protects spiffs from reentrancy on api level
// SPIFFS_LOCK and SPIFFS_UNLOCK protects spiffs from reentrancy on API level
// These should be defined on a multithreaded system

// define this to enter a mutex if you're running on a multithreaded system
Expand Down Expand Up @@ -253,8 +253,8 @@
// Enable this to compile a read only version of spiffs.
// This will reduce binary size of spiffs. All code comprising modification
// of the file system will not be compiled. Some config will be ignored.
// HAL functions for erasing and writing to spi-flash may be null. Cache
// can be disabled for even further binary size reduction (and ram savings).
// HAL functions for erasing and writing to SPI-flash may be null. Cache
// can be disabled for even further binary size reduction (and RAM savings).
// Functions modifying the fs will return SPIFFS_ERR_RO_NOT_IMPL.
// If the file system cannot be mounted due to aborted erase operation and
// SPIFFS_USE_MAGIC is enabled, SPIFFS_ERR_RO_ABORTED_OPERATION will be
Expand All @@ -267,7 +267,7 @@
// Enable this to add a temporal file cache using the fd buffer.
// The effects of the cache is that SPIFFS_open will find the file faster in
// certain cases. It will make it a lot easier for spiffs to find files
// opened frequently, reducing number of readings from the spi flash for
// opened frequently, reducing number of readings from the SPI flash for
// finding those files.
// This will grow each fd by 6 bytes. If your files are opened in patterns
// with a degree of temporal locality, the system is optimized.
Expand Down Expand Up @@ -323,7 +323,7 @@
#endif

// Set SPIFFS_TEST_VISUALISATION to non-zero to enable SPIFFS_vis function
// in the api. This function will visualize all filesystem using given printf
// in the API. This function will visualize all filesystem using given printf
// function.
#ifndef SPIFFS_TEST_VISUALISATION
#define SPIFFS_TEST_VISUALISATION 1
Expand Down
34 changes: 17 additions & 17 deletions src/spiffs.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,20 +81,20 @@ struct spiffs_t;

#if SPIFFS_HAL_CALLBACK_EXTRA

/* spi read call function type */
/* SPI read call function type */
typedef s32_t (*spiffs_read)(struct spiffs_t *fs, u32_t addr, u32_t size, u8_t *dst);
/* spi write call function type */
/* SPI write call function type */
typedef s32_t (*spiffs_write)(struct spiffs_t *fs, u32_t addr, u32_t size, u8_t *src);
/* spi erase call function type */
/* SPI erase call function type */
typedef s32_t (*spiffs_erase)(struct spiffs_t *fs, u32_t addr, u32_t size);

#else // SPIFFS_HAL_CALLBACK_EXTRA

/* spi read call function type */
/* SPI read call function type */
typedef s32_t (*spiffs_read)(u32_t addr, u32_t size, u8_t *dst);
/* spi write call function type */
/* SPI write call function type */
typedef s32_t (*spiffs_write)(u32_t addr, u32_t size, u8_t *src);
/* spi erase call function type */
/* SPI erase call function type */
typedef s32_t (*spiffs_erase)(u32_t addr, u32_t size);
#endif // SPIFFS_HAL_CALLBACK_EXTRA

Expand Down Expand Up @@ -196,7 +196,7 @@ typedef void (*spiffs_file_callback)(struct spiffs_t *fs, spiffs_fileop_type op,

// phys structs

// spiffs spi configuration struct
// spiffs SPI configuration struct
typedef struct {
// physical read function
spiffs_read hal_read_f;
Expand All @@ -205,9 +205,9 @@ typedef struct {
// physical erase function
spiffs_erase hal_erase_f;
#if SPIFFS_SINGLETON == 0
// physical size of the spi flash
// physical size of the SPI flash
u32_t phys_size;
// physical offset in spi flash used for spiffs,
// physical offset in SPI flash used for spiffs,
// must be on block boundary
u32_t phys_addr;
// physical size when erasing a block
Expand Down Expand Up @@ -437,7 +437,7 @@ spiffs_file SPIFFS_open_by_dirent(spiffs *fs, struct spiffs_dirent *e, spiffs_fl
/**
* Opens a file by given page index.
* Optimization purposes, opens a file by directly pointing to the page
* index in the spi flash.
* index in the SPI flash.
* If the page index does not point to a file header SPIFFS_ERR_NOT_A_FILE
* is returned.
* @param fs the file system struct
Expand Down Expand Up @@ -478,7 +478,7 @@ s32_t SPIFFS_write(spiffs *fs, spiffs_file fh, void *buf, s32_t len);
* @param offs how much/where to move the offset
* @param whence if SPIFFS_SEEK_SET, the file offset shall be set to offset bytes
* if SPIFFS_SEEK_CUR, the file offset shall be set to its current location plus offset
* if SPIFFS_SEEK_END, the file offset shall be set to the size of the file plus offse, which should be negative
* if SPIFFS_SEEK_END, the file offset shall be set to the size of the file plus offset, which should be negative
*/
s32_t SPIFFS_lseek(spiffs *fs, spiffs_file fh, s32_t offs, int whence);

Expand Down Expand Up @@ -597,7 +597,7 @@ s32_t SPIFFS_check(spiffs *fs);

/**
* Returns number of total bytes available and number of used bytes.
* This is an estimation, and depends on if there a many files with little
* This is an estimation, and depends on if there are many files with little
* data or few files with much data.
* NB: If used number of bytes exceeds total bytes, a SPIFFS_check should
* run. This indicates a power loss in midst of things. In worst case
Expand Down Expand Up @@ -632,7 +632,7 @@ u8_t SPIFFS_mounted(spiffs *fs);

/**
* Tries to find a block where most or all pages are deleted, and erase that
* block if found. Does not care for wear levelling. Will not move pages
* block if found. Does not care for wear leveling. Will not move pages
* around.
* If parameter max_free_pages are set to 0, only blocks with only deleted
* pages will be selected.
Expand Down Expand Up @@ -694,8 +694,8 @@ s32_t SPIFFS_tell(spiffs *fs, spiffs_file fh);
* mechanisms. Any operations on the actual file system being callbacked from
* in this callback will mess things up for sure - do not do this.
* This can be used to track where files are and move around during garbage
* collection, which in turn can be used to build location tables in ram.
* Used in conjuction with SPIFFS_open_by_page this may improve performance
* collection, which in turn can be used to build location tables in RAM.
* Used in conjunction with SPIFFS_open_by_page this may improve performance
* when opening a lot of files.
* Must be invoked after mount.
*
Expand All @@ -710,7 +710,7 @@ s32_t SPIFFS_set_file_callback_func(spiffs *fs, spiffs_file_callback cb_func);
* Maps the first level index lookup to a given memory map.
* This will make reading big files faster, as the memory map will be used for
* looking up data pages instead of searching for the indices on the physical
* medium. When mapping, all affected indicies are found and the information is
* medium. When mapping, all affected indices are found and the information is
* copied to the array.
* Whole file or only parts of it may be mapped. The index map will cover file
* contents from argument offset until and including arguments (offset+len).
Expand Down Expand Up @@ -751,7 +751,7 @@ s32_t SPIFFS_ix_unmap(spiffs *fs, spiffs_file fh);

/**
* Moves the offset for the index map given in function SPIFFS_ix_map. Parts or
* all of the map buffer will repopulated.
* all of the map buffer will be repopulated.
* @param fs the file system struct
* @param fh the mapped file handle of the file to remap
* @param offset new absolute file offset where to start the index map
Expand Down
10 changes: 5 additions & 5 deletions src/spiffs_cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ static s32_t spiffs_cache_page_remove_oldest(spiffs *fs, u8_t flag_mask, u8_t fl
return SPIFFS_OK;
}

// all busy, scan thru all to find the cpage which has oldest access
// all busy, scan through all to find the cpage which has oldest access
int i;
int cand_ix = -1;
u32_t oldest_val = 0;
Expand Down Expand Up @@ -119,7 +119,7 @@ void spiffs_cache_drop_page(spiffs *fs, spiffs_page_ix pix) {

// ------------------------------

// reads from spi flash or the cache
// reads from SPI flash or the cache
s32_t spiffs_phys_rd(
spiffs *fs,
u8_t op,
Expand Down Expand Up @@ -180,7 +180,7 @@ s32_t spiffs_phys_rd(
return res;
}

// writes to spi flash and/or the cache
// writes to SPI flash and/or the cache
s32_t spiffs_phys_wr(
spiffs *fs,
u8_t op,
Expand Down Expand Up @@ -211,13 +211,13 @@ s32_t spiffs_phys_wr(
cp->last_access = cache->last_access;

if (cp->flags & SPIFFS_CACHE_FLAG_WRTHRU) {
// page is being updated, no write-cache, just pass thru
// page is being updated, no write-cache, just pass through
return SPIFFS_HAL_WRITE(fs, addr, len, src);
} else {
return SPIFFS_OK;
}
} else {
// no cache page, no write cache - just write thru
// no cache page, no write cache - just write through
return SPIFFS_HAL_WRITE(fs, addr, len, src);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/spiffs_check.c
Original file line number Diff line number Diff line change
Expand Up @@ -987,7 +987,7 @@ s32_t spiffs_object_index_consistency_check(spiffs *fs) {
s32_t res = SPIFFS_OK;
// impl note:
// fs->work is used for a temporary object index memory, listing found object ids and
// indicating whether they can be reached or not. Acting as a fifo if object ids cannot fit.
// indicating whether they can be reached or not. Acting as a FIFO if object ids cannot fit.
// In the temporary object index memory, SPIFFS_OBJ_ID_IX_FLAG bit is used to indicate
// a reachable/unreachable object id.
memset(fs->work, 0, SPIFFS_CFG_LOG_PAGE_SZ(fs));
Expand Down
Loading