Search code examples
linuxkernelxilinxrootfszynq

Do modification to rootfs (petalinux on zynq)


I've installed Petalinux 2014.4 on my Zynq board, but the NAND flash is not mounted when I boot up the board. I'm wondering if it's possible to change rootfs.cpio by extracting the package and then do changes to fstab and so make a cpio arhcive back. If yes, is it enough to just run petalinux-build after that?

Thanks :)


Solution

  • If you have access to the ramdisk image file, then yes, you can modify its contents. I assume that your image file is compressed using gzip. Furthermore I assume that you use U-Boot and your compressed ramdisk image has a U-Boot preamble.

    First you need to strip the U-Boot header:

    dd bs=64 skip=1 if=uramdisk.cpio.gz of=ramdisk.cpio.gz
    

    Next, we decompress:

    gunzip ramdisk.cpio.gz
    

    Finally we extract the CPIO archive:

    mkdir ramdisk && cd ramdisk
    cpio -i -F ../ramdisk.cpio
    

    Either you execute the latter command as root or you change the file ownership back to root before archiving again. This is necessary for your init program to start. After your modifications you can create your image file again:

    find . | cpio -o -H newc | gzip -9 > ../ramdisk_new.cpio.gz
    mkimage -A arm -T ramdisk -C gzip -d ramdisk_new.cpio.gz uramdisk.image.gz
    

    Notice that the mkimage tool is part of U-Boot and is located in the respective sources in the tools directory.

    I am not familiar with PetaLinux so I don't know whether this general answer suits your needs and expectations.