mrdump_setup.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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) 2016. 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. #include <block_generic_interface.h>
  32. #include <malloc.h>
  33. #include <printf.h>
  34. #include <stdarg.h>
  35. #include <stdint.h>
  36. #include <stdlib.h>
  37. #include <string.h>
  38. #include <video.h>
  39. #include <dev/mrdump.h>
  40. #include <platform/mtk_key.h>
  41. #include <platform/mtk_wdt.h>
  42. #include <platform/mt_gpt.h>
  43. #include <target/cust_key.h>
  44. #include <platform/boot_mode.h>
  45. #include <platform/ram_console.h>
  46. #include <arch/ops.h>
  47. #include <libfdt.h>
  48. #include <platform.h>
  49. #include "aee.h"
  50. #include "mrdump_private.h"
  51. /* +++ ddr reserve mode +++ */
  52. extern BOOT_ARGUMENT *g_boot_arg;
  53. static void mrdump_ddr_rsv_fdt(void *fdt, int offset, const void *enable)
  54. {
  55. if (0 == fdt_setprop_string(fdt, offset, "mrdump,ddr_rsv", enable)) {
  56. dprintf(CRITICAL, "%s: set ddr_rsv = %s\n",
  57. __func__, (char*)enable);
  58. } else {
  59. dprintf(CRITICAL, "%s: failed to set ddr_rsv %s\n",
  60. __func__, (char*)enable);
  61. }
  62. }
  63. /* +++ mrdump control block params +++ */
  64. static void mrdump_cb_fdt(void *fdt, int offset)
  65. {
  66. int ret = fdt_setprop_u32(fdt, offset, "mrdump,cblock", MRDUMP_CB_ADDR);
  67. if (ret) {
  68. goto error;
  69. }
  70. ret = fdt_appendprop_u32(fdt, offset, "mrdump,cblock", MRDUMP_CB_SIZE);
  71. if (ret) {
  72. goto error;
  73. }
  74. return;
  75. error:
  76. dprintf(CRITICAL, "%s: failed to set mrdump,cblock entry\n", __func__);
  77. }
  78. #if defined(MTK_MRDUMP_SUPPORT)
  79. static void mrdump_lk_version_fdt(void *fdt, int offset, const void *lk_version)
  80. {
  81. if (0 == fdt_setprop_string(fdt, offset, "mrdump,lk", lk_version)) {
  82. dprintf(CRITICAL, "%s: set lk_version = %s\n",
  83. __func__, (char*)lk_version);
  84. } else {
  85. dprintf(CRITICAL, "%s: failed to set lk_version %s\n",
  86. __func__, (char*)lk_version);
  87. }
  88. }
  89. #endif
  90. /* +++ mrdump initialization +++ */
  91. void mrdump_init(void *fdt)
  92. {
  93. int res, chosen_offset;
  94. /* +++ mrdump_key +++ */
  95. mrdump_key_fdt_init(fdt);
  96. chosen_offset = fdt_path_offset(fdt, "/chosen");
  97. if (chosen_offset < 0) {
  98. dprintf(CRITICAL, "%s: /chosen not found\n", __func__);
  99. return;
  100. }
  101. /* +++ ddr rsv +++ */
  102. if (g_boot_arg->ddr_reserve_ready != AEE_MRDUMP_DDR_RSV_READY) {
  103. mrdump_ddr_rsv_fdt(fdt, chosen_offset, "no");
  104. dprintf(CRITICAL, "MT-RAMDUMP: DDR reserve mode not ready (0x%x)\n",
  105. g_boot_arg->ddr_reserve_ready);
  106. res = 0;
  107. }
  108. else {
  109. mrdump_ddr_rsv_fdt(fdt, chosen_offset, "yes");
  110. res = 1;
  111. }
  112. /* +++ mrdump control block params +++ */
  113. mrdump_cb_fdt(fdt, chosen_offset);
  114. #if defined(MTK_MRDUMP_SUPPORT)
  115. if (res && (mrdump_check_enable() <= MRDUMP_ALWAYS_ENABLE)) {
  116. mrdump_lk_version_fdt(fdt, chosen_offset, MRDUMP_GO_DUMP);
  117. }
  118. /* default setting */
  119. int output_device = mrdump_get_default_output_device();
  120. if (output_device == MRDUMP_DEV_UNKNOWN)
  121. dprintf(CRITICAL, "MT-RAMDUMP: unknown output device.\n");
  122. #endif
  123. #ifdef MRDUMP_PARTITION_ENABLE
  124. mrdump_partition_resize();
  125. #endif
  126. }