rksd.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. static void rksd_set_header(void *buf, struct stat *sbuf, int ifd,
  15. struct image_tool_params *params)
  16. {
  17. unsigned int size;
  18. int ret;
  19. /*
  20. * We need to calculate this using 'RK_SPL_HDR_START' and not using
  21. * 'tparams->header_size', as the additional byte inserted when
  22. * 'is_boot0' is true counts towards the payload (and not towards the
  23. * header).
  24. */
  25. size = params->file_size - RK_SPL_HDR_START;
  26. ret = rkcommon_set_header(buf, size, params);
  27. if (ret) {
  28. /* TODO(sjg@chromium.org): This method should return an error */
  29. printf("Warning: SPL image is too large (size %#x) and will "
  30. "not boot\n", size);
  31. }
  32. }
  33. static int rksd_check_image_type(uint8_t type)
  34. {
  35. if (type == IH_TYPE_RKSD)
  36. return EXIT_SUCCESS;
  37. else
  38. return EXIT_FAILURE;
  39. }
  40. static int rksd_vrec_header(struct image_tool_params *params,
  41. struct image_type_params *tparams)
  42. {
  43. /*
  44. * Pad to a 2KB alignment, as required for init_size by the ROM
  45. * (see https://lists.denx.de/pipermail/u-boot/2017-May/293268.html)
  46. */
  47. return rkcommon_vrec_header(params, tparams, RK_INIT_SIZE_ALIGN);
  48. }
  49. /*
  50. * rk_sd parameters
  51. */
  52. U_BOOT_IMAGE_TYPE(
  53. rksd,
  54. "Rockchip SD Boot Image support",
  55. 0,
  56. NULL,
  57. rkcommon_check_params,
  58. rkcommon_verify_header,
  59. rkcommon_print_header,
  60. rksd_set_header,
  61. NULL,
  62. rksd_check_image_type,
  63. NULL,
  64. rksd_vrec_header
  65. );