rksd.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * (C) Copyright 2015 Google, Inc
  4. * Written by Simon Glass <sjg@chromium.org>
  5. *
  6. * See README.rockchip for details of the rksd format
  7. */
  8. #include "imagetool.h"
  9. #include <image.h>
  10. #include <rc4.h>
  11. #include "mkimage.h"
  12. #include "rkcommon.h"
  13. static void rksd_set_header(void *buf, struct stat *sbuf, int ifd,
  14. struct image_tool_params *params)
  15. {
  16. unsigned int size;
  17. int ret;
  18. /*
  19. * We need to calculate this using 'RK_SPL_HDR_START' and not using
  20. * 'tparams->header_size', as the additional byte inserted when
  21. * 'is_boot0' is true counts towards the payload (and not towards the
  22. * header).
  23. */
  24. size = params->file_size - RK_SPL_HDR_START;
  25. ret = rkcommon_set_header(buf, size, params);
  26. if (ret) {
  27. /* TODO(sjg@chromium.org): This method should return an error */
  28. printf("Warning: SPL image is too large (size %#x) and will "
  29. "not boot\n", size);
  30. }
  31. }
  32. static int rksd_check_image_type(uint8_t type)
  33. {
  34. if (type == IH_TYPE_RKSD)
  35. return EXIT_SUCCESS;
  36. else
  37. return EXIT_FAILURE;
  38. }
  39. static int rksd_vrec_header(struct image_tool_params *params,
  40. struct image_type_params *tparams)
  41. {
  42. /*
  43. * Pad to a 2KB alignment, as required for init_size by the ROM
  44. * (see https://lists.denx.de/pipermail/u-boot/2017-May/293268.html)
  45. */
  46. return rkcommon_vrec_header(params, tparams, RK_INIT_SIZE_ALIGN);
  47. }
  48. /*
  49. * rk_sd parameters
  50. */
  51. U_BOOT_IMAGE_TYPE(
  52. rksd,
  53. "Rockchip SD Boot Image support",
  54. 0,
  55. NULL,
  56. rkcommon_check_params,
  57. rkcommon_verify_header,
  58. rkcommon_print_header,
  59. rksd_set_header,
  60. NULL,
  61. rksd_check_image_type,
  62. NULL,
  63. rksd_vrec_header
  64. );