Skip to content

Commit

Permalink
Move remaining device-specific linker scripts into esp-hal-common (#…
Browse files Browse the repository at this point in the history
…963)

* Move remaining linker scripts to `esp-hal-common`, rename as needed

* Update build scripts
  • Loading branch information
jessebraham authored Nov 20, 2023
1 parent 15f4dad commit 04f63b7
Show file tree
Hide file tree
Showing 36 changed files with 23 additions and 73 deletions.
8 changes: 6 additions & 2 deletions esp-hal-common/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,12 +208,14 @@ fn main() -> Result<(), Box<dyn Error>> {
println!("cargo:rustc-link-search={}", out.display());

if cfg!(feature = "esp32") || cfg!(feature = "esp32s2") || cfg!(feature = "esp32s3") {
fs::copy("ld/xtensa/hal-defaults.x", out.join("hal-defaults.x")).unwrap();
fs::copy("ld/xtensa/hal-defaults.x", out.join("hal-defaults.x"))?;

let (irtc, drtc) = if cfg!(feature = "esp32s3") {
("rtc_fast_seg", "rtc_fast_seg")
} else {
("rtc_fast_iram_seg", "rtc_fast_dram_seg")
};

let alias = format!(
r#"
REGION_ALIAS("ROTEXT", irom_seg);
Expand All @@ -225,14 +227,16 @@ fn main() -> Result<(), Box<dyn Error>> {
"#,
irtc, drtc
);
fs::write(out.join("alias.x"), alias).unwrap();

fs::write(out.join("alias.x"), alias)?;
} else {
fs::copy("ld/riscv/hal-defaults.x", out.join("hal-defaults.x"))?;
fs::copy("ld/riscv/asserts.x", out.join("asserts.x"))?;
fs::copy("ld/riscv/debug.x", out.join("debug.x"))?;
}

copy_dir_all("ld/sections", &out)?;
copy_dir_all(format!("ld/{device_name}"), &out)?;

// Generate the eFuse table from the selected device's CSV file:
gen_efuse_table(device_name, out)?;
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions esp32-hal/ld/linkall.x → esp-hal-common/ld/esp32/linkall.x
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
INCLUDE "memory.x"
INCLUDE "alias.x"
INCLUDE "link-esp32.x"
INCLUDE "esp32.x"
INCLUDE "hal-defaults.x"
INCLUDE "rom-functions.x"
INCLUDE "rom-functions.x"
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ REGION_ALIAS("RODATA", DROM);
REGION_ALIAS("RWDATA", DRAM);
REGION_ALIAS("RWTEXT", IRAM);

INCLUDE "bl-riscv-link.x"
INCLUDE "esp32c2.x"
INCLUDE "hal-defaults.x"
INCLUDE "rom-functions.x"
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ REGION_ALIAS("RWTEXT", IRAM);
REGION_ALIAS("RTC_FAST_RWTEXT", RTC_FAST);
REGION_ALIAS("RTC_FAST_RWDATA", RTC_FAST);

INCLUDE "bl-riscv-link.x"
INCLUDE "esp32c3.x"
INCLUDE "hal-defaults.x"
INCLUDE "rom-functions.x"
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ REGION_ALIAS("RWDATA", RAM);
REGION_ALIAS("RTC_FAST_RWTEXT", RTC_FAST);
REGION_ALIAS("RTC_FAST_RWDATA", RTC_FAST);

INCLUDE "bl-riscv-link.x"
INCLUDE "esp32c6.x"
INCLUDE "hal-defaults.x"
INCLUDE "rom-functions.x"
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ REGION_ALIAS("RWDATA", RAM);
REGION_ALIAS("RTC_FAST_RWTEXT", RTC_FAST);
REGION_ALIAS("RTC_FAST_RWDATA", RTC_FAST);

INCLUDE "bl-riscv-link.x"
INCLUDE "esp32h2.x"
INCLUDE "hal-defaults.x"
INCLUDE "rom-functions.x"
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
INCLUDE "memory.x"
INCLUDE "alias.x"
INCLUDE "link-esp32s2.x"
INCLUDE "esp32s2.x"
INCLUDE "hal-defaults.x"
INCLUDE "rom-functions.x"
INCLUDE "rom-functions.x"
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
INCLUDE "memory.x"
INCLUDE "alias.x"
INCLUDE "link-esp32s3.x"
INCLUDE "esp32s3.x"
INCLUDE "hal-defaults.x"
INCLUDE "rom-functions.x"
INCLUDE "rom-functions.x"
File renamed without changes.
File renamed without changes.
14 changes: 1 addition & 13 deletions esp32-hal/build.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,10 @@
use std::{
env,
error::Error,
fs::{self, File},
io::Write,
path::PathBuf,
};
use std::{env, error::Error, fs::File, io::Write, path::PathBuf};

fn main() -> Result<(), Box<dyn Error>> {
// Put the linker script somewhere the linker can find it
let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap());
println!("cargo:rustc-link-search={}", out.display());

fs::copy("ld/memory.x", out.join("memory.x"))?;
fs::copy("ld/link-esp32.x", out.join("link-esp32.x"))?;
fs::copy("ld/linkall.x", out.join("linkall.x"))?;

fs::copy("ld/rom-functions.x", out.join("rom-functions.x"))?;

let memory_extras = generate_memory_extras();
File::create(out.join("memory_extras.x"))?.write_all(&memory_extras)?;

Expand Down
8 changes: 1 addition & 7 deletions esp32c2-hal/build.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{env, error::Error, fs, path::PathBuf};
use std::{env, error::Error, path::PathBuf};

fn main() -> Result<(), Box<dyn Error>> {
check_features();
Expand All @@ -7,12 +7,6 @@ fn main() -> Result<(), Box<dyn Error>> {
let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap());
println!("cargo:rustc-link-search={}", out.display());

fs::copy("ld/bl-esp32c2-memory.x", out.join("memory.x")).unwrap();
fs::copy("ld/bl-riscv-link.x", out.join("bl-riscv-link.x")).unwrap();
fs::copy("ld/bl-linkall.x", out.join("linkall.x")).unwrap();

fs::copy("ld/rom-functions.x", out.join("rom-functions.x"))?;

// Only re-run the build script when memory.x is changed,
// instead of when any part of the source code changes.
println!("cargo:rerun-if-changed=ld/memory.x");
Expand Down
8 changes: 1 addition & 7 deletions esp32c3-hal/build.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
use std::{env, error::Error, fs, path::PathBuf};
use std::{env, error::Error, path::PathBuf};

fn main() -> Result<(), Box<dyn Error>> {
// Put the linker script somewhere the linker can find it
let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap());
println!("cargo:rustc-link-search={}", out.display());

fs::copy("ld/bl-esp32c3-memory.x", out.join("memory.x"))?;
fs::copy("ld/bl-riscv-link.x", out.join("bl-riscv-link.x"))?;
fs::copy("ld/bl-linkall.x", out.join("linkall.x"))?;

fs::copy("ld/rom-functions.x", out.join("rom-functions.x"))?;

// Only re-run the build script when memory.x is changed,
// instead of when any part of the source code changes.
println!("cargo:rerun-if-changed=ld/memory.x");
Expand Down
8 changes: 1 addition & 7 deletions esp32c6-hal/build.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
use std::{env, error::Error, fs, path::PathBuf};
use std::{env, error::Error, path::PathBuf};

fn main() -> Result<(), Box<dyn Error>> {
// Put the linker script somewhere the linker can find it
let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap());
println!("cargo:rustc-link-search={}", out.display());

fs::copy("ld/bl-esp32c6-memory.x", out.join("memory.x"))?;
fs::copy("ld/bl-riscv-link.x", out.join("bl-riscv-link.x"))?;
fs::copy("ld/bl-linkall.x", out.join("linkall.x"))?;

fs::copy("ld/rom-functions.x", out.join("rom-functions.x"))?;

// Only re-run the build script when memory.x is changed,
// instead of when any part of the source code changes.
println!("cargo:rerun-if-changed=ld/memory.x");
Expand Down
8 changes: 1 addition & 7 deletions esp32h2-hal/build.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
use std::{env, error::Error, fs, path::PathBuf};
use std::{env, error::Error, path::PathBuf};

fn main() -> Result<(), Box<dyn Error>> {
// Put the linker script somewhere the linker can find it
let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap());
println!("cargo:rustc-link-search={}", out.display());

fs::copy("ld/bl-esp32h2-memory.x", out.join("memory.x"))?;
fs::copy("ld/bl-riscv-link.x", out.join("bl-riscv-link.x"))?;
fs::copy("ld/bl-linkall.x", out.join("linkall.x"))?;

fs::copy("ld/rom-functions.x", out.join("rom-functions.x"))?;

// Only re-run the build script when memory.x is changed,
// instead of when any part of the source code changes.
println!("cargo:rerun-if-changed=ld/memory.x");
Expand Down
14 changes: 1 addition & 13 deletions esp32s2-hal/build.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,10 @@
use std::{
env,
error::Error,
fs::{self, File},
io::Write,
path::PathBuf,
};
use std::{env, error::Error, fs::File, io::Write, path::PathBuf};

fn main() -> Result<(), Box<dyn Error>> {
// Put the linker script somewhere the linker can find it
let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap());
println!("cargo:rustc-link-search={}", out.display());

fs::copy("ld/memory.x", out.join("memory.x"))?;
fs::copy("ld/link-esp32s2.x", out.join("link-esp32s2.x"))?;
fs::copy("ld/linkall.x", out.join("linkall.x"))?;

fs::copy("ld/rom-functions.x", out.join("rom-functions.x"))?;

let memory_extras = generate_memory_extras();
File::create(out.join("memory_extras.x"))?.write_all(&memory_extras)?;

Expand Down
8 changes: 1 addition & 7 deletions esp32s3-hal/build.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
use std::{env, error::Error, fs, path::PathBuf};
use std::{env, error::Error, path::PathBuf};

fn main() -> Result<(), Box<dyn Error>> {
// Put the linker script somewhere the linker can find it
let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap());
println!("cargo:rustc-link-search={}", out.display());

fs::copy("ld/memory.x", out.join("memory.x"))?;
fs::copy("ld/link-esp32s3.x", out.join("link-esp32s3.x"))?;
fs::copy("ld/linkall.x", out.join("linkall.x"))?;

fs::copy("ld/rom-functions.x", out.join("rom-functions.x"))?;

// Only re-run the build script when memory.x is changed,
// instead of when any part of the source code changes.
println!("cargo:rerun-if-changed=ld/memory.x");
Expand Down

0 comments on commit 04f63b7

Please sign in to comment.