rksd.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*
  2. * (C) Copyright 2015 Google, Inc
  3. * Written by Simon Glass <sjg@chromium.org>
  4. *
  5. * SPDX-License-Identifier: GPL-2.0+
  6. *
  7. * See README.rockchip for details of the rksd format
  8. */
  9. #include "imagetool.h"
  10. #include <image.h>
  11. #include <rc4.h>
  12. #include "mkimage.h"
  13. #include "rkcommon.h"
  14. enum {
  15. RKSD_SPL_HDR_START = RK_CODE1_OFFSET * RK_BLK_SIZE,
  16. RKSD_SPL_START = RKSD_SPL_HDR_START + 4,
  17. RKSD_HEADER_LEN = RKSD_SPL_START,
  18. };
  19. static char dummy_hdr[RKSD_HEADER_LEN];
  20. static int rksd_check_params(struct image_tool_params *params)
  21. {
  22. return 0;
  23. }
  24. static int rksd_verify_header(unsigned char *buf, int size,
  25. struct image_tool_params *params)
  26. {
  27. return 0;
  28. }
  29. static void rksd_print_header(const void *buf)
  30. {
  31. }
  32. static void rksd_set_header(void *buf, struct stat *sbuf, int ifd,
  33. struct image_tool_params *params)
  34. {
  35. unsigned int size;
  36. int ret;
  37. size = params->file_size - RKSD_SPL_HDR_START;
  38. ret = rkcommon_set_header(buf, size);
  39. if (ret) {
  40. /* TODO(sjg@chromium.org): This method should return an error */
  41. printf("Warning: SPL image is too large (size %#x) and will not boot\n",
  42. size);
  43. }
  44. memcpy(buf + RKSD_SPL_HDR_START, "RK32", 4);
  45. }
  46. static int rksd_extract_subimage(void *buf, struct image_tool_params *params)
  47. {
  48. return 0;
  49. }
  50. static int rksd_check_image_type(uint8_t type)
  51. {
  52. if (type == IH_TYPE_RKSD)
  53. return EXIT_SUCCESS;
  54. else
  55. return EXIT_FAILURE;
  56. }
  57. /* We pad the file out to a fixed size - this method returns that size */
  58. static int rksd_vrec_header(struct image_tool_params *params,
  59. struct image_type_params *tparams)
  60. {
  61. int pad_size;
  62. pad_size = RKSD_SPL_HDR_START + RK_MAX_CODE1_SIZE;
  63. debug("pad_size %x\n", pad_size);
  64. return pad_size - params->file_size;
  65. }
  66. /*
  67. * rk_sd parameters
  68. */
  69. U_BOOT_IMAGE_TYPE(
  70. rksd,
  71. "Rockchip SD Boot Image support",
  72. RKSD_HEADER_LEN,
  73. dummy_hdr,
  74. rksd_check_params,
  75. rksd_verify_header,
  76. rksd_print_header,
  77. rksd_set_header,
  78. rksd_extract_subimage,
  79. rksd_check_image_type,
  80. NULL,
  81. rksd_vrec_header
  82. );