gpimage-common.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. * (C) Copyright 2014
  3. * Texas Instruments Incorporated
  4. * Refactored common functions in to gpimage-common.c.
  5. *
  6. * (C) Copyright 2010
  7. * Linaro LTD, www.linaro.org
  8. * Author: John Rigby <john.rigby@linaro.org>
  9. * Based on TI's signGP.c
  10. *
  11. * (C) Copyright 2009
  12. * Stefano Babic, DENX Software Engineering, sbabic@denx.de.
  13. *
  14. * (C) Copyright 2008
  15. * Marvell Semiconductor <www.marvell.com>
  16. * Written-by: Prafulla Wadaskar <prafulla@marvell.com>
  17. *
  18. * SPDX-License-Identifier: GPL-2.0+
  19. */
  20. #include "imagetool.h"
  21. #include <compiler.h>
  22. #include <image.h>
  23. #include "gpheader.h"
  24. /* Helper to convert size and load_addr to big endian */
  25. void to_be32(uint32_t *gph_size, uint32_t *gph_load_addr)
  26. {
  27. *gph_size = cpu_to_be32(*gph_size);
  28. *gph_load_addr = cpu_to_be32(*gph_load_addr);
  29. }
  30. int gph_verify_header(struct gp_header *gph, int be)
  31. {
  32. uint32_t gph_size = gph->size;
  33. uint32_t gph_load_addr = gph->load_addr;
  34. if (be)
  35. to_be32(&gph_size, &gph_load_addr);
  36. if (!gph_size || !gph_load_addr)
  37. return -1;
  38. return 0;
  39. }
  40. void gph_print_header(const struct gp_header *gph, int be)
  41. {
  42. uint32_t gph_size = gph->size, gph_load_addr = gph->load_addr;
  43. if (be)
  44. to_be32(&gph_size, &gph_load_addr);
  45. if (!gph_size) {
  46. fprintf(stderr, "Error: invalid image size %x\n", gph_size);
  47. exit(EXIT_FAILURE);
  48. }
  49. if (!gph_load_addr) {
  50. fprintf(stderr, "Error: invalid image load address %x\n",
  51. gph_load_addr);
  52. exit(EXIT_FAILURE);
  53. }
  54. printf("GP Header: Size %x LoadAddr %x\n", gph_size, gph_load_addr);
  55. }
  56. void gph_set_header(struct gp_header *gph, uint32_t size, uint32_t load_addr,
  57. int be)
  58. {
  59. gph->size = size;
  60. gph->load_addr = load_addr;
  61. if (be)
  62. to_be32(&gph->size, &gph->load_addr);
  63. }
  64. int gpimage_check_params(struct image_tool_params *params)
  65. {
  66. return (params->dflag && (params->fflag || params->lflag)) ||
  67. (params->fflag && (params->dflag || params->lflag)) ||
  68. (params->lflag && (params->dflag || params->fflag));
  69. }