@@ -76,6 +76,10 @@ die() {
7676 exit 1
7777}
7878
79+ simg_expanded_size () {
80+ echo " $(( $(simg_dump "$1 " | sed - E 's/ .*? Total of ([0 - 9 ]+ ) ([0 - 9 ]+ )- byte .*/ \1 * \2 / ')) )"
81+ }
82+
7983keywriter_log () {
8084 echo " $@ " >> /var/log/rpi-sb-provisioner/" ${TARGET_DEVICE_SERIAL} " /keywriter.log
8185}
@@ -636,6 +640,7 @@ check_command_exists mount
636640
637641# Fastboot is used as a transfer mechanism to get images and metadata to and from the Raspberry Pi device
638642check_command_exists fastboot
643+ check_command_exists simg_dump
639644
640645check_command_exists blockdev
641646
@@ -969,12 +974,12 @@ announce_start "Resizing OS images"
969974# https://dl.google.com/android/repository/platform-tools-latest-darwin.zip
970975# https://dl.google.com/android/repository/platform-tools-latest-windows.zip
971976TARGET_STORAGE_ROOT_EXTENT=" $( get_variable partition-size:mapper/cryptroot) "
972- if [ -f " ${RPI_SB_WORKDIR} /rootfs-temporary.simg" ] && [ " $(( TARGET_STORAGE_ROOT_EXTENT)) " -eq " $( stat -c%s " ${RPI_SB_WORKDIR} " /rootfs-temporary.simg) " ]; then
977+ if [ -f " ${RPI_SB_WORKDIR} /rootfs-temporary.simg" ] && [ " $(( TARGET_STORAGE_ROOT_EXTENT)) " -eq " $( simg_expanded_size " ${RPI_SB_WORKDIR} " /rootfs-temporary.simg) " ]; then
973978 announce_stop " Resizing OS images: Not required, already the correct size"
974979else
975- mke2fs -t ext4 -b 4096 -d " ${TMP_DIR} " /rpi-rootfs-img-mount " ${RPI_SB_WORKDIR} " /rootfs-temporary.simg $(( TARGET_STORAGE_ROOT_EXTENT / 4096 ))
976- # TODO: Re-enable android_sparse
977- # mke2fs -t ext4 -b 4096 -d ${TMP_DIR}/rpi-rootfs-img-mount -E android_sparse ${ RPI_SB_WORKDIR}/rootfs-temporary.simg $((TARGET_STORAGE_ROOT_EXTENT / 4096))
980+ mke2fs -t ext4 -b 4096 -d " ${TMP_DIR} " /rpi-rootfs-img-mount " ${RPI_SB_WORKDIR} " /rootfs-temporary.img $(( TARGET_STORAGE_ROOT_EXTENT / 4096 ))
981+ img2simg -s " ${RPI_SB_WORKDIR} " /rootfs-temporary.img " ${RPI_SB_WORKDIR} " /rootfs-temporary.simg
982+ rm -f " ${ RPI_SB_WORKDIR}" /rootfs-temporary.img
978983 announce_stop " Resizing OS images: Resized to $(( TARGET_STORAGE_ROOT_EXTENT)) "
979984fi
980985
0 commit comments