Build Linux Kernel for gem5

In this page, we will explain how to prepare Linux Kernel for gem5.

Prerequisite

Prepare kernel config files

Before starting, please download kernel_configs directory from here. This directory contains two files, config_arm and config_x86.

Download Linux Kernel source code

You can download Linux Kernel from The Linux Kernel Archives.

This table shows minimum Linux Kernel version supported by architectures and interfaces:

Architecture

NVMe

OCSSD * 1.2

OCSSD 2.0

SATA

UFS

ARMv7

3.3 1

4.12 4

4.17 5

All

4.8 6

ARMv8

4.4 2

4.12 4

4.17 5

4.4 2

4.8 6

X86

4.4 3

4.12 4

4.17 5

4.4 3

Not supported

*

OCSSD stands for Open-Channel SSD.

1

NVMe driver is added to Linux Kernel from 3.3.

2(1,2)

ARMv8 (aarch64) is supported from Linux Kernel 3.7 but PCI host controller used by gem5 is supported from 4.4.

3(1,2)

X86 architecture of gem5 is quite unstable. Linux Kernel 3.4.113 ~ 4.3 does not boot.

4(1,2,3)

pblk driver of Open-Channel SSD is available from 4.12. rrpc is not supported by SimpleSSD.

5(1,2,3)

Linux Kernel supports Open-Channel SSD 2.0 from 4.17. But, we recommend to use 4.18 or greater.

6(1,2)

UFS driver that SimpleSSD uses is added to Linux Kernel from 4.8.

Download toolchain

Prepare compiler for kernel compilation.

For X86 architecture, you can just use GNU C/C++ Compiler installed on your host X86 machine. If you are using non-x86 machine, you need to prepare x86 cross-compiler for your machine.

For ARM architecture, you need to download ARM cross-compiler. We recommend to use Linaro Toolchain. Download arm-linux-gnueabihf for ARMv7, aarch64-linux-gnu for ARMv8.

Install toolchain and properly set PATH environment variable.

Download dependencies

Install utilities and libraries used by Linux Kernel.

# For Debian based Linux
apt install libncurses-dev bc libssl-dev libelf-dev flex bison

# For Red Hat based Linux
yum install ncurses-devel bc openssl-devel elfutils-libelf-devel

Build Linux Kernel

Extract downloaded Linux Kernel archive and cd to extracted directory.

Set ARCH and CROSS_COMPILE correctly using following table:

Variable

ARMv7

ARMv8

X86

ARCH

arm

arm64

x86 or <Empty>

CROSS_COMPILE

arm-linux-gnueabihf-

aarch64-linux-gnu-

<Empty>

Create default kernel configuration file:

ARCH="<arch to build>" CROSS_COMPILE="<prefix of compiler>" make defconfig

Override created .config file with provided sample configuration file.

# For ARMv7 and ARMv8
cp -f config_arm .config

# For X86
cp -f config_x86 .config

Open kernel configuration page at least once. This will fix undefined configuration entitles in .config file. You can also change configuration here.

ARCH="<arch to build>" CROSS_COMPILE="<prefix of compiler>" make menuconfig

Build Linux Kernel image:

ARCH="<arch to build>" CROSS_COMPILE="<prefix of compiler>" make vmlinux -j 8

After build, copy vmlinux image to $M5_PATH/binaries directory.

cp vmlinux $M5_PATH/binaries/my_new_kernel_image