Skip to content

[CI] Run a thumbv7m-none-eabi binary using qemu-system-arm [IRR-2018-embedded] #53996

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Nov 6, 2018
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/ci/docker/dist-various-1/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
libssl-dev \
pkg-config \
gcc-arm-none-eabi \
libnewlib-arm-none-eabi
libnewlib-arm-none-eabi \
qemu-system-arm

WORKDIR /build

Expand Down
33 changes: 33 additions & 0 deletions src/test/run-make/thumb-none-qemu/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
-include ../../run-make-fulldeps/tools.mk

# How to run this
# $ ./x.py clean
# $ ./x.py test --target thumbv7m-none-eabi src/test/run-make

ifneq (,$(filter $(TARGET),thumbv6m-none-eabi thumbv7m-none-eabi))

# For cargo setting
RUSTC := $(RUSTC_ORIGINAL)
LD_LIBRARY_PATH := $(HOST_RPATH_DIR)
# We need to be outside of 'src' dir in order to run cargo
WORK_DIR := $(TMPDIR)
HERE := $(shell pwd)


# hint: we could set variables per $(TARGET) basis in order to support other targets.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

qemu-system-arm only supports full system emulation of the LM3S6965 and LM3S811 microcontrollers. They are both Cortex-M3 microcontrollers so we can test the thumbv6m-none-eabi and thumbv7m-none-eabi targets with either QEMU target. The thumbv7em-none-eabi and thumbv7em-none-eabihf targets have incompatible ISAs and they can crash QEMU.

It would be great to also test the thumbv6m-none-eabi target here since it's an older ARM architecture. If you are up to it you can do that in a follow-up PR.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahem, older... ;) Cortex-M0 is still very relevant, is there any support for a CM0 MCU in qemu?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@therealprof I've run 4 binaries on qemu-system-arm. As I remember, some worked in different board setting. My theory is if an ISA (thumbv6m-none-eabi) is roughly a subset of another (thumbv7m-none-eabi), and there's no harmful register changes, it has chance to run successfully. I'll try with existing qemu setting for thumbv6m (Cortex-M0) also.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sekineh thumbv6m-none-eabi is indeed a subset of thumbv7m-none-eabi and code might run just fine on higher ISA versions. However to be on the safe(r) side you really want to test on a Cortex-M0(+) target or emulation.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@therealprof these are the Cortex CPUs QEMU 3.0.0 supports:

  cortex-a15
  cortex-a7
  cortex-a8
  cortex-a9
  cortex-m3
  cortex-m33
  cortex-m4
  cortex-r5
  cortex-r5f

No cortex-m0 or cortex-m4f but you can run code compiled for thumbv6m-none-eabi using -cpu cortex-m3 since the M0 ISA is a subset of the M3 ISA. We can't run code compiled for the thumbv7em-none-eabihf though because the FPU instructions crash QEMU.

I'm not entirely sure if -machine is completely orthogonal to -cpu but I would prefer not to mix a Cortex-M3 machine with -cpu cortex-m4.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I successfully ran the thumv6m-none-eabi binary on qemu -cpu cortex-m3

sekineh@sekineh-VirtualBox:~/cortex-m-rt_me$ cargo run --example qemu --target thumbv6m-none-eabi
    Finished dev [unoptimized + debuginfo] target(s) in 0.03s                                                    
     Running `qemu-system-arm -cpu cortex-m3 -machine lm3s6965evb -nographic -semihosting-config enable=on,target=native -kernel target/thumbv6m-none-eabi/debug/examples/qemu`
x = 42

CRATE := cortex-m-rt
CRATE_URL := https://github.com/rust-embedded/cortex-m-rt
CRATE_SHA1 := 62972c8a89ff54b76f9ef0d600c1fcf7a233aabd

all:
env
mkdir -p $(WORK_DIR)
-cd $(WORK_DIR) && rm -rf $(CRATE)
cd $(WORK_DIR) && bash -x $(HERE)/../git_clone_sha1.sh $(CRATE) $(CRATE_URL) $(CRATE_SHA1)
cd $(WORK_DIR)/$(CRATE) && $(CARGO) run --target $(TARGET) --example qemu | grep "x = 42"
cd $(WORK_DIR)/$(CRATE) && $(CARGO) run --target $(TARGET) --example qemu --release | grep "x = 42"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move logic l23-28 into separate file like script.sh? It will make error log clearer.

else

all:

endif