imagetool.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /*
  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. #include "imagetool.h"
  9. #include <image.h>
  10. /*
  11. * Callback function to register a image type within a tool
  12. */
  13. static imagetool_register_t register_func;
  14. /*
  15. * register_image_tool -
  16. *
  17. * The tool provides its own registration function in order to all image
  18. * types initialize themselves.
  19. */
  20. void register_image_tool(imagetool_register_t image_register)
  21. {
  22. /*
  23. * Save the image tool callback function. It will be used to register
  24. * image types within that tool
  25. */
  26. register_func = image_register;
  27. /* Init ATMEL ROM Boot Image generation/list support */
  28. init_atmel_image_type();
  29. /* Init Freescale PBL Boot image generation/list support */
  30. init_pbl_image_type();
  31. /* Init Kirkwood Boot image generation/list support */
  32. init_kwb_image_type();
  33. /* Init Freescale imx Boot image generation/list support */
  34. init_imx_image_type();
  35. /* Init Freescale mxs Boot image generation/list support */
  36. init_mxs_image_type();
  37. /* Init FIT image generation/list support */
  38. init_fit_image_type();
  39. /* Init TI OMAP Boot image generation/list support */
  40. init_omap_image_type();
  41. /* Init Default image generation/list support */
  42. init_default_image_type();
  43. /* Init Davinci UBL support */
  44. init_ubl_image_type();
  45. /* Init Davinci AIS support */
  46. init_ais_image_type();
  47. /* Init Altera SOCFPGA support */
  48. init_socfpga_image_type();
  49. /* Init TI Keystone boot image generation/list support */
  50. init_gpimage_type();
  51. }
  52. /*
  53. * register_image_type -
  54. *
  55. * Register a image type within a tool
  56. */
  57. void register_image_type(struct image_type_params *tparams)
  58. {
  59. register_func(tparams);
  60. }
  61. struct image_type_params *imagetool_get_type(
  62. int type,
  63. struct image_type_params *tparams)
  64. {
  65. struct image_type_params *curr;
  66. for (curr = tparams; curr != NULL; curr = curr->next) {
  67. if (curr->check_image_type) {
  68. if (!curr->check_image_type(type))
  69. return curr;
  70. }
  71. }
  72. return NULL;
  73. }
  74. int imagetool_verify_print_header(
  75. void *ptr,
  76. struct stat *sbuf,
  77. struct image_type_params *tparams,
  78. struct image_tool_params *params)
  79. {
  80. int retval = -1;
  81. struct image_type_params *curr;
  82. for (curr = tparams; curr != NULL; curr = curr->next) {
  83. if (curr->verify_header) {
  84. retval = curr->verify_header((unsigned char *)ptr,
  85. sbuf->st_size, params);
  86. if (retval == 0) {
  87. /*
  88. * Print the image information if verify is
  89. * successful
  90. */
  91. if (curr->print_header) {
  92. curr->print_header(ptr);
  93. } else {
  94. fprintf(stderr,
  95. "%s: print_header undefined for %s\n",
  96. params->cmdname, curr->name);
  97. }
  98. break;
  99. }
  100. }
  101. }
  102. return retval;
  103. }