domingo, mayo 28, 2017

Compile and run Linux Kernel and Busybox for ARM 64 bits aarch64 on QEMU

Hello everyone, in this post you can read how to and where to download, compile and run Linux kernel and busybox for ARM64 processor.

the first step is to get the toolchain, linux kernel source and busybox source,   in this case we will do it using.

- CodeSourcery Lite for ARM64, the version i have is:  aarch64-amd-2014.11.tar it could be download for free from


Sourcery CodeBench Lite Edition for AMD64 ARM GNU/Linux


as the second step you need to source code for kernel linux and busybox,

to download the kernel, you can do it from    https://www.kernel.org/,  in my case  version 4.11.3
stable:4.11.32017-05-25[tarball]
Busybox can be downloaded from  https://busybox.net/downloads/  latest for today is version  1.26.2


Let take on hands to compile and test  busybox

once you have decompress the toolchain and the sourcecode for busybox, lets compile  using the next command.

Path for toolchain
/media/backups/mariotpc/developer/gcc-arm-none-eabi-6-2017-q1-update/bin/arm-none-eabi-

Path for busybox sourcecode
/media/backups/mariotpc/developer/kernel-and-qemu/busybox-1.26.2

command to configure busybox
make ARCH=arm64 CROSS_COMPILE=/media/backups/mariotpc/developer/aarch64-amd-2014.11/bin/aarch64-amd-linux-gnu- menuconfig

indicate the toolchain path and sysroot for your codesourcery toolchain





command to compile
make ARCH=arm64 CROSS_COMPILE=/media/backups/mariotpc/developer/aarch64-amd-2014.11/bin/aarch64-amd-linux-gnu- install


once the compilation has been complete,  you get the file  busybox in format aarch64, you can check it as follows

[mariotpc@laptop busybox-1.26.2]$ file busybox
busybox: ELF 64-bit LSB executable, ARM aarch64, version 1 (SYSV), statically linked, for GNU/Linux 3.7.0, stripped

Great !!!! the busybox for ARM aarch64 has been success !!!!!


Hands on the Linux Kernel
the configuration parameters are being taken from the ARCH indicated on the command,  for example, the default configuration  for aarch64 is readed from ARCH=arm64

it is located on
/media/backups/mariotpc/developer/kernel-and-qemu/linux-4.11.3/arch/arm64/configs/defconfig


make ARCH=arm64 CROSS_COMPILE=/media/backups/mariotpc/developer/aarch64-amd-2014.11/bin/aarch64-amd-linux-gnu-  defconfig



Generate, compile, build the linux kernel using command:

make ARCH=arm64 CROSS_COMPILE=/media/backups/mariotpc/developer/aarch64-amd-2014.11/bin/aarch64-amd-linux-gnu-  defconfig


  CHK     include/generated/compile.h
  CHK     kernel/config_data.h
  Building modules, stage 2.
  MODPOST 193 modules
[mariotpc@laptop linux-4.11.3]$ 




At this time, we have the linux kernel and the busybox compiled, we need to create the init for boot the kernel, from busybox

1.- create the  rcS  file in the /etc directory as follows.

[mariotpc@laptop etc]$ cat init.d/rcS 
#!/bin/sh
mount -t proc none /proc
mount -t sysfs none /sys
/sbin/mdev -s


inside busybox, on the _install directory run the next commands

find . | cpio -o --format=newc > ../rootfs.img


All has been done,   now start the qemu emulator and lets the linux kernel and busybox to run inside of it,  

Congratulations...!!!!  you are ready to test your production environment 


qemu-system-aarch64 -machine virt -cpu cortex-a57 -machine type=virt -nographic -smp 1 -m 2048 -kernel linux-4.11.3/arch/arm64/boot/Image -initrd busybox-1.26.2/rootfs.img -append "root=/dev/ram rdinit=/sbin/init"


Booting the linux kernel on the qemu environment

[    0.000000] Booting Linux on physical CPU 0x0
[    0.000000] Linux version 4.11.3 (mariotpc@laptop.chutzpah) (gcc version 4.9.1 (Sourcery CodeBench Lite 2014.11-95) ) #1 SMP PREEMPT Sat May 27 23:54:08 CST 2017
[    0.000000] Boot CPU: AArch64 Processor [411fd070]
[    0.000000] efi: Getting EFI parameters from FDT:
[    0.000000] efi: UEFI not found.
[    0.000000] cma: Reserved 16 MiB at 0x00000000bf000000
[    0.000000] NUMA: No NUMA configuration found
[    0.000000] NUMA: Faking a node at [mem 0x0000000000000000-0x00000000bfffffff]
[    0.000000] NUMA: Adding memblock [0x40000000 - 0xbfffffff] on node 0


.....

[    1.328196] Freeing unused kernel memory: 1088K

Please press Enter to activate this console.
/ # uname -a
Linux (none) 4.11.3 #1 SMP PREEMPT Sat May 27 23:54:08 CST 2017 aarch64 GNU/Linux

/ # busybox 
BusyBox v1.26.2-MarioTPC (2017-05-27 22:50:31 CST) multi-call binary.
BusyBox is copyrighted by many authors between 1998-2015.
Licensed under GPLv2. See source distribution for detailed
copyright notices.

Usage: busybox [function [arguments]...]
   or: busybox --list[-full]
   or: busybox --install [-s] [DIR]
   or: function [arguments]...

        BusyBox is a multi-call binary that combines many common Unix
        utilities into a single executable.  Most people will create a
        link to busybox for each function they wish to use and BusyBox
        will act like whatever it was invoked as.

Currently defined functions:
        [, [[, acpid, add-shell, addgroup, adduser, adjtimex, arp, arping, ash,
        awk, base64, basename, beep, blkdiscard, blkid, blockdev, bootchartd,


No hay comentarios.:

Compile and run Linux Kernel and Busybox for ARM 64 bits aarch64 on QEMU

Hello everyone, in this post you can read how to and where to download, compile and run Linux kernel and busybox for ARM64 processor. the ...