From 72e914069c6bde59c9999bcc80e08bc3aaca4dde Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Sat, 25 Aug 2018 19:26:05 +0200 Subject: [PATCH 1/7] use LLD as the default linker closes #39 --- .cargo/config | 45 +++++++++++++++++++++++++++++++++++++-------- src/lib.rs | 9 +++++---- 2 files changed, 42 insertions(+), 12 deletions(-) diff --git a/.cargo/config b/.cargo/config index 5999ced..b84a4d2 100644 --- a/.cargo/config +++ b/.cargo/config @@ -1,27 +1,56 @@ [target.thumbv6m-none-eabi] runner = 'arm-none-eabi-gdb' rustflags = [ - "-C", "link-arg=-Wl,-Tlink.x", - "-C", "link-arg=-nostartfiles", + # LLD (shipped with the Rust toolchain) is used as the default linker + "-C", "link-arg=-Tlink.x", + + # if you run into problems with LLD switch to the GNU linker by commenting out + # this line + # "-C", "linker=arm-none-eabi-ld", + + # if you need to link to pre-compiled C libraries provided by a C toolchain + # use GCC as the linker by commenting out both lines above and then + # uncommenting the three lines below + # "-C", "linker=arm-none-eabi-gcc", + # "-C", "link-arg=-Wl,-Tlink.x", + # "-C", "link-arg=-nostartfiles", ] [target.thumbv7m-none-eabi] runner = 'arm-none-eabi-gdb' rustflags = [ - "-C", "link-arg=-Wl,-Tlink.x", - "-C", "link-arg=-nostartfiles", + # the comments under `[target.thumbv6m-none-eabi]` also apply here + "-C", "link-arg=-Tlink.x", + + # "-C", "linker=arm-none-eabi-ld", + + # "-C", "linker=arm-none-eabi-gcc", + # "-C", "link-arg=-Wl,-Tlink.x", + # "-C", "link-arg=-nostartfiles", ] [target.thumbv7em-none-eabi] runner = 'arm-none-eabi-gdb' rustflags = [ - "-C", "link-arg=-Wl,-Tlink.x", - "-C", "link-arg=-nostartfiles", + # the comments under `[target.thumbv6m-none-eabi]` also apply here + "-C", "link-arg=-Tlink.x", + + # "-C", "linker=arm-none-eabi-ld", + + # "-C", "linker=arm-none-eabi-gcc", + # "-C", "link-arg=-Wl,-Tlink.x", + # "-C", "link-arg=-nostartfiles", ] [target.thumbv7em-none-eabihf] runner = 'arm-none-eabi-gdb' rustflags = [ - "-C", "link-arg=-Wl,-Tlink.x", - "-C", "link-arg=-nostartfiles", + # the comments under `[target.thumbv6m-none-eabi]` also apply here + "-C", "link-arg=-Tlink.x", + + # "-C", "linker=arm-none-eabi-ld", + + # "-C", "linker=arm-none-eabi-gcc", + # "-C", "link-arg=-Wl,-Tlink.x", + # "-C", "link-arg=-nostartfiles", ] diff --git a/src/lib.rs b/src/lib.rs index 686b362..9246535 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -4,7 +4,6 @@ //! //! - Nightly Rust toolchain newer than `nightly-2018-04-08`: `rustup default nightly` //! - Cargo `clone` subcommand: `cargo install cargo-clone` -//! - ARM toolchain: `sudo apt-get install gcc-arm-none-eabi` (on Ubuntu) //! - GDB: `sudo apt-get install gdb-arm-none-eabi` (on Ubuntu) //! - OpenOCD: `sudo apt-get install OpenOCD` (on Ubuntu) //! - [Optional] Cargo `add` subcommand: `cargo install cargo-edit` @@ -179,11 +178,13 @@ //! ``` text //! $ cargo build //! Compiling demo v0.1.0 (file:///home/japaric/tmp/demo) -//! error: linking with `arm-none-eabi-ld` failed: exit code: 1 +//! error: linking with `rust-lld` failed: exit code: 1 //! | -//! = note: "arm-none-eabi-gcc" "-L" (..) +//! = note: "rust-lld" "-flavor" "gnu" "-L" (..) +//! (..) +//! = note: rust-lld: error: section '.vector_table' will not fit in region 'FLASH': overflowed by X bytes +//! rust-lld: error: section '.vector_table' will not fit in region 'FLASH': overflowed by Y bytes //! (..) -//! (..)/ld: region `FLASH' overflowed by XXX bytes //! ``` //! //! Solution: Specify your device memory layout in the `memory.x` linker script. See [Usage] From 34d34975c365cc5e2da3f1e9e63d7d00d0166501 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Mon, 27 Aug 2018 15:19:48 +0200 Subject: [PATCH 2/7] update symptom for the 'overwrite .cargo/config' problem --- src/lib.rs | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 9246535..548fead 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -207,24 +207,15 @@ //! //! ## Overwrote the original `.cargo/config` file //! -//! Error message: +//! You won't get an error message but the output binary will be empty //! //! ``` text -//! error: linking with `arm-none-eabi-gcc` failed: exit code: 1 -//! | -//! = note: (..) -//! (..) -//! (..)/crt0.o: In function `_start': -//! (.text+0x90): undefined reference to `memset' -//! (..)/crt0.o: In function `_start': -//! (.text+0xd0): undefined reference to `atexit' -//! (..)/crt0.o: In function `_start': -//! (.text+0xd4): undefined reference to `__libc_init_array' -//! (..)/crt0.o: In function `_start': -//! (.text+0xe4): undefined reference to `exit' -//! (..)/crt0.o: In function `_start': -//! (.text+0x100): undefined reference to `__libc_fini_array' -//! collect2: error: ld returned 1 exit status +//! $ cargo build && echo OK +//! OK +//! +//! $ size target/thumbv7m-none-eabi/debug/app +//! text data bss dec hex filename +//! 0 0 0 0 0 target/thumbv7m-none-eabi/debug/app //! ``` //! //! Solution: You probably overwrote the original `.cargo/config` instead of appending the default From a79ea9bee7efae8ce569c38df01efcfb442d20d4 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Mon, 27 Aug 2018 17:34:01 +0200 Subject: [PATCH 3/7] bump dependencies to not depend on arm-none-eabi-gcc --- .travis.yml | 16 ---------------- Cargo.toml | 6 +++--- 2 files changed, 3 insertions(+), 19 deletions(-) diff --git a/.travis.yml b/.travis.yml index 4a1a305..9da57d6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,34 +4,18 @@ matrix: include: - env: TARGET=thumbv6m-none-eabi rust: nightly - addons: - apt: - packages: - - gcc-arm-none-eabi if: (branch = staging OR branch = trying) OR (type = pull_request AND branch = master) - env: TARGET=thumbv7m-none-eabi rust: nightly - addons: - apt: - packages: - - gcc-arm-none-eabi if: (branch = staging OR branch = trying) OR (type = pull_request AND branch = master) - env: TARGET=thumbv7em-none-eabi rust: nightly - addons: - apt: - packages: - - gcc-arm-none-eabi if: (branch = staging OR branch = trying) OR (type = pull_request AND branch = master) - env: TARGET=thumbv7em-none-eabihf rust: nightly - addons: - apt: - packages: - - gcc-arm-none-eabi if: (branch = staging OR branch = trying) OR (type = pull_request AND branch = master) before_install: set -e diff --git a/Cargo.toml b/Cargo.toml index a8c6f7e..d12aaf8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,9 +9,9 @@ repository = "https://github.com/japaric/cortex-m-quickstart" version = "0.3.3" [dependencies] -cortex-m = "0.5.0" -cortex-m-rt = "0.5.0" -cortex-m-semihosting = "0.3.0" +cortex-m = "0.5.6" +cortex-m-rt = "0.5.3" +cortex-m-semihosting = "0.3.1" panic-semihosting = "0.3.0" # Uncomment for the panic example. From 3e39a0b927483df06db4f1fbf25633535b374d17 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Mon, 27 Aug 2018 17:44:55 +0200 Subject: [PATCH 4/7] publish docs on GH pages --- .travis.yml | 7 +++++++ Cargo.toml | 3 ++- ci/after-success.sh | 20 ++++++++++++++++++++ ci/install.sh | 4 +++- ci/script.sh | 4 +++- 5 files changed, 35 insertions(+), 3 deletions(-) create mode 100644 ci/after-success.sh diff --git a/.travis.yml b/.travis.yml index 9da57d6..e620b74 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,6 +2,10 @@ language: rust matrix: include: + - env: TARGET=x86_64-unknown-linux-gnu + rust: nightly + if: branch = master AND type != pull_request + - env: TARGET=thumbv6m-none-eabi rust: nightly if: (branch = staging OR branch = trying) OR (type = pull_request AND branch = master) @@ -26,6 +30,9 @@ install: script: - bash ci/script.sh +after_success: + - bash ci/after-success.sh + after_script: set +e cache: cargo diff --git a/Cargo.toml b/Cargo.toml index d12aaf8..5cefdda 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,11 +2,12 @@ authors = ["Jorge Aparicio "] categories = ["embedded", "no-std"] description = "A template for building applications for ARM Cortex-M microcontrollers" +documentation = "https://rust-embedded.github.io/cortex-m-quickstart/cortex_m_quickstart" keywords = ["arm", "cortex-m", "template"] license = "MIT OR Apache-2.0" name = "cortex-m-quickstart" repository = "https://github.com/japaric/cortex-m-quickstart" -version = "0.3.3" +version = "0.3.4" [dependencies] cortex-m = "0.5.6" diff --git a/ci/after-success.sh b/ci/after-success.sh new file mode 100644 index 0000000..4377267 --- /dev/null +++ b/ci/after-success.sh @@ -0,0 +1,20 @@ +set -euxo pipefail + +main() { + cargo doc + + mkdir ghp-import + + curl -Ls https://github.com/davisp/ghp-import/archive/master.tar.gz | + tar --strip-components 1 -C ghp-import -xz + + ./ghp-import/ghp_import.py target/doc + + set +x + git push -fq https://$GH_TOKEN@github.com/$TRAVIS_REPO_SLUG.git gh-pages && echo OK +} + +# only publish on successful merges to master +if [ $TRAVIS_BRANCH = master ] && [ $TRAVIS_PULL_REQUEST = false ] && [ $TARGET = x86_64-unknown-linux-gnu ]; then + main +fi diff --git a/ci/install.sh b/ci/install.sh index ea7997c..3c41921 100644 --- a/ci/install.sh +++ b/ci/install.sh @@ -1,7 +1,9 @@ set -euxo pipefail main() { - rustup target add $TARGET + if [ $TARGET != x86_64-unknown-linux-gnu ]; then + rustup target add $TARGET + fi } main diff --git a/ci/script.sh b/ci/script.sh index d2195a2..ed81f53 100644 --- a/ci/script.sh +++ b/ci/script.sh @@ -67,4 +67,6 @@ EOF rm -rf $td } -main +if [ $TARGET != x86_64-unknown-linux-gnu ]; then + main +fi From 0eaa0de3c602761d78f4110f7d882c8b9b72bcd0 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Mon, 27 Aug 2018 22:52:02 +0200 Subject: [PATCH 5/7] update the minimal example --- examples/minimal.rs | 22 ---------------------- 1 file changed, 22 deletions(-) diff --git a/examples/minimal.rs b/examples/minimal.rs index db91840..e174f0d 100644 --- a/examples/minimal.rs +++ b/examples/minimal.rs @@ -15,14 +15,6 @@ //! define a panicking behavior is to link to a [panic handler crate][0] //! //! [0]: https://crates.io/keywords/panic-impl -//! -//! - Define the `HardFault` handler using the [`exception!`] macro. This handler (function) is -//! called when a hard fault exception is raised by the hardware. -//! -//! [`exception!`]: https://docs.rs/cortex-m-rt/~0.5/cortex_m_rt/macro..html -//! -//! - Define a default handler using the [`exception!`] macro. This function will be used to handle -//! all interrupts and exceptions which have not been assigned a specific handler. #![no_main] // <- IMPORTANT! #![no_std] @@ -47,17 +39,3 @@ fn main() -> ! { asm::bkpt(); } } - -// define the hard fault handler -exception!(HardFault, hard_fault); - -fn hard_fault(ef: &ExceptionFrame) -> ! { - panic!("HardFault at {:#?}", ef); -} - -// define the default exception handler -exception!(*, default_handler); - -fn default_handler(irqn: i16) { - panic!("Unhandled exception (IRQn = {})", irqn); -} From 7bb74b21234f240975bbb40197820fa5ec691307 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Tue, 28 Aug 2018 14:54:40 +0200 Subject: [PATCH 6/7] fix some warnings --- examples/allocator.rs | 3 +-- examples/minimal.rs | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/examples/allocator.rs b/examples/allocator.rs index 652a04c..5e242c8 100644 --- a/examples/allocator.rs +++ b/examples/allocator.rs @@ -11,7 +11,6 @@ #![feature(alloc)] #![feature(alloc_error_handler)] -#![feature(global_allocator)] #![feature(lang_items)] #![no_main] #![no_std] @@ -58,7 +57,7 @@ fn main() -> ! { // define what happens in an Out Of Memory (OOM) condition #[alloc_error_handler] #[no_mangle] -pub fn alloc_error(layout: Layout) -> ! { +pub fn alloc_error(_layout: Layout) -> ! { asm::bkpt(); loop {} diff --git a/examples/minimal.rs b/examples/minimal.rs index e174f0d..e573932 100644 --- a/examples/minimal.rs +++ b/examples/minimal.rs @@ -21,14 +21,13 @@ extern crate cortex_m; -#[macro_use(entry, exception)] +#[macro_use(entry)] extern crate cortex_m_rt as rt; // makes `panic!` print messages to the host stderr using semihosting extern crate panic_semihosting; use cortex_m::asm; -use rt::ExceptionFrame; // the program entry point is ... entry!(main); From b89c76e3fc6c321311b9ccb681949f978c90b524 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Tue, 28 Aug 2018 14:55:02 +0200 Subject: [PATCH 7/7] use size instead of arm-none-eabi-size --- ci/script.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci/script.sh b/ci/script.sh index ed81f53..cfc0c34 100644 --- a/ci/script.sh +++ b/ci/script.sh @@ -61,7 +61,7 @@ EOF examples+=( $ex ) fi - IFS=,;eval arm-none-eabi-size target/$TARGET/release/examples/"{${examples[*]}}" + IFS=,;eval size target/$TARGET/release/examples/"{${examples[*]}}" popd rm -rf $td