Make arm linux gnueabihf gcc

Cross compiling Linux ARM kernel modules

This guide will allow you to cross-compile a loadable kernel module (LKM; a.k.a. device driver) for a ARM Linux system.

1. Target system

I will use this configuration as an example, but you can apply the same method for other environments.

2. Download linux kernel source

You must download the exact version which is running in the qemu.

Note that source for 3.2.0 is named linux-3.2.tar.gz , not linux-3.2.0.tar.gz .

3. Download cross compiler toolchain

Linaro’s prebuilt toolchain generally works well. Download one from https://releases.linaro.org/components/toolchain/binaries.

Pick a version, and choose the appropriate architecture. In our case, it would be arm-linux-gnueabihf (ARM 32-bit, linux, little endian, hard float).

There are three kinds of files: gcc-linaro- , runtime-gcc-linaro- , and sysroot-eglibc-linaro- . You only need the first one. For more info, refer to this Linaro wiki page.

For instance, go to 4.9-2017.01/arm-linux-gnueabihf/ directory and download gcc-linaro-4.9.4-2017.01-x86_64_arm-linux-gnueabihf.tar.xz .

4. Take out kernel build config

We need to build the kernel first, and then build a kernel module. But to compile a kernel, we must have the exact build configuration of the currently running Linux system. Fortunately, you can get a copy from a running system. Look at these locations:

Copy the file out of the qemu using scp or something.

5. Build the kernel

You need auto-generated files in order to build a kernel module. Otherwise you may encounter an error message like this:

/home/ubuntu/linux-3.2/include/linux/kconfig.h:4:32: fatal error: generated/autoconf.h: No such file or directory #include ^ 

To build a kernel with given config file,

cd cp .config make ARCH=arm CROSS_COMPILE=/bin/arm-linux-gnueabihf- oldconfig make ARCH=arm CROSS_COMPILE=/bin/arm-linux-gnueabihf- 

Complete kernel build may not be necessary because what you need is generated header files.

6. Build the module

Write a Makefile as follows:

PWD := $(shell pwd) obj-m += hello.o all: make ARCH=arm CROSS_COMPILE=$(CROSS) -C $(KERNEL) SUBDIRS=$(PWD) modules clean: make -C $(KERNEL) SUBDIRS=$(PWD) clean 

And create a hello world module.

// hello.c #include #include  int init_module(void)  printk(KERN_INFO "Hello world.\n"); return 0; > void cleanup_module(void)  printk(KERN_INFO "Goodbye world.\n"); > 
make KERNEL= CROSS=/bin/arm-linux-gnueabihf- 

Then you will get hello.ko compatible with the running ARM Linux.

Источник

Toolchain

The toolchain is a set of binaries, system libraries and tools which allow you to build (in our case, cross-compile) u-boot and the kernel for a target platform. This will, to some limited extent, need to match the target rootfs. A large and incompatible change has taken place recently, through the Hard Float ABI. Now, two different debian and ubuntu ports are binary incompatible with each other.

Contents

  • 1 Part of distributions
    • 1.1 Ubuntu
    • 1.2 Debian
    • 1.3 Fedora
    • 1.4 Gentoo
      • 1.4.1 ARM crosscompiler
      • 1.4.2 ARM64 crosscompiler
      • 1.4.3 OpenRISC crosscompiler
      • 2.1 Linaro toolchain
        • 2.1.1 Download
        • 2.1.2 Usage
        • 2.1.3 no hardfloat?

        Part of distributions

        Ubuntu

        A complete cross toolchain is available as a package, just run:

        apt-get install gcc-arm-linux-gnueabihf

        The gcc cross compiler from the standard package in Ubuntu 16 may have a bug that manifests itself as the following error while compiling U-Boot:

        : Assembler messages: :323: Error: push/pop do not support ^ -- `pop ^' scripts/Makefile.build:280: recipe for target 'arch/arm/cpu/armv7/sunxi/psci.o' failed

        Version of the compiler with the bug:

        arm-linux-gnueabihf-gcc-5 (Ubuntu/Linaro 5.4.0-6ubuntu1~16.04.4) 5.4.0 20160609

        A suggested solution is to use the Linaro toolchain

        Debian

        Details on cross-development Toolchains for Debian are at the Debian Wiki.

        Installing Cross Compiler and build utilities:

        dpkg --add-architecture armhf apt-get update apt-get install g++-arm-linux-gnueabihf 
        dpkg --add-architecture arm64 apt-get update apt-get install g++-aarch64-linux-gnu 

        You might want additional tools for building a sunxi system that are not related to the cross-compiler:

        apt-get install build-essential git debootstrap u-boot-tools device-tree-compiler

        Fedora

        A complete cross toolchain is available as a package, just run:

        yum install gcc-arm-linux-gnu

        Gentoo

        The crossdev tool [1] is the standard way of dealing with crosscompilers in Gentoo. Command line options are used to specify any arbitrary mix of different versions of the kernel headers, glibc, binutils and gcc. You can also use the -S option instead (to pick whatever is considered to be stable at the moment), but in this case the crosscompiler will be also upgraded as part of the regular distribution updates, which might be a bit annoying.

        ARM crosscompiler

        Even though Gentoo normally uses armv7a-hardfloat-linux-gnueabi as the toolchain triplet on ARM, we can also use Debian alike arm-linux-gnueabihf variant in order to be able to use the compilation instructions from the linux-sunxi wiki as-is (without substituting the toolchain name).

        emerge crossdev crossdev --kernel =3.18 --libc =2.20-r2 --binutils =2.24-r3 --gcc =4.8.5 \ --genv 'USE="-fortran -mudflap -nls -openmp multilib" EXTRA_ECONF="--with-cpu=cortex-a8 --with-float=hard"' -t arm-linux-gnueabihf

        ARM64 crosscompiler

        emerge crossdev crossdev --kernel =3.18 --libc =2.21-r1 --binutils =9999 --gcc =4.9.3 \ --genv 'USE="-fortran -mudflap -nls -openmp multilib -sanitize" EXTRA_ECONF="--enable-fix-cortex-a53-843419"' -t aarch64-linux-gnu

        Note: binutils =9999 (fetch sources from git) should be replaced with =2.26 as soon as binutils 2.26 is added to portage. Such new binutils version is necessary for having a Cortex-A53 erratum 843419 workaround.

        OpenRISC crosscompiler

        If you have one of the Allwinner SoC variants with an additional OpenRISC core (for example A31 and H3 have it), then you might want to also build an OpenRISC crosscompiler too:

        emerge crossdev mkdir -p /etc/portage/patches/cross-or1k-elf/gcc-5.2.0 cd /etc/portage/patches/cross-or1k-elf/gcc-5.2.0 wget https://gist.githubusercontent.com/ssvb/28e22f4086af26ec9cd0/raw/8d3d091177156a92497f31de3bfb3d7da9e52649/0001-OpenRISC-support-for-GCC-5.2.0.patch crossdev --binutils =2.25.1-r1 --gcc =5.2.0 --libc =2.2.0.20150423 \ --genv 'USE="cxx multilib -fortran -mudflap -nls -openmp -sanitize"' \ -s4 -t or1k-elf

        Please note that the upstream GCC does not support OpenRISC yet, so the OpenRISC code is still brewing in https://github.com/openrisc/or1k-gcc.git and we can solve this problem by just providing a patch for GCC in the /etc/portage/patches directory.

        1. ↑ The Gentoo website has undergone a major overhaul as of April 2015. While a backup of the old content is still available, it seems to have left the Gentoo Embedded Handbook in a non-functional state. You can still find a copy via archive.org. The wiki article on Raspberry Pi Cross building might also be helpful.

        Standalone

        These standalone toolchains are big tarballs which come with everything you need.

        Linaro toolchain

        Download

        Linaro has been very good at changing the location and availability of just about everything, making it very hard to keep a wiki up to date which refers to it. So the below download locations might be stale already.

        It lists the following toolchains:

        When in doubt, try 4.9 first.

        WARNING: Do not use the 4.8 gcc versions of the linaro toolchain to build legacy kernels (sunxi-3.4 etc.), those seem to have issues building the kernel. ( TODO: Verify that this is still true today ).

        Usage

        Take a gcc-linaro-.-..tar.xz file and untar it. You will find a bin directory in there. Temporarily add it to the environment you are building from:

        export PATH="$PATH":/home/user/folder/gcc-linaro-arm-linux-gnueabihf-*_linux/bin/

        no hardfloat?

        Recent linaro toolchains are Hard Float (hf), this will be used throughout the wiki you see something like:

        make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf-

        Replace arm-linux-gnueabihf- with arm-linux-gnueabi- if your are not using a hardfloat toolchain.

        Code Sourcery

        Another option is to install the Sourcery toolchain from Code Sourcery (now in Mentor Graphics). Download Code Sourcery G++ 2010 9-50 https://sourcery.mentor.com/sgpp/lite/arm/portal/release1600 (official link, email registration required)

        chmod +x arm-2010.09-50-arm-none-linux-gnueabi.bin ./arm-2010.09-50-arm-none-linux-gnueabi.bin

        If you are using Ubuntu, you may need to switch to use bash shell (instead of dash shell)

        sudo dpkg-reconfigure -plow dash ( then choose [No], this changes from using dash shell to using bash shell )

        It will now install CodeSourcery with a GUI installer

        Follow default settings and do Next , Next, Next, etc…

        It should install in: ~/CodeSourcery/ ( for example: /home/penguin/CodeSourcery/ )

        Make sure the CodeSourcery binaries are added to your path (if your username is penguin, then this should be correct):

        echo "export PATH=~/CodeSourcery/Sourcery_G++_Lite/bin:\$" >> ~/.bashrc export PATH=~/CodeSourcery/Sourcery_G++_Lite/bin:$PATH (or you can just spawn a new terminal window to update the path) echo $PATH (make sure your path is updated)

        Bootlin

        Bootlin also provices glibc / musl / uclibc based toolchains for building:

        Источник

        Install the ARM cross compiler toolchain on your Linux PC

        This article illustrates how to install on a Linux PC the complete toolchain to cross compile the Linux Kernel, device drivers and applications for the Acme Systems Linux board.

        This procedure has been tested on: Ubuntu 18.04.4 LTS and Debian Buster 10

        Install the Cross Compilers, utilities, etc.

        Install the GCC, G++ cross compilers and support programs by typing:

        sudo apt update sudo apt install libc6-armel-cross libc6-dev-armel-cross binutils-arm-linux-gnueabi libncurses5-dev build-essential bison flex libssl-dev bc

        If you are using an Acqua or RoadRunner board:

        Now you are ready to cross-compile on your PC all the source available for the Acme Boards based on Microchip MPUs.

        Try the cross C compiler

        Let’s try to cross compile a Hello World example in C and running it on an Acme board.

        #include "stdio.h" int main(void)

        Compile it by typing, if you are using an Arietta, Aria or FOX G20 board:

        or, if you are using an Acqua or RoadRunner board:

        As you can see we are using the ARM version of gcc just installed on your PC. It will generate an executable file for your Linux board.

        Copy the executable file on the board via ssh:

        Then open a command session on your board and run the example:

        Try the cross C++ compiler

        Let’s try to cross compile a Hello World example in C++ and running it on an Acme board.

        #include "iostream" using namespace std; int main(int argc, char *argv[])

        Compile it typing, if you are using an Arietta, Aria or FOX G20 board:

        or, if you are using an Acqua or RoadRunner board:

        As you can see we are using the ARM version of gcc just installed on your PC. It will generate an executable file for your Linux board.

        Copy the executable file on the board via ssh:

        Then open a command session on your board and run the example:

        RoadRunner D2

        • CPU Microchip SAMA5D27
        • Cortex A5 @ 500 MHz
        • Very low power consumption:
          396mW in full speed mode
          198mW at Linux prompt
          17mW in standby mode
          10mW in suspend to RAM mode
        • Armhf architecture
        • DDR3L RAM 256 MB
        • QuadSPI 0/16/64/128MB
        • Size: 40×30 mm
        • Plug-in module
        • 200 pins 0.4 mm pitch
        • TFT parallel interface
        • Boot from internal Quad SPI or external uSD/eMMC
        • Linux Kernel 5.15 LTS
        • Debian, Buildroot and Yocto
        • Open source drivers

        H10

        • Single Board Computer based on RoadRunner Linux SOM (Included)
        • Classic «Credit Card» form factor
        • Two USB Host 2.0 ports (one configurable as USB client on the USB-C connector)
        • One 10/100 Mbit/s Lan port
        • Two AcmeSensor ports
        • Double placements for 2.54mm pitch 20×2 pinstrips (not soldered) for GPIOS, SPI, I2C, Serial etc ports

        • All the circuitries you need to test the RoadRunner SOM
        • USB host, USB device, Ethernet port, MicroSD socket
        • Test points for power consumption measurements
        • All the Roadrunner signals exposed on 2.54mm pitch pins
        • On-board supercap for RTC and backup memory circuit

        Источник

        Читайте также:  Iso to wbfs linux
Оцените статью
Adblock
detector