gpimage-common.c 1.9 KB

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