1 // SPDX-License-Identifier: GPL-2.0+
3 * (C) Copyright 2008 Semihalf
5 * (C) Copyright 2000-2009
6 * DENX Software Engineering
7 * Wolfgang Denk, wd@denx.de
10 #include "imagetool.h"
13 #include <fit_common.h>
18 #include <sys/ioctl.h>
21 static void copy_file(int, const char *, int);
23 /* parameters initialized by core will be used by the image type code */
24 static struct image_tool_params params
= {
27 .type
= IH_TYPE_KERNEL
,
29 .dtc
= MKIMAGE_DEFAULT_DTC_OPTIONS
,
34 static enum ih_category cur_category
;
36 static int h_compare_category_name(const void *vtype1
, const void *vtype2
)
38 const int *type1
= vtype1
;
39 const int *type2
= vtype2
;
40 const char *name1
= genimg_get_cat_short_name(cur_category
, *type1
);
41 const char *name2
= genimg_get_cat_short_name(cur_category
, *type2
);
43 return strcmp(name1
, name2
);
46 static int show_valid_options(enum ih_category category
)
53 count
= genimg_get_cat_count(category
);
54 order
= calloc(count
, sizeof(*order
));
58 /* Sort the names in order of short name for easier reading */
59 for (i
= 0, item
= 0; i
< count
; i
++, item
++) {
60 while (!genimg_cat_has_id(category
, item
) && i
< count
) {
66 cur_category
= category
;
67 qsort(order
, count
, sizeof(int), h_compare_category_name
);
69 fprintf(stderr
, "\nInvalid %s, supported are:\n",
70 genimg_get_cat_desc(category
));
71 for (i
= 0; i
< count
; i
++) {
73 fprintf(stderr
, "\t%-15s %s\n",
74 genimg_get_cat_short_name(category
, item
),
75 genimg_get_cat_name(category
, item
));
77 fprintf(stderr
, "\n");
83 static void usage(const char *msg
)
85 fprintf(stderr
, "Error: %s\n", msg
);
86 fprintf(stderr
, "Usage: %s [-T type] -l image\n"
87 " -l ==> list image header information\n"
88 " -T ==> parse image file as 'type'\n"
92 " %s [-x] -A arch -O os -T type -C comp -a addr -e ep -n name -d data_file[:data_file...] image\n"
93 " -A ==> set architecture to 'arch'\n"
94 " -O ==> set operating system to 'os'\n"
95 " -T ==> set image type to 'type'\n"
96 " -C ==> set compression type 'comp'\n"
97 " -a ==> set load address to 'addr' (hex)\n"
98 " -e ==> set entry point to 'ep' (hex)\n"
99 " -n ==> set image name to 'name'\n"
100 " -R ==> set second image name to 'name'\n"
101 " -d ==> use image data from 'datafile'\n"
102 " -x ==> set XIP (execute in place)\n"
103 " -s ==> create an image with no data\n"
107 " %s [-D dtc_options] [-f fit-image.its|-f auto|-f auto-conf|-F] [-b <dtb> [-b <dtb>]] [-E] [-B size] [-i <ramdisk.cpio.gz>] fit-image\n"
108 " <dtb> file is used with -f auto, it may occur multiple times.\n",
111 " -D => set all options for device tree compiler\n"
112 " -f => input filename for FIT source\n"
113 " -i => input filename for ramdisk file\n"
114 " -E => place data outside of the FIT structure\n"
115 " -B => align size in hex for FIT structure and header\n"
116 " -b => append the device tree binary to the FIT\n"
117 " -t => update the timestamp in the FIT\n");
118 #if CONFIG_IS_ENABLED(FIT_SIGNATURE)
120 "Signing / verified boot options: [-k keydir] [-K dtb] [ -c <comment>] [-p addr] [-r] [-N engine]\n"
121 " -k => set directory containing private keys\n"
122 " -K => write public keys to this .dtb file\n"
123 " -g => set key name hint\n"
124 " -G => use this signing key (in lieu of -k)\n"
125 " -c => add comment in signature node\n"
126 " -F => re-sign existing FIT image\n"
127 " -p => place external data at a static position\n"
128 " -r => mark keys used as 'required' in dtb\n"
129 " -N => openssl engine to use for signing\n"
130 " -o => algorithm to use for signing\n");
133 "Signing / verified boot not supported (CONFIG_TOOLS_FIT_SIGNATURE undefined)\n");
136 fprintf(stderr
, " %s -V ==> print version information and exit\n",
138 fprintf(stderr
, "Use '-T list' to see a list of available image types\n");
139 fprintf(stderr
, "Long options are available; read the man page for details\n");
144 static int add_content(int type
, const char *fname
)
146 struct content_info
*cont
;
148 cont
= calloc(1, sizeof(*cont
));
153 if (params
.content_tail
)
154 params
.content_tail
->next
= cont
;
156 params
.content_head
= cont
;
157 params
.content_tail
= cont
;
162 static const char optstring
[] =
163 "a:A:b:B:c:C:d:D:e:Ef:Fg:G:i:k:K:ln:N:o:O:p:qrR:stT:vVx";
165 static const struct option longopts
[] = {
166 { "load-address", required_argument
, NULL
, 'a' },
167 { "architecture", required_argument
, NULL
, 'A' },
168 { "device-tree", required_argument
, NULL
, 'b' },
169 { "alignment", required_argument
, NULL
, 'B' },
170 { "comment", required_argument
, NULL
, 'c' },
171 { "compression", required_argument
, NULL
, 'C' },
172 { "image", required_argument
, NULL
, 'd' },
173 { "dtcopts", required_argument
, NULL
, 'D' },
174 { "entry-point", required_argument
, NULL
, 'e' },
175 { "external", no_argument
, NULL
, 'E' },
176 { "fit", required_argument
, NULL
, 'f' },
177 { "update", no_argument
, NULL
, 'F' },
178 { "key-name-hint", required_argument
, NULL
, 'g' },
179 { "key-file", required_argument
, NULL
, 'G' },
180 { "help", no_argument
, NULL
, 'h' },
181 { "initramfs", required_argument
, NULL
, 'i' },
182 { "key-dir", required_argument
, NULL
, 'k' },
183 { "key-dest", required_argument
, NULL
, 'K' },
184 { "list", no_argument
, NULL
, 'l' },
185 { "config", required_argument
, NULL
, 'n' },
186 { "engine", required_argument
, NULL
, 'N' },
187 { "algo", required_argument
, NULL
, 'o' },
188 { "os", required_argument
, NULL
, 'O' },
189 { "position", required_argument
, NULL
, 'p' },
190 { "quiet", no_argument
, NULL
, 'q' },
191 { "key-required", no_argument
, NULL
, 'r' },
192 { "secondary-config", required_argument
, NULL
, 'R' },
193 { "no-copy", no_argument
, NULL
, 's' },
194 { "touch", no_argument
, NULL
, 't' },
195 { "type", required_argument
, NULL
, 'T' },
196 { "verbose", no_argument
, NULL
, 'v' },
197 { "version", no_argument
, NULL
, 'V' },
198 { "xip", no_argument
, NULL
, 'x' },
202 static void process_args(int argc
, char **argv
)
205 int type
= IH_TYPE_INVALID
;
206 char *datafile
= NULL
;
209 while ((opt
= getopt_long(argc
, argv
, optstring
,
210 longopts
, NULL
)) != -1) {
213 params
.addr
= strtoull(optarg
, &ptr
, 16);
215 fprintf(stderr
, "%s: invalid load address %s\n",
216 params
.cmdname
, optarg
);
221 params
.arch
= genimg_get_arch_id(optarg
);
222 if (params
.arch
< 0) {
223 show_valid_options(IH_ARCH
);
224 usage("Invalid architecture");
229 if (add_content(IH_TYPE_FLATDT
, optarg
)) {
231 "%s: Out of memory adding content '%s'",
232 params
.cmdname
, optarg
);
237 params
.bl_len
= strtoull(optarg
, &ptr
, 16);
239 fprintf(stderr
, "%s: invalid block length %s\n",
240 params
.cmdname
, optarg
);
246 params
.comment
= optarg
;
249 params
.comp
= genimg_get_comp_id(optarg
);
250 if (params
.comp
< 0) {
251 show_valid_options(IH_COMP
);
252 usage("Invalid compression type");
256 params
.datafile
= optarg
;
263 params
.ep
= strtoull(optarg
, &ptr
, 16);
265 fprintf(stderr
, "%s: invalid entry point %s\n",
266 params
.cmdname
, optarg
);
272 params
.external_data
= true;
276 if (!strcmp(datafile
, "auto"))
277 params
.auto_fit
= AF_HASHED_IMG
;
278 else if (!strcmp(datafile
, "auto-conf"))
279 params
.auto_fit
= AF_SIGNED_CONF
;
283 * The flattened image tree (FIT) format
284 * requires a flattened device tree image type
286 params
.type
= IH_TYPE_FLATDT
;
290 params
.keyname
= optarg
;
293 params
.keyfile
= optarg
;
296 params
.fit_ramdisk
= optarg
;
299 params
.keydir
= optarg
;
302 params
.keydest
= optarg
;
308 params
.imagename
= optarg
;
311 params
.engine_id
= optarg
;
314 params
.algo_name
= optarg
;
317 params
.os
= genimg_get_os_id(optarg
);
319 show_valid_options(IH_OS
);
320 usage("Invalid operating system");
324 params
.external_offset
= strtoull(optarg
, &ptr
, 16);
326 fprintf(stderr
, "%s: invalid offset size %s\n",
327 params
.cmdname
, optarg
);
335 params
.require_keys
= 1;
339 * This entry is for the second configuration
340 * file, if only one is not enough.
342 params
.imagename2
= optarg
;
348 params
.reset_timestamp
= 1;
351 if (strcmp(optarg
, "list") == 0) {
352 show_valid_options(IH_TYPE
);
355 type
= genimg_get_type_id(optarg
);
357 show_valid_options(IH_TYPE
);
358 usage("Invalid image type");
365 printf("mkimage version %s\n", PLAIN_VERSION
);
371 usage("Invalid option");
375 /* The last parameter is expected to be the imagefile */
377 params
.imagefile
= argv
[optind
];
379 if (params
.auto_fit
== AF_SIGNED_CONF
) {
380 if (!params
.keyname
|| !params
.algo_name
)
381 usage("Missing key/algo for auto-FIT with signed configs (use -g -o)");
382 } else if (params
.auto_fit
== AF_HASHED_IMG
&& params
.keyname
) {
383 params
.auto_fit
= AF_SIGNED_IMG
;
384 if (!params
.algo_name
)
385 usage("Missing algorithm for auto-FIT with signed images (use -g)");
389 * For auto-generated FIT images we need to know the image type to put
390 * in the FIT, which is separate from the file's image type (which
391 * will always be IH_TYPE_FLATDT in this case).
393 if (params
.type
== IH_TYPE_FLATDT
) {
394 params
.fit_image_type
= type
? type
: IH_TYPE_KERNEL
;
395 /* For auto-FIT, datafile has to be provided with -d */
396 if (!params
.auto_fit
)
397 params
.datafile
= datafile
;
398 else if (!params
.datafile
)
399 usage("Missing data file for auto-FIT (use -d)");
400 } else if (params
.lflag
|| type
!= IH_TYPE_INVALID
) {
401 if (type
== IH_TYPE_SCRIPT
&& !params
.datafile
)
402 usage("Missing data file for script (use -d)");
406 if (!params
.imagefile
)
407 usage("Missing output filename");
410 static void verify_image(const struct image_type_params
*tparams
)
416 ifd
= open(params
.imagefile
, O_RDONLY
| O_BINARY
);
418 fprintf(stderr
, "%s: Can't open %s: %s\n",
419 params
.cmdname
, params
.imagefile
,
424 if (fstat(ifd
, &sbuf
) < 0) {
425 fprintf(stderr
, "%s: Can't stat %s: %s\n",
426 params
.cmdname
, params
.imagefile
, strerror(errno
));
429 params
.file_size
= sbuf
.st_size
;
431 ptr
= mmap(0, params
.file_size
, PROT_READ
, MAP_SHARED
, ifd
, 0);
432 if (ptr
== MAP_FAILED
) {
433 fprintf(stderr
, "%s: Can't map %s: %s\n",
434 params
.cmdname
, params
.imagefile
, strerror(errno
));
438 if (tparams
->verify_header((unsigned char *)ptr
, params
.file_size
, ¶ms
) != 0) {
439 fprintf(stderr
, "%s: Failed to verify header of %s\n",
440 params
.cmdname
, params
.imagefile
);
444 (void)munmap(ptr
, params
.file_size
);
448 void copy_datafile(int ifd
, char *file
)
453 char *sep
= strchr(file
, ':');
457 copy_file(ifd
, file
, 1);
461 copy_file(ifd
, file
, 0);
467 int main(int argc
, char **argv
)
473 struct image_type_params
*tparams
= NULL
;
478 params
.cmdname
= *argv
;
482 process_args(argc
, argv
);
484 /* set tparams as per input type_id */
485 tparams
= imagetool_get_type(params
.type
);
486 if (tparams
== NULL
&& !params
.lflag
) {
487 fprintf (stderr
, "%s: unsupported type %s\n",
488 params
.cmdname
, genimg_get_type_name(params
.type
));
493 * check the passed arguments parameters meets the requirements
494 * as per image type to be generated/listed
496 if (tparams
&& tparams
->check_params
)
497 if (tparams
->check_params (¶ms
))
498 usage("Bad parameters for image type");
501 params
.ep
= params
.addr
;
502 /* If XIP, entry point must be after the U-Boot header */
503 if (params
.xflag
&& tparams
)
504 params
.ep
+= tparams
->header_size
;
509 fprintf(stderr
, "%s: Missing FIT support\n",
513 if (tparams
->fflag_handle
)
515 * in some cases, some additional processing needs
516 * to be done if fflag is defined
518 * For ex. fit_handle_file for Fit file support
520 retval
= tparams
->fflag_handle(¶ms
);
522 if (retval
!= EXIT_SUCCESS
)
523 usage("Bad parameters for FIT image type");
526 if (params
.lflag
|| params
.fflag
) {
527 ifd
= open (params
.imagefile
, O_RDONLY
|O_BINARY
);
529 ifd
= open (params
.imagefile
,
530 O_RDWR
|O_CREAT
|O_TRUNC
|O_BINARY
, 0666);
534 fprintf (stderr
, "%s: Can't open %s: %s\n",
535 params
.cmdname
, params
.imagefile
,
540 if (params
.lflag
|| params
.fflag
) {
543 * list header information of existing image
545 if (fstat(ifd
, &sbuf
) < 0) {
546 fprintf (stderr
, "%s: Can't stat %s: %s\n",
547 params
.cmdname
, params
.imagefile
,
552 if ((sbuf
.st_mode
& S_IFMT
) == S_IFBLK
) {
554 #if defined(__linux__) && defined(_IOR) && !defined(BLKGETSIZE64)
555 #define BLKGETSIZE64 _IOR(0x12,114,size_t) /* return device size in bytes (u64 *arg) */
557 if (ioctl(ifd
, BLKGETSIZE64
, &size
) < 0) {
559 "%s: failed to get size of block device \"%s\"\n",
560 params
.cmdname
, params
.imagefile
);
565 "%s: \"%s\" is block device, don't know how to get its size\n",
566 params
.cmdname
, params
.imagefile
);
569 } else if (tparams
&& sbuf
.st_size
< (off_t
)tparams
->header_size
) {
571 "%s: Bad size: \"%s\" is not valid image: size %llu < %u\n",
572 params
.cmdname
, params
.imagefile
,
573 (unsigned long long) sbuf
.st_size
,
574 tparams
->header_size
);
580 ptr
= mmap(0, size
, PROT_READ
, MAP_SHARED
, ifd
, 0);
581 if (ptr
== MAP_FAILED
) {
582 fprintf (stderr
, "%s: Can't read %s: %s\n",
583 params
.cmdname
, params
.imagefile
,
589 * Verifies the header format based on the expected header for image
590 * type in tparams. If tparams is NULL simply check all image types
591 * to find one that matches our header.
593 retval
= imagetool_verify_print_header(ptr
, &sbuf
, tparams
, ¶ms
);
595 (void) munmap((void *)ptr
, sbuf
.st_size
);
598 summary_show(¶ms
.summary
, params
.imagefile
,
604 if (!params
.skipcpy
&& params
.type
!= IH_TYPE_MULTI
&& params
.type
!= IH_TYPE_SCRIPT
) {
605 if (!params
.datafile
) {
606 fprintf(stderr
, "%s: Option -d with image data file was not specified\n",
610 dfd
= open(params
.datafile
, O_RDONLY
| O_BINARY
);
612 fprintf(stderr
, "%s: Can't open %s: %s\n",
613 params
.cmdname
, params
.datafile
,
618 if (fstat(dfd
, &sbuf
) < 0) {
619 fprintf(stderr
, "%s: Can't stat %s: %s\n",
620 params
.cmdname
, params
.datafile
,
625 params
.file_size
= sbuf
.st_size
+ tparams
->header_size
;
630 * In case there an header with a variable
631 * length will be added, the corresponding
632 * function is called. This is responsible to
633 * allocate memory for the header itself.
635 if (tparams
->vrec_header
)
636 pad_len
= tparams
->vrec_header(¶ms
, tparams
);
638 memset(tparams
->hdr
, 0, tparams
->header_size
);
640 if (write(ifd
, tparams
->hdr
, tparams
->header_size
)
641 != tparams
->header_size
) {
642 fprintf (stderr
, "%s: Write error on %s: %s\n",
643 params
.cmdname
, params
.imagefile
, strerror(errno
));
647 if (!params
.skipcpy
) {
648 if (params
.type
== IH_TYPE_MULTI
||
649 params
.type
== IH_TYPE_SCRIPT
) {
650 char *file
= params
.datafile
;
657 if ((sep
= strchr(file
, ':')) != NULL
) {
661 if (stat (file
, &sbuf
) < 0) {
662 fprintf (stderr
, "%s: Can't stat %s: %s\n",
663 params
.cmdname
, file
, strerror(errno
));
666 size
= cpu_to_uimage (sbuf
.st_size
);
671 if (write(ifd
, (char *)&size
, sizeof(size
)) != sizeof(size
)) {
672 fprintf (stderr
, "%s: Write error on %s: %s\n",
673 params
.cmdname
, params
.imagefile
,
689 copy_datafile(ifd
, params
.datafile
);
690 } else if (params
.type
== IH_TYPE_PBLIMAGE
) {
691 /* PBL has special Image format, implements its' own */
692 pbl_load_uboot(ifd
, ¶ms
);
693 } else if (params
.type
== IH_TYPE_ZYNQMPBIF
) {
694 /* Image file is meta, walk through actual targets */
697 ret
= zynqmpbif_copy_image(ifd
, ¶ms
);
700 } else if (params
.type
== IH_TYPE_IMX8IMAGE
) {
701 /* i.MX8/8X has special Image format */
704 ret
= imx8image_copy_image(ifd
, ¶ms
);
707 } else if (params
.type
== IH_TYPE_IMX8MIMAGE
) {
708 /* i.MX8M has special Image format */
711 ret
= imx8mimage_copy_image(ifd
, ¶ms
);
714 } else if ((params
.type
== IH_TYPE_RKSD
) ||
715 (params
.type
== IH_TYPE_RKSPI
)) {
716 /* Rockchip has special Image format */
719 ret
= rockchip_copy_image(ifd
, ¶ms
);
723 copy_file(ifd
, params
.datafile
, pad_len
);
725 if (params
.type
== IH_TYPE_FIRMWARE_IVT
) {
726 /* Add alignment and IVT */
727 uint32_t aligned_filesize
= ALIGN(params
.file_size
,
729 flash_header_v2_t ivt_header
= { { 0xd1, 0x2000, 0x40 },
730 params
.addr
, 0, 0, 0, params
.addr
732 - tparams
->header_size
,
733 params
.addr
+ aligned_filesize
734 - tparams
->header_size
736 int i
= params
.file_size
;
737 for (; i
< aligned_filesize
; i
++) {
738 if (write(ifd
, (char *) &i
, 1) != 1) {
740 "%s: Write error on %s: %s\n",
747 if (write(ifd
, &ivt_header
, sizeof(flash_header_v2_t
))
748 != sizeof(flash_header_v2_t
)) {
749 fprintf(stderr
, "%s: Write error on %s: %s\n",
758 /* We're a bit of paranoid */
759 #if defined(_POSIX_SYNCHRONIZED_IO) && \
760 !defined(__sun__) && \
761 !defined(__FreeBSD__) && \
762 !defined(__OpenBSD__) && \
764 (void) fdatasync (ifd
);
769 if (fstat(ifd
, &sbuf
) < 0) {
770 fprintf (stderr
, "%s: Can't stat %s: %s\n",
771 params
.cmdname
, params
.imagefile
, strerror(errno
));
774 params
.file_size
= sbuf
.st_size
;
776 map_len
= sbuf
.st_size
;
777 ptr
= mmap(0, map_len
, PROT_READ
| PROT_WRITE
, MAP_SHARED
, ifd
, 0);
778 if (ptr
== MAP_FAILED
) {
779 fprintf (stderr
, "%s: Can't map %s: %s\n",
780 params
.cmdname
, params
.imagefile
, strerror(errno
));
784 /* Setup the image header as per input image type*/
785 if (tparams
->set_header
)
786 tparams
->set_header (ptr
, &sbuf
, ifd
, ¶ms
);
788 fprintf (stderr
, "%s: Can't set header for %s\n",
789 params
.cmdname
, tparams
->name
);
793 /* Print the image information by processing image header */
794 if (tparams
->print_header
)
795 tparams
->print_header (ptr
, ¶ms
);
797 fprintf (stderr
, "%s: Can't print header for %s\n",
798 params
.cmdname
, tparams
->name
);
801 (void)munmap((void *)ptr
, map_len
);
803 /* We're a bit of paranoid */
804 #if defined(_POSIX_SYNCHRONIZED_IO) && \
805 !defined(__sun__) && \
806 !defined(__FreeBSD__) && \
807 !defined(__OpenBSD__) && \
809 (void) fdatasync (ifd
);
815 fprintf (stderr
, "%s: Write error on %s: %s\n",
816 params
.cmdname
, params
.imagefile
, strerror(errno
));
820 if (tparams
->verify_header
)
821 verify_image(tparams
);
827 copy_file (int ifd
, const char *datafile
, int pad
)
837 struct image_type_params
*tparams
= imagetool_get_type(params
.type
);
839 memset(zeros
, 0, sizeof(zeros
));
842 fprintf (stderr
, "Adding Image %s\n", datafile
);
845 if ((dfd
= open(datafile
, O_RDONLY
|O_BINARY
)) < 0) {
846 fprintf (stderr
, "%s: Can't open %s: %s\n",
847 params
.cmdname
, datafile
, strerror(errno
));
851 if (fstat(dfd
, &sbuf
) < 0) {
852 fprintf (stderr
, "%s: Can't stat %s: %s\n",
853 params
.cmdname
, datafile
, strerror(errno
));
857 if (sbuf
.st_size
== 0) {
858 fprintf (stderr
, "%s: Input file %s is empty, bailing out\n",
859 params
.cmdname
, datafile
);
863 ptr
= mmap(0, sbuf
.st_size
, PROT_READ
, MAP_SHARED
, dfd
, 0);
864 if (ptr
== MAP_FAILED
) {
865 fprintf (stderr
, "%s: Can't read %s: %s\n",
866 params
.cmdname
, datafile
, strerror(errno
));
871 (((params
.type
> IH_TYPE_INVALID
) && (params
.type
< IH_TYPE_FLATDT
)) ||
872 (params
.type
== IH_TYPE_KERNEL_NOLOAD
) || (params
.type
== IH_TYPE_FIRMWARE_IVT
))) {
873 unsigned char *p
= NULL
;
875 * XIP: do not append the struct legacy_img_hdr at the
876 * beginning of the file, but consume the space
880 if ((unsigned)sbuf
.st_size
< tparams
->header_size
) {
882 "%s: Bad size: \"%s\" is too small for XIP\n",
883 params
.cmdname
, datafile
);
887 for (p
= ptr
; p
< ptr
+ tparams
->header_size
; p
++) {
890 "%s: Bad file: \"%s\" has invalid buffer for XIP\n",
891 params
.cmdname
, datafile
);
896 offset
= tparams
->header_size
;
899 size
= sbuf
.st_size
- offset
;
901 ret
= write(ifd
, ptr
+ offset
, size
);
904 fprintf (stderr
, "%s: Write error on %s: %s\n",
905 params
.cmdname
, params
.imagefile
, strerror(errno
));
907 fprintf (stderr
, "%s: Write only %d/%d bytes, "\
908 "probably no space left on the device\n",
909 params
.cmdname
, ret
, size
);
914 if ((pad
== 1) && (tail
!= 0)) {
916 if (write(ifd
, (char *)&zero
, 4-tail
) != 4-tail
) {
917 fprintf (stderr
, "%s: Write error on %s: %s\n",
918 params
.cmdname
, params
.imagefile
,
922 } else if (pad
> 1) {
924 int todo
= sizeof(zeros
);
928 if (write(ifd
, (char *)&zeros
, todo
) != todo
) {
929 fprintf(stderr
, "%s: Write error on %s: %s\n",
930 params
.cmdname
, params
.imagefile
,
938 (void) munmap((void *)ptr
, sbuf
.st_size
);