Bootloader restore

The rust situation is a bit of a pickle atm. Disasm is working on getting it working using .cargo/config that specifies the memory layout provided by a new version of the hifive1 crate and a patched version of the rust-rt crate. You can find that all in his workspace here.

NOTE: all those repos are modified, so if you get the originals/master branches it won’t work.

You can also use the current versions of all the crates and get the same result by providing your own memory.x file with

{
	RAM : ORIGIN = 0x80000000, LENGTH = 0x4000
	FLASH : ORIGIN = 0x20010000, LENGTH = 0x6a120
}

that will force it to go to 0x20010000 as a workaround for now. The way this works is that the risc-rt crate provides a link.x with all the section definitions, but it expects a INCLUDE memory.x on linktime in there. By providing one with the right offset you override the default old-version hifive1 one. That’s how I do it atm. but I don’t have any repo published yet.

You need the memory.x file to be placed in the right build directory by creating a build.rs file in your project root with:

use std::{env, fs};
use std::path::PathBuf;
use std::io::Write;

fn main() {
    // Put the linker script somewhere the linker can find it
    let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
    println!("cargo:rustc-link-search={}", out_dir.display());

    fs::File::create(out_dir.join("memory.x")).unwrap()
        .write_all(include_bytes!("memory.x")).unwrap();
    println!("cargo:rerun-if-changed=memory.x");
}

WARNING: make sure to check the final binary (elf) with riscv objdump to ensure it was linked properly and points to 0x20010000 as entrypoint before attempting an upload, otherwise you’ll wipe the bootloader again :smiley:

Hope this helps for now, I plan to put some things together and start a blog series about all the little tidbits as I go along.

1 Like