From 7b59c9e76d42372fb74a4db0bff0394e3347e0f2 Mon Sep 17 00:00:00 2001 From: bjoernQ Date: Fri, 18 Feb 2022 12:00:05 +0100 Subject: [PATCH] Move linker scripts to sub-folders --- esp-hal-common/src/interrupt/riscv.rs | 3 ++- esp-hal-procmacros/src/lib.rs | 3 +-- esp32-hal/.cargo/config.toml | 4 ++-- esp32-hal/build.rs | 11 ++++++---- esp32-hal/{ => ld}/hal-defaults.x | 0 esp32-hal/ld/linkall.x | 2 ++ esp32-hal/{ => ld}/memory.x | 0 esp32-hal/{ => ld}/rom.x | 0 esp32c3-hal/.cargo/config.toml | 2 ++ esp32c3-hal/build.rs | 26 +++++++++++++++--------- esp32c3-hal/examples/hello_world.rs | 2 +- esp32c3-hal/{ => ld}/bl-esp32c3-memory.x | 0 esp32c3-hal/ld/bl-linkall.x | 3 +++ esp32c3-hal/{ => ld}/bl-riscv-link.x | 0 esp32c3-hal/{ => ld}/db-esp32c3-link.x | 0 esp32c3-hal/{ => ld}/db-esp32c3-memory.x | 0 esp32c3-hal/ld/db-linkall.x | 2 ++ esp32c3-hal/{ => ld}/db-riscv-link.x | 0 esp32c3-hal/{ => ld}/hal-defaults.x | 0 esp32s2-hal/.cargo/config.toml | 4 ++-- esp32s2-hal/build.rs | 11 ++++++---- esp32s2-hal/{ => ld}/hal-defaults.x | 0 esp32s2-hal/ld/linkall.x | 2 ++ esp32s2-hal/{ => ld}/memory.x | 0 esp32s2-hal/{ => ld}/rom.x | 0 esp32s2-hal/src/lib.rs | 2 +- esp32s3-hal/.cargo/config.toml | 4 ++-- esp32s3-hal/build.rs | 13 +++++++----- esp32s3-hal/{ => ld}/esp32s3.x | 0 esp32s3-hal/{ => ld}/hal-defaults.x | 0 esp32s3-hal/ld/linkall.x | 2 ++ esp32s3-hal/{ => ld}/memory.x | 0 esp32s3-hal/{ => ld}/rom.x | 0 33 files changed, 62 insertions(+), 34 deletions(-) rename esp32-hal/{ => ld}/hal-defaults.x (100%) create mode 100644 esp32-hal/ld/linkall.x rename esp32-hal/{ => ld}/memory.x (100%) rename esp32-hal/{ => ld}/rom.x (100%) rename esp32c3-hal/{ => ld}/bl-esp32c3-memory.x (100%) create mode 100644 esp32c3-hal/ld/bl-linkall.x rename esp32c3-hal/{ => ld}/bl-riscv-link.x (100%) rename esp32c3-hal/{ => ld}/db-esp32c3-link.x (100%) rename esp32c3-hal/{ => ld}/db-esp32c3-memory.x (100%) create mode 100644 esp32c3-hal/ld/db-linkall.x rename esp32c3-hal/{ => ld}/db-riscv-link.x (100%) rename esp32c3-hal/{ => ld}/hal-defaults.x (100%) rename esp32s2-hal/{ => ld}/hal-defaults.x (100%) create mode 100644 esp32s2-hal/ld/linkall.x rename esp32s2-hal/{ => ld}/memory.x (100%) rename esp32s2-hal/{ => ld}/rom.x (100%) rename esp32s3-hal/{ => ld}/esp32s3.x (100%) rename esp32s3-hal/{ => ld}/hal-defaults.x (100%) create mode 100644 esp32s3-hal/ld/linkall.x rename esp32s3-hal/{ => ld}/memory.x (100%) rename esp32s3-hal/{ => ld}/rom.x (100%) diff --git a/esp-hal-common/src/interrupt/riscv.rs b/esp-hal-common/src/interrupt/riscv.rs index 2ac5061eaf4..030ad48f6e3 100644 --- a/esp-hal-common/src/interrupt/riscv.rs +++ b/esp-hal-common/src/interrupt/riscv.rs @@ -48,7 +48,8 @@ pub enum InterruptKind { } /// Enumeration of available CPU interrupts. -/// It is possible to create a handler for each of the interrupts. (e.g. `interrupt3`) +/// It is possible to create a handler for each of the interrupts. (e.g. +/// `interrupt3`) pub enum CpuInterrupt { Interrupt1 = 1, Interrupt2, diff --git a/esp-hal-procmacros/src/lib.rs b/esp-hal-procmacros/src/lib.rs index 2050cbb8676..cdc8213d2a2 100644 --- a/esp-hal-procmacros/src/lib.rs +++ b/esp-hal-procmacros/src/lib.rs @@ -1,6 +1,5 @@ use darling::FromMeta; -use proc_macro::TokenStream; -use proc_macro::{self, Span}; +use proc_macro::{self, Span, TokenStream}; use proc_macro_error::{abort, proc_macro_error}; use quote::quote; use syn::{parse_macro_input, AttributeArgs}; diff --git a/esp32-hal/.cargo/config.toml b/esp32-hal/.cargo/config.toml index e64a8d30889..1161ee50fef 100644 --- a/esp32-hal/.cargo/config.toml +++ b/esp32-hal/.cargo/config.toml @@ -1,10 +1,10 @@ [target.xtensa-esp32-none-elf] -runner = "xtensa-esp32-elf-gdb -q -x xtensa.gdb" +runner = "espflash --monitor" [build] rustflags = [ "-C", "link-arg=-nostartfiles", - "-C", "link-arg=-Wl,-Tlink.x", + "-C", "link-arg=-Wl,-Tlinkall.x", ] target = "xtensa-esp32-none-elf" diff --git a/esp32-hal/build.rs b/esp32-hal/build.rs index ef0b853979f..e057c9ce098 100644 --- a/esp32-hal/build.rs +++ b/esp32-hal/build.rs @@ -5,20 +5,23 @@ fn main() { let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap()); File::create(out.join("memory.x")) .unwrap() - .write_all(include_bytes!("memory.x")) + .write_all(include_bytes!("ld/memory.x")) .unwrap(); File::create(out.join("alias.x")) .unwrap() - .write_all(include_bytes!("rom.x")) + .write_all(include_bytes!("ld/rom.x")) .unwrap(); File::create(out.join("hal-defaults.x")) .unwrap() - .write_all(include_bytes!("hal-defaults.x")) + .write_all(include_bytes!("ld/hal-defaults.x")) .unwrap(); - println!("cargo:rustc-link-arg=-Thal-defaults.x"); + File::create(out.join("linkall.x")) + .unwrap() + .write_all(include_bytes!("ld/linkall.x")) + .unwrap(); println!("cargo:rustc-link-search={}", out.display()); diff --git a/esp32-hal/hal-defaults.x b/esp32-hal/ld/hal-defaults.x similarity index 100% rename from esp32-hal/hal-defaults.x rename to esp32-hal/ld/hal-defaults.x diff --git a/esp32-hal/ld/linkall.x b/esp32-hal/ld/linkall.x new file mode 100644 index 00000000000..f4be5b1ec1c --- /dev/null +++ b/esp32-hal/ld/linkall.x @@ -0,0 +1,2 @@ +INCLUDE "link.x" +INCLUDE "hal-defaults.x" diff --git a/esp32-hal/memory.x b/esp32-hal/ld/memory.x similarity index 100% rename from esp32-hal/memory.x rename to esp32-hal/ld/memory.x diff --git a/esp32-hal/rom.x b/esp32-hal/ld/rom.x similarity index 100% rename from esp32-hal/rom.x rename to esp32-hal/ld/rom.x diff --git a/esp32c3-hal/.cargo/config.toml b/esp32c3-hal/.cargo/config.toml index 4fb89dfd769..d8bdbe8ac1e 100644 --- a/esp32c3-hal/.cargo/config.toml +++ b/esp32c3-hal/.cargo/config.toml @@ -1,5 +1,7 @@ [target.riscv32imc-unknown-none-elf] +runner = "espflash --format direct-boot --monitor" rustflags = [ + "-C", "link-arg=-Tlinkall.x" ] [build] diff --git a/esp32c3-hal/build.rs b/esp32c3-hal/build.rs index cb3059faeda..a5ba9a642b0 100644 --- a/esp32c3-hal/build.rs +++ b/esp32c3-hal/build.rs @@ -14,17 +14,22 @@ fn main() { File::create(out.join("memory.x")) .unwrap() - .write_all(include_bytes!("db-esp32c3-memory.x")) + .write_all(include_bytes!("ld/db-esp32c3-memory.x")) .unwrap(); File::create(out.join("esp32c3-link.x")) .unwrap() - .write_all(include_bytes!("db-esp32c3-link.x")) + .write_all(include_bytes!("ld/db-esp32c3-link.x")) .unwrap(); File::create(out.join("riscv-link.x")) .unwrap() - .write_all(include_bytes!("db-riscv-link.x")) + .write_all(include_bytes!("ld/db-riscv-link.x")) + .unwrap(); + + File::create(out.join("linkall.x")) + .unwrap() + .write_all(include_bytes!("ld/db-linkall.x")) .unwrap(); println!("cargo:rustc-link-search={}", out.display()); @@ -32,7 +37,6 @@ fn main() { // 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=memory.x"); - println!("cargo:rustc-link-arg=-Tesp32c3-link.x"); add_defaults(); prepare_trap(); @@ -44,12 +48,17 @@ fn main() { let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap()); File::create(out.join("memory.x")) .unwrap() - .write_all(include_bytes!("bl-esp32c3-memory.x")) + .write_all(include_bytes!("ld/bl-esp32c3-memory.x")) .unwrap(); File::create(out.join("bl-riscv-link.x")) .unwrap() - .write_all(include_bytes!("bl-riscv-link.x")) + .write_all(include_bytes!("ld/bl-riscv-link.x")) + .unwrap(); + + File::create(out.join("linkall.x")) + .unwrap() + .write_all(include_bytes!("ld/bl-linkall.x")) .unwrap(); println!("cargo:rustc-link-search={}", out.display()); @@ -57,8 +66,6 @@ fn main() { // 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=memory.x"); - println!("cargo:rustc-link-arg=-Tmemory.x"); - println!("cargo:rustc-link-arg=-Tbl-riscv-link.x"); add_defaults(); prepare_trap(); @@ -68,11 +75,10 @@ fn add_defaults() { let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap()); File::create(out.join("hal-defaults.x")) .unwrap() - .write_all(include_bytes!("hal-defaults.x")) + .write_all(include_bytes!("ld/hal-defaults.x")) .unwrap(); println!("cargo:rustc-link-search={}", out.display()); - println!("cargo:rustc-link-arg=-Thal-defaults.x"); } fn prepare_trap() { diff --git a/esp32c3-hal/examples/hello_world.rs b/esp32c3-hal/examples/hello_world.rs index 62fb1af1fd9..e38ebaaf383 100644 --- a/esp32c3-hal/examples/hello_world.rs +++ b/esp32c3-hal/examples/hello_world.rs @@ -29,4 +29,4 @@ fn main() -> ! { writeln!(serial0, "Hello world!").unwrap(); block!(timer0.wait()).unwrap(); } -} \ No newline at end of file +} diff --git a/esp32c3-hal/bl-esp32c3-memory.x b/esp32c3-hal/ld/bl-esp32c3-memory.x similarity index 100% rename from esp32c3-hal/bl-esp32c3-memory.x rename to esp32c3-hal/ld/bl-esp32c3-memory.x diff --git a/esp32c3-hal/ld/bl-linkall.x b/esp32c3-hal/ld/bl-linkall.x new file mode 100644 index 00000000000..9fbe9cd3584 --- /dev/null +++ b/esp32c3-hal/ld/bl-linkall.x @@ -0,0 +1,3 @@ +INCLUDE "memory.x" +INCLUDE "bl-riscv-link.x" +INCLUDE "hal-defaults.x" diff --git a/esp32c3-hal/bl-riscv-link.x b/esp32c3-hal/ld/bl-riscv-link.x similarity index 100% rename from esp32c3-hal/bl-riscv-link.x rename to esp32c3-hal/ld/bl-riscv-link.x diff --git a/esp32c3-hal/db-esp32c3-link.x b/esp32c3-hal/ld/db-esp32c3-link.x similarity index 100% rename from esp32c3-hal/db-esp32c3-link.x rename to esp32c3-hal/ld/db-esp32c3-link.x diff --git a/esp32c3-hal/db-esp32c3-memory.x b/esp32c3-hal/ld/db-esp32c3-memory.x similarity index 100% rename from esp32c3-hal/db-esp32c3-memory.x rename to esp32c3-hal/ld/db-esp32c3-memory.x diff --git a/esp32c3-hal/ld/db-linkall.x b/esp32c3-hal/ld/db-linkall.x new file mode 100644 index 00000000000..8eb0c0d6c07 --- /dev/null +++ b/esp32c3-hal/ld/db-linkall.x @@ -0,0 +1,2 @@ +INCLUDE "esp32c3-link.x" +INCLUDE "hal-defaults.x" \ No newline at end of file diff --git a/esp32c3-hal/db-riscv-link.x b/esp32c3-hal/ld/db-riscv-link.x similarity index 100% rename from esp32c3-hal/db-riscv-link.x rename to esp32c3-hal/ld/db-riscv-link.x diff --git a/esp32c3-hal/hal-defaults.x b/esp32c3-hal/ld/hal-defaults.x similarity index 100% rename from esp32c3-hal/hal-defaults.x rename to esp32c3-hal/ld/hal-defaults.x diff --git a/esp32s2-hal/.cargo/config.toml b/esp32s2-hal/.cargo/config.toml index e1b5c081e8a..6518c11d6a9 100644 --- a/esp32s2-hal/.cargo/config.toml +++ b/esp32s2-hal/.cargo/config.toml @@ -1,10 +1,10 @@ [target.xtensa-esp32s2-none-elf] -runner = "xtensa-esp32s2-elf-gdb -q -x xtensa.gdb" +runner = "espflash --monitor" [build] rustflags = [ "-C", "link-arg=-nostartfiles", - "-C", "link-arg=-Wl,-Tlink.x", + "-C", "link-arg=-Wl,-Tlinkall.x", ] target = "xtensa-esp32s2-none-elf" diff --git a/esp32s2-hal/build.rs b/esp32s2-hal/build.rs index ef0b853979f..e057c9ce098 100644 --- a/esp32s2-hal/build.rs +++ b/esp32s2-hal/build.rs @@ -5,20 +5,23 @@ fn main() { let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap()); File::create(out.join("memory.x")) .unwrap() - .write_all(include_bytes!("memory.x")) + .write_all(include_bytes!("ld/memory.x")) .unwrap(); File::create(out.join("alias.x")) .unwrap() - .write_all(include_bytes!("rom.x")) + .write_all(include_bytes!("ld/rom.x")) .unwrap(); File::create(out.join("hal-defaults.x")) .unwrap() - .write_all(include_bytes!("hal-defaults.x")) + .write_all(include_bytes!("ld/hal-defaults.x")) .unwrap(); - println!("cargo:rustc-link-arg=-Thal-defaults.x"); + File::create(out.join("linkall.x")) + .unwrap() + .write_all(include_bytes!("ld/linkall.x")) + .unwrap(); println!("cargo:rustc-link-search={}", out.display()); diff --git a/esp32s2-hal/hal-defaults.x b/esp32s2-hal/ld/hal-defaults.x similarity index 100% rename from esp32s2-hal/hal-defaults.x rename to esp32s2-hal/ld/hal-defaults.x diff --git a/esp32s2-hal/ld/linkall.x b/esp32s2-hal/ld/linkall.x new file mode 100644 index 00000000000..f4be5b1ec1c --- /dev/null +++ b/esp32s2-hal/ld/linkall.x @@ -0,0 +1,2 @@ +INCLUDE "link.x" +INCLUDE "hal-defaults.x" diff --git a/esp32s2-hal/memory.x b/esp32s2-hal/ld/memory.x similarity index 100% rename from esp32s2-hal/memory.x rename to esp32s2-hal/ld/memory.x diff --git a/esp32s2-hal/rom.x b/esp32s2-hal/ld/rom.x similarity index 100% rename from esp32s2-hal/rom.x rename to esp32s2-hal/ld/rom.x diff --git a/esp32s2-hal/src/lib.rs b/esp32s2-hal/src/lib.rs index 44fe037d922..4ee90230738 100644 --- a/esp32s2-hal/src/lib.rs +++ b/esp32s2-hal/src/lib.rs @@ -1,7 +1,7 @@ #![no_std] pub use embedded_hal as ehal; -pub use esp_hal_common::{pac, prelude, Delay, Serial, Timer, ram}; +pub use esp_hal_common::{pac, prelude, ram, Delay, Serial, Timer}; #[no_mangle] extern "C" fn DefaultHandler(_level: u32, _interrupt: pac::Interrupt) {} diff --git a/esp32s3-hal/.cargo/config.toml b/esp32s3-hal/.cargo/config.toml index 9b1b1e67534..cd11d7d0014 100644 --- a/esp32s3-hal/.cargo/config.toml +++ b/esp32s3-hal/.cargo/config.toml @@ -1,10 +1,10 @@ [target.xtensa-esp32s3-none-elf] -runner = "xtensa-esp32s3-elf-gdb -q -x xtensa.gdb" +runner = "espflash --monitor" [build] rustflags = [ "-C", "link-arg=-nostartfiles", - "-C", "link-arg=-Wl,-Tesp32s3.x", + "-C", "link-arg=-Wl,-Tlinkall.x", ] target = "xtensa-esp32s3-none-elf" diff --git a/esp32s3-hal/build.rs b/esp32s3-hal/build.rs index 970b42d9fcc..72225eec41c 100644 --- a/esp32s3-hal/build.rs +++ b/esp32s3-hal/build.rs @@ -5,25 +5,28 @@ fn main() { let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap()); File::create(out.join("memory.x")) .unwrap() - .write_all(include_bytes!("memory.x")) + .write_all(include_bytes!("ld/memory.x")) .unwrap(); File::create(out.join("alias.x")) .unwrap() - .write_all(include_bytes!("rom.x")) + .write_all(include_bytes!("ld/rom.x")) .unwrap(); File::create(out.join("hal-defaults.x")) .unwrap() - .write_all(include_bytes!("hal-defaults.x")) + .write_all(include_bytes!("ld/hal-defaults.x")) .unwrap(); File::create(out.join("esp32s3.x")) .unwrap() - .write_all(include_bytes!("esp32s3.x")) + .write_all(include_bytes!("ld/esp32s3.x")) .unwrap(); - println!("cargo:rustc-link-arg=-Thal-defaults.x"); + File::create(out.join("linkall.x")) + .unwrap() + .write_all(include_bytes!("ld/linkall.x")) + .unwrap(); println!("cargo:rustc-link-search={}", out.display()); diff --git a/esp32s3-hal/esp32s3.x b/esp32s3-hal/ld/esp32s3.x similarity index 100% rename from esp32s3-hal/esp32s3.x rename to esp32s3-hal/ld/esp32s3.x diff --git a/esp32s3-hal/hal-defaults.x b/esp32s3-hal/ld/hal-defaults.x similarity index 100% rename from esp32s3-hal/hal-defaults.x rename to esp32s3-hal/ld/hal-defaults.x diff --git a/esp32s3-hal/ld/linkall.x b/esp32s3-hal/ld/linkall.x new file mode 100644 index 00000000000..551a29d70ad --- /dev/null +++ b/esp32s3-hal/ld/linkall.x @@ -0,0 +1,2 @@ +INCLUDE "esp32s3.x" +INCLUDE "hal-defaults.x" diff --git a/esp32s3-hal/memory.x b/esp32s3-hal/ld/memory.x similarity index 100% rename from esp32s3-hal/memory.x rename to esp32s3-hal/ld/memory.x diff --git a/esp32s3-hal/rom.x b/esp32s3-hal/ld/rom.x similarity index 100% rename from esp32s3-hal/rom.x rename to esp32s3-hal/ld/rom.x