rkcommon.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * (C) Copyright 2015 Google, Inc
  4. * Written by Simon Glass <sjg@chromium.org>
  5. */
  6. #ifndef _RKCOMMON_H
  7. #define _RKCOMMON_H
  8. enum {
  9. RK_BLK_SIZE = 512,
  10. RK_INIT_SIZE_ALIGN = 2048,
  11. RK_INIT_OFFSET = 4,
  12. RK_MAX_BOOT_SIZE = 512 << 10,
  13. RK_SPL_HDR_START = RK_INIT_OFFSET * RK_BLK_SIZE,
  14. RK_SPL_HDR_SIZE = 4,
  15. RK_SPL_START = RK_SPL_HDR_START + RK_SPL_HDR_SIZE,
  16. RK_IMAGE_HEADER_LEN = RK_SPL_START,
  17. };
  18. /**
  19. * rkcommon_check_params() - check params
  20. *
  21. * @return 0 if OK, -1 if ERROR.
  22. */
  23. int rkcommon_check_params(struct image_tool_params *params);
  24. /**
  25. * rkcommon_get_spl_hdr() - get 4-bytes spl hdr for a Rockchip boot image
  26. *
  27. * Rockchip's bootrom requires the spl loader to start with a 4-bytes
  28. * header. The content of this header depends on the chip type.
  29. */
  30. const char *rkcommon_get_spl_hdr(struct image_tool_params *params);
  31. /**
  32. * rkcommon_get_spl_size() - get spl size for a Rockchip boot image
  33. *
  34. * Different chip may have different sram size. And if we want to jump
  35. * back to the bootrom after spl, we may need to reserve some sram space
  36. * for the bootrom.
  37. * The spl loader size should be sram size minus reserved size(if needed)
  38. */
  39. int rkcommon_get_spl_size(struct image_tool_params *params);
  40. /**
  41. * rkcommon_set_header() - set up the header for a Rockchip boot image
  42. *
  43. * This sets up a 2KB header which can be interpreted by the Rockchip boot ROM.
  44. *
  45. * @buf: Pointer to header place (must be at least 2KB in size)
  46. * @file_size: Size of the file we want the boot ROM to load, in bytes
  47. * @return 0 if OK, -ENOSPC if too large
  48. */
  49. int rkcommon_set_header(void *buf, uint file_size,
  50. struct image_tool_params *params);
  51. /**
  52. * rkcommon_verify_header() - verify the header for a Rockchip boot image
  53. *
  54. * @buf: Pointer to the image file
  55. * @file_size: Size of entire bootable image file (incl. all padding)
  56. * @return 0 if OK
  57. */
  58. int rkcommon_verify_header(unsigned char *buf, int size,
  59. struct image_tool_params *params);
  60. /**
  61. * rkcommon_print_header() - print the header for a Rockchip boot image
  62. *
  63. * This prints the header, spl_name and whether this is a SD/MMC or SPI image.
  64. *
  65. * @buf: Pointer to the image (can be a read-only file-mapping)
  66. */
  67. void rkcommon_print_header(const void *buf);
  68. /**
  69. * rkcommon_need_rc4_spl() - check if rc4 encoded spl is required
  70. *
  71. * Some socs cannot disable the rc4-encryption of the spl binary.
  72. * rc4 encryption is disabled normally except on socs that cannot
  73. * handle unencrypted binaries.
  74. * @return true or false depending on rc4 being required.
  75. */
  76. bool rkcommon_need_rc4_spl(struct image_tool_params *params);
  77. /**
  78. * rkcommon_rc4_encode_spl() - encode the spl binary
  79. *
  80. * Encrypts the SPL binary using the generic rc4 key as required
  81. * by some socs.
  82. *
  83. * @buf: Pointer to the SPL data (header and SPL binary)
  84. * @offset: offset inside buf to start at
  85. * @size: number of bytes to encode
  86. */
  87. void rkcommon_rc4_encode_spl(void *buf, unsigned int offset, unsigned int size);
  88. /**
  89. * rkcommon_vrec_header() - allocate memory for the header
  90. *
  91. * @params: Pointer to the tool params structure
  92. * @tparams: Pointer tot the image type structure (for setting
  93. * the header and header_size)
  94. * @alignment: Alignment (a power of two) that the image should be
  95. * padded to (e.g. 512 if we want to align with SD/MMC
  96. * blocksizes or 2048 for the SPI format)
  97. *
  98. * @return bytes of padding required/added (does not include the header_size)
  99. */
  100. int rkcommon_vrec_header(struct image_tool_params *params,
  101. struct image_type_params *tparams,
  102. unsigned int alignment);
  103. #endif