adjust link.x based on board target

EVB is ram-based, uses jtag to load
baosec is rom-based, uses python script to load
This commit is contained in:
bunnie 2025-08-08 03:37:56 +08:00
parent a22cf7f58c
commit ee3cae2a8b

View file

@ -7,7 +7,7 @@ use utils::*;
mod builder;
use builder::*;
mod verifier;
use std::{env, fs, path::PathBuf};
use std::{env, fs, path::Path, path::PathBuf};
use verifier::*;
@ -649,6 +649,14 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
Some("baremetal-cramsoc") => {
builder.set_baremetal(true);
update_flash_origin("baremetal/src/platform/cramium/link.x", 0x6000_0000)?;
builder.target_baremetal_cramsoc();
}
Some("baremetal-cramsoc-evb") => {
builder.set_baremetal(true);
update_flash_origin("baremetal/src/platform/cramium/link.x", 0x6100_0000)?;
builder.add_loader_feature("nto-evb");
builder.target_baremetal_cramsoc();
}
@ -1030,3 +1038,24 @@ fn locate_workspace_root() -> Option<PathBuf> {
}
Some(dir)
}
fn update_flash_origin<P: AsRef<Path>>(path: P, new_origin: u32) -> std::io::Result<()> {
let content = fs::read_to_string(&path)?;
let updated = content
.lines()
.map(|line| {
if line.trim_start().starts_with("FLASH") && line.contains("ORIGIN") {
let parts: Vec<&str> = line.split(',').collect();
let origin_part = format!("ORIGIN = 0x{:08X}", new_origin);
let length_part = parts.iter().find(|s| s.trim().starts_with("LENGTH")).unwrap_or(&"");
format!(" FLASH : {}, {}", origin_part, length_part.trim())
} else {
line.to_string()
}
})
.collect::<Vec<String>>()
.join("\n");
fs::write(path, updated)?;
Ok(())
}