Build and Modify a Rootfs
This how-to describes the process to build a RAM disk or init.rd image. This is a part of the Xilinx design flow described in Xilinx Open Source Linux.
Table of Contents
Task Dependencies (Pre-requisites)
- Build U-Boot (mkimage utility)
Tools Required
- None
Input Files Required
- ramdisk.image.gz (required for Zynq AP SoC)
- initramfs.cpio.gz (required for MicroBlaze and PowerPC)
Output Files Produced
- uramdisk.image.gz
Task Description
There are two types of formats being used for root filesystems. Before Vivado/SDK version 2013.1, Linux for Zynq AP SoC used an initial ramdisk/initrd (ramdisk.image.gz); Since then, the Zynq uses initramfs. MicroBlaze and PowerPC are using initramfs (initramfs.cpio.gz).Prebuilt images
Prebuilt images can be found here:arm_ramdisk.image.gz: for Zynq AP SoC (ARM) systems. (initrd)
microblaze-le_minimal.cpio.gz: for AXI (Little Endian) MicroBlaze systems. (initramfs)
microblaze_minimal.cpio.gzf: or PLB (Big Endian) MicroBlaze systems. (initramfs)
microblaze_complete.cpio.gz: for PLB (Big Endian) MicroBlaze systems. (initramfs)
Modifying the root filesystem
Initrd
To modify an initial ramdisk:1. Extract the initrd image from the gzip archive.
gunzip ramdisk.image.gz
chmod u+rwx ramdisk.image mkdir tmp_mnt/ sudo mount -o loop ramdisk.image tmp_mnt/ cd tmp_mnt/
4. Unmount the initrd image and compress the image.
sudo umount tmp_mnt/ gzip ramdisk.image
To create an initrd from scratch, tools such as Buildroot or Yocto may be used to populate the filesystem (with BusyBox, tools, etc.).
Alternatively, an empty initrd may be created and then populated with the desired filesystem contents as specified above. To create an empty (8MB) initrd:
dd if=/dev/zero of=ramdisk.image bs=1024 count=8192 mke2fs -F ramdisk.image -L "ramdisk" -b 1024 -m 0 tune2fs ramdisk.image -i 0 chmod a+rwx ramdisk.image
Initramfs
To modify an initramfs:1. Extract the contents of the cpio.gz archive.
mkdir tmp_mnt/ gunzip -c initramfs.cpio.gz | sh -c 'cd tmp_mnt/ && cpio -i' cd tmp_mnt/
3. Repack the filesystem into a cpio.gz archive.
sh -c 'cd tmp_mnt/ && find . | cpio -H newc -o' | gzip -9 > new_initramfs.cpio.gz
To create an initramfs from scratch, tools such as Buildroot or Yocto may be used to populate the filesystem (with BusyBox, tools, etc.).
Alternatively, initramfs image may be created by populating a directory with the desired filesystem contents and packing these contents into a cpio.gz archive as mentioned above.
Wrapping the image with a U-Boot header
For Zynq SoC devices the ramdisk.image.gz needs to be wrapped with a U-Boot header in order for U-Boot to boot with it. The architecture option (-A) will be 'arm' for Zynq7000 and 'arm64' for ZynqUS+ devices.mkimage -A arm -T ramdisk -C gzip -d ramdisk.image.gz uramdisk.image.gz
For MicroBlaze and PowerPC, the initramfs.cpio.gz presently needs to be embedded into the kernel (see Build Linux Kernel).
Unwrap the image with the u-boot header
dd if=uRamdisk bs=64 skip=1 of=ramdisk.gz
Check File Type
file uramdisk.image.gz uramdisk.image.gz: u-boot legacy uImage, , Linux/ARM, RAMDisk Image (gzip), 4815459 bytes, Fri May 30 01:52:10 2014, Load Address: 0x00000000, Entry Point: 0x00000000, Header CRC: 0x265787C1, Data CRC: 0x2CA30F4B file ramdisk.image.gz ramdisk.image.gz: gzip compressed data, was "rootfs.cpio", from Unix, last modified: Fri May 30 01:52:08 2014
Build Steps
- Fetch Sources
- Build FSBL
- Build Device Tree Compiler (DTC)
- Build PMU Firmware
- Build Arm Trusted Firmware (ATF)
- Build U-Boot
- (You are here) Build and Modify a Root File System
- Build Device Tree Blob
- Build Linux Kernel
- Prepare Boot Image
- Prepare Boot Medium
- Setup a Serial Console
- Additional Information: Build Qt and Qwt Libraries
Related Links
© Copyright 2019 - 2022 Xilinx Inc. Privacy Policy