use std::env; use std::fs; use std::path::PathBuf; const LINKER_SCRIPT_FILENAME: &str = "rustsbi-jh7110.ld"; const FLASH: &[u8] = br#" OUTPUT_ARCH(riscv) ENTRY(_start) MEMORY { SRAM : ORIGIN = 0x08000000, LENGTH = 0x200000 FLASH : ORIGIN = 0x21000000, LENGTH = 0x8000000 RAM : ORIGIN = 0x40000000, LENGTH = 0x80000000 } SECTIONS { .head : { *(.head.text) } > SRAM .text : { KEEP(*(.text.entry)) *(.text .text.*) . = ALIGN(8); } > SRAM .trap : { *(.trap .trap.*) . = ALIGN(8); } > SRAM .bss : { _sbss = .; *(.bss .bss.*); _ebss = .; } > SRAM .rodata : { *(.rodata .rodata.*); } > SRAM #FLASH .data : { _sdata = .; *(.data .data.*); _edata = .; } > SRAM _sidata = LOADADDR(.data); /DISCARD/ : { *(.eh_frame) *(.debug_*) *(.comment*) } } _max_hart_id = 4;"#; fn main() { let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap()); // Put the linker script somewhere the linker can find it. fs::write(out_dir.join(LINKER_SCRIPT_FILENAME), FLASH).unwrap(); println!("cargo:rustc-link-search={}", out_dir.display()); println!("cargo:rerun-if-changed=build.rs"); }