Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial multiple-board config #31

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 1 addition & 29 deletions src/address_range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,32 +29,4 @@ impl Default for AddressRange {
from: 0,
}
}
}

pub const FLASH_SECTOR_ERASE_SIZE: u32 = 4096;
pub const MAIN_RAM_START: u32 = 0x20000000;
pub const MAIN_RAM_END: u32 = 0x20042000;
pub const FLASH_START: u32 = 0x10000000;
pub const FLASH_END: u32 = 0x15000000;
pub const XIP_SRAM_START: u32 = 0x15000000;
pub const XIP_SRAM_END: u32 = 0x15004000;
pub const MAIN_RAM_BANKED_START: u32 = 0x21000000;
pub const MAIN_RAM_BANKED_END: u32 = 0x21040000;
pub const ROM_START: u32 = 0x00000000;
pub const ROM_END: u32 = 0x00004000;

pub const RP2040_ADDRESS_RANGES_FLASH: &[AddressRange] = &[
AddressRange::new(FLASH_START, FLASH_END, AddressRangeType::Contents),
AddressRange::new(MAIN_RAM_START, MAIN_RAM_END, AddressRangeType::NoContents),
AddressRange::new(
MAIN_RAM_BANKED_START,
MAIN_RAM_BANKED_END,
AddressRangeType::NoContents,
),
];

pub const RP2040_ADDRESS_RANGES_RAM: &[AddressRange] = &[
AddressRange::new(MAIN_RAM_START, MAIN_RAM_END, AddressRangeType::Contents),
AddressRange::new(XIP_SRAM_START, XIP_SRAM_END, AddressRangeType::Contents),
AddressRange::new(ROM_START, ROM_END, AddressRangeType::Ignore), // for now we ignore the bootrom if present
];
}
70 changes: 70 additions & 0 deletions src/boards/circuit_playground_bluefruit.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// Based off info from
// https://infocenter.nordicsemi.com/index.jsp?topic=%2Fps_nrf52840%2Fmemory.html
// and https://github.com/adafruit/Adafruit_nRF52_Bootloader/blob/master/src/boards/circuitplayground_nrf52840/pinconfig.c

use crate::address_range::{AddressRange, AddressRangeType};

use super::BoardConfig;

const FLASH_SECTOR_ERASE_SIZE: u32 = 4096;
const MAIN_RAM_START: u32 = 0x00800000;
const MAIN_RAM_END: u32 = 0x10000000;
const FLASH_START: u32 = 0x00100000;
const FLASH_END: u32 = 0x00800000;
const XIP_SRAM_START: u32 = 0x12000000;
const XIP_SRAM_END: u32 = 0x19FFFFFF;
const MAIN_RAM_BANKED_START: u32 = 0x60000000;
const MAIN_RAM_BANKED_END: u32 = 0xA0000000;
const BOOTLOADER_FLASH_START: u32 = 0x00000000;
const BOOTLOADER_FLASH_END: u32 = 0x00100000;

pub struct CircuitPlaygroundBluefruit {}

impl BoardConfig for CircuitPlaygroundBluefruit {
fn flash_sector_erase_size(&self) -> u32 {
FLASH_SECTOR_ERASE_SIZE
}

fn main_ram_start(&self) -> u32 {
MAIN_RAM_START
}

fn main_ram_end(&self) -> u32 {
MAIN_RAM_END
}

fn xip_ram_start(&self) -> u32 {
XIP_SRAM_START
}

fn xip_ram_end(&self) -> u32 {
XIP_SRAM_END
}

fn family_id(&self) -> u32 {
0xada52840
}

fn address_ranges_flash(&self) -> Vec<AddressRange> {
vec![
AddressRange::new(FLASH_START, FLASH_END, AddressRangeType::Contents),
AddressRange::new(MAIN_RAM_START, MAIN_RAM_END, AddressRangeType::NoContents),
AddressRange::new(
MAIN_RAM_BANKED_START,
MAIN_RAM_BANKED_END,
AddressRangeType::NoContents,
),
]
}

fn address_range_ram(&self) -> Vec<AddressRange> {
vec![
AddressRange::new(MAIN_RAM_START, MAIN_RAM_END, AddressRangeType::Contents),
AddressRange::new(XIP_SRAM_START, XIP_SRAM_END, AddressRangeType::Contents),
AddressRange::new(
BOOTLOADER_FLASH_START,
BOOTLOADER_FLASH_END, AddressRangeType::Ignore
)
]
}
}
16 changes: 16 additions & 0 deletions src/boards/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
use crate::address_range::AddressRange;

pub trait BoardConfig {
fn flash_sector_erase_size(&self) -> u32;
fn main_ram_start(&self) -> u32;
fn main_ram_end(&self) -> u32;
fn xip_ram_start(&self) -> u32;
fn xip_ram_end(&self) -> u32;
fn family_id(&self) -> u32;

fn address_ranges_flash(&self) -> Vec<AddressRange>;
fn address_range_ram(&self) -> Vec<AddressRange>;
}

pub mod rp2040;
pub mod circuit_playground_bluefruit;
63 changes: 63 additions & 0 deletions src/boards/rp2040.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
use crate::address_range::{AddressRange, AddressRangeType};

use super::BoardConfig;

const FLASH_SECTOR_ERASE_SIZE: u32 = 4096;
const MAIN_RAM_START: u32 = 0x20000000;
const MAIN_RAM_END: u32 = 0x20042000;
const FLASH_START: u32 = 0x10000000;
const FLASH_END: u32 = 0x15000000;
const XIP_SRAM_START: u32 = 0x15000000;
const XIP_SRAM_END: u32 = 0x15004000;
const MAIN_RAM_BANKED_START: u32 = 0x21000000;
const MAIN_RAM_BANKED_END: u32 = 0x21040000;
const ROM_START: u32 = 0x00000000;
const ROM_END: u32 = 0x00004000;

pub struct RP2040 {}

impl BoardConfig for RP2040 {
fn flash_sector_erase_size(&self) -> u32 {
FLASH_SECTOR_ERASE_SIZE
}

fn main_ram_start(&self) -> u32 {
MAIN_RAM_START
}

fn main_ram_end(&self) -> u32 {
MAIN_RAM_END
}

fn xip_ram_start(&self) -> u32 {
XIP_SRAM_START
}

fn xip_ram_end(&self) -> u32 {
XIP_SRAM_END
}

fn family_id(&self) -> u32 {
0xe48bff56
}

fn address_ranges_flash(&self) -> Vec<AddressRange> {
vec![
AddressRange::new(FLASH_START, FLASH_END, AddressRangeType::Contents),
AddressRange::new(MAIN_RAM_START, MAIN_RAM_END, AddressRangeType::NoContents),
AddressRange::new(
MAIN_RAM_BANKED_START,
MAIN_RAM_BANKED_END,
AddressRangeType::NoContents,
)
]
}

fn address_range_ram(&self) -> Vec<AddressRange> {
vec![
AddressRange::new(MAIN_RAM_START, MAIN_RAM_END, AddressRangeType::Contents),
AddressRange::new(XIP_SRAM_START, XIP_SRAM_END, AddressRangeType::Contents),
AddressRange::new(ROM_START, ROM_END, AddressRangeType::Ignore), // for now we ignore the bootrom if present
]
}
}
8 changes: 4 additions & 4 deletions src/elf.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use crate::{
address_range::{self, AddressRange, RP2040_ADDRESS_RANGES_FLASH, RP2040_ADDRESS_RANGES_RAM},
Opts,
address_range::{self, AddressRange}, boards::BoardConfig, get_board_config, Opts
};
use assert_into::AssertInto;
use std::{
Expand Down Expand Up @@ -107,9 +106,10 @@ impl Elf32Header {
// so call THAT a flash binary
if self.entry >= entry.vaddr && self.entry < entry.vaddr + mapped_size {
let effective_entry = self.entry + entry.paddr - entry.vaddr;
if RP2040_ADDRESS_RANGES_RAM.is_address_initialized(effective_entry) {
let board_config: Box<dyn BoardConfig> = get_board_config();
if board_config.address_range_ram().iter().is_address_initialized(effective_entry) {
return Some(true);
} else if RP2040_ADDRESS_RANGES_FLASH
} else if board_config.address_ranges_flash().iter()
.is_address_initialized(effective_entry)
{
return Some(false);
Expand Down
Loading