antoinealb / rust-demo-cortex-m4

A simple blinking LED project based on Rust, for fun
Other
61 stars 9 forks source link

Question: arm cortex a9 #2

Open Arnold1 opened 9 years ago

Arnold1 commented 9 years ago

Hi,

great work. how much effort is it to port the led blink example to arm cortex a9 - bare metal?

quick question to your project. why is your main.rs a staticlib? how does it create the executable .ldf?

Thanks, A

antoinealb commented 9 years ago

Hello Arnold, I don't know how long it would take, but you would need to write a few different things:

My main.rs is a static library because I want to link it using arm-none-eabi-ld (here: https://github.com/antoinealb/rust-demo-cortex-m4/blob/master/Makefile#L140) with Tivaware and it was the easiest option. Maybe there is a way to link with LLVM, but I am not familiar with it.

I don't know which ldf file you are talking about ?

Antoine

Arnold1 commented 9 years ago

thanks for your quick reply.

sorry i mean .elf file, the following project uses arm cortex m4 and creates a elf file to be the executable: https://github.com/neykov/armboot

i have a linker script (ld file) and startup.s file...

antoinealb commented 9 years ago

So once you assembled your startup.s file you will have a startup.o file. Using Rust's compiler you can compile your rust main to a main.o file by telling it that you want to create a static library.

Then, using arm-none-eabi-ld (GCC's arm linker) you link together your .o files to create an ELF file. The linker script is used at this step to explain where to put variables in RAM, functions in ROM, etc. For example, here is my command to do this (from the Makefile): arm-none-eabi-ld -T LM4F.ld --gc-sections -o main.axf LM4F_startup.o main.o tivaware/driverlib/gcc/libdriver.a

Small breakdown:

Hops that helps

Arnold1 commented 9 years ago

thanks for the info.

first i need to build the rust cross compiler.

do you know how my rust target description (.json) would look like? im not sure about the llvm-target, the rest should be the same...

here is the compiler i use:

arm-xilinx-eabi-gcc -v
Using built-in specs.
COLLECT_GCC=arm-xilinx-eabi-gcc
COLLECT_LTO_WRAPPER=/opt/Xilinx/SDK/2015.1/gnu/arm/lin/bin/../libexec/gcc/arm-xilinx-eabi/4.9.1/lto-wrapper
Target: arm-xilinx-eabi
Configured with: /scratch/cltang/xilinx/eabi/src/gcc-4.9-2014.11/configure --build=i686-pc-linux-gnu --host=i686-pc-linux-gnu --target=arm-xilinx-eabi --enable-threads --disable-libmudflap --disable-libssp --disable-libstdcxx-pch --with-arch=armv7-a --with-cpu=cortex-a9 --with-float=softfp --with-fpu=neon-fp16 --disable-multilib --with-gnu-as --with-gnu-ld --with-specs='%{save-temps: -fverbose-asm} -D__CS_SOURCERYGXX_MAJ__=2014 -D__CS_SOURCERYGXX_MIN__=11 -D__CS_SOURCERYGXX_REV__=31' --enable-languages=c,c++ --disable-shared --enable-lto --with-newlib --with-pkgversion='Sourcery CodeBench Lite 2014.11-31' --with-bugurl=https://s...content-available-to-author-only...r.com/GNUToolchain/ --disable-nls --prefix=/opt/codesourcery --with-headers=yes --with-sysroot=/opt/codesourcery/arm-xilinx-eabi --with-build-sysroot=/scratch/cltang/xilinx/eabi/install/opt/codesourcery/arm-xilinx-eabi --with-gmp=/scratch/cltang/xilinx/eabi/obj/pkg-2014.11-31-arm-xilinx-eabi/xilinx-2014.11-31-arm-xilinx-eabi.extras/host-libs-i686-pc-linux-gnu/usr --with-mpfr=/scratch/cltang/xilinx/eabi/obj/pkg-2014.11-31-arm-xilinx-eabi/xilinx-2014.11-31-arm-xilinx-eabi.extras/host-libs-i686-pc-linux-gnu/usr --with-mpc=/scratch/cltang/xilinx/eabi/obj/pkg-2014.11-31-arm-xilinx-eabi/xilinx-2014.11-31-arm-xilinx-eabi.extras/host-libs-i686-pc-linux-gnu/usr --with-isl=/scratch/cltang/xilinx/eabi/obj/pkg-2014.11-31-arm-xilinx-eabi/xilinx-2014.11-31-arm-xilinx-eabi.extras/host-libs-i686-pc-linux-gnu/usr --with-cloog=/scratch/cltang/xilinx/eabi/obj/pkg-2014.11-31-arm-xilinx-eabi/xilinx-2014.11-31-arm-xilinx-eabi.extras/host-libs-i686-pc-linux-gnu/usr --disable-libgomp --disable-libitm --disable-libatomic --disable-libssp --enable-poison-system-directories --with-build-time-tools=/scratch/cltang/xilinx/eabi/install/opt/codesourcery/arm-xilinx-eabi/bin --with-build-time-tools=/scratch/cltang/xilinx/eabi/install/opt/codesourcery/arm-xilinx-eabi/bin SED=sed
Thread model: single
gcc version 4.9.1 (Sourcery CodeBench Lite 2014.11-31)

target description:

{
    "arch": "arm",
    "cpu": "cortex-a9",
    "data-layout": "e-m:e-p:32:32-i1:8:32-i8:8:32-i16:16:32-i64:64-v128:64:128-a:0:32-n32-S64",
    "disable-redzone": true,
    "executables": true,
    "llvm-target": "arm-unknown-eabi",  or armv7a-arm-none-eabi ????
    "morestack": false,
    "os": "none",
    "relocation-model": "static",
    "target-endian": "little",
    "target-pointer-width": "32"
}
antoinealb commented 9 years ago

I think the llvm target should be "armv7a-arm-none-eabi" but I am not sure. Perhaps the easiest is to try ? :)