Skip to content

How to build rootfs separately from Linux image for ARC

EvgeniiDidin edited this page Sep 4, 2017 · 1 revision

Here you can find step-by-step instruction for separately building Linux image and rootfs using Buildroot, which can be stored on SD-сard.

Getting Buildroot

Stable Buildroot releases are published every three months. Tarballs are available for each stable release (http://buildroot.org/downloads/). However, it is generally more convenient to clone the upstream Git repository.

$ git clone https://git.busybox.net/buildroot
$ cd buildroot

Configure Buildroot

In this instruction axs103 configuration was selected:

make  snps_archs38_axs103_defconfig

After that we need to disable integrating of the root filesystem generated by Buildroot as an initramfs inside the kernel image. It can be easily done like:

make menuconfig

Exclude next feature: 'Filesystem images -> [ ]initial RAM filesystem linked into linux kernel'. Exit menuconfig and save configuration

Modifying buildroot

Here will be few steps if modifying buildroot which are necessary for successful building Linux image and rootfs separately.

First we need modify linux make file. From buildroot directory execute: cd linux, edit linux.mk file. Near 240 line find next lines:

$(if $(BR2_TARGET_ROOTFS_INITRAMFS),
    touch $(BINARIES_DIR)/rootfs.cpio
    $(call KCONFIG_SET_OPT,CONFIG_INITRAMFS_SOURCE,"$${BR_BINARIES_DIR}/rootfs.cpio",$(@D)/.config)
    $(call KCONFIG_SET_OPT,CONFIG_INITRAMFS_ROOT_UID,0,$(@D)/.config)
    $(call KCONFIG_SET_OPT,CONFIG_INITRAMFS_ROOT_GID,0,$(@D)/.config))

After this part add lines below:

$(if !$(BR2_TARGET_ROOTFS_INITRAMFS),
       $(call KCONFIG_SET_OPT,CONFIG_INITRAMFS_SOURCE,"",$(@D)/.config))

By default snps_archs38_axs103_defconfig set 'INITRAMFS_SOURCE' variable, so we need forcefully clear it to prevent errors.

Next we need to add path to root filesystem in bootargs so kernel will find it. From buildroot directory execute:

make linux-patch
cd output/build/linux-<version>/arch/arc/boot/dts
gedit axs103_idu.dts

Add "root=/dev/mmcblk0p2 rootwait" in 'bootargs' variable. Save and exit file, go back to buildroot directory, execute make

Writing files to SD-card

Take your SD-card, plug it into your laptop. You need to divide free space into two partitions. First is FAT32(200MB), second is ex4(remaining). For example gparted utility can be used for this operation. Replug SD-card, execute lsblk, you will see something like:

mmcblk0     179:0    0  14.9G  0 disk 
├─mmcblk0p2 179:2    0  14.7G  0 part /path/to/ext4_mount_directory
└─mmcblk0p1 179:1    0   200M  0 part /path/to/FAT32_mount_directory

From buildroot directory:

cd output/images
cp uImage /path/to/FAT32_mount_directory
cp rootfs.tar /path/to/any_convenient_directory
cd /path/to/any_convenient_directory
sudo chown root:root rootfs.tar
sudo tar -xvf rootfs.tar
sudo rm rootfs.tar
sudo cp -r * /path/to/ext4_mount_directory

unmount partitions of SD-card, unplug it from laptop. Now SD-card is ready for work.

Clone this wiki locally