blob: c480687ec13884c43cb99ac39a977847198aa375 [file] [log] [blame]
Guilherme Maciel Ferreiraf86ed6a2013-12-01 12:43:10 -07001/*
2 * (C) Copyright 2013
3 *
4 * Written by Guilherme Maciel Ferreira <guilherme.maciel.ferreira@gmail.com>
5 *
6 * SPDX-License-Identifier: GPL-2.0+
7 */
8
9#ifndef _IMAGETOOL_H_
10#define _IMAGETOOL_H_
11
12#include "os_support.h"
13#include <errno.h>
14#include <fcntl.h>
15#include <stdio.h>
16#include <stdlib.h>
17#include <string.h>
18#include <sys/stat.h>
19#include <time.h>
20#include <unistd.h>
21#include <sha1.h>
22#include "fdt_host.h"
23
24#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
25
26#define IH_ARCH_DEFAULT IH_ARCH_INVALID
27
28/*
29 * This structure defines all such variables those are initialized by
30 * mkimage and dumpimage main core and need to be referred by image
31 * type specific functions
32 */
33struct image_tool_params {
34 int dflag;
35 int eflag;
36 int fflag;
Guilherme Maciel Ferreiraa804b5c2013-12-01 12:43:11 -070037 int iflag;
Guilherme Maciel Ferreiraf86ed6a2013-12-01 12:43:10 -070038 int lflag;
Guilherme Maciel Ferreiraa804b5c2013-12-01 12:43:11 -070039 int pflag;
Guilherme Maciel Ferreiraf86ed6a2013-12-01 12:43:10 -070040 int vflag;
41 int xflag;
42 int skipcpy;
43 int os;
44 int arch;
45 int type;
46 int comp;
47 char *dtc;
48 unsigned int addr;
49 unsigned int ep;
50 char *imagename;
51 char *imagename2;
52 char *datafile;
53 char *imagefile;
54 char *cmdname;
Guilherme Maciel Ferreiraa804b5c2013-12-01 12:43:11 -070055 const char *outfile; /* Output filename */
Guilherme Maciel Ferreiraf86ed6a2013-12-01 12:43:10 -070056 const char *keydir; /* Directory holding private keys */
57 const char *keydest; /* Destination .dtb for public key */
58 const char *comment; /* Comment to add to signature node */
59 int require_keys; /* 1 to mark signing keys as 'required' */
60};
61
62/*
63 * image type specific variables and callback functions
64 */
65struct image_type_params {
66 /* name is an identification tag string for added support */
67 char *name;
68 /*
69 * header size is local to the specific image type to be supported,
70 * mkimage core treats this as number of bytes
71 */
72 uint32_t header_size;
73 /* Image type header pointer */
74 void *hdr;
75 /*
76 * There are several arguments that are passed on the command line
77 * and are registered as flags in image_tool_params structure.
78 * This callback function can be used to check the passed arguments
79 * are in-lined with the image type to be supported
80 *
81 * Returns 1 if parameter check is successful
82 */
83 int (*check_params) (struct image_tool_params *);
84 /*
85 * This function is used by list command (i.e. mkimage -l <filename>)
86 * image type verification code must be put here
87 *
88 * Returns 0 if image header verification is successful
89 * otherwise, returns respective negative error codes
90 */
91 int (*verify_header) (unsigned char *, int, struct image_tool_params *);
92 /* Prints image information abstracting from image header */
93 void (*print_header) (const void *);
94 /*
95 * The header or image contents need to be set as per image type to
96 * be generated using this callback function.
97 * further output file post processing (for ex. checksum calculation,
98 * padding bytes etc..) can also be done in this callback function.
99 */
100 void (*set_header) (void *, struct stat *, int,
101 struct image_tool_params *);
102 /*
Guilherme Maciel Ferreiraa804b5c2013-12-01 12:43:11 -0700103 * This function is used by the command to retrieve a data file from
104 * the image (i.e. dumpimage -i <image> -p <position> <data_file>).
105 * Thus the code to extract a file from an image must be put here.
106 *
107 * Returns 0 if the file was successfully retrieved from the image,
108 * or a negative value on error.
109 */
110 int (*extract_datafile) (void *, struct image_tool_params *);
111 /*
Guilherme Maciel Ferreiraf86ed6a2013-12-01 12:43:10 -0700112 * Some image generation support for ex (default image type) supports
113 * more than one type_ids, this callback function is used to check
114 * whether input (-T <image_type>) is supported by registered image
115 * generation/list low level code
116 */
117 int (*check_image_type) (uint8_t);
118 /* This callback function will be executed if fflag is defined */
119 int (*fflag_handle) (struct image_tool_params *);
120 /*
121 * This callback function will be executed for variable size record
122 * It is expected to build this header in memory and return its length
123 * and a pointer to it by using image_type_params.header_size and
124 * image_type_params.hdr. The return value shall indicate if an
125 * additional padding should be used when copying the data image
126 * by returning the padding length.
127 */
128 int (*vrec_header) (struct image_tool_params *,
129 struct image_type_params *);
130 /* pointer to the next registered entry in linked list */
131 struct image_type_params *next;
132};
133
134/*
135 * Tool registration function.
136 */
137typedef void (*imagetool_register_t)(struct image_type_params *);
138
139/*
140 * Initializes all image types with the given registration callback
141 * function.
142 * An image tool uses this function to initialize all image types.
143 */
144void register_image_tool(imagetool_register_t image_register);
145
146/*
147 * Register a image type within a tool.
148 * An image type uses this function to register itself within
149 * all tools.
150 */
151void register_image_type(struct image_type_params *tparams);
152
153/*
154 * There is a c file associated with supported image type low level code
155 * for ex. default_image.c, fit_image.c
156 * init_xxx_type() is the only function referred by image tool core to avoid
157 * a single lined header file, you can define them here
158 *
159 * Supported image types init functions
160 */
161void init_default_image_type(void);
Andreas Bießmann7b1a4112014-05-19 14:23:39 +0200162void init_atmel_image_type(void);
Guilherme Maciel Ferreiraf86ed6a2013-12-01 12:43:10 -0700163void init_pbl_image_type(void);
164void init_ais_image_type(void);
165void init_kwb_image_type(void);
166void init_imx_image_type(void);
167void init_mxs_image_type(void);
168void init_fit_image_type(void);
169void init_ubl_image_type(void);
170void init_omap_image_type(void);
Karicheri, Muralidharanbf411ea2014-04-04 13:16:48 -0400171void init_gpimage_type(void);
Guilherme Maciel Ferreiraf86ed6a2013-12-01 12:43:10 -0700172
173void pbl_load_uboot(int fd, struct image_tool_params *mparams);
174
175#endif /* _IMAGETOOL_H_ */