pengutronix / genimage

tool to generate multiple filesystem and flash images from a tree
GNU General Public License v2.0
309 stars 110 forks source link

Image size in % does not work #227

Open Zlika opened 11 months ago

Zlika commented 11 months ago

Hello, I'm using genimage 15 (through buildroot 2022.02.8) and specifying an image size in % does not seem to work. My configuration file is:

image boot.vfat {
    vfat {
        files = {
            "zImage",
            "socfpga_cyclone5_de10_standard.dtb"
        }
        file extlinux/extlinux.conf {
            image = "extlinux.conf"
        }
    }

    size = 20M
}

image sdcard.img {
    hdimage {
    }

    partition boot {
        partition-type = 0xc
        bootable = "true"
        image = "boot.vfat"
    }

    partition uboot {
        partition-type = 0xa2
        image = "u-boot-with-spl.sfp"
    }
}

This config file works, but if I replace the "size = 20M" with a percent value (e.g. "size=120%" or even "size=200%") I always have the following error message: mkdosfs: Attempting to create a too small or too large filesystem.

Here is the full log with --loglevel=3:

>>>   Executing post-image script support/scripts/genimage.sh
INFO: cmd: "mkdir -p "/home/thomas/git/buildroot/output/build/genimage.tmp"" (stderr+stdout):
INFO: cmd: "rm -rf "/home/thomas/git/buildroot/output/build/genimage.tmp"/*" (stderr+stdout):
DEBUG: vfat(boot.vfat): adding implicit file rule for 'extlinux.conf'
DEBUG: vfat(boot.vfat): adding implicit file rule for 'zImage'
DEBUG: vfat(boot.vfat): adding implicit file rule for 'socfpga_cyclone5_de10_standard.dtb'
DEBUG: hdimage(sdcard.img): adding implicit file rule for 'u-boot-with-spl.sfp'
INFO: cmd: "mkdir -p "/home/thomas/git/buildroot/output/build/genimage.tmp"" (stderr+stdout):
INFO: cmd: "cp -a "/tmp/tmp.sOOkd31ndS" "/home/thomas/git/buildroot/output/build/genimage.tmp/root"" (stderr+stdout):
INFO: cmd: "find '/home/thomas/git/buildroot/output/build/genimage.tmp/root' -depth -type d -printf '%P\0' | xargs -0 -I {} touch -r '/tmp/tmp.sOOkd31ndS/{}' '/home/thomas/git/buildroot/output/build/genimage.tmp/root/{}'" (stderr+stdout):
INFO: cmd: "mkdir -p "/home/thomas/git/buildroot/output/images"" (stderr+stdout):
INFO: vfat(boot.vfat): cmd: "dd if=/dev/zero of="/home/thomas/git/buildroot/output/images/boot.vfat" seek=6144 count=0 bs=1 2>/dev/null" (stderr+stdout):
INFO: vfat(boot.vfat): cmd: "mkdosfs   '/home/thomas/git/buildroot/output/images/boot.vfat'" (stderr+stdout):
mkfs.fat 4.2 (2021-01-31)
mkdosfs: Attempting to create a too small or a too large filesystem
INFO: vfat(boot.vfat): cmd: "rm -f "/home/thomas/git/buildroot/output/images/boot.vfat"" (stderr+stdout):
ERROR: vfat(boot.vfat): failed to generate boot.vfat
michaelolbrich commented 11 months ago

Ah, I see the issue. For vfat images there are two ways to provide content:

  1. The rootpath / mountpount stuff also used by other filesystems
  2. The special file / files properties

The automatic size calculation only takes the rootpath into account.

Zlika commented 11 months ago

Ok, thanks for your quick answer. Is it a possible future improvement to make it work on this use case?

michaelolbrich commented 11 months ago

Certainly. But I'm not sure when I'll find the time to do that. The fastest way would be to implement it yourself and open a pull request. Basically you need to modify vfat_setup() and there

if (image->size_is_percent) {
    for all  extra files
        image->size += file size
}