Showing posts with label emulation. Show all posts
Showing posts with label emulation. Show all posts

Compiling ARM1176 for QEMU Raspberry Pi Emulation Kernel

This is referred from this forum post and optimized for Mac OSX users. This blog post will show you how to compile a QEMU-ready Linux kernel for the ARM1176JZF-S CPU used by the Raspberry Pi. If you want to skip all of this and just have a kernel you can use, you can download 3.18 kernel here.


1. Preparing the development environment

Installing brew

First you need to have a package manager. HomeBrew is a good choice(for more info. refer this post). Or you can use any other such as "macport".
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Installing libcurses5 library

libncurses5-dev
brew install homebrew/dupes/ncurses
brew link --force ncurses

Installing crosee-compiler tools

You can download pre-compiled cross-compiler tools for MAC OSX from this blog.
After the installation add the binaries to your path.
echo "/usr/local/linaro/arm-linux-gnueabihf-raspbian/bin" >> /etc/paths

2. Preparing the Linux Kernel

Installing Git

Installing any package on homebrew is simple as "brew install <package_name>".
brew install git

Download the source

Download linux source from raspberrypi linux repository.
git clone https://github.com/raspberrypi/linux.git

3. Configure the Kernel

Then we need to configure the kernel accordingly:
cd linux
make ARCH=arm versatile_defconfig
make ARCH=arm menuconfig

Specify the cross-compiler:

General Setup --->
    Cross-compiler tool prefix
        (arm-linux-gnueabihf-)

Note: Do not forget the '-' at the end of this string.
Note: When you select an option make sure you don't see 'M', but '*' (you may need to press space twice).

Select the right CPU options:

System Type --->
    [*] Support ARM V6 processor
    [*] ARM errata: Invalidation of the Instruction Cache operation can fail
    [*] ARM errata: Possible cache data corruption with hit-under-miss enabled

Enable support for hard-float binaries:

Floating point emulation  --->
    [*] VFP-format floating point maths

Enable ARM EABI:

Kernel Features --->
    [*] Use ARM EABI to compile the kernel
    [*] Allow old ABI binaries to run with this kernel

Enable QEMU's disk support:

Bus Support --->
    [*] PCI Support
Device Drivers --->
    SCSI Device Support --->
        [*] SCSI Device Support
        [*] SCSI Disk Support
        [*] SCSI CDROM support
        [*] SCSI low-lever drivers --->
        [*] SYM53C8XX  Version 2 SCSI support

Enable devtmpfs:

    Device Drivers --->
        Generic Driver Options--->
            [*] Maintain a devtmpfs filesystem to mount at /dev
            [*] Automount devtmpfs at /dev, after the kernel mounted the root

Enable the important file systems:

    File systems -->
        <*> Ext3 journalling file system support
         <*> The Extended 4 (ext4) filesystem

Enable tmpfs:

File systems --->
    Pseudo filesystems--->
        [*] Virtual memory file system support (former shm fs)

Enable the event interface:

Device Drivers --->
    Input device support--->
        [*] Event interface

Adding RaspberryPi Logo into Kernel:

Device Drivers --->
    Graphics Support --->
        Console display driver support --->
            [ ] Select compiled-in fonts
                [*] Bootup logo (optional)

Exit, saving the configuration.

4. Compiling the Kernel

make ARCH=arm
mkdir ../modules
make ARCH=arm INSTALL_MOD_PATH=../modules modules_install

Troubleshooting

Error 1:
scripts/mod/modpost.c:1465:7: error: use of undeclared identifier 'R_386_32'
        case R_386_32:

Create a new file elf.h and paste this code from the opensource.apple.com.

nano /usr/local/include/elf.h

In the same file append these...

#define R_386_NONE 0
#define R_386_32 1
#define R_386_PC32 2
#define R_ARM_NONE 0
#define R_ARM_PC24 1
#define R_ARM_ABS32 2
#define R_MIPS_NONE 0
#define R_MIPS_16 1
#define R_MIPS_32 2
#define R_MIPS_REL32 3
#define R_MIPS_26 4
#define R_MIPS_HI16 5
#define R_MIPS_LO16 6

Error2:

/usr/local/include/elf.h:45:10: fatal error: 'elftypes.h' file not found
#include "elftypes.h" /* In lieu of Solaris <sys/elftypes.h> */

create a new file elftypes.h and paste this code from  the opensource.apple.com.

nano /usr/local/include/elftypes.h

Error 3:

xargs: illegal option -- r

This is because BSD xargs doesn't have the same options as GNU xargs. Install GNU xargs from macports (It should show up earlier in your search path)

# Install GNU `find`, `locate`, `updatedb`, and `xargs`, g-prefixed
brew install findutils

Replace all files using 'xargs' to 'gxargs'. (Use a sublime or any texteditor).

5. Copy compiled Kernel

Copy the compiled kernel to your working directory:

cp arch/arm/boot/zImage ../

Done! You should name have a QEMU-bootable linux kernel and modules in your work directory.