Skip to content

Commit 15d7704

Browse files
committed
Auto merge of #53996 - sekineh:thumb-run, r=japaric
[CI] Run a `thumbv7m-none-eabi` binary using `qemu-system-arm` [IRR-2018-embedded] ## What's included? - Run a `thumbv7m-none-eabi` binary using `qemu-system-arm` - We are using `cortex-m-rt = "=0.5.4"` which does not use `proc_macro`. (reason: stage2 build of rustc does not work well with `proc_macro` in `run-make` phase.) - We are using GNU LD for now. ## Blocker All resolved. - ~[Waiting] `#[panic_handler]` is not available in stable.~ - [Merged] #53619 - ~[Waiting] https://github.com/japaric/lm3s6965evb: does not compile on stable.~ - [OK] dependent crate ~`panic-abort`~ `panic-halt`: already moved to use `#[panic_handler]`. ## Update `#[panic_handler]` will be stabilized in Rust 1.30. CC @kennytm @jamesmunns @nerdyvaishali
2 parents bdfeace + f872303 commit 15d7704

File tree

7 files changed

+143
-1
lines changed

7 files changed

+143
-1
lines changed

src/ci/docker/dist-various-1/Dockerfile

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
2222
libssl-dev \
2323
pkg-config \
2424
gcc-arm-none-eabi \
25-
libnewlib-arm-none-eabi
25+
libnewlib-arm-none-eabi \
26+
qemu-system-arm
2627

2728
WORKDIR /build
2829

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
-include ../../run-make-fulldeps/tools.mk
2+
3+
# How to run this
4+
# $ ./x.py clean
5+
# $ ./x.py test --target thumbv7m-none-eabi src/test/run-make
6+
7+
ifneq (,$(filter $(TARGET),thumbv6m-none-eabi thumbv7m-none-eabi))
8+
9+
# For cargo setting
10+
export RUSTC := $(RUSTC_ORIGINAL)
11+
export LD_LIBRARY_PATH := $(HOST_RPATH_DIR)
12+
# We need to be outside of 'src' dir in order to run cargo
13+
export WORK_DIR := $(TMPDIR)
14+
export HERE := $(shell pwd)
15+
16+
## clean up unused env variables which might cause harm.
17+
unexport RUSTC_LINKER
18+
unexport RUSTC_BOOTSTRAP
19+
unexport RUST_BUILD_STAGE
20+
unexport RUST_TEST_THREADS
21+
unexport RUST_TEST_TMPDIR
22+
unexport AR
23+
unexport CC
24+
unexport CXX
25+
26+
all:
27+
bash script.sh
28+
else
29+
all:
30+
endif
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
[target.thumbv7m-none-eabi]
2+
# uncomment this to make `cargo run` execute programs on QEMU
3+
runner = "qemu-system-arm -cpu cortex-m3 -machine lm3s6965evb -nographic -semihosting-config enable=on,target=native -kernel"
4+
5+
[target.thumbv6m-none-eabi]
6+
# uncomment this to make `cargo run` execute programs on QEMU
7+
# For now, we use cortex-m3 instead of cortex-m0 which are not supported by QEMU
8+
runner = "qemu-system-arm -cpu cortex-m3 -machine lm3s6965evb -nographic -semihosting-config enable=on,target=native -kernel"
9+
10+
[target.'cfg(all(target_arch = "arm", target_os = "none"))']
11+
# uncomment ONE of these three option to make `cargo run` start a GDB session
12+
# which option to pick depends on your system
13+
# runner = "arm-none-eabi-gdb -q -x openocd.gdb"
14+
# runner = "gdb-multiarch -q -x openocd.gdb"
15+
# runner = "gdb -q -x openocd.gdb"
16+
17+
rustflags = [
18+
# LLD (shipped with the Rust toolchain) is used as the default linker
19+
"-C", "link-arg=-Tlink.x",
20+
21+
# if you run into problems with LLD switch to the GNU linker by commenting out
22+
# this line
23+
# "-C", "linker=arm-none-eabi-ld",
24+
25+
# if you need to link to pre-compiled C libraries provided by a C toolchain
26+
# use GCC as the linker by commenting out both lines above and then
27+
# uncommenting the three lines below
28+
# "-C", "linker=arm-none-eabi-gcc",
29+
# "-C", "link-arg=-Wl,-Tlink.x",
30+
# "-C", "link-arg=-nostartfiles",
31+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[package]
2+
name = "example"
3+
version = "0.1.0"
4+
authors = ["Hideki Sekine <[email protected]>"]
5+
# edition = "2018"
6+
7+
[dependencies]
8+
cortex-m = "0.5.4"
9+
cortex-m-rt = "=0.5.4"
10+
panic-halt = "0.2.0"
11+
cortex-m-semihosting = "0.3.1"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/* Device specific memory layout */
2+
3+
/* This file is used to build the cortex-m-rt examples,
4+
but not other applications using cortex-m-rt. */
5+
6+
MEMORY
7+
{
8+
/* FLASH and RAM are mandatory memory regions */
9+
/* Update examples/data_overflow.rs if you change these sizes. */
10+
FLASH : ORIGIN = 0x00000000, LENGTH = 256K
11+
RAM : ORIGIN = 0x20000000, LENGTH = 64K
12+
13+
/* More memory regions can declared: for example this is a second RAM region */
14+
/* CCRAM : ORIGIN = 0x10000000, LENGTH = 8K */
15+
}
16+
17+
/* The location of the stack can be overridden using the `_stack_start` symbol.
18+
By default it will be placed at the end of the RAM region */
19+
/* _stack_start = ORIGIN(CCRAM) + LENGTH(CCRAM); */
20+
21+
/* The location of the .text section can be overridden using the `_stext` symbol.
22+
By default it will place after .vector_table */
23+
/* _stext = ORIGIN(FLASH) + 0x40c; */
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// #![feature(stdsimd)]
2+
#![no_main]
3+
#![no_std]
4+
5+
extern crate cortex_m;
6+
7+
extern crate cortex_m_rt as rt;
8+
extern crate cortex_m_semihosting as semihosting;
9+
extern crate panic_halt;
10+
11+
use core::fmt::Write;
12+
use cortex_m::asm;
13+
use rt::entry;
14+
15+
entry!(main);
16+
17+
fn main() -> ! {
18+
let x = 42;
19+
20+
loop {
21+
asm::nop();
22+
23+
// write something through semihosting interface
24+
let mut hstdout = semihosting::hio::hstdout().unwrap();
25+
write!(hstdout, "x = {}\n", x);
26+
27+
// exit from qemu
28+
semihosting::debug::exit(semihosting::debug::EXIT_SUCCESS);
29+
}
30+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
set -exuo pipefail
2+
3+
CRATE=example
4+
5+
env | sort
6+
mkdir -p $WORK_DIR
7+
pushd $WORK_DIR
8+
rm -rf $CRATE || echo OK
9+
cp -a $HERE/example .
10+
pushd $CRATE
11+
env RUSTFLAGS="-C linker=arm-none-eabi-ld -C link-arg=-Tlink.x" \
12+
$CARGO run --target $TARGET | grep "x = 42"
13+
env RUSTFLAGS="-C linker=arm-none-eabi-ld -C link-arg=-Tlink.x" \
14+
$CARGO run --target $TARGET --release | grep "x = 42"
15+
popd
16+
popd

0 commit comments

Comments
 (0)