kernel/utilities/
storage_volume.rs

1// Licensed under the Apache License, Version 2.0 or the MIT License.
2// SPDX-License-Identifier: Apache-2.0 OR MIT
3// Copyright Tock Contributors 2022.
4
5//! Utility for creating non-volatile storage regions.
6
7/// Allocates space in the kernel image for on-chip non-volatile storage.
8///
9/// Storage volumes are placed after the kernel code and before relocated
10/// variables (those copied into RAM on boot). They are placed in a section
11/// called `.storage`.
12///
13/// Non-volatile storage abstractions can then refer to the block of allocate
14/// flash in terms of the name of the volume. For example,
15///
16/// ```ignore
17/// storage_volume!(LOG, 32);
18/// ```
19///
20/// will allocate 32kB of space in the flash and define a symbol `LOG` at the
21/// start address of that flash region. The intention is that storage
22/// abstractions can then be passed this address and size to initialize their
23/// state. The default Tock linker script makes sure that the `.storage` section
24/// is aligned on a 512-byte boundary and the next section is aligned as well.
25#[macro_export]
26macro_rules! storage_volume {
27    ($N:ident, $kB:expr $(,)?) => {
28        #[link_section = ".storage"]
29        #[used]
30        #[no_mangle]
31        pub static $N: [u8; $kB * 1024] = [0x00; $kB * 1024];
32    };
33}