Wear Levelling Component (WLC) is a software component, implemented to prolong the service life of a storage media. This is done by preventing frequent erase operations at specific locations of the storage media memory space, which cause wear out of that particular memory while other locations are possibly not used at all. The WLC controls access attempts to all the media sectors available.
The component requires the storage media access driver as its parameter, in order to manipulate target sectors. As the WLC implements wear-levelling for the SPI Flash device, the driver is controlled through the Flash_Access interface.
Current implementation of WLC has version 2. The data format from current version incompatible with data format from previous versions, and could not be
- wl_partition_start_addr - wear levelled partition starting address (in the flash memory)
- wl_partition_size - size of the wear-levelled partition
- flash_sector_size - flash memory sector size
- wl_page_size - one WLC page size (in bytes). wl_page_size >= (N * sector_size), where N > 0
- wl_update_rate - erase operation count after which the physical sector and the WLC dummy sector swap their addresses
- wl_pos_update_record_size - number of bytes for storing position-update record, appended to the WLC state sector data after each expiration of wl_update_rate.
The Configuration - a region used to store the WLC configuration information. User can use this information to restore the WL partition from a memory dump.
The States - a region to store internal WLC status information. The States region contains two copies of the WLC status record - this is to help safely recover last-known WLC status in case of power outage.
The Data - a region where the user data is stored.
The WLC uses two types of flash memory-access addresses: virtual (logical) address and real (physical) address. The virtual address is used by users as a common target address, while the real address is used internally by the WLC to access the actual memory block.
The Data region is divided into N pages (page could be equal to the sector size, see above). One WLC page is defined as a "dummy" page, which implies the users can use only N-1 pages to store the data.
The WLC has two internal counters to calculate virtual and real addresses: erase counter (access_count) and move counter (move_count).
Every erase operation increments the erase counter. When the counter reaches the *wl_update_rate* number, the contents of the page next after the actual "dummy" page is copied to the dummy page and the next page itself becomes a new WLC dummy page (the last partition page swaps its position with the first one). This way, the WLC dummy page will traverses across whole partition, ensuring the wear burden is distributed evenly. After a completion of one cycle, the move counter is incremented too.
On the increment of the move counter, the WLC status record is stored to the State sector in the flash memory.
The example below shows 4 available memory pages and their corresponding states after each wl_update_rate change. The 'X' is the WLC dummy page.
As can be seen, erase cycles of the sectors get distributed across the entire flash at the cost of small memory part used by the WLC, which is thus not available to the users.