rkcommon.h 3.6 KB

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