Creating ARM architecture environment inside x86/x64 linux

If you want your hands on arm architecture assembly then you probably would be wondering how can I generate the *ARM* assembly or use ARM toolset in general inside my intel x86 or x64 architecture system. In this article we will explain you how you can do that by using qemu and chroot.

Creating ARM architecture environment inside x86/x64 linux

If you want your hands on arm architecture assembly then you probably would be wondering how can I generate the ARM assembly or use ARM toolset in general inside my intel x86 or x64 architecture system. In this article we will explain you how you can do that by creating chroot environment for ARM arch.

First lets have a quick background on arm architecture and where it is used.
According to wikipedia:

ARM, previously Advanced RISC Machine, originally Acorn RISC Machine, is a family of reduced instruction set computing (RISC) architectures for computer processors, configured for various environments.

In 2005, about 98% of all mobile phones sold used at least one ARM processor. In 2010, producers of chips based on ARM architectures reported shipments of 6.1 billion ARM-based processors, representing 95% of smartphones, 35% of digital televisions and set-top boxes and 10% of mobile computers. In 2011, the 32-bit ARM architecture was the most widely used architecture in mobile devices and the most popular 32-bit one in embedded systems. In 2013, 10 billion were produced and "ARM-based chips are found in nearly 60 percent of the world’s mobile devices".

So, leaning or being familiar with ARM is a great investment. Hence,without wasting further time, lets get started.

Creating chroot environment for ARM

In general chroot is only capable of creating virtual environment of same architecture distributions. For example: you can only create debian x86 system inside the x86 host system. So, for successfully creating a ARM system we need to use qemu which is capable of providing successful emulatation for a number of ARM platforms.

I am using ubuntu 17.10(x64) as the host system

Install required packages

$ apt-get install binfmt-support qemu qemu-user-static

If you want to be able to cross-compile using your host computer to build code to run on the simulator, you'll need to install the GCC packages for doing so:

$ sudo apt-get install gcc-arm-linux-gnueabi g++-arm-linux-gnueabi

Download the base ARM system

First you need to install debootstrap for downloading the debian ARM system.

apt-get install debootstrap

Download the minimal system

You require root permission for below command.

$ qemu-debootstrap --arch armel stretch armDebian http://deb.debian.org/debian/

where armDebian is the directory inside which you want to install the system and stretch is the debian flavor you want to use.

It may take little time to download and configure the system with above command but once complete you can start chrooting inside it.

Starting the chroot

Before chroot inside armDebian you need to mount few things inside that environment to make it work completely. Its better to put those commands on a script so that every time you want to chroot, just run the script.

$ cat runArm.sh 
#!/bin/bash
mount --bind /dev/ /home/0day/armDebian/dev
mount --bind /dev/pts /home/0day/armDebian/dev/pts
mount --bind /dev/shm /home/0day/armDebian/dev/shm
mount -t sysfs sysfs /home/0day/armDebian/sys
mount -t proc proc /home/0day/armDebian/proc
cp -L /etc/resolv.conf /home/0day/armDebian/etc/resolv.conf
chroot /home/0day/armDebian

Once you have created this script just change its permissions and run it using following:

$ chmod +x runArm.sh
$ sudo ./runArm.sh

Now you are inside a minimal ARM based system. First thing that you should do inside the system is to update and install the few required packages like gdb, python etc.

What is still missing

ARM systems doesn't required BIOS for their functionality since the bootloader is directly installed on hardware. They have U-boot installed as their bootloader. If you want to play or learn u-boot then you cannot do that with chroot environment. For that you need to install it inside full virtual environment like qemu to get the booting process. We will look into how to do that using linaro toolchain in other article.

0 Comments
Loading...