how to port intel based linux application to ARM platform - arm

I need to port a few Intel based Linux applications to the ARM platform. Can anybody tell me
what are the best cross compiling tools for this project?
Thanks.

On the Ubuntu Linux host you may use just a default ARM toolchain:
sudo apt-get install gcc-arm-linux-gnueabi
To build your linux applications you just have to use the same tools,
but prefixed with:
arm-linux-gnueabi-
For example, to build a simple helloworld.c:
arm-linux-gnueabi-gcc -o helloworld helloworld.c
You can also set some ARM-related flags to optimize your build or to specify your target platform. Here some examples of important ARM GCC flags, depending on the target ARM CPU:
ARM 11: -mtune=arm1136j-s -mfpu=vfp -mfp=vfp -march=armv6 -mfloat-abi=softfp
Cortex A8: -mtune=cortex-a8 -mfpu=neon -mfloat-abi=softfp -Wl,--fix-cortex-a8
Cortex A9: -mtune=cortex-a9 -mfpu=neon -mfloat-abi=softfp
Note, that your target ARM CPU may require another options, for example if it doesn't support NEON instructions. GCC compilers from CodeSourcery may also need another options set - just read the docs from CodeSourcery for a particular GCC version.

Related

Does the the 'linux' version of arm gcc compiler support -cpu=cortex-m4?

I am using aarch64-none-linux-gnu-gcc for compiling the applications on my Ubuntu 20.04. It has support for cortex-a and few other processor cores. But not on cortex-m4 (or cores which use armv7. Can anyone recommend or provide a link to the compiler installer which supports cortex-m4?
The compiler for 32-bit ARM on Ubuntu is arm-linux-gnueabihf-gcc or arm-none-eabi-gcc, roughly according to whether you want to compile code to run on a Linux OS or on bare metal. Look for the packages gcc-arm-linux-gnueabihf or gcc-arm-none-eabi.
The aarch64 compilers only support 64-bit ARM.

gnu toolchain; bare meta aarch64l; osx host platform;

I'm looking for a GNU toolchain:
target platform is aarch64 bare metal (cortex-a53/armv8-a)
host Mac OSX
Or by other words I need a bunch of aarch64-none-elf-* files
Any advise where could I get these tools?
Thanks
You don't need the -none- version of the toolchain anymore on aarch64. You can simply use aarch64-linux-gnu-gcc for instance, with the right parameters (no standard libs or headers):
aarch64-linux-gnu-gcc -march=armv8-a -nostdinc -fno-builtin -c -o main.o main.c

Can't run GNU ARM Hello world

I'm trying to follow this tutorial
http://gnuarmeclipse.livius.net/blog/test-project/
to run a GNU ARM hello world.
I'm using eclipse luna on windows 8.1 x64.
I've installed the GNU ARM toolchain, and everything else the tutorial states.
The build passes, and gives the result specified in the tutorial
> 02:15:01 **** Build of configuration Debug for project ARMTest4 ****
> make all Building file: ../src/main.c Invoking: Cross ARM C Compiler
> arm-none-eabi-gcc -mcpu=cortex-m3 -mthumb -O0 -fmessage-length=0
> -fsigned-char -ffunction-sections -fdata-sections -g3 -std=gnu11 -MMD -MP -MF"src/main.d" -MT"src/main.o" -c -o "src/main.o" "../src/main.c" Finished building: ../src/main.c Building target: ARMTest4.elf
> Invoking: Cross ARM C Linker arm-none-eabi-gcc -mcpu=cortex-m3 -mthumb
> -O0 -fmessage-length=0 -fsigned-char -ffunction-sections -fdata-sections -g3 -Xlinker --gc-sections -Wl,-Map,"ARMTest4.map" --specs=rdimon.specs -Wl,--start-group -lgcc -lc -lc -lm -lrdimon -Wl,--end-group -o "ARMTest4.elf" ./src/main.o Finished building target: ARMTest4.elf Invoking: Cross ARM GNU Create Flash Image
> arm-none-eabi-objcopy -O ihex "ARMTest4.elf" "ARMTest4.hex" Finished
> building: ARMTest4.hex Invoking: Cross ARM GNU Print Size
> arm-none-eabi-size --format=berkeley "ARMTest4.elf" text data
> bss dec hex filename 8256 2396 260 10912
> 2aa0 ARMTest4.elf Finished building: ARMTest4.siz
>
> 02:15:06 Build Finished (took 5s.110ms)
Then, I try to run, and it fails, I have no idea why. It says "Error starting process"
The details in the error box state
> Error starting process. Cannot run program
> "C:\Users\Noam\workspace\cpp\ARMTest3\Debug\ARMTest3.elf": Launching
> failed Cannot run program
> "C:\Users\Noam\workspace\cpp\ARMTest3\Debug\ARMTest3.elf": Launching
> failed Cannot run program
> "C:\Users\Noam\workspace\cpp\ARMTest3\Debug\ARMTest3.elf": Launching
> failed
The only thing I can come up with is the code is supposed to run on some emulator and not my PC, which i have no idea how to do.
If this isn't the problem, please tell me what is.
I have also tried many other configurations for the hello world project, to no success.
My expected output for a working result: some console saying "Hello ARM world" to me.
Thanks.
You can't run ARM executables on an x64 processor. The tutorial expects you to have an ARM system available, like an emulator or a Raspberry Pi.
I can't make comments yet, so this is actually a follow up to wavemode's answer:
The quickest way to set up an emulator is with (depending on your platform) VirtualBox, or QEMU. Install Linux(or another OS that supports ARM binaries) into the image and boot from it. You'll need to transfer the binary to the emulated system, for example by SSH or HTTP.
Finding ARM images is relatively easy, and Debian, Fedora, ArchLinux, and others all provide pre-made images.
As others have stated, the GNU ARM tools are intended to target an external ARM microprocessor or microcontroller and the compiled programs will not run on your workstation.
There are a great number of ARM-based chips and development boards from several manufacturers that can be used with the GNU ARM tools and the idea is usually to create your own system with an embedded microcontroller. The program will need to be adapted for the specific microcontroller and board you are using.
The tutorial isn't clear, but the "Prerequisites" page linked from the tutorial has a section "Assign a device to the project", with a screenshot showing STM32F4-Discovery/STM32F407VG circled - I would assume the author is using that board.
The STM32 Discovery boards are low-cost (some under US$20), and include an ST-Link programmer/debugger and interesting peripherals to learn with. Other manufacturers usually have similar development boards featuring their parts.

C - Unable to statically link to OpenSSL on Ubuntu

Following the instructions given here, I’ve downloaded the latest version of OpenSSL (openssl-1.0.1e.tar.gz) from here and installed it on Ubuntu v12.10 (32-bit).
I have a C project in Eclipse CDT (v1.2.0.201212170456) that statically links to the following two .a files:
home/usr/local/ssl/lib/libcrypto.a
home/usr/local/ssl/lib/ libssl.a
However when I build my project I get these errors:
/home/tashimaya/Applications/CodeSourcery/bin/../lib/gcc/arm-none-linux-gnueabi/4.4.1/../../../../arm-none-linux-gnueabi/bin/ld: skipping incompatible /usr/local/ssl/lib/libssl.a when searching for -lssl
/home/tashimaya/Applications/CodeSourcery/bin/../lib/gcc/arm-none-linux-gnueabi/4.4.1/../../../../arm-none-linux-gnueabi/bin/ld: cannot find –lssl
My toolchain is CodeSourcery (Sourcery G++ Lite 2010q1-202) and is for 32-bit OS.
What am I doing wrong?
Compiler command line I'm using:
arm-none-linux-gnueabi-gcc -I"/path to my/include" -O0 -g3 -Wall -c -fmessage-length=0 -v -MMD -MP -MF"main.d" -MT"main.d" -o "main.o" "../main.c"
You have installed OpenSSL on an Ubuntu 32-bit machine (assuming x86), but are trying to link it to an ARM binary:
/home/tashimaya/Applications/CodeSourcery/bin/../lib/gcc/arm-none-linux-gnueabi: your ARM toolchain
/usr/local/ssl/lib/libssl.a: a 32-bit x86 version of OpenSSL
You will have to cross-compile OpenSSL for ARM using your ARM toolchain (i.e.: arm-none-linux-gnueabi-gcc), then you will be able to link it to an ARM binary.
It says that /usr/local/ssl/lib/libssl.a is not in the size expected. Try file on it to check if you compiled it in 32 or 64 bit version. And check how you are compiling your own program too. If both matches linker (ld) will link it fine.
If you compile your program into 64 bit and link it with libssl.a in 32 bit, this will not work
example:
file a.out
/* kind ofoutput */ a.out: Mach-O 64-bit executable x86_64
http://unixhelp.ed.ac.uk/CGI/man-cgi?file

Clang Cross Compiling for ARM?

Is it possible to set up Clang for cross compiling for the ARM processor? The host will likely be on x86 ( AMD64 - Probably Ubuntu 12.04 ) and the target would be ARM ( Raspberry Pi as well as Pandaboard - will do separate compilations for each ), I may at some point also wish to cross compile for the PowerPC architecture? The program source is in C.
To cross-compile for Raspberry Pi running soft-float Linux distros add flags -ccc-host-triple arm-eabi -marm -mfpu=vfp -mcpu=arm1176jzf-s -mtune=arm1176jzf-s -mfloat-abi=softfp
To cross-compile for Raspberry Pi running hard-float Linux distros use the flags -ccc-host-triple arm-eabi -marm -mfpu=vfp -mcpu=arm1176jzf-s -mtune=arm1176jzf-s -mfloat-abi=hard
To cross-compile for Pandaboard use flags -ccc-host-triple arm-eabiv7 -mthumb -mfpu=neon-fp16 -mcpu=cortex-a9 -mtune=cortex-a9 -mfloat-abi=hard (assuming that your Pandaboard runs Ubuntu)
Note: more recent clang version use -target option instead of -ccc-host-triple
See EmbToolkit project. It gives ability to generate clang/llvm
or gcc based cross compiler toolchain.

Resources