Skip to content

Commit

Permalink
Now builds on stable.
Browse files Browse the repository at this point in the history
Tested working with probe-rs CLI. Slightly larger binary, but I can live with that for not having to use nightly rust.
  • Loading branch information
thejpster committed Dec 8, 2023
1 parent 1bf17aa commit a141ca3
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 40 deletions.
5 changes: 0 additions & 5 deletions .cargo/config
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
[unstable]
build-std = ["core"]
build-std-features = ["panic_immediate_abort"]

[target.'cfg(all(target_arch = "arm", target_os = "none"))']

rustflags = [
"-C", "link-arg=--nmagic",
"-C", "link-arg=-Tlink.x",

# Code-size optimizations.
"-Z", "trap-unreachable=no",
"-C", "inline-threshold=5",
"-C", "no-vectorize-loops",
"-C", "force-frame-pointers=no",
Expand Down
5 changes: 0 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,12 @@ env:

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Install Dependencies
run: |
sudo apt update
rustup component add rust-src
cargo install cargo-binutils
rustup component add llvm-tools-preview
- name: Build
run: |
./build.sh
Expand Down
16 changes: 10 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,27 @@ It implements the CMSIS-Pack ABI, so it's compatible with any tools that use it,

## Dependencies

Run the following requirements:
Run the following to install the requirements:

```bash
cargo install cargo-binutils && rustup component add llvm-tools-preview rust-src
cargo install cargo-binutils
```
## Building

Building requires nightly Rust.
The `rust-toolchain` file will get you the targets and components you need.

## Building

Just run `build.sh`. It spits out the flash algo in the probe-rs YAML format:

flash-algo$ ./build.sh
```console
flash-algo$ ./build.sh
instructions: sLUUIACIGUoBRguI...wRwAgcEc=
pc_init: 0x00000000
pc_uninit: 0x0000007c
pc_program_page: 0x00000088
pc_erase_sector: 0x00000084
pc_erase_all: 0x00000080
```

## Hacking

Expand All @@ -30,7 +34,7 @@ the glue functions for a given struct implementing it. This is generic for all c

`main.rs` has the actual implementation for RP2040.

# License
## License

This thingy is licensed under either of

Expand Down
6 changes: 5 additions & 1 deletion rust-toolchain
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
nightly
[toolchain]
channel = "stable"
components = [ "llvm-tools" ]
profile = "minimal"
targets = ["thumbv6m-none-eabi"]
6 changes: 1 addition & 5 deletions src/algo.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#![macro_use]


use core::arch::asm;
use core::num::NonZeroU32;

#[panic_handler]
Expand All @@ -11,10 +11,6 @@ fn panic(_info: &core::panic::PanicInfo) -> ! {
}
}

pub const FUNCTION_ERASE: u32 = 1;
pub const FUNCTION_PROGRAM: u32 = 2;
pub const FUNCTION_VERIFY: u32 = 3;

pub type ErrorCode = NonZeroU32;

pub trait FlashAlgo: Sized + 'static {
Expand Down
25 changes: 7 additions & 18 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,31 +1,21 @@
#![no_std]
#![no_main]
#![feature(asm)]

mod algo;

use core::mem;
use core::mem::MaybeUninit;

use self::algo::*;

fn find_func<T>(tag: [u8; 2]) -> T {
let tag = u16::from_le_bytes(tag);

let tag = u16::from_le_bytes(tag) as u32;
type RomTableLookupFn = unsafe extern "C" fn(table: *const u16, code: u32) -> usize;
unsafe {
let mut entry = *(0x00000014 as *const u16) as *const u16;
loop {
let entry_tag = entry.read();
if entry_tag == 0 {
panic!("Func not found");
}
entry = entry.add(1);
let entry_addr = entry.read();
entry = entry.add(1);
if entry_tag == tag {
return mem::transmute_copy(&(entry_addr as u32));
}
}
let lookup_func = core::ptr::read(0x0000_0018 as *const u16) as usize;
let lookup_func: RomTableLookupFn = core::mem::transmute(lookup_func);
let table = core::ptr::read(0x0000_00014 as *const u16) as usize;
let result = lookup_func(table as *const u16, tag);
core::mem::transmute_copy(&result)
}
}

Expand Down Expand Up @@ -59,7 +49,6 @@ algo!(RP2040Algo);

const BLOCK_SIZE: u32 = 65536;
const SECTOR_SIZE: u32 = 4096;
const PAGE_SIZE: u32 = 256;
const BLOCK_ERASE_CMD: u8 = 0xd8;
const FLASH_BASE: u32 = 0x1000_0000;

Expand Down

0 comments on commit a141ca3

Please sign in to comment.