1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
//! RP2350 Boot Block (PICOBIN) definitions
//!
//! The Boot ROM looks for a valid Block in the first 4KB of flash to determine
//! how to boot the image. The block format is defined by the PICOBIN specification.
//!
//! ## Automatic Generation
//!
//! The `#[main]` macro automatically generates an `ImageDef::exe()` block in
//! the `.start_block` section. For most applications, no manual Image Definition
//! is needed — just use `#[main]` and the correct boot block is emitted.
//!
//! ## Manual Definition (Advanced)
//!
//! To use `ImageDefWithVersion`, opt out of automatic generation with
//! `#[main(no_image_def)]` and define your own static:
//!
//! ```ignore
//! use rp2350::block::ImageDefWithVersion;
//! use rp2350::main;
//!
//! #[unsafe(link_section = ".start_block")]
//! #[used]
//! pub static IMAGE_DEF: ImageDefWithVersion =
//! ImageDefWithVersion::exe_with_version(1, 0);
//!
//! #[main(no_image_def)]
//! fn main() -> ! {
//! loop {}
//! }
//! ```
//!
//! ## Security Mode
//!
//! All images are built in Secure mode (TrustZone-M enabled, `0xd000_0000`).
//!
//! [`ImageDef::exe()`] and [`ImageDefWithVersion::exe_with_version()`] always
//! set the Secure flag.
//!
//! ## Architecture Support
//!
//! Currently this module supports ARM Cortex-M33 images only.
// ============================================================================
// PICOBIN Constants
// ============================================================================
/// Magic value marking the start of a block (PICOBIN_BLOCK_MARKER_START)
pub const BLOCK_MARKER_START: u32 = 0xffffded3;
/// Magic value marking the end of a block (PICOBIN_BLOCK_MARKER_END)
pub const BLOCK_MARKER_END: u32 = 0xab123579;
// Block item type identifiers
const ITEM_1BS_IMAGE_TYPE: u8 = 0x42;
const ITEM_1BS_VERSION: u8 = 0x48;
const ITEM_2BS_LAST: u8 = 0xff;
// Image type field values
const IMAGE_TYPE_EXE: u16 = 0x0001;
// Security mode (bits 4–5)
const IMAGE_TYPE_EXE_SECURITY_S: u16 = 0x0020;
// CPU type (bits 8–10)
const IMAGE_TYPE_EXE_CPU_ARM: u16 = 0x0000;
// Chip type (bits 12–14)
const IMAGE_TYPE_EXE_CHIP_RP2350: u16 = 0x1000;
// ============================================================================
// Compile-time Security Selection
// ============================================================================
/// Security flag — always Secure mode (`IMAGE_TYPE_EXE_SECURITY_S`).
const SECURITY: u16 = IMAGE_TYPE_EXE_SECURITY_S;
// ============================================================================
// Item Builders
// ============================================================================
/// Make an item header with 1-byte size (tag | size<<8 | value<<16)
const
/// Make an item header with 2-byte size (tag | size<<8)
const
/// Create the IMAGE_TYPE item for an ARM executable
const
// ============================================================================
// ImageDef
// ============================================================================
/// RP2350 Image Definition Block
///
/// This structure must be placed in the `.start_block` section in the first 4K
/// of flash. It tells the Boot ROM that this is a valid executable image.
///
/// All images are built in Secure mode (TrustZone-M enabled); there is
/// currently no `non-secure` Cargo feature to override this.
///
/// # Example
///
/// ```ignore
/// #[link_section = ".start_block"]
/// #[used]
/// pub static IMAGE_DEF: ImageDef = ImageDef::exe();
/// ```
// SAFETY: ImageDef contains only u32 values and a null pointer, making it safe to share
unsafe
// ============================================================================
// ImageDefWithVersion
// ============================================================================
/// Extended Image Definition Block with version information.
///
/// Use this when you want to include version metadata in your binary.
///
/// # Example
///
/// ```ignore
/// #[link_section = ".start_block"]
/// #[used]
/// pub static IMAGE_DEF: ImageDefWithVersion =
/// ImageDefWithVersion::exe_with_version(1, 0);
/// ```
unsafe
// ============================================================================
// Boot Configuration Constants
// ============================================================================
/// Boot configuration constants.