aboutsummaryrefslogtreecommitdiff
path: root/embassy-boot
diff options
context:
space:
mode:
Diffstat (limited to 'embassy-boot')
-rw-r--r--embassy-boot/src/boot_loader.rs53
-rw-r--r--embassy-boot/src/firmware_updater/asynch.rs13
-rw-r--r--embassy-boot/src/firmware_updater/blocking.rs43
-rw-r--r--embassy-boot/src/firmware_updater/mod.rs2
4 files changed, 90 insertions, 21 deletions
diff --git a/embassy-boot/src/boot_loader.rs b/embassy-boot/src/boot_loader.rs
index e568001bc..ca1a1b10c 100644
--- a/embassy-boot/src/boot_loader.rs
+++ b/embassy-boot/src/boot_loader.rs
@@ -49,16 +49,51 @@ pub struct BootLoaderConfig<ACTIVE, DFU, STATE> {
49 pub state: STATE, 49 pub state: STATE,
50} 50}
51 51
52impl<'a, FLASH: NorFlash> 52impl<'a, ACTIVE: NorFlash, DFU: NorFlash, STATE: NorFlash>
53 BootLoaderConfig< 53 BootLoaderConfig<
54 BlockingPartition<'a, NoopRawMutex, FLASH>, 54 BlockingPartition<'a, NoopRawMutex, ACTIVE>,
55 BlockingPartition<'a, NoopRawMutex, FLASH>, 55 BlockingPartition<'a, NoopRawMutex, DFU>,
56 BlockingPartition<'a, NoopRawMutex, FLASH>, 56 BlockingPartition<'a, NoopRawMutex, STATE>,
57 > 57 >
58{ 58{
59 /// Create a bootloader config from the flash and address symbols defined in the linkerfile 59 /// Constructs a `BootLoaderConfig` instance from flash memory and address symbols defined in the linker file.
60 ///
61 /// This method initializes `BlockingPartition` instances for the active, DFU (Device Firmware Update),
62 /// and state partitions, leveraging start and end addresses specified by the linker. These partitions
63 /// are critical for managing firmware updates, application state, and boot operations within the bootloader.
64 ///
65 /// # Parameters
66 /// - `active_flash`: A reference to a mutex-protected `RefCell` for the active partition's flash interface.
67 /// - `dfu_flash`: A reference to a mutex-protected `RefCell` for the DFU partition's flash interface.
68 /// - `state_flash`: A reference to a mutex-protected `RefCell` for the state partition's flash interface.
69 ///
70 /// # Safety
71 /// The method contains `unsafe` blocks for dereferencing raw pointers that represent the start and end addresses
72 /// of the bootloader's partitions in flash memory. It is crucial that these addresses are accurately defined
73 /// in the memory.x file to prevent undefined behavior.
74 ///
75 /// The caller must ensure that the memory regions defined by these symbols are valid and that the flash memory
76 /// interfaces provided are compatible with these regions.
77 ///
78 /// # Returns
79 /// A `BootLoaderConfig` instance with `BlockingPartition` instances for the active, DFU, and state partitions.
80 ///
81 /// # Example
82 /// ```ignore
83 /// // Assume `active_flash`, `dfu_flash`, and `state_flash` all share the same flash memory interface.
84 /// let layout = Flash::new_blocking(p.FLASH).into_blocking_regions();
85 /// let flash = Mutex::new(RefCell::new(layout.bank1_region));
86 ///
87 /// let config = BootLoaderConfig::from_linkerfile_blocking(&flash, &flash, &flash);
88 /// // `config` can now be used to create a `BootLoader` instance for managing boot operations.
89 /// ```
90 /// Working examples can be found in the bootloader examples folder.
60 // #[cfg(target_os = "none")] 91 // #[cfg(target_os = "none")]
61 pub fn from_linkerfile_blocking(flash: &'a Mutex<NoopRawMutex, RefCell<FLASH>>) -> Self { 92 pub fn from_linkerfile_blocking(
93 active_flash: &'a Mutex<NoopRawMutex, RefCell<ACTIVE>>,
94 dfu_flash: &'a Mutex<NoopRawMutex, RefCell<DFU>>,
95 state_flash: &'a Mutex<NoopRawMutex, RefCell<STATE>>,
96 ) -> Self {
62 extern "C" { 97 extern "C" {
63 static __bootloader_state_start: u32; 98 static __bootloader_state_start: u32;
64 static __bootloader_state_end: u32; 99 static __bootloader_state_end: u32;
@@ -73,21 +108,21 @@ impl<'a, FLASH: NorFlash>
73 let end = &__bootloader_active_end as *const u32 as u32; 108 let end = &__bootloader_active_end as *const u32 as u32;
74 trace!("ACTIVE: 0x{:x} - 0x{:x}", start, end); 109 trace!("ACTIVE: 0x{:x} - 0x{:x}", start, end);
75 110
76 BlockingPartition::new(flash, start, end - start) 111 BlockingPartition::new(active_flash, start, end - start)
77 }; 112 };
78 let dfu = unsafe { 113 let dfu = unsafe {
79 let start = &__bootloader_dfu_start as *const u32 as u32; 114 let start = &__bootloader_dfu_start as *const u32 as u32;
80 let end = &__bootloader_dfu_end as *const u32 as u32; 115 let end = &__bootloader_dfu_end as *const u32 as u32;
81 trace!("DFU: 0x{:x} - 0x{:x}", start, end); 116 trace!("DFU: 0x{:x} - 0x{:x}", start, end);
82 117
83 BlockingPartition::new(flash, start, end - start) 118 BlockingPartition::new(dfu_flash, start, end - start)
84 }; 119 };
85 let state = unsafe { 120 let state = unsafe {
86 let start = &__bootloader_state_start as *const u32 as u32; 121 let start = &__bootloader_state_start as *const u32 as u32;
87 let end = &__bootloader_state_end as *const u32 as u32; 122 let end = &__bootloader_state_end as *const u32 as u32;
88 trace!("STATE: 0x{:x} - 0x{:x}", start, end); 123 trace!("STATE: 0x{:x} - 0x{:x}", start, end);
89 124
90 BlockingPartition::new(flash, start, end - start) 125 BlockingPartition::new(state_flash, start, end - start)
91 }; 126 };
92 127
93 Self { active, dfu, state } 128 Self { active, dfu, state }
diff --git a/embassy-boot/src/firmware_updater/asynch.rs b/embassy-boot/src/firmware_updater/asynch.rs
index 2e43e1cc1..668f16f16 100644
--- a/embassy-boot/src/firmware_updater/asynch.rs
+++ b/embassy-boot/src/firmware_updater/asynch.rs
@@ -16,11 +16,14 @@ pub struct FirmwareUpdater<'d, DFU: NorFlash, STATE: NorFlash> {
16} 16}
17 17
18#[cfg(target_os = "none")] 18#[cfg(target_os = "none")]
19impl<'a, FLASH: NorFlash> 19impl<'a, DFU: NorFlash, STATE: NorFlash>
20 FirmwareUpdaterConfig<Partition<'a, NoopRawMutex, FLASH>, Partition<'a, NoopRawMutex, FLASH>> 20 FirmwareUpdaterConfig<Partition<'a, NoopRawMutex, DFU>, Partition<'a, NoopRawMutex, STATE>>
21{ 21{
22 /// Create a firmware updater config from the flash and address symbols defined in the linkerfile 22 /// Create a firmware updater config from the flash and address symbols defined in the linkerfile
23 pub fn from_linkerfile(flash: &'a embassy_sync::mutex::Mutex<NoopRawMutex, FLASH>) -> Self { 23 pub fn from_linkerfile(
24 dfu_flash: &'a embassy_sync::mutex::Mutex<NoopRawMutex, DFU>,
25 state_flash: &'a embassy_sync::mutex::Mutex<NoopRawMutex, STATE>,
26 ) -> Self {
24 extern "C" { 27 extern "C" {
25 static __bootloader_state_start: u32; 28 static __bootloader_state_start: u32;
26 static __bootloader_state_end: u32; 29 static __bootloader_state_end: u32;
@@ -33,14 +36,14 @@ impl<'a, FLASH: NorFlash>
33 let end = &__bootloader_dfu_end as *const u32 as u32; 36 let end = &__bootloader_dfu_end as *const u32 as u32;
34 trace!("DFU: 0x{:x} - 0x{:x}", start, end); 37 trace!("DFU: 0x{:x} - 0x{:x}", start, end);
35 38
36 Partition::new(flash, start, end - start) 39 Partition::new(dfu_flash, start, end - start)
37 }; 40 };
38 let state = unsafe { 41 let state = unsafe {
39 let start = &__bootloader_state_start as *const u32 as u32; 42 let start = &__bootloader_state_start as *const u32 as u32;
40 let end = &__bootloader_state_end as *const u32 as u32; 43 let end = &__bootloader_state_end as *const u32 as u32;
41 trace!("STATE: 0x{:x} - 0x{:x}", start, end); 44 trace!("STATE: 0x{:x} - 0x{:x}", start, end);
42 45
43 Partition::new(flash, start, end - start) 46 Partition::new(state_flash, start, end - start)
44 }; 47 };
45 48
46 Self { dfu, state } 49 Self { dfu, state }
diff --git a/embassy-boot/src/firmware_updater/blocking.rs b/embassy-boot/src/firmware_updater/blocking.rs
index 514070639..3e83366af 100644
--- a/embassy-boot/src/firmware_updater/blocking.rs
+++ b/embassy-boot/src/firmware_updater/blocking.rs
@@ -16,12 +16,43 @@ pub struct BlockingFirmwareUpdater<'d, DFU: NorFlash, STATE: NorFlash> {
16} 16}
17 17
18#[cfg(target_os = "none")] 18#[cfg(target_os = "none")]
19impl<'a, FLASH: NorFlash> 19impl<'a, DFU: NorFlash, STATE: NorFlash>
20 FirmwareUpdaterConfig<BlockingPartition<'a, NoopRawMutex, FLASH>, BlockingPartition<'a, NoopRawMutex, FLASH>> 20 FirmwareUpdaterConfig<BlockingPartition<'a, NoopRawMutex, DFU>, BlockingPartition<'a, NoopRawMutex, STATE>>
21{ 21{
22 /// Create a firmware updater config from the flash and address symbols defined in the linkerfile 22 /// Constructs a `FirmwareUpdaterConfig` instance from flash memory and address symbols defined in the linker file.
23 ///
24 /// This method initializes `BlockingPartition` instances for the DFU (Device Firmware Update), and state
25 /// partitions, leveraging start and end addresses specified by the linker. These partitions are critical
26 /// for managing firmware updates, application state, and boot operations within the bootloader.
27 ///
28 /// # Parameters
29 /// - `dfu_flash`: A reference to a mutex-protected `RefCell` for the DFU partition's flash interface.
30 /// - `state_flash`: A reference to a mutex-protected `RefCell` for the state partition's flash interface.
31 ///
32 /// # Safety
33 /// The method contains `unsafe` blocks for dereferencing raw pointers that represent the start and end addresses
34 /// of the bootloader's partitions in flash memory. It is crucial that these addresses are accurately defined
35 /// in the memory.x file to prevent undefined behavior.
36 ///
37 /// The caller must ensure that the memory regions defined by these symbols are valid and that the flash memory
38 /// interfaces provided are compatible with these regions.
39 ///
40 /// # Returns
41 /// A `FirmwareUpdaterConfig` instance with `BlockingPartition` instances for the DFU, and state partitions.
42 ///
43 /// # Example
44 /// ```ignore
45 /// // Assume `dfu_flash`, and `state_flash` share the same flash memory interface.
46 /// let layout = Flash::new_blocking(p.FLASH).into_blocking_regions();
47 /// let flash = Mutex::new(RefCell::new(layout.bank1_region));
48 ///
49 /// let config = FirmwareUpdaterConfig::from_linkerfile_blocking(&flash, &flash);
50 /// // `config` can now be used to create a `FirmwareUpdater` instance for managing boot operations.
51 /// ```
52 /// Working examples can be found in the bootloader examples folder.
23 pub fn from_linkerfile_blocking( 53 pub fn from_linkerfile_blocking(
24 flash: &'a embassy_sync::blocking_mutex::Mutex<NoopRawMutex, core::cell::RefCell<FLASH>>, 54 dfu_flash: &'a embassy_sync::blocking_mutex::Mutex<NoopRawMutex, core::cell::RefCell<DFU>>,
55 state_flash: &'a embassy_sync::blocking_mutex::Mutex<NoopRawMutex, core::cell::RefCell<STATE>>,
25 ) -> Self { 56 ) -> Self {
26 extern "C" { 57 extern "C" {
27 static __bootloader_state_start: u32; 58 static __bootloader_state_start: u32;
@@ -35,14 +66,14 @@ impl<'a, FLASH: NorFlash>
35 let end = &__bootloader_dfu_end as *const u32 as u32; 66 let end = &__bootloader_dfu_end as *const u32 as u32;
36 trace!("DFU: 0x{:x} - 0x{:x}", start, end); 67 trace!("DFU: 0x{:x} - 0x{:x}", start, end);
37 68
38 BlockingPartition::new(flash, start, end - start) 69 BlockingPartition::new(dfu_flash, start, end - start)
39 }; 70 };
40 let state = unsafe { 71 let state = unsafe {
41 let start = &__bootloader_state_start as *const u32 as u32; 72 let start = &__bootloader_state_start as *const u32 as u32;
42 let end = &__bootloader_state_end as *const u32 as u32; 73 let end = &__bootloader_state_end as *const u32 as u32;
43 trace!("STATE: 0x{:x} - 0x{:x}", start, end); 74 trace!("STATE: 0x{:x} - 0x{:x}", start, end);
44 75
45 BlockingPartition::new(flash, start, end - start) 76 BlockingPartition::new(state_flash, start, end - start)
46 }; 77 };
47 78
48 Self { dfu, state } 79 Self { dfu, state }
diff --git a/embassy-boot/src/firmware_updater/mod.rs b/embassy-boot/src/firmware_updater/mod.rs
index 4814786bf..4c4f4f10b 100644
--- a/embassy-boot/src/firmware_updater/mod.rs
+++ b/embassy-boot/src/firmware_updater/mod.rs
@@ -8,7 +8,7 @@ use embedded_storage::nor_flash::{NorFlashError, NorFlashErrorKind};
8/// Firmware updater flash configuration holding the two flashes used by the updater 8/// Firmware updater flash configuration holding the two flashes used by the updater
9/// 9///
10/// If only a single flash is actually used, then that flash should be partitioned into two partitions before use. 10/// If only a single flash is actually used, then that flash should be partitioned into two partitions before use.
11/// The easiest way to do this is to use [`FirmwareUpdaterConfig::from_linkerfile`] or [`FirmwareUpdaterConfig::from_linkerfile_blocking`] which will partition 11/// The easiest way to do this is to use [`FirmwareUpdaterConfig::from_linkerfile_blocking`] or [`FirmwareUpdaterConfig::from_linkerfile_blocking`] which will partition
12/// the provided flash according to symbols defined in the linkerfile. 12/// the provided flash according to symbols defined in the linkerfile.
13pub struct FirmwareUpdaterConfig<DFU, STATE> { 13pub struct FirmwareUpdaterConfig<DFU, STATE> {
14 /// The dfu flash partition 14 /// The dfu flash partition