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