Galanakis, Minos | dc6694b | 2020-01-06 13:54:56 +0000 | [diff] [blame] | 1 | ############################################################### |
Galanakis, Minos | f765790 | 2019-10-25 16:47:23 +0100 | [diff] [blame] | 2 | Add support for block-aligned flash in Internal Trusted Storage |
Galanakis, Minos | dc6694b | 2020-01-06 13:54:56 +0000 | [diff] [blame] | 3 | ############################################################### |
Galanakis, Minos | f765790 | 2019-10-25 16:47:23 +0100 | [diff] [blame] | 4 | |
| 5 | :Author: Minos Galanakis |
| 6 | :Organization: Arm Limited |
| 7 | :Contact: Minos Galanakis <minos.galanakis@arm.com> |
| 8 | :Status: Accepted |
| 9 | |
| 10 | Abstract |
| 11 | ======== |
| 12 | |
| 13 | The proposal is describing a mechanism to enable the use of larger flash |
| 14 | devices, imposing a requirement for word-aligned full-block program operations, |
Edison Ai | f7990c8 | 2020-07-16 18:31:48 +0800 | [diff] [blame^] | 15 | in Trusted Firmware-M. |
Galanakis, Minos | f765790 | 2019-10-25 16:47:23 +0100 | [diff] [blame] | 16 | |
| 17 | |
| 18 | Requirements |
| 19 | ============ |
| 20 | |
| 21 | - Allow page-aligned writes for up to 512 Bytes per page. |
| 22 | - Guarantee data integrity and power-failure reliability. |
| 23 | - Do not alter existing supported platform behaviour. |
| 24 | |
| 25 | Current implementation |
| 26 | ====================== |
| 27 | |
| 28 | In the current ITS filesystem design, each filesystem create or write operation |
| 29 | requires two flash blocks to be updated: first the data block and then the |
| 30 | metadata block. Buffering is avoided as much as possible to reduce |
| 31 | RAM requirements. |
| 32 | |
| 33 | However, if the ITS_FLASH_PROGRAM_UNIT is 512 Bytes then the data will have to |
| 34 | stored in a temporary memory location in order to be able to write |
| 35 | that much data in one-shot. |
| 36 | |
| 37 | Proposed implementation overview |
| 38 | ================================ |
| 39 | |
| 40 | 1. A new block-sized static buffer should be added to its_flash.c when |
Galanakis, Minos | dc6694b | 2020-01-06 13:54:56 +0000 | [diff] [blame] | 41 | ``ITS_FLASH_PROGRAM_UNIT`` is larger than currently supported. |
Galanakis, Minos | f765790 | 2019-10-25 16:47:23 +0100 | [diff] [blame] | 42 | 2. Methods calling the flash API such as ``its_flash_write()`` or |
Galanakis, Minos | dc6694b | 2020-01-06 13:54:56 +0000 | [diff] [blame] | 43 | ``its_flash_block_to_block_move()`` will populate the buffer instead of |
| 44 | directly programming the flash. |
Galanakis, Minos | f765790 | 2019-10-25 16:47:23 +0100 | [diff] [blame] | 45 | 3. A new method ``its_flash_flush()``, should be provided in order to flush |
Galanakis, Minos | dc6694b | 2020-01-06 13:54:56 +0000 | [diff] [blame] | 46 | the block buffer to the device. |
| 47 | 4. ``its_flash_flush()`` should be called twice: Once after a data block |
| 48 | update and once more after the metadata block update is completed. |
| 49 | 5. The proposed design should require that the data block update is always |
| 50 | completed before the metadata block update starts |
| 51 | 6. Writes to the block buffer should be atomic, and guarded against corruption |
| 52 | by data from different blocks. |
Galanakis, Minos | f765790 | 2019-10-25 16:47:23 +0100 | [diff] [blame] | 53 | |
| 54 | Considerations |
| 55 | ============== |
| 56 | |
| 57 | - The proposed implementation will increase the RAM usage of ITS by the size |
Galanakis, Minos | dc6694b | 2020-01-06 13:54:56 +0000 | [diff] [blame] | 58 | of a block, only for platforms which require block-aligned writes. |
Galanakis, Minos | f765790 | 2019-10-25 16:47:23 +0100 | [diff] [blame] | 59 | - Currently power-failure is detected by software by incrementing an 8-bit |
Galanakis, Minos | dc6694b | 2020-01-06 13:54:56 +0000 | [diff] [blame] | 60 | metadata header field (``swap_count``), as the last written byte. When the |
| 61 | proposed block-buffer is used, the block is programmed in one-shot and the |
| 62 | order the bytes are written on the physical device, is hardware dependent. |
Galanakis, Minos | f765790 | 2019-10-25 16:47:23 +0100 | [diff] [blame] | 63 | - A set of guarantees are required by the supported flash ECC devices. |
Galanakis, Minos | dc6694b | 2020-01-06 13:54:56 +0000 | [diff] [blame] | 64 | The device's flash APIs should provide a mechanism to capture and raise |
| 65 | incomplete program operations, as well as write bytes in a sequential order. |
Galanakis, Minos | f765790 | 2019-10-25 16:47:23 +0100 | [diff] [blame] | 66 | |
| 67 | For example, if a board powers down through a 512 page program operation, the |
| 68 | next read operation should return an error rather than read invalid data. |
| 69 | |
| 70 | Functional flow diagram |
| 71 | ======================= |
| 72 | |
| 73 | The logic of the proposal is described in the following diagram |
| 74 | |
Galanakis, Minos | dc6694b | 2020-01-06 13:54:56 +0000 | [diff] [blame] | 75 | .. code-block:: |
| 76 | |
Galanakis, Minos | f765790 | 2019-10-25 16:47:23 +0100 | [diff] [blame] | 77 | |----------------------| |
| 78 | | data write() | |
| 79 | |----------------------| |
| 80 | | | |------------------------------| |
| 81 | |-> | its_flash_write | ---> | data[] -> its_block_buffer[] | |
| 82 | | | | |------------------------------| |
| 83 | | |----------------------| |
| 84 | | | | |------------------------------------| |
| 85 | | | its_flash_flush | ---> | its_block_buffer[] -> flash dev IO | |
| 86 | | | | |------------------------------------| |
| 87 | | |----------------------| |
| 88 | | | |
| 89 | | ------------------------------------ |
| 90 | | | |
| 91 | | V |
| 92 | | |----------------------| |--------------------------| |
| 93 | | | data write() complete| | metadata write() complete| |
| 94 | | |----------------------| |--------------------------| |
| 95 | | <-| Metadata write() | | |
| 96 | |----------------------| | |
| 97 | V |
| 98 | |--------------------------| |
| 99 | | Operation Complete | |
| 100 | |--------------------------| |
| 101 | |
Galanakis, Minos | f765790 | 2019-10-25 16:47:23 +0100 | [diff] [blame] | 102 | -------------- |
| 103 | |
Galanakis, Minos | dc6694b | 2020-01-06 13:54:56 +0000 | [diff] [blame] | 104 | *Copyright (c) 2019-2020, Arm Limited. All rights reserved.* |