The problem
Generating a Yocto image with bitbake, I get a xyz.rootfs.tar.gz file as output. I flash my system by extracting the archive in my system's root partition.
I noticed that, if I extract the archive in a folder and create an xyz_2.tar.gz archive from the extracted folder, archives xyz.rootfs.tar.gz and xyz_2.rootfs.tar.gz differs (~200kB size difference).
My test
I extract the archive with the command
sudo tar -xf xyz.rootfs.tar.gz -C extract/
First, I recompressed the folder with command
cd extract
sudo tar -czf ../xyz_2.tar.gz *
but noticed the generated archive differs from the original one created by bitbake.
Since I got different size, I investigated to find the exact command(s) used by bitbake to generate the tar. Running bitbake verbosely, I got this output:
+ do_image_tar
+ tar --numeric-owner -cf /home/user/yocto/build/tmp/work/xyz-poky-linux-gnueabi/xyz/1.0-r0/xyz-image-complete/xyz-20240321132953.rootfs.tar -C /home/user/yocto/build/tmp/work/xyz-poky-linux-gnueabi/xyz/1.0-r0/rootfs .
+ cd /home/user/yocto/build/tmp/work/xyz-poky-linux-gnueabi/xyz/1.0-r0/xyz-image-complete/
+ gzip -f -9 -n -c --rsyncable xyz-20240321132953.rootfs.tar
So, I generated my archive from the decompressed one with those commands
tar --numeric-owner -cf xyz_2.rootfs.tar -C extract/ .
gzip -f -9 -n -c --rsyncable xyz_2.rootfs.tar > xyz_2.rootfs.tar.gz
Still different sizes.
Why is this happening?
Why I need this
I'm creating a system upgrade routine that reflash the entire image on a different partition, then boot the system from this second partition. My idea is to change uboot env boot partition ONLY if the flashed image is ok. In case of errors, the system will still boot from the original, untouched partition.
How to check if the copied data are ok?
My quick and dirty idea is:
- generate MD5 file of rootfs archive (on develop PC, (probably) as part of bitbake image generation)
- on system, extract rootfs archive in partition
- re-create rootfs archive from extracted data
- compute MD5 of new archive
- check original rootfs archive MD5 with extracted data's archive MD5; if they differs, something went wrong (data extracted with errors, original archive corrupted during copy on system, ...)
I do this back-and-forth operation because I couldn't think of a better way to check the copied data. If you have any simpler suggestion on how to do this, I'll be interested.