How to Decompress PetaLinux rootfs.cpio.gz with Script

Test environment: PetaLinux 2021.2

During development, it is often necessary to check the contents of the rootfs.¬†Using the command, “gzip -d rootfs.cpio.gz”, “cpio -i < rootfs.cpio”, you can decompress the contents of rootfs.cpio.gz.
If you decompress frequently, you can use the following script to simplify the operation.

#!/bin/bash

echo -e "\nBegin to run script: $0"

# array definition, work for /bin/bash, does not work for /bin/sh
file_array_check=( 
bl31.bin
bl31.elf
BOOT.BIN
boot.scr
Image
image.ub
rootfs.cpio.gz
rootfs.manifest
system.dtb
u-boot.bin
u-boot.elf
vmlinux
)

# Get array elements number
file_array_check_length=${#file_array_check[@]}

# C-language style loop
# Check PetaLinux image/linux directory.
for (( i=0; i<$file_array_check_length; i++))
{
    CHECK_FILE=${file_array_check[i]}
    echo "Check No.$i directory: $CHECK_FILE";
    if [ ! -f  $CHECK_FILE ]; then 
        echo "Not PetaLinux project image directory. No file: $CHECK_FILE. "
        echo "Exit."
        exit 1
    fi 
}

mkdir -p rootfs
rm -rf ./rootfs/*
ls -l ./rootfs

cd rootfs
cp ../rootfs.cpio.gz ./
gzip -d rootfs.cpio.gz 
cpio -i < rootfs.cpio 
ls -l 

cd ../

Similar Posts:

Leave a Reply

Your email address will not be published. Required fields are marked *