4 * Written by Guilherme Maciel Ferreira <guilherme.maciel.ferreira@gmail.com>
6 * SPDX-License-Identifier: GPL-2.0+
13 struct image_type_params *imagetool_get_type(int type)
15 struct image_type_params **curr;
16 INIT_SECTION(image_type);
18 struct image_type_params **start = __start_image_type;
19 struct image_type_params **end = __stop_image_type;
21 for (curr = start; curr != end; curr++) {
22 if ((*curr)->check_image_type) {
23 if (!(*curr)->check_image_type(type))
30 int imagetool_verify_print_header(
33 struct image_type_params *tparams,
34 struct image_tool_params *params)
37 struct image_type_params **curr;
38 INIT_SECTION(image_type);
40 struct image_type_params **start = __start_image_type;
41 struct image_type_params **end = __stop_image_type;
43 for (curr = start; curr != end; curr++) {
44 if ((*curr)->verify_header) {
45 retval = (*curr)->verify_header((unsigned char *)ptr,
46 sbuf->st_size, params);
50 * Print the image information if verify is
53 if ((*curr)->print_header) {
55 (*curr)->print_header(ptr);
58 "%s: print_header undefined for %s\n",
59 params->cmdname, (*curr)->name);
69 int imagetool_save_subimage(
70 const char *file_name,
76 dfd = open(file_name, O_RDWR | O_CREAT | O_TRUNC | O_BINARY,
79 fprintf(stderr, "Can't open \"%s\": %s\n",
80 file_name, strerror(errno));
84 if (write(dfd, (void *)file_data, file_len) != (ssize_t)file_len) {
85 fprintf(stderr, "Write error on \"%s\": %s\n",
86 file_name, strerror(errno));
96 int imagetool_get_filesize(struct image_tool_params *params, const char *fname)
101 fd = open(fname, O_RDONLY | O_BINARY);
103 fprintf(stderr, "%s: Can't open %s: %s\n",
104 params->cmdname, fname, strerror(errno));
108 if (fstat(fd, &sbuf) < 0) {
109 fprintf(stderr, "%s: Can't stat %s: %s\n",
110 params->cmdname, fname, strerror(errno));
119 time_t imagetool_get_source_date(
120 struct image_tool_params *params,
123 char *source_date_epoch = getenv("SOURCE_DATE_EPOCH");
125 if (source_date_epoch == NULL)
128 time_t time = (time_t) strtol(source_date_epoch, NULL, 10);
130 if (gmtime(&time) == NULL) {
131 fprintf(stderr, "%s: SOURCE_DATE_EPOCH is not valid\n",