Move default initializer function to Default trait implementation
This commit is contained in:
parent
eed34f945c
commit
97d18c5ffb
@ -17,9 +17,9 @@ pub struct BootLoader {
|
|||||||
page: AlignedBuffer<PAGE_SIZE>,
|
page: AlignedBuffer<PAGE_SIZE>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl BootLoader {
|
impl Default for BootLoader {
|
||||||
/// Create a new bootloader instance using parameters from linker script
|
/// Create a new bootloader instance using parameters from linker script
|
||||||
pub fn default() -> Self {
|
fn default() -> Self {
|
||||||
extern "C" {
|
extern "C" {
|
||||||
static __bootloader_state_start: u32;
|
static __bootloader_state_start: u32;
|
||||||
static __bootloader_state_end: u32;
|
static __bootloader_state_end: u32;
|
||||||
@ -54,7 +54,9 @@ impl BootLoader {
|
|||||||
|
|
||||||
Self::new(active, dfu, state)
|
Self::new(active, dfu, state)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl BootLoader {
|
||||||
/// Create a new bootloader instance using the supplied partitions for active, dfu and state.
|
/// Create a new bootloader instance using the supplied partitions for active, dfu and state.
|
||||||
pub fn new(active: Partition, dfu: Partition, state: Partition) -> Self {
|
pub fn new(active: Partition, dfu: Partition, state: Partition) -> Self {
|
||||||
Self {
|
Self {
|
||||||
|
@ -14,43 +14,6 @@ pub struct BootLoader<const PAGE_SIZE: usize, const WRITE_SIZE: usize> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<const PAGE_SIZE: usize, const WRITE_SIZE: usize> BootLoader<PAGE_SIZE, WRITE_SIZE> {
|
impl<const PAGE_SIZE: usize, const WRITE_SIZE: usize> BootLoader<PAGE_SIZE, WRITE_SIZE> {
|
||||||
/// Create a new bootloader instance using parameters from linker script
|
|
||||||
pub fn default() -> Self {
|
|
||||||
extern "C" {
|
|
||||||
static __bootloader_state_start: u32;
|
|
||||||
static __bootloader_state_end: u32;
|
|
||||||
static __bootloader_active_start: u32;
|
|
||||||
static __bootloader_active_end: u32;
|
|
||||||
static __bootloader_dfu_start: u32;
|
|
||||||
static __bootloader_dfu_end: u32;
|
|
||||||
}
|
|
||||||
|
|
||||||
let active = unsafe {
|
|
||||||
Partition::new(
|
|
||||||
&__bootloader_active_start as *const u32 as usize,
|
|
||||||
&__bootloader_active_end as *const u32 as usize,
|
|
||||||
)
|
|
||||||
};
|
|
||||||
let dfu = unsafe {
|
|
||||||
Partition::new(
|
|
||||||
&__bootloader_dfu_start as *const u32 as usize,
|
|
||||||
&__bootloader_dfu_end as *const u32 as usize,
|
|
||||||
)
|
|
||||||
};
|
|
||||||
let state = unsafe {
|
|
||||||
Partition::new(
|
|
||||||
&__bootloader_state_start as *const u32 as usize,
|
|
||||||
&__bootloader_state_end as *const u32 as usize,
|
|
||||||
)
|
|
||||||
};
|
|
||||||
|
|
||||||
trace!("ACTIVE: 0x{:x} - 0x{:x}", active.from, active.to);
|
|
||||||
trace!("DFU: 0x{:x} - 0x{:x}", dfu.from, dfu.to);
|
|
||||||
trace!("STATE: 0x{:x} - 0x{:x}", state.from, state.to);
|
|
||||||
|
|
||||||
Self::new(active, dfu, state)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Create a new bootloader instance using the supplied partitions for active, dfu and state.
|
/// Create a new bootloader instance using the supplied partitions for active, dfu and state.
|
||||||
pub fn new(active: Partition, dfu: Partition, state: Partition) -> Self {
|
pub fn new(active: Partition, dfu: Partition, state: Partition) -> Self {
|
||||||
Self {
|
Self {
|
||||||
@ -85,3 +48,42 @@ impl<const PAGE_SIZE: usize, const WRITE_SIZE: usize> BootLoader<PAGE_SIZE, WRIT
|
|||||||
cortex_m::asm::bootload(start as *const u32)
|
cortex_m::asm::bootload(start as *const u32)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<const PAGE_SIZE: usize, const WRITE_SIZE: usize> Default for BootLoader<PAGE_SIZE, WRITE_SIZE> {
|
||||||
|
/// Create a new bootloader instance using parameters from linker script
|
||||||
|
fn default() -> Self {
|
||||||
|
extern "C" {
|
||||||
|
static __bootloader_state_start: u32;
|
||||||
|
static __bootloader_state_end: u32;
|
||||||
|
static __bootloader_active_start: u32;
|
||||||
|
static __bootloader_active_end: u32;
|
||||||
|
static __bootloader_dfu_start: u32;
|
||||||
|
static __bootloader_dfu_end: u32;
|
||||||
|
}
|
||||||
|
|
||||||
|
let active = unsafe {
|
||||||
|
Partition::new(
|
||||||
|
&__bootloader_active_start as *const u32 as usize,
|
||||||
|
&__bootloader_active_end as *const u32 as usize,
|
||||||
|
)
|
||||||
|
};
|
||||||
|
let dfu = unsafe {
|
||||||
|
Partition::new(
|
||||||
|
&__bootloader_dfu_start as *const u32 as usize,
|
||||||
|
&__bootloader_dfu_end as *const u32 as usize,
|
||||||
|
)
|
||||||
|
};
|
||||||
|
let state = unsafe {
|
||||||
|
Partition::new(
|
||||||
|
&__bootloader_state_start as *const u32 as usize,
|
||||||
|
&__bootloader_state_end as *const u32 as usize,
|
||||||
|
)
|
||||||
|
};
|
||||||
|
|
||||||
|
trace!("ACTIVE: 0x{:x} - 0x{:x}", active.from, active.to);
|
||||||
|
trace!("DFU: 0x{:x} - 0x{:x}", dfu.from, dfu.to);
|
||||||
|
trace!("STATE: 0x{:x} - 0x{:x}", state.from, state.to);
|
||||||
|
|
||||||
|
Self::new(active, dfu, state)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user