rkspi.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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 rkspi 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. RKSPI_SECT_LEN = RK_BLK_SIZE * 4,
  16. };
  17. static int rkspi_verify_header(unsigned char *buf, int size,
  18. struct image_tool_params *params)
  19. {
  20. return 0;
  21. }
  22. static void rkspi_print_header(const void *buf)
  23. {
  24. }
  25. static void rkspi_set_header(void *buf, struct stat *sbuf, int ifd,
  26. struct image_tool_params *params)
  27. {
  28. int sector;
  29. unsigned int size;
  30. int ret;
  31. size = params->orig_file_size;
  32. ret = rkcommon_set_header(buf, size, params);
  33. debug("size %x\n", size);
  34. if (ret) {
  35. /* TODO(sjg@chromium.org): This method should return an error */
  36. printf("Warning: SPL image is too large (size %#x) and will not boot\n",
  37. size);
  38. }
  39. /*
  40. * Spread the image out so we only use the first 2KB of each 4KB
  41. * region. This is a feature of the SPI format required by the Rockchip
  42. * boot ROM. Its rationale is unknown.
  43. */
  44. for (sector = size / RKSPI_SECT_LEN - 1; sector >= 0; sector--) {
  45. debug("sector %u\n", sector);
  46. memmove(buf + sector * RKSPI_SECT_LEN * 2,
  47. buf + sector * RKSPI_SECT_LEN,
  48. RKSPI_SECT_LEN);
  49. memset(buf + sector * RKSPI_SECT_LEN * 2 + RKSPI_SECT_LEN,
  50. '\0', RKSPI_SECT_LEN);
  51. }
  52. }
  53. static int rkspi_extract_subimage(void *buf, struct image_tool_params *params)
  54. {
  55. return 0;
  56. }
  57. static int rkspi_check_image_type(uint8_t type)
  58. {
  59. if (type == IH_TYPE_RKSPI)
  60. return EXIT_SUCCESS;
  61. else
  62. return EXIT_FAILURE;
  63. }
  64. /* We pad the file out to a fixed size - this method returns that size */
  65. static int rkspi_vrec_header(struct image_tool_params *params,
  66. struct image_type_params *tparams)
  67. {
  68. int pad_size;
  69. rkcommon_vrec_header(params, tparams);
  70. pad_size = (rkcommon_get_spl_size(params) + 0x7ff) / 0x800 * 0x800;
  71. params->orig_file_size = pad_size;
  72. /* We will double the image size due to the SPI format */
  73. pad_size *= 2;
  74. pad_size += RK_SPL_HDR_START;
  75. debug("pad_size %x\n", pad_size);
  76. return pad_size - params->file_size - tparams->header_size;
  77. }
  78. /*
  79. * rk_spi parameters
  80. */
  81. U_BOOT_IMAGE_TYPE(
  82. rkspi,
  83. "Rockchip SPI Boot Image support",
  84. 0,
  85. NULL,
  86. rkcommon_check_params,
  87. rkspi_verify_header,
  88. rkspi_print_header,
  89. rkspi_set_header,
  90. rkspi_extract_subimage,
  91. rkspi_check_image_type,
  92. NULL,
  93. rkspi_vrec_header
  94. );