RaspBerry-HowTo-Linux-CrossTool-NG

Funtoo Desktop RaspBerry Cross Tool on Linux   1      Reference. 2 1.1       Crosstool-ng.2 1.2       info. 2 1.3       remote debug. 2 1.4       Create a module.2 2      Buildroot2 3      Crosstool–ng on VM […]
Print Friendly, PDF & Email

Funtoo Desktop

RaspBerry Cross Tool on Linux

 

1      Reference. 2

1.1       Crosstool-ng.2

1.2       info. 2

1.3       remote debug. 2

1.4       Create a module.2

2      Buildroot2

3      Crosstoolng on VM Funtoo.3

3.1       install crosstool-ng. 3

3.2       Crosstoll-ng configuration.3

3.3       Crosstoll-ng build.4

3.4       Modify the Path. 5

3.5       Check the Compiler.5

3.6       Heelo World on the RaspberryPi.5

4      Transfer files to the raspberry.6

4.1       Transfer with SCP and SSH.. 6

4.1.1       SSH : How to avoid password indentification.6

4.2       Transfer through share.6

4.3       Configure samba on the VM Funtoo.6

4.4       Configure samba on the raspberry.6

4.5       Mount the share.7

5      Setting up additional bin and lib files for cross compiling.8

6      Create a module for Linux Kernel.9

6.1       Resources.9

6.2       Get  the Raspberry kernel.9

 


1      Reference

1.1   Crosstool-ng.

1.2   info

 

1.3   remote debug

1.4   Create a module.

2      Buildroot

 

 

cd /home/pi/files/crosstoll

wget http://buildroot.uclibc.org/downloads/buildroot-2013.02.tar.bz2

tar xjf buildroot-2013.02.tar.bz2

cd /home/pi/files/crosstoll/buildroot-2013.02

wget http://www.blaess.fr/christophe/files/article-2012-10-12/config-buildroot

mv config-buildroot .config

sudo make

 

 


3      Crosstoolng on VM Funtoo.

This section is mostly inspired by the following Chris Boot’s article:

3.1   install crosstool-ng

To install crosstool-ng on Funtoo :

emerge -av sys-devel/ct-ng

 * IMPORTANT: 2 news items need reading for repository ‘gentoo’.

 * Use eselect news to read news items.

These are the packages that would be merged, in order:

Calculating dependencies… done!

[ebuild  N     ] dev-libs/apr-1.4.6-r1:1  USE=”urandom uuid -doc -older-kernels-compatibility -static-libs” 768 kB

[ebuild  N     ] dev-libs/apr-util-1.5.1:1  USE=”berkdb gdbm -doc -freetds -ldap -mysql -nss -odbc -openssl -postgres -sqlite -static-libs” 637 kB

[ebuild  N     ] net-libs/neon-0.29.6-r5  USE=”nls ssl zlib -doc -expat -gnutls -kerberos -libproxy -pkcs11 -static-libs” LINGUAS=”fr -cs -de -ja -nn -pl -ru -tr -zh_CN” 862 kB

[ebuild  N     ] dev-vcs/subversion-1.7.9-r1000  USE=”berkdb dso magic nls python webdav-neon -apache2 -ctypes-python -debug -doc -extras -gnome-keyring -java -kde -kerberos -perl -ruby -sasl -static-libs {-test} -webdav-serf” PYTHON_ABIS=”2.7 -2.5 -2.6” 5,899 kB

[ebuild  N     ] dev-vcs/cvs-1.12.12-r10  USE=”crypt nls pam -doc -kerberos -server” 3,123 kB

[ebuild  N     ] sys-devel/ct-ng-1.18.0  USE=”-bash-completion -doc” 1,841 kB

Total: 6 packages (6 new), Size of downloads: 13,127 kB

Would you like to merge these packages? [Yes/No]

3.2   Crosstoll-ng configuration.

  • Create a directory : mkdir /home/crosstoll-ng
    This will contain your toolchain configuration, downloaded files, and intermediary build results. This is not where your final toolchain will end up
  • cd into your chosen directory.
  • ct-ng menuconfig
  • Go into Paths and misc options. Enable Try features marked as EXPERIMENTAL.
  • Go back to the main menu and select Target options
  • Change the Target architecture to arm. Leave Endianness set to Little endian and Bitness set to 32-bit.
  • Go back to the main menu and select Operating system → Change Target OS to linux
  • Go back to the main menu and select Binary utilities. → Change binutils to  the latest that isn’t marked as experimental
  • Go back to the main menu and select C compiler. → Enable the Show Linaro versions (EXPERIMENTAL) option → In the gcc version field, choose the linaro-4.6-2012.04 (EXPERIMENTAL) compiler. You’re free to choose a different one but I know this one works well.http://www.linaro.org/
    If you want C++ enable it.
  • Save and exit


3.3   Crosstoll-ng build.

  • Run ct-ng build. It had taken 1h30 on my VM.

 

crosstoll-ng # ct-ng build

[INFO ]  Performing some trivial sanity checks

[INFO ]  Build started 20130413.180412

[INFO ]  Building environment variables

[INFO ]  =================================================================

[INFO ]  Retrieving needed toolchain components’ tarballs

[INFO ]  Retrieving needed toolchain components’ tarballs: done in 249.83s (at 04:19)

[INFO ]  =================================================================

[INFO ]  Extracting and patching toolchain components

[INFO ]  Extracting and patching toolchain components: done in 239.18s (at 08:18)

[INFO ]  =================================================================

[INFO ]  Installing GMP for host

[INFO ]  Installing GMP for host: done in 166.33s (at 11:05)

[INFO ]  =================================================================

[INFO ]  Installing MPFR for host

[INFO ]  Installing MPFR for host: done in 82.98s (at 12:28)

[INFO ]  =================================================================

[INFO ]  Installing PPL for host

[INFO ]  Installing PPL for host: done in 450.31s (at 19:58)

[INFO ]  =================================================================

[INFO ]  Installing CLooG/PPL for host

[INFO ]  Installing CLooG/PPL for host: done in 28.00s (at 20:26)

[INFO ]  =================================================================

[INFO ]  Installing MPC for host

[INFO ]  Installing MPC for host: done in 33.77s (at 21:00)

[INFO ]  =================================================================

[INFO ]  Installing binutils for host

[INFO ]  Installing binutils for host: done in 281.03s (at 25:41)

[INFO ]  =================================================================

[INFO ]  Installing pass-1 core C compiler

[INFO ]  Installing pass-1 core C compiler: done in 799.91s (at 39:01)

[INFO ]  =================================================================

[INFO ]  Installing kernel headers

[INFO ]  Installing kernel headers: done in 24.12s (at 39:25)

[INFO ]  =================================================================

[INFO ]  Installing C library headers & start files

[INFO ]  Installing C library headers & start files: done in 67.25s (at 40:33)

[INFO ]  =================================================================

[INFO ]  Installing pass-2 core C compiler

[INFO ]  Installing pass-2 core C compiler: done in 726.55s (at 52:39)

[INFO ]  =================================================================

[INFO ]  Installing C library

[INFO ]  Installing C library: done in 890.37s (at 67:30)

[INFO ]  =================================================================

[INFO ]  Installing final compiler

[INFO ]  Installing final compiler: done in 1115.67s (at 86:06)

[INFO ]  =================================================================

[INFO ]  Cleaning-up the toolchain’s directory

[INFO ]    Stripping all toolchain executables

[INFO ]  Cleaning-up the toolchain’s directory: done in 8.57s (at 86:14)

[INFO ]  Build completed at 20130413.193024

[INFO ]  (elapsed: 86:12.79)

[INFO ]  Finishing installation (may take a few seconds)…

 

The toolchain has been installed in the “Prefix directory” defined in the ct-ng configuration menu.

Has I was logged as root, it is /root/x-tools → /root/x-tools/arm-unknown-linux-gnueabi

But, you can move it to another patch → I move the toolchain to the folder : /opt/x-crosstools-ng.


3.4   Modify the Path

Add your compiler directory to your $PATH → /opt/x-crosstools-ng/arm-unknown-linux-gnueabi/bin.

On Gentoo, create a file  91crossng above /etc/env.d

With the following : PATH=”/opt/x-crosstools-ng/arm-unknown-linux-gnueabi/bin”

Remark : if you are logged as ROOT, you must change ROOTPATH and not PATH → ROOTPATH=”/opt/x-crosstools-ng/arm-unknown-linux-gnueabi/bin”

Then execute : env-update && source /etc/profile

Check if it is updated : /etc/profile.env must give :

 

Then Check with echo $PATH :

echo $PATH

/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/bin:/usr/i686-pc-linux-gnu/gcc-bin/4.6.3:/opt/x-crosstools-ng/arm-unknown-linux-gnueabi/bin

 

3.5   Check the Compiler.

arm-unknown-linux-gnueabi-gcc –version

arm-unknown-linux-gnueabi-gcc (crosstool-NG 1.18.0) 4.6.4 20130102 (prerelease)

Copyright (C) 2011 Free Software Foundation, Inc.

This is free software; see the source for copying conditions.  There is NO

warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

3.6   Heelo World on the RaspberryPi.

Create a little program.

cat > test.c

#include <stdio.h>

int main() { printf(“Hello, world!\n”); return 0; }

^D

Compile it : arm-unknown-linux-gnueabi-gcc -o test test.c

 

You can copy the binary “test” to the raspberry and check:

 


4      Transfer files to the raspberry.

4.1   Transfer with SCP and SSH

Transfer to the Rpi : scp test pi@192.168.1.23:./projects/FromFunto/test/

Execute on the Rpi : ssh pi@192.168.1.23 ./projects/FromFunto/test/test

4.1.1      SSH : How to avoid password indentification.

  • On the host Funtoo : ssh-keygen -t rsa
    This will create two ckey (private and public)
  • scp ~/.ssh/id_rsa.pub pi@192.168.1.23:pi.pub
    This will copy the public key on the raspberry.
  • ssh pi@192.168.1.23
    Login to the raspberry to add the public key into the authorized_keys.
  • ssh-keygen -t rsa → to create the folder ./ssh
    only necessary if there is no folder ./ssh. It will also create the two keys for the raspberry.
  • cat pi.pub >> ~/.ssh/authorized_keys
  • ssh pi@192.168.1.23 → the next logon will not ask to enter a password.

4.2   Transfer through share.

I have a lot of problem with share on Linux ! I think it’s due to my Virtual Machine on VMWare.

After a while, I get a “freeze” and the share is “stuck”. That’s why I use SCP from my VM.

I give the information in case it’s working in other configuration.

4.3   Configure samba on the VM Funtoo.

On the Funtoo VM, share the homes folders → see the document : “RaspBerry-HowTo-02-Tool.doc”

On the VM linux  :

  • Install samba : emerge samba
  • Start samba : /etc/init.d/samba start

 

Check with : smbclient -L localhost -U user01

Enter user01’s password:

 

Domain=[MYGROUP] OS=[Unix] Server=[Samba 3.6.13]

 

        Sharename       Type      Comment

        ———       —-      ——-

        homes           Disk      Home Directories

        IPC$            IPC       IPC Service (Samba Server)

        user01          Disk      Home Directories

 

4.4   Configure samba on the raspberry.

On the raspberry, share the homes folders → see the document : “RaspBerry-HowTo-02-Tool.doc”

 

To know the share on the raspberry : smbclient -L 192.168.1.23

 

Domain=[WORKGROUP] OS=[Unix] Server=[Samba 3.6.6]

 

        Sharename       Type      Comment

        ———       —-      ——-

        homes           Disk      Home Directories

        print$          Disk      Printer Drivers

        IPC$            IPC       IPC Service (raspberrypi server)

 

4.5   Mount the share.

From Funtoo : mount //192.168.1.23/homes /mnt/raspberry -o username=pi,password=raspberry

From Raspberry : mount //192.168.1.31/user01 /mnt/funtoo -o username=user01,password=funtoo

mount error(112): Host is down

Refer to the mount.cifs(8) manual page (e.g. man mount.cifs)

Why ??


5      Setting up additional bin and lib files for cross compiling.

 

 


6      Create a module for Linux Kernel.

6.1   Resources.

6.2   Get  the Raspberry kernel.

  • wget https://github.com/raspberrypi/linux/archive/rpi-3.2.27.tar.gz -O – | tar xzf –
    The kernel has been uploaded to : /home/files/raspberry/kernel/linux-rpi-3.2.27
  • Create the .config : ssh pi@192.168.1.23 cat /proc/config.gz | gunzip – > linux-rpi-3.2.27/.config

 

 

linux-rpi-3.2.27 # make ARCH=arm CROSS_COMPILE=arm-unknown-linux-gnueabi- oldconfig

  HOSTCC  scripts/basic/fixdep

  HOSTCC  scripts/kconfig/conf.o

  SHIPPED scripts/kconfig/zconf.tab.c

  SHIPPED scripts/kconfig/zconf.lex.c

  SHIPPED scripts/kconfig/zconf.hash.c

  HOSTCC  scripts/kconfig/zconf.tab.o

scripts/kconfig/zconf.tab.c: In function ‘header_print_comment’:

scripts/kconfig/confdata.c:540:10: warning: ignoring return value of ‘fwrite’, declared with attribute warn_unused_result [-Wunused-result]

scripts/kconfig/zconf.tab.c: In function ‘kconfig_print_comment’:

scripts/kconfig/confdata.c:467:10: warning: ignoring return value of ‘fwrite’, declared with attribute warn_unused_result [-Wunused-result]

  HOSTLD  scripts/kconfig/conf

scripts/kconfig/conf –oldconfig Kconfig

*

* Restart config…

*

*

* Broadcom BCM2708 Implementations

*

Broadcom BCM2708 Development Platform (MACH_BCM2708) [Y/?] y

  BCM2708 gpio support (BCM2708_GPIO) [Y/n/?] y

  Videocore Memory (BCM2708_VCMEM) [Y/n/?] y

  Videocore L2 cache disable (BCM2708_NOL2CACHE) [N/y/?] n

  BCM2708 DMA helper (BCM2708_DMAER) [N/m/y/?] (NEW)

#

# configuration written to .config

#

 

linux-rpi-3.2.27 # make ARCH=arm CROSS_COMPILE=arm-unknown-linux-gnueabi- prepare

scripts/kconfig/conf –silentoldconfig Kconfig

  WRAP    arch/arm/include/generated/asm/auxvec.h

  WRAP    arch/arm/include/generated/asm/bitsperlong.h

  WRAP    arch/arm/include/generated/asm/cputime.h

  WRAP    arch/arm/include/generated/asm/emergency-restart.h

  WRAP    arch/arm/include/generated/asm/errno.h

  WRAP    arch/arm/include/generated/asm/ioctl.h

  WRAP    arch/arm/include/generated/asm/irq_regs.h

  WRAP    arch/arm/include/generated/asm/kdebug.h

  WRAP    arch/arm/include/generated/asm/local.h

  WRAP    arch/arm/include/generated/asm/local64.h

  WRAP    arch/arm/include/generated/asm/percpu.h

  WRAP    arch/arm/include/generated/asm/poll.h

  WRAP    arch/arm/include/generated/asm/resource.h

  WRAP    arch/arm/include/generated/asm/sections.h

  WRAP    arch/arm/include/generated/asm/siginfo.h

  WRAP    arch/arm/include/generated/asm/sizes.h

  CHK     include/linux/version.h

  UPD     include/linux/version.h

  CHK     include/generated/utsrelease.h

  UPD     include/generated/utsrelease.h

  Generating include/generated/mach-types.h

  CC      kernel/bounds.s

  GEN     include/generated/bounds.h

  CC      arch/arm/kernel/asm-offsets.s

  GEN     include/generated/asm-offsets.h

  CALL    scripts/checksyscalls.sh

 

  • make –j2 ARCH=arm CROSS_COMPILE=arm-unknown-linux-gnueabi-

 

 

CROSS_COMPILE=arm-unknown-linux-gnueabi-

La macro CROSS_COMPILE sert à indiquer le préfixe des outils de la toolchain. Cela permet au make d’invoquer le bon compilateur – c’est à dire celui de la cible et non pas celui de l’hôte par erreur.

Dans mon cas, avec une toolchain générée en conservant au maximum les options par défaut de crosstool-NG, ces outils sont:

    arm-unknown-linux-gnueabi-gcc

    arm-unknown-linux-gnueabi-as

    arm-unknown-linux-gnueabi-ld

 

 

Follow the step here : Compiler son propre module → http://www.chicoree.fr/w/Compilation_crois%C3%A9e_d%27un_module_Linux_pour_Rasberry_Pi

 

 

make ARCH=arm CROSS_COMPILE=arm-unknown-linux-gnueabi-

 

make ARCH=arm CROSS_COMPILE=arm-unknown-linux-gnueabi-

make -C /home/files/raspberry/kernel/linux-rpi-3.2.27/ M=/home/files/raspberry/programme/module-test-chicore modules

make[1]: Entering directory `/home/files/raspberry/kernel/linux-rpi-3.2.27′

  CC [M]  /home/files/raspberry/programme/module-test-chicore/my-module.o

  Building modules, stage 2.

  MODPOST 1 modules

  CC      /home/files/raspberry/programme/module-test-chicore/my-module.mod.o

  LD [M]  /home/files/raspberry/programme/module-test-chicore/my-module.ko

make[1]: Leaving directory `/home/files/raspberry/kernel/linux-rpi-3.2.27′

funtoo-XFCE module-test-chicore # ls -la

total 84

drwxr-xr-x 3 root root  4096 Apr 14 18:10 .

drwxr-xr-x 5 root root  4096 Apr 14 16:19 ..

-rw-r–r– 1 root root   396 Apr 14 18:10 .my-module.ko.cmd

-rw-r–r– 1 root root 16948 Apr 14 18:10 .my-module.mod.o.cmd

-rw-r–r– 1 root root 16845 Apr 14 18:10 .my-module.o.cmd

drwxr-xr-x 2 root root  4096 Apr 14 18:10 .tmp_versions

-rw-r–r– 1 root root   206 Apr 14 16:22 Makefile

-rw-r–r– 1 root root     0 Apr 14 18:10 Module.symvers

-rw-r–r– 1 root root    72 Apr 14 18:10 modules.order

-rw-r–r– 1 root root   460 Apr 14 16:20 my-module.c

-rw-r–r– 1 root root  3086 Apr 14 18:10 my-module.ko

-rw-r–r– 1 root root   749 Apr 14 18:10 my-module.mod.c

-rw-r–r– 1 root root  2012 Apr 14 18:10 my-module.mod.o

-rw-r–r– 1 root root  1772 Apr 14 18:10 my-module.o

 

 

scp my-module.ko pi@192.168.1.23:.

 

module-test-chicore # ssh pi@192.168.1.23

Linux raspberrypi 3.2.27+ #250 PREEMPT Thu Oct 18 19:03:02 BST 2012 armv6l

pi@raspberrypi ~ $

 

sudo insmod my-module.ko

dmesg

[  307.121685] Hello world

sudo rmmod my_module

[  335.509932] Goodbye world

dmesg