Operating the Raspberry Pi 3 in 64-bit mode

Voila: Wide Bit

Various possibilities exist for determining whether you are running a 64-bit Linux. For example, dmesg outputs boot messages, and Linux identifies the architecture right in the first four lines. The root cat /proc/cpuinfo command notifies you at the very minimum that an ARMv8 set of commands is involved, and uname -a indicates that the kernel is a 64-bit variant.

If you want to be definite, use the C source code from Listing 1 and save it as hello.c. However, the test system offers only a single editor, Vim, for doing this. If you want to use a different editor like Nano or Joe, you will first need to activate the network and then retrofit it by installing the editor:

# dhclient -i eth0
# apt-get install joe nano

Listing 1

hello.c

/* hello.c */
#include <stdio.h>
int main( int argc, char **argv, char **envp ) {
  printf("Hello World\n");
  printf("This is %d-bit architecture\n", sizeof(int *)*8);
  return 0;
}

After startup, the modified "Hello World" from Listing 1 outputs the bit width for the pointer variables. These are 64 bits wide only if they are on a 64-bit system. It is sufficient for compiling the source code to enter make hello in the source code directory. Then call the binary using ./hello (Figure 3).

Figure 3: The RPi3 is eminently capable of running as a 64-bit system even though the Raspberry Pi Foundation did not originally intend for this to be the case.

The 64-bit Linux for the Rasp Pi may be lean, but it is completely functional. The configuration does come across as rudimentary. For example, it will not generate a connection to the Internet by default. Once connected to the Internet, though, the system can be updated and extended without any problems. Debian is well known for having a huge treasure trove of packages available.

Creating Your Own Kernel

If you want to create something more exciting, then you can compile your own current 64-bit kernel. The RPi3 is probably not the best computer for this task because of the amount of effort involved. It is quicker to use cross-development techniques and start with a PC [5]. The development tools necessary for compiling the kernel are easy to install on a current Ubuntu system as a gcc-aarch64-linux-gnu package.

The Linux kernel source code is ready and waiting for cross compiling. You will need the kernel sources from the Rasp Pi archive. They are only slightly different from those for the Vanilla Linux kernel, but they guarantee error-free compilation. In particular, the Foundation archive includes the required 64-bit default configuration bcmrpi3_defconfig, which is missing from the original.

You should store the source code in the directory tree underneath /usr/src/arm/, for example, by using git clone. The Git archive contains all of the versions of the kernel so that you only need to check out the current kernel version (4.8).

First, set two environment variables to be used for instructing the kernel build system. This approach avoids the need for the cross-compiler aarch64-linux-gnu-gcc from the gcc host compiler. Before starting to generate, you should configure the kernel for the RPi3. A make -j 4 Image dtbs modules starts the build. The -j 4 option makes it possible for make to run up to four processes simultaneously.

Depending on the hardware, compiling the kernel, modules, and device tree can take a good hour to complete. Listing 2 contains the precise commands plus accompanying comments for everything from downloading the source code to generating all of the components.

Listing 2

Compiling a 64-bit Kernel

$ sudo su
// Install crosscompiler
# apt-get install gcc-aarch64-linux-gnu
//Download kernel source code for the Raspberry Pi
# mkdir -p /usr/src/arm/
# cd /usr/src/arm
# git clone https://github.com/raspberrypi/linux.git
# cd linux
// Indicate versions available in the  Git Archive
// and check out an updated version
# git branch -a
# git checkout rpi-4.8.y
// cross generate the kernel
# export CROSS_COMPILE=aarch64-linux-gnu-
# export ARCH=arm64
# make bcmrpi3_defconfig
# make -j 4 Image dtbs modules

Buy this article as PDF

Express-Checkout as PDF

Pages: 8

Price $2.95
(incl. VAT)

Buy Raspberry Pi Geek

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content