odm_mdtbo.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /* Copyright Statement:
  2. *
  3. * This software/firmware and related documentation ("MediaTek Software") are
  4. * protected under relevant copyright laws. The information contained herein
  5. * is confidential and proprietary to MediaTek Inc. and/or its licensors.
  6. * Without the prior written permission of MediaTek inc. and/or its licensors,
  7. * any reproduction, modification, use or disclosure of MediaTek Software,
  8. * and information contained herein, in whole or in part, shall be strictly prohibited.
  9. */
  10. /* MediaTek Inc. (C) 2017. All rights reserved.
  11. *
  12. * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
  13. * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
  14. * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER ON
  15. * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
  16. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
  17. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
  18. * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
  19. * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
  20. * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND RECEIVER AGREES TO LOOK ONLY TO SUCH
  21. * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. RECEIVER EXPRESSLY ACKNOWLEDGES
  22. * THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES
  23. * CONTAINED IN MEDIATEK SOFTWARE. MEDIATEK SHALL ALSO NOT BE RESPONSIBLE FOR ANY MEDIATEK
  24. * SOFTWARE RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
  25. * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND
  26. * CUMULATIVE LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
  27. * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
  28. * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY RECEIVER TO
  29. * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
  30. */
  31. #ifndef _ODM_MDTBO_H_
  32. #define _ODM_MDTBO_H_
  33. #ifdef MTK_GPT_SCHEME_SUPPORT
  34. #include <platform/partition.h>
  35. #else
  36. #include <mt_partition.h>
  37. #endif // MTK_GPT_SCHEME_SUPPORT
  38. /******************************************************************************
  39. * Some platform, e.g. mt6755, defines the symbol BLK_SIZE rather than
  40. * PART_HDR_DATA_SIZE. in "partition.h". If PART_HDR_DATA_SIZE is not defined,
  41. * define it here to avoid compilation error on those platforms.
  42. * TO DO: The interface (e.g. partition.h) should be common code.
  43. ******************************************************************************/
  44. #ifndef PART_HDR_DATA_SIZE
  45. #define PART_HDR_DATA_SIZE 512
  46. #endif // PART_HDR_DATA_SIZE
  47. #define ODM_MDTBO_HDR_SIZE (512)
  48. #define ODM_MDTBO_HDR_PROLOG (32)
  49. #define MAX_NUM_OF_ODM_MDTBO ((ODM_MDTBO_HDR_SIZE - ODM_MDTBO_HDR_PROLOG) / 4)
  50. #define ODM_MDTBO_MAGIC (0xdeaddead)
  51. #define ODM_MDTBO_VERSION (2)
  52. /******************************************************************************
  53. * MDTBO: Multiple Device Tree Blob for Overlay
  54. ******************************************************************************/
  55. typedef union {
  56. struct {
  57. unsigned int magic; /* magic: PART_MAGIC = 0xdeaddead */
  58. unsigned int dsize; /* data size (not including this 512-byte header) */
  59. unsigned int hdr_size; /* header size */
  60. unsigned int hdr_version; /* header version: ODM_MDTBO_VERSION */
  61. unsigned int num_of_dtbo; /* number of dtbo */
  62. unsigned int reserved[3]; /* reserved */
  63. /* The data above this is the "header prolog". */
  64. unsigned int dtbo_offset[MAX_NUM_OF_ODM_MDTBO]; /* offset of dtbo (not including this header) */
  65. } info;
  66. unsigned char data[ODM_MDTBO_HDR_SIZE];
  67. } mdtbo_hdr_t;
  68. /******************************************************************************
  69. * New DTBO partition format defined since Android P
  70. ******************************************************************************/
  71. #define DT_TABLE_MAGIC 0xd7b7ab1e
  72. #define LARGE_DT_ENTRY_SIZE 0 //can be customized in case of built-in super large # of DT
  73. struct dt_table_header {
  74. uint32_t magic; // DT_TABLE_MAGIC
  75. uint32_t total_size; // includes dt_table_header + all dt_table_entry and all dtb/dtbo
  76. uint32_t header_size; // sizeof(dt_table_header)
  77. uint32_t dt_entry_size; // sizeof(dt_table_entry)
  78. uint32_t dt_entry_count; // number of dt_table_entry
  79. uint32_t dt_entries_offset; // offset to the first dt_table_entry from head of dt_table_header
  80. uint32_t page_size; // flash page size we assume
  81. uint32_t version; // DTBOage version, the current version is 0.
  82. // The version will be incremented when the
  83. // dt_table_header struct is updated.
  84. };
  85. struct dt_table_entry {
  86. uint32_t dt_size;
  87. uint32_t dt_offset; // offset from head of dt_table_header
  88. uint32_t id; // use this field as index of CONFIG_BUILD_ARM_DTB_OVERLAY_IMAGE_NAMES
  89. uint32_t rev; // optional, must be zero if unused
  90. uint32_t custom[4]; // optional, must be zero if unused
  91. };
  92. /******************************************************************************
  93. * NOTE: Customers need to implement their own customized_get_odm_mdtbo_index()
  94. * function. If customized_get_odm_mdtbo_index() is not implemented, the
  95. * value 0 will be used as the default dtbo index. Each customer can
  96. * maintain their own implementation of customized_get_odm_mdtbo_index()
  97. * in a separate source file as long as it can be linked.
  98. ******************************************************************************/
  99. int customized_get_odm_mdtbo_index(void) __attribute__((weak));
  100. int get_odm_mdtbo_index(void);
  101. char *load_overlay_dtbo(char *part_name, unsigned int *size, uint64_t recovery_dtbo_offset);
  102. int get_dtbo_index(void);
  103. void set_dtbo_index(int dtbo_idx);
  104. #endif // _ODM_MDTBO_H_