aboutsummaryrefslogtreecommitdiff
path: root/embassy-boot/src
diff options
context:
space:
mode:
authorBadr Bouslikhin <[email protected]>2024-02-06 16:25:45 +0100
committerBadr Bouslikhin <[email protected]>2024-02-06 16:25:45 +0100
commitc267cb9ab764176bc8514535f4db8ac2331e30ce (patch)
treec997f07d290e0c30f1a583a15ee1557368569ce2 /embassy-boot/src
parentad7d4494fad12f98c7e8e2b776bc12453a66be9a (diff)
feat: enhance bootloader for multiple flash support
Diffstat (limited to 'embassy-boot/src')
-rw-r--r--embassy-boot/src/boot_loader.rs20
-rw-r--r--embassy-boot/src/firmware_updater/asynch.rs13
-rw-r--r--embassy-boot/src/firmware_updater/blocking.rs14
3 files changed, 29 insertions, 18 deletions
diff --git a/embassy-boot/src/boot_loader.rs b/embassy-boot/src/boot_loader.rs
index e568001bc..54ae8a34b 100644
--- a/embassy-boot/src/boot_loader.rs
+++ b/embassy-boot/src/boot_loader.rs
@@ -49,16 +49,20 @@ pub struct BootLoaderConfig<ACTIVE, DFU, STATE> {
49 pub state: STATE, 49 pub state: STATE,
50} 50}
51 51
52impl<'a, FLASH: NorFlash> 52impl<'a, ActiveFlash: NorFlash, DFUFlash: NorFlash, StateFlash: NorFlash>
53 BootLoaderConfig< 53 BootLoaderConfig<
54 BlockingPartition<'a, NoopRawMutex, FLASH>, 54 BlockingPartition<'a, NoopRawMutex, ActiveFlash>,
55 BlockingPartition<'a, NoopRawMutex, FLASH>, 55 BlockingPartition<'a, NoopRawMutex, DFUFlash>,
56 BlockingPartition<'a, NoopRawMutex, FLASH>, 56 BlockingPartition<'a, NoopRawMutex, StateFlash>,
57 > 57 >
58{ 58{
59 /// Create a bootloader config from the flash and address symbols defined in the linkerfile 59 /// Create a bootloader config from the flash and address symbols defined in the linkerfile
60 // #[cfg(target_os = "none")] 60 // #[cfg(target_os = "none")]
61 pub fn from_linkerfile_blocking(flash: &'a Mutex<NoopRawMutex, RefCell<FLASH>>) -> Self { 61 pub fn from_linkerfile_blocking(
62 active_flash: &'a Mutex<NoopRawMutex, RefCell<ActiveFlash>>,
63 dfu_flash: &'a Mutex<NoopRawMutex, RefCell<DFUFlash>>,
64 state_flash: &'a Mutex<NoopRawMutex, RefCell<StateFlash>>,
65 ) -> Self {
62 extern "C" { 66 extern "C" {
63 static __bootloader_state_start: u32; 67 static __bootloader_state_start: u32;
64 static __bootloader_state_end: u32; 68 static __bootloader_state_end: u32;
@@ -73,21 +77,21 @@ impl<'a, FLASH: NorFlash>
73 let end = &__bootloader_active_end as *const u32 as u32; 77 let end = &__bootloader_active_end as *const u32 as u32;
74 trace!("ACTIVE: 0x{:x} - 0x{:x}", start, end); 78 trace!("ACTIVE: 0x{:x} - 0x{:x}", start, end);
75 79
76 BlockingPartition::new(flash, start, end - start) 80 BlockingPartition::new(active_flash, start, end - start)
77 }; 81 };
78 let dfu = unsafe { 82 let dfu = unsafe {
79 let start = &__bootloader_dfu_start as *const u32 as u32; 83 let start = &__bootloader_dfu_start as *const u32 as u32;
80 let end = &__bootloader_dfu_end as *const u32 as u32; 84 let end = &__bootloader_dfu_end as *const u32 as u32;
81 trace!("DFU: 0x{:x} - 0x{:x}", start, end); 85 trace!("DFU: 0x{:x} - 0x{:x}", start, end);
82 86
83 BlockingPartition::new(flash, start, end - start) 87 BlockingPartition::new(dfu_flash, start, end - start)
84 }; 88 };
85 let state = unsafe { 89 let state = unsafe {
86 let start = &__bootloader_state_start as *const u32 as u32; 90 let start = &__bootloader_state_start as *const u32 as u32;
87 let end = &__bootloader_state_end as *const u32 as u32; 91 let end = &__bootloader_state_end as *const u32 as u32;
88 trace!("STATE: 0x{:x} - 0x{:x}", start, end); 92 trace!("STATE: 0x{:x} - 0x{:x}", start, end);
89 93
90 BlockingPartition::new(flash, start, end - start) 94 BlockingPartition::new(state_flash, start, end - start)
91 }; 95 };
92 96
93 Self { active, dfu, state } 97 Self { active, dfu, state }
diff --git a/embassy-boot/src/firmware_updater/asynch.rs b/embassy-boot/src/firmware_updater/asynch.rs
index 2e43e1cc1..5634b48d4 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, DFUFlash: NorFlash, StateFlash: NorFlash>
20 FirmwareUpdaterConfig<Partition<'a, NoopRawMutex, FLASH>, Partition<'a, NoopRawMutex, FLASH>> 20 FirmwareUpdaterConfig<Partition<'a, NoopRawMutex, DFUFlash>, Partition<'a, NoopRawMutex, StateFlash>>
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, DFUFlash>,
25 state_flash: &'a embassy_sync::mutex::Mutex<NoopRawMutex, StateFlash>,
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 f1368540d..3814b6c31 100644
--- a/embassy-boot/src/firmware_updater/blocking.rs
+++ b/embassy-boot/src/firmware_updater/blocking.rs
@@ -16,12 +16,16 @@ 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, DFUFlash: NorFlash, StateFlash: NorFlash>
20 FirmwareUpdaterConfig<BlockingPartition<'a, NoopRawMutex, FLASH>, BlockingPartition<'a, NoopRawMutex, FLASH>> 20 FirmwareUpdaterConfig<
21 BlockingPartition<'a, NoopRawMutex, DFUFlash>,
22 BlockingPartition<'a, NoopRawMutex, StateFlash>,
23 >
21{ 24{
22 /// Create a firmware updater config from the flash and address symbols defined in the linkerfile 25 /// Create a firmware updater config from the flash and address symbols defined in the linkerfile
23 pub fn from_linkerfile_blocking( 26 pub fn from_linkerfile_blocking(
24 flash: &'a embassy_sync::blocking_mutex::Mutex<NoopRawMutex, core::cell::RefCell<FLASH>>, 27 dfu_flash: &'a embassy_sync::blocking_mutex::Mutex<NoopRawMutex, core::cell::RefCell<DFUFlash>>,
28 state_flash: &'a embassy_sync::blocking_mutex::Mutex<NoopRawMutex, core::cell::RefCell<StateFlash>>,
25 ) -> Self { 29 ) -> Self {
26 extern "C" { 30 extern "C" {
27 static __bootloader_state_start: u32; 31 static __bootloader_state_start: u32;
@@ -35,14 +39,14 @@ impl<'a, FLASH: NorFlash>
35 let end = &__bootloader_dfu_end as *const u32 as u32; 39 let end = &__bootloader_dfu_end as *const u32 as u32;
36 trace!("DFU: 0x{:x} - 0x{:x}", start, end); 40 trace!("DFU: 0x{:x} - 0x{:x}", start, end);
37 41
38 BlockingPartition::new(flash, start, end - start) 42 BlockingPartition::new(dfu_flash, start, end - start)
39 }; 43 };
40 let state = unsafe { 44 let state = unsafe {
41 let start = &__bootloader_state_start as *const u32 as u32; 45 let start = &__bootloader_state_start as *const u32 as u32;
42 let end = &__bootloader_state_end as *const u32 as u32; 46 let end = &__bootloader_state_end as *const u32 as u32;
43 trace!("STATE: 0x{:x} - 0x{:x}", start, end); 47 trace!("STATE: 0x{:x} - 0x{:x}", start, end);
44 48
45 BlockingPartition::new(flash, start, end - start) 49 BlockingPartition::new(state_flash, start, end - start)
46 }; 50 };
47 51
48 Self { dfu, state } 52 Self { dfu, state }