renesas_spkgimage.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /* SPDX-License-Identifier: BSD-2-Clause */
  2. /*
  3. * Renesas RZ/N1 Package Table format
  4. * (C) 2015-2016 Renesas Electronics Europe, LTD
  5. * All rights reserved.
  6. *
  7. * Converted to mkimage plug-in
  8. * (C) Copyright 2022 Schneider Electric
  9. */
  10. #ifndef _SPKGIMAGE_H_
  11. #define _SPKGIMAGE_H_
  12. #ifdef __GNUC__
  13. #define __packed __attribute((packed))
  14. #else
  15. #define __packed
  16. #endif
  17. #define SPKG_HEADER_MARKER {'R', 'Z', 'N', '1'}
  18. #define SPKG_HEADER_SIZE 24
  19. #define SPKG_HEADER_COUNT 8
  20. #define SPKG_BLP_SIZE 264
  21. #define SPKG_CRC_SIZE 4
  22. /**
  23. * struct spkg_hdr - SPKG header
  24. * @marker: magic pattern "RZN1"
  25. * @version: header version (currently 1)
  26. * @ecc: ECC enable and block size.
  27. * @ecc_scheme: ECC algorithm selction
  28. * @ecc_bytes: ECC bytes per block
  29. * @payload_length: length of the payload (including CRC)
  30. * @load_address: address in memory where payload should be loaded
  31. * @execution_offset: offset from @load_address where execution starts
  32. * @crc: 32-bit CRC of the above header fields
  33. *
  34. * SPKG header format is defined by Renesas. It is documented in the Reneasas
  35. * RZ/N1 User Manual, Chapter 7.4 ("SPKG format").
  36. *
  37. * The BootROM searches this header in order to find and validate the boot
  38. * payload. It is therefore mandatory to wrap the payload in this header.
  39. *
  40. * The ECC-related fields @ecc @ecc_scheme @ecc_bytes are used only when
  41. * booting from NAND flash, and they are only used while fetching the payload.
  42. * These values are used to initialize the ECC controller. To avoid using
  43. * non-portable bitfields, struct spkg_hdr uses uint8_t for these fields, so
  44. * the user must shift the values into the correct spot.
  45. *
  46. * The payload will be loaded into memory at @payload_address.
  47. * Execution then jumps to @payload_address + @execution_offset.
  48. * The LSB of @execution_offset selects between ARM and Thumb mode,
  49. * as per the usual ARM interworking convention.
  50. */
  51. struct spkg_hdr {
  52. uint8_t marker[4]; /* aka magic */
  53. uint8_t version;
  54. uint8_t ecc;
  55. uint8_t ecc_scheme;
  56. uint8_t ecc_bytes;
  57. uint32_t payload_length; /* only HIGHER 24 bits */
  58. uint32_t load_address;
  59. uint32_t execution_offset;
  60. uint32_t crc; /* of this header */
  61. } __packed;
  62. /**
  63. * struct spkg_file - complete SPKG image
  64. *
  65. * A SPKG image consists of 8 identical copies of struct spkg_hdr, each one
  66. * occupying 24 bytes, for a total of 192 bytes.
  67. *
  68. * This is followed by the payload (the u-boot binary), and a 32-bit CRC.
  69. *
  70. * Optionally, the payload can be being with security header ("BLp_header").
  71. * This feature is not currently supported in mkimage.
  72. *
  73. * The payload is typically padded with 0xFF bytes so as to bring the total
  74. * image size to a multiple of the flash erase size (often 64kB).
  75. */
  76. struct spkg_file {
  77. struct spkg_hdr header[SPKG_HEADER_COUNT];
  78. uint8_t payload[0];
  79. /* then the CRC */
  80. } __packed;
  81. #endif