mkimage.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /*
  2. * (C) Copyright 2000-2004
  3. * DENX Software Engineering
  4. * Wolfgang Denk, wd@denx.de
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License as
  8. * published by the Free Software Foundation; either version 2 of
  9. * the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  19. * MA 02111-1307 USA
  20. */
  21. #ifndef _MKIIMAGE_H_
  22. #define _MKIIMAGE_H_
  23. #include "os_support.h"
  24. #include <errno.h>
  25. #include <fcntl.h>
  26. #include <stdio.h>
  27. #include <stdlib.h>
  28. #include <string.h>
  29. #include <sys/stat.h>
  30. #include <time.h>
  31. #include <unistd.h>
  32. #include <sha1.h>
  33. #include "fdt_host.h"
  34. #undef MKIMAGE_DEBUG
  35. #ifdef MKIMAGE_DEBUG
  36. #define debug(fmt,args...) printf (fmt ,##args)
  37. #else
  38. #define debug(fmt,args...)
  39. #endif /* MKIMAGE_DEBUG */
  40. #define MKIMAGE_TMPFILE_SUFFIX ".tmp"
  41. #define MKIMAGE_MAX_TMPFILE_LEN 256
  42. #define MKIMAGE_DEFAULT_DTC_OPTIONS "-I dts -O dtb -p 500"
  43. #define MKIMAGE_MAX_DTC_CMDLINE_LEN 512
  44. #define MKIMAGE_DTC "dtc" /* assume dtc is in $PATH */
  45. /*
  46. * This structure defines all such variables those are initialized by
  47. * mkimage main core and need to be referred by image type specific
  48. * functions
  49. */
  50. struct mkimage_params {
  51. int dflag;
  52. int eflag;
  53. int fflag;
  54. int lflag;
  55. int vflag;
  56. int xflag;
  57. int skipcpy;
  58. int os;
  59. int arch;
  60. int type;
  61. int comp;
  62. char *dtc;
  63. unsigned int addr;
  64. unsigned int ep;
  65. char *imagename;
  66. char *imagename2;
  67. char *datafile;
  68. char *imagefile;
  69. char *cmdname;
  70. };
  71. /*
  72. * image type specific variables and callback functions
  73. */
  74. struct image_type_params {
  75. /* name is an identification tag string for added support */
  76. char *name;
  77. /*
  78. * header size is local to the specific image type to be supported,
  79. * mkimage core treats this as number of bytes
  80. */
  81. uint32_t header_size;
  82. /* Image type header pointer */
  83. void *hdr;
  84. /*
  85. * There are several arguments that are passed on the command line
  86. * and are registered as flags in mkimage_params structure.
  87. * This callback function can be used to check the passed arguments
  88. * are in-lined with the image type to be supported
  89. *
  90. * Returns 1 if parameter check is successful
  91. */
  92. int (*check_params) (struct mkimage_params *);
  93. /*
  94. * This function is used by list command (i.e. mkimage -l <filename>)
  95. * image type verification code must be put here
  96. *
  97. * Returns 0 if image header verification is successful
  98. * otherwise, returns respective negative error codes
  99. */
  100. int (*verify_header) (unsigned char *, int, struct mkimage_params *);
  101. /* Prints image information abstracting from image header */
  102. void (*print_header) (const void *);
  103. /*
  104. * The header or image contents need to be set as per image type to
  105. * be generated using this callback function.
  106. * further output file post processing (for ex. checksum calculation,
  107. * padding bytes etc..) can also be done in this callback function.
  108. */
  109. void (*set_header) (void *, struct stat *, int,
  110. struct mkimage_params *);
  111. /*
  112. * 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 mkimage_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
  124. */
  125. int (*vrec_header) (struct mkimage_params *,
  126. struct image_type_params *);
  127. /* pointer to the next registered entry in linked list */
  128. struct image_type_params *next;
  129. };
  130. /*
  131. * Exported functions
  132. */
  133. void mkimage_register (struct image_type_params *tparams);
  134. /*
  135. * There is a c file associated with supported image type low level code
  136. * for ex. default_image.c, fit_image.c
  137. * init is the only function referred by mkimage core.
  138. * to avoid a single lined header file, you can define them here
  139. *
  140. * Supported image types init functions
  141. */
  142. void pbl_load_uboot(int fd, struct mkimage_params *mparams);
  143. void init_pbl_image_type(void);
  144. void init_ais_image_type(void);
  145. void init_kwb_image_type (void);
  146. void init_imx_image_type (void);
  147. void init_default_image_type (void);
  148. void init_fit_image_type (void);
  149. void init_ubl_image_type(void);
  150. void init_omap_image_type(void);
  151. #endif /* _MKIIMAGE_H_ */