[PATCH v3 5/7] mkimage: add fatfs image type for FAT partition images
Simon Glass
sjg at chromium.org
Mon Apr 20 06:06:49 CEST 2026
Hi Aswin,
On 2026-04-17T12:09:44, Aswin Murugan <aswin.murugan at oss.qualcomm.com> wrote:
> mkimage: add fatfs image type for FAT partition images
>
> Add a new mkimage image type 'fatfs' that creates a raw FAT
> filesystem partition image from a directory of files.
>
> The image handler (fatimage.c) uses mkfs.vfat (dosfstools)
> to format the image and mcopy (mtools) to populate it. The
> image size is calculated automatically from the input
> directory size plus FAT metadata overhead.
>
> New long options added to mkimage:
> --fat-extra-space <KB> extra padding (default: 512 KB)
> --fat-type <0|12|16|32> FAT type (0 = auto-detect)
> --fat-volume-id <label> volume label (default: BOOT)
> --fat-mkfs-opts <opts> extra mkfs.vfat options
>
> Usage:
> mkimage -T fatfs -d <input-dir> \
> --fat-extra-space 512 \
> --fat-volume-id "MYBOOT" \
> [...]
>
> tools/Makefile | 1 +
> tools/fatimage.c | 495 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
> tools/fatimage.h | 25 +++
> tools/mkimage.c | 21 +++
> tools/mkimage.h | 15 ++
> 5 files changed, 557 insertions(+)
> diff --git a/tools/mkimage.c b/tools/mkimage.c
> @@ -204,6 +204,10 @@ static const struct option longopts[] = {
> +{ "fat-extra-space", required_argument, NULL, OPT_FAT_EXTRA },
> + { "fat-type", required_argument, NULL, OPT_FAT_TYPE },
The first line is missing its leading tab.
> diff --git a/tools/fatimage.c b/tools/fatimage.c
> @@ -0,0 +1,495 @@
> +static int fatimage_set_header(void *ptr, struct stat *sbuf, int ifd,
> + struct image_tool_params *params)
The set_header callback in struct image_type_params returns void, not int
Assuming you don't want to update that (which you might?), please
change the return type to void and call exit() on unrecoverable
errors, like the other image handlers.
> diff --git a/tools/fatimage.c b/tools/fatimage.c
> @@ -0,0 +1,495 @@
> +static int fatimage_check_params(struct image_tool_params *params)
> +{
> + if (!fatparams.input_dir) {
> + fprintf(stderr, "Error: Input directory not specified\n");
> + fprintf(stderr, "Use -d <directory> to specify input directory\n");
> + return -1;
> + }
> +
> + struct stat st;
> + if (stat(fatparams.input_dir, &st) < 0) {
Please move the decl to the start to the top of the function.
> diff --git a/tools/fatimage.c b/tools/fatimage.c
> @@ -0,0 +1,495 @@
> +void fatimage_set_dir(const char *dir)
> +{
> + fatparams.input_dir = strdup(dir);
> +}
> +
> +void fatimage_set_extra_space(int space_kb)
> +{
> + fatparams.extra_space = space_kb;
> +}
> +
> +void fatimage_set_fat_type(int type)
> +{
> + fatparams.fat_type = type;
> +}
> +
> +void fatimage_set_volume_id(const char *volid)
> +{
> + fatparams.volume_id = strdup(volid);
> +}
> +
> +void fatimage_set_mkfs_opts(const char *opts)
> +{
> + fatparams.mkfs_opts = strdup(opts);
> +}
The strdup() calls in fatimage_set_dir(), fatimage_set_volume_id() and
fatimage_set_mkfs_opts() can return NULL, but the return value is not
checked. Please check for NULL and handle the error.
Regards,
Simon
More information about the U-Boot
mailing list