Skip to content

Building Linux kernel and Filesystem Separately

Yuriy Kolerov edited this page Aug 1, 2023 · 1 revision

Preface

Sometimes it's more convenient to build root file system and a Linux kernel separately. This guide covers an example when it's necessary to build those images separately for ARC HS38 target.

Suppose, that a toolchain for ARC HS38 is preinstalled in /tools/toolchains/arc-linux-gnu. The version is 2023.03 and it's based on glibc standard library.

Building Root Filesystem

Clone Buildroot:

# Clone the latest Buildroot
$ git clone https://git.busybox.net/buildroot

# ... or use a custom repository for support of ARCv3 targets
$ https://github.com/foss-for-synopsys-dwc-arc-processors/buildroot

$ cd buildroot

Use snps_archs38_haps_defconfig configuration file for this example and enter a configuration menu:

$ make snps_archs38_haps_defconfig
$ make menuconfig

Deselect an option for the Linux kernel and select an appropriate filesystem for your needs:

Kernel -> [ ] Linux kernel
Filesystem images -> [*] cpio the root filesystem # For use as an initial RAM filesystem
                  -> ext2/3/4 root filesystem     # For mounting from a storage

Choose a preinstalled toolchain:

Toolchain -> Toolchain type -> (X) External toolchain
          -> (X) Custom toolchain
          -> Toolchain origin -> (X) Pre-installed toolchain
          -> Toolchain path -> /tools/toolchains/arc-linux-gnu
          -> External toolchain gcc version -> (X) 12.x
          -> External toolchain kernel headers series -> (X) 5.16.x
          -> External toolchain C library -> (X) glibc
          -> [ ] Toolchain has RPC support?
          -> [X] Toolchain has C++ support?
          -> [X] Toolchain has Fortran support?

Build the filesystem image:

make

Building the Linux Kernel Without Initial Root Filesystem

Clone a Linux kernel repository and choose a version you want:

$ git clone https://github.com/torvalds/linux
$ cd linux
$ git checkout v6.4

Configure the kernel:

$ make ARCH=arc haps_hs_defconfig

Put the toolchain to PATH environment variable and build the kernel:

$ export PATH=/tools/toolchains/arc-linux-gnu:$PATH
$ make ARCH=arc CROSS_COMPILE=arc-linux-

The Linux kernel is saved as vmlinux file.

Building the Linux Kernel With Initial Root Filesystem

To link the Linux kernel with previously built root filesystem image (with .cpio extension), it's necessary to set CONFIG_INITRAMFS_SOURCE options for the kernel. Configure the kernel and enter a configuration menu:

$ make ARCH=arc haps_hs_defconfig
$ make ARCH=arc menuconfig

Fill CONFIG_INITRAMFS_SOURCE parameter with a path to rootfs.cpio, which was built previously:

General setup -> Initial RAM filesystem and RAM disk support
                 -> Initramfs source file(s) -> <Buildroot-source-tree>/output/images/rootfs.cpio

Put the toolchain to PATH environment variable and build the kernel:

$ export PATH=/tools/toolchains/arc-linux-gnu:$PATH
$ make ARCH=arc CROSS_COMPILE=arc-linux-

The Linux kernel with root file system is saved as vmlinux file.

Clone this wiki locally