aboutsummaryrefslogtreecommitdiff
path: root/embassy-rp
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2023-06-05 23:41:26 +0200
committerDario Nieuwenhuis <[email protected]>2023-06-05 23:41:26 +0200
commit162d48530436be9cfa6a0d4aba88d97f52a5ad4a (patch)
tree73c5fd1b22c73200df2e012c832e93c474fbc803 /embassy-rp
parent70e1b976d87c5bde4b07e7e0b0fcf1499e4d98ef (diff)
rp/flash: centralize `USE_BOOT2` in a single const.
Diffstat (limited to 'embassy-rp')
-rw-r--r--embassy-rp/src/flash.rs41
1 files changed, 21 insertions, 20 deletions
diff --git a/embassy-rp/src/flash.rs b/embassy-rp/src/flash.rs
index cd34e605e..0372afb1e 100644
--- a/embassy-rp/src/flash.rs
+++ b/embassy-rp/src/flash.rs
@@ -10,6 +10,7 @@ use crate::pac;
10use crate::peripherals::FLASH; 10use crate::peripherals::FLASH;
11 11
12pub const FLASH_BASE: *const u32 = 0x10000000 as _; 12pub const FLASH_BASE: *const u32 = 0x10000000 as _;
13pub const USE_BOOT2: bool = true;
13 14
14// **NOTE**: 15// **NOTE**:
15// 16//
@@ -89,7 +90,7 @@ impl<'d, T: Instance, const FLASH_SIZE: usize> Flash<'d, T, FLASH_SIZE> {
89 90
90 let len = to - from; 91 let len = to - from;
91 92
92 unsafe { self.in_ram(|| ram_helpers::flash_range_erase(from, len, true))? }; 93 unsafe { self.in_ram(|| ram_helpers::flash_range_erase(from, len))? };
93 94
94 Ok(()) 95 Ok(())
95 } 96 }
@@ -114,7 +115,7 @@ impl<'d, T: Instance, const FLASH_SIZE: usize> Flash<'d, T, FLASH_SIZE> {
114 115
115 let unaligned_offset = offset as usize - start; 116 let unaligned_offset = offset as usize - start;
116 117
117 unsafe { self.in_ram(|| ram_helpers::flash_range_program(unaligned_offset as u32, &pad_buf, true))? } 118 unsafe { self.in_ram(|| ram_helpers::flash_range_program(unaligned_offset as u32, &pad_buf))? }
118 } 119 }
119 120
120 let remaining_len = bytes.len() - start_padding; 121 let remaining_len = bytes.len() - start_padding;
@@ -132,12 +133,12 @@ impl<'d, T: Instance, const FLASH_SIZE: usize> Flash<'d, T, FLASH_SIZE> {
132 if bytes.as_ptr() as usize >= 0x2000_0000 { 133 if bytes.as_ptr() as usize >= 0x2000_0000 {
133 let aligned_data = &bytes[start_padding..end_padding]; 134 let aligned_data = &bytes[start_padding..end_padding];
134 135
135 unsafe { self.in_ram(|| ram_helpers::flash_range_program(aligned_offset as u32, aligned_data, true))? } 136 unsafe { self.in_ram(|| ram_helpers::flash_range_program(aligned_offset as u32, aligned_data))? }
136 } else { 137 } else {
137 for chunk in bytes[start_padding..end_padding].chunks_exact(PAGE_SIZE) { 138 for chunk in bytes[start_padding..end_padding].chunks_exact(PAGE_SIZE) {
138 let mut ram_buf = [0xFF_u8; PAGE_SIZE]; 139 let mut ram_buf = [0xFF_u8; PAGE_SIZE];
139 ram_buf.copy_from_slice(chunk); 140 ram_buf.copy_from_slice(chunk);
140 unsafe { self.in_ram(|| ram_helpers::flash_range_program(aligned_offset as u32, &ram_buf, true))? } 141 unsafe { self.in_ram(|| ram_helpers::flash_range_program(aligned_offset as u32, &ram_buf))? }
141 aligned_offset += PAGE_SIZE; 142 aligned_offset += PAGE_SIZE;
142 } 143 }
143 } 144 }
@@ -152,7 +153,7 @@ impl<'d, T: Instance, const FLASH_SIZE: usize> Flash<'d, T, FLASH_SIZE> {
152 153
153 let unaligned_offset = end_offset - (PAGE_SIZE - rem_offset); 154 let unaligned_offset = end_offset - (PAGE_SIZE - rem_offset);
154 155
155 unsafe { self.in_ram(|| ram_helpers::flash_range_program(unaligned_offset as u32, &pad_buf, true))? } 156 unsafe { self.in_ram(|| ram_helpers::flash_range_program(unaligned_offset as u32, &pad_buf))? }
156 } 157 }
157 158
158 Ok(()) 159 Ok(())
@@ -190,7 +191,7 @@ impl<'d, T: Instance, const FLASH_SIZE: usize> Flash<'d, T, FLASH_SIZE> {
190 191
191 /// Read SPI flash unique ID 192 /// Read SPI flash unique ID
192 pub fn unique_id(&mut self, uid: &mut [u8]) -> Result<(), Error> { 193 pub fn unique_id(&mut self, uid: &mut [u8]) -> Result<(), Error> {
193 unsafe { self.in_ram(|| ram_helpers::flash_unique_id(uid, true))? }; 194 unsafe { self.in_ram(|| ram_helpers::flash_unique_id(uid))? };
194 Ok(()) 195 Ok(())
195 } 196 }
196 197
@@ -199,7 +200,7 @@ impl<'d, T: Instance, const FLASH_SIZE: usize> Flash<'d, T, FLASH_SIZE> {
199 let mut jedec = None; 200 let mut jedec = None;
200 unsafe { 201 unsafe {
201 self.in_ram(|| { 202 self.in_ram(|| {
202 jedec.replace(ram_helpers::flash_jedec_id(true)); 203 jedec.replace(ram_helpers::flash_jedec_id());
203 })?; 204 })?;
204 }; 205 };
205 Ok(jedec.unwrap()) 206 Ok(jedec.unwrap())
@@ -307,7 +308,7 @@ mod ram_helpers {
307 /// 308 ///
308 /// `addr` and `len` must be multiples of 4096 309 /// `addr` and `len` must be multiples of 4096
309 /// 310 ///
310 /// If `use_boot2` is `true`, a copy of the 2nd stage boot loader 311 /// If `USE_BOOT2` is `true`, a copy of the 2nd stage boot loader
311 /// is used to re-initialize the XIP engine after flashing. 312 /// is used to re-initialize the XIP engine after flashing.
312 /// 313 ///
313 /// # Safety 314 /// # Safety
@@ -319,9 +320,9 @@ mod ram_helpers {
319 /// - DMA must not access flash memory 320 /// - DMA must not access flash memory
320 /// 321 ///
321 /// `addr` and `len` parameters must be valid and are not checked. 322 /// `addr` and `len` parameters must be valid and are not checked.
322 pub unsafe fn flash_range_erase(addr: u32, len: u32, use_boot2: bool) { 323 pub unsafe fn flash_range_erase(addr: u32, len: u32) {
323 let mut boot2 = [0u32; 256 / 4]; 324 let mut boot2 = [0u32; 256 / 4];
324 let ptrs = if use_boot2 { 325 let ptrs = if USE_BOOT2 {
325 rom_data::memcpy44(&mut boot2 as *mut _, FLASH_BASE, 256); 326 rom_data::memcpy44(&mut boot2 as *mut _, FLASH_BASE, 256);
326 flash_function_pointers_with_boot2(true, false, &boot2) 327 flash_function_pointers_with_boot2(true, false, &boot2)
327 } else { 328 } else {
@@ -337,7 +338,7 @@ mod ram_helpers {
337 /// 338 ///
338 /// `addr` and `data.len()` must be multiples of 4096 339 /// `addr` and `data.len()` must be multiples of 4096
339 /// 340 ///
340 /// If `use_boot2` is `true`, a copy of the 2nd stage boot loader 341 /// If `USE_BOOT2` is `true`, a copy of the 2nd stage boot loader
341 /// is used to re-initialize the XIP engine after flashing. 342 /// is used to re-initialize the XIP engine after flashing.
342 /// 343 ///
343 /// # Safety 344 /// # Safety
@@ -349,9 +350,9 @@ mod ram_helpers {
349 /// - DMA must not access flash memory 350 /// - DMA must not access flash memory
350 /// 351 ///
351 /// `addr` and `len` parameters must be valid and are not checked. 352 /// `addr` and `len` parameters must be valid and are not checked.
352 pub unsafe fn flash_range_erase_and_program(addr: u32, data: &[u8], use_boot2: bool) { 353 pub unsafe fn flash_range_erase_and_program(addr: u32, data: &[u8]) {
353 let mut boot2 = [0u32; 256 / 4]; 354 let mut boot2 = [0u32; 256 / 4];
354 let ptrs = if use_boot2 { 355 let ptrs = if USE_BOOT2 {
355 rom_data::memcpy44(&mut boot2 as *mut _, FLASH_BASE, 256); 356 rom_data::memcpy44(&mut boot2 as *mut _, FLASH_BASE, 256);
356 flash_function_pointers_with_boot2(true, true, &boot2) 357 flash_function_pointers_with_boot2(true, true, &boot2)
357 } else { 358 } else {
@@ -372,7 +373,7 @@ mod ram_helpers {
372 /// 373 ///
373 /// `addr` and `data.len()` must be multiples of 256 374 /// `addr` and `data.len()` must be multiples of 256
374 /// 375 ///
375 /// If `use_boot2` is `true`, a copy of the 2nd stage boot loader 376 /// If `USE_BOOT2` is `true`, a copy of the 2nd stage boot loader
376 /// is used to re-initialize the XIP engine after flashing. 377 /// is used to re-initialize the XIP engine after flashing.
377 /// 378 ///
378 /// # Safety 379 /// # Safety
@@ -384,9 +385,9 @@ mod ram_helpers {
384 /// - DMA must not access flash memory 385 /// - DMA must not access flash memory
385 /// 386 ///
386 /// `addr` and `len` parameters must be valid and are not checked. 387 /// `addr` and `len` parameters must be valid and are not checked.
387 pub unsafe fn flash_range_program(addr: u32, data: &[u8], use_boot2: bool) { 388 pub unsafe fn flash_range_program(addr: u32, data: &[u8]) {
388 let mut boot2 = [0u32; 256 / 4]; 389 let mut boot2 = [0u32; 256 / 4];
389 let ptrs = if use_boot2 { 390 let ptrs = if USE_BOOT2 {
390 rom_data::memcpy44(&mut boot2 as *mut _, FLASH_BASE, 256); 391 rom_data::memcpy44(&mut boot2 as *mut _, FLASH_BASE, 256);
391 flash_function_pointers_with_boot2(false, true, &boot2) 392 flash_function_pointers_with_boot2(false, true, &boot2)
392 } else { 393 } else {
@@ -509,9 +510,9 @@ mod ram_helpers {
509 /// - DMA must not access flash memory 510 /// - DMA must not access flash memory
510 /// 511 ///
511 /// Credit: taken from `rp2040-flash` (also licensed Apache+MIT) 512 /// Credit: taken from `rp2040-flash` (also licensed Apache+MIT)
512 pub unsafe fn flash_unique_id(out: &mut [u8], use_boot2: bool) { 513 pub unsafe fn flash_unique_id(out: &mut [u8]) {
513 let mut boot2 = [0u32; 256 / 4]; 514 let mut boot2 = [0u32; 256 / 4];
514 let ptrs = if use_boot2 { 515 let ptrs = if USE_BOOT2 {
515 rom_data::memcpy44(&mut boot2 as *mut _, FLASH_BASE, 256); 516 rom_data::memcpy44(&mut boot2 as *mut _, FLASH_BASE, 256);
516 flash_function_pointers_with_boot2(false, false, &boot2) 517 flash_function_pointers_with_boot2(false, false, &boot2)
517 } else { 518 } else {
@@ -537,9 +538,9 @@ mod ram_helpers {
537 /// - DMA must not access flash memory 538 /// - DMA must not access flash memory
538 /// 539 ///
539 /// Credit: taken from `rp2040-flash` (also licensed Apache+MIT) 540 /// Credit: taken from `rp2040-flash` (also licensed Apache+MIT)
540 pub unsafe fn flash_jedec_id(use_boot2: bool) -> u32 { 541 pub unsafe fn flash_jedec_id() -> u32 {
541 let mut boot2 = [0u32; 256 / 4]; 542 let mut boot2 = [0u32; 256 / 4];
542 let ptrs = if use_boot2 { 543 let ptrs = if USE_BOOT2 {
543 rom_data::memcpy44(&mut boot2 as *mut _, FLASH_BASE, 256); 544 rom_data::memcpy44(&mut boot2 as *mut _, FLASH_BASE, 256);
544 flash_function_pointers_with_boot2(false, false, &boot2) 545 flash_function_pointers_with_boot2(false, false, &boot2)
545 } else { 546 } else {