Skip to content
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

Add support for 'arm-none-eabi' #464

Closed
JayKickliter opened this issue May 14, 2016 · 15 comments
Closed

Add support for 'arm-none-eabi' #464

JayKickliter opened this issue May 14, 2016 · 15 comments

Comments

@JayKickliter
Copy link

My coworkers and I are keen to use Rust on bare-metal ARM Cortex-M microcontrollers, but the current process of getting set up is too complicated to get everyone onboard. It would be a much easier sell if rustup could set up the toolchain and libcore (no standard library).

@vapor99
Copy link

vapor99 commented May 14, 2016

I have the same intention of using it on bare ARM Cortex-M and have the same issue as above. I think because Rust doesn't have GC, it would be extremely useful for IoT devices.

@japaric
Copy link
Member

japaric commented May 18, 2016

FWIW, I'm currently working on documenting how to set up a Rust development environment for bare metal programming ARM Cortex-M devices. I'm still drafting the process to go from zero to blinking an LED, but once it's done I'll push it to this repository.

After I'm done with that documentation, I'm going to propose an RFC that will let rustup install a target specification file and libcore (plus other freestanding crates like liballoc) binaries with just e.g. rustup target add cortex-m3.

I'm going to postpone the automatic installation of a C toolchain (arm-none-eabi-gcc) to another RFC as that feature needs to be general enough to also handle other scenarios like installing an SDK for Android/iOS targets and I haven't thought about how that would work.

@toothbrush7777777
Copy link

toothbrush7777777 commented May 18, 2016

@japaric Cool. I am in great need of this feature, but I don't understand (yet) the process of cross-compiling or the Rust set-up.

However, as far as I understand, there are several EABIs for ARM:

  • arm-linux-gnu (now obsolete)
  • arm-linux-gnueabi
  • arm-linux-gnueabihf (hard-float version)
  • aarch64-linux-gnu (AMD64)

Also, big-endian variants exist (I personally need to target the big-endian versions of both arm-linux-gnueabihf and aarch64-linux-gnu).

@vapor99
Copy link

vapor99 commented May 18, 2016

@japaric Oh, that's fantastic! I think that will really help a lot of people like myself that want to use Rust for embedded development.

@japaric
Copy link
Member

japaric commented May 19, 2016

@toothbrush7777777

Cool. I am in great need of this feature, but I don't understand (yet) the process of cross-compiling or the Rust set-up.

Might want to take a look at rust-cross to understand the requirements of cross compilation and how to cross compile with rustc/cargo.

However, as far as I understand, there are several EABIs for ARM:

What devices do you have in mind? Those targets sound like you want to do bare metal programming of Cortex A processors like the Raspberry Pi. I'm not familiar with bare metal programming of those though.

If you actually meant targets like arm-unknown-linux-gnueabi and co (that run Linux) cross compiling to those is already supported by the compiler and relatively straightforward. See rust-cross.

I personally need to target the big-endian versions of both arm-none-gnueabihf and aarch64-none-gnu

I think the big endian version of the arm target is armeb-*-*. I don't know what's the counterpart for the aarch64 target. Supporting the big endian version of those targets may need changes in the standard libraries/libc crate. AFAIK no one has tried/reported cross compiling to those targets before.

@vapor99

😄 The docs I'm writing are aimed to people that haven't done embedded development before. My goal is to lower the entry barrier to this area of programming as much as possible. Using Rust instead of C is part of that goal but the tooling could be improved hence the RFC I mentioned above.

@toothbrush7777777
Copy link

toothbrush7777777 commented May 19, 2016

@japaric Thanks, I'll take a look.

I am trying to cross compile for Raspberry Pi 1 model B+ (ARM1176JZF-S) and Raspberry Pi 3 model b (ARM Cortex-A53).
And yes, I meant arm-unknown-linux-*.

@JayKickliter
Copy link
Author

JayKickliter commented May 28, 2016

It turns out this a lot easier that I thought. I discovered this when building someone else's project, and being surprised that it worked without any hassle. There's a libcore crate you can put in your Cargo.toml. Just to make sure, I completely wiped any trace of rust/rustup/cargo from my system and did the following:

$ curl https://sh.rustup.rs -sSf | sh
$ source ~/.cargo/env
$ git clone https://github.com/thejpster/bare-metal-arm-rust.git
$ cd bare-metal-arm-rust/
$ rustup override add nightly
$ rustup override set nightly
$ cargo build --target=lm4f120
    Updating git repository `https://github.com/hackndev/rust-libcore`
   Compiling rust-libcore v0.0.3 (https://github.com/hackndev/rust-libcore#44866049)
   Compiling bare-metal-arm-rust v0.2.2 (file:///Users/jay/Downloads/bare-metal-arm-rust)
   Compiling primer v0.2.0 (file:///Users/jay/Downloads/bare-metal-arm-rust/primer)

It's a good workaround in the meantime.

@japaric
Copy link
Member

japaric commented May 29, 2016

@JayKickliter

There's a libcore crate you can put in your Cargo.toml.

That works fine until you have to add dependencies from crates.io like e.g. byteorder that don't depend on the rust-libcore crate. When you hit that wall, check out xargo.

@toothbrush7777777

(Didn't see you edited your post until now)

Those linux targets are currently supported. The RPi1 is the arm-unknown-linux-gnueabi (or the hf variant depending on whether its OS is using the hard float ABI or the soft one) target, and the RPi3 is the aarch64-unknown-linux-gnu target. Cross compiling to those targets is done the standard way as documented in rust-cross: install C cross toolchain, rustup target add $TARGET, set linker in .cargo/config, cargo build --target $TARGET.

You need big endian variants of those targets, right? We would have to decide how to handle conditional compilation between those two variants (little & big) before adding support for them in the compiler / standard libraries.

@toothbrush7777777 Can you point me to a linux distribution that provides releases for big endian ARM? Those would be helpful for testing.

@japaric
Copy link
Member

japaric commented Jun 8, 2016

After I'm done with that documentation, I'm going to propose an RFC that will let rustup install a target specification file and libcore (plus other freestanding crates like liballoc) binaries with just e.g. rustup target add cortex-m3.

PSA: I have submitted the RFC.

@japaric
Copy link
Member

japaric commented Jul 7, 2016

FWIW, I'm currently working on documenting how to set up a Rust development environment for bare metal programming ARM Cortex-M devices.

PSA: The documentation is up now.

@vapor99
Copy link

vapor99 commented Jul 12, 2016

Oh that's terrific, I will definitely check it out. Nice work!

On Thu, Jul 7, 2016 at 3:50 PM, Jorge Aparicio notifications@github.com
wrote:

FWIW, I'm currently working on documenting how to set up a Rust
development environment for bare metal programming ARM Cortex-M devices.

PSA: The documentation http://japaric.github.io/copper is up now.


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#464 (comment),
or mute the thread
https://github.com/notifications/unsubscribe/AL7EPloWU4CU3tFVXwyuUxgLk6WxbgtUks5qTViigaJpZM4IenQO
.

@fabricedesre
Copy link

Now that rust-lang/rust#36874 landed would that be easier to add the new targets?

@japaric
Copy link
Member

japaric commented Oct 28, 2016

@fabricedesre The Rust/tooling team is leaning towards not providing binary releases of the core crate as making Cargo capable of (cross) compiling core/std would be a better solution. Right now, the stop gap solution is Xargo which cross compiles the core crate on the fly.

Installing the toolchain using rustup could be handled by rustup plugin. An alternative to having rustup install the toolchain is to make rustc no longer depend on arm-none-eabi-gcc by embedding lld, LLVM's linker, in rustc; that internal lld would handle linking Rust programs.

@JasonKleban
Copy link

@kinnison
Copy link
Contributor

I believe appropriate targets now exist in Rust.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants