ram_console.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549
  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 <stdio.h>
  32. #include <stdlib.h> // for ALIGN()
  33. #include <string.h>
  34. #include <arch/arm/mmu.h>
  35. #include <platform/boot_mode.h>
  36. #include <platform/ram_console.h>
  37. #include <libfdt.h>
  38. #define RAM_CONSOLE_SIG (0x43474244) /* DBGC */
  39. #define MOD "RAM_CONSOLE"
  40. struct ram_console_buffer {
  41. u32 sig;
  42. /* for size comptible */
  43. u32 off_pl;
  44. u32 off_lpl; /* last preloader */
  45. u32 sz_pl;
  46. u32 off_lk;
  47. u32 off_llk; /* last lk */
  48. u32 sz_lk;
  49. u32 padding[2]; /* size = 2 * 16 = 32 byte */
  50. u32 dump_step;
  51. u32 sz_buffer;
  52. u32 off_linux;
  53. u32 off_console;
  54. u32 padding2[3];
  55. };
  56. #define RAM_CONSOLE_LK_SIZE 16
  57. struct reboot_reason_lk {
  58. u32 last_func[RAM_CONSOLE_LK_SIZE];
  59. };
  60. struct reboot_reason_pl {
  61. u32 wdt_status;
  62. u32 last_func[0];
  63. };
  64. struct reboot_reason_kernel {
  65. u32 fiq_step;
  66. /* 0xaeedeadX: X=1 (HWT), X=2 (KE), X=3 (nested panic) */
  67. /* details see enum AEE_EXP_TYPE_NUM in ram_console_common.h */
  68. u32 exp_type;
  69. u32 others[0];
  70. };
  71. extern int sLOG(char *fmt, ...);
  72. #define LOG(fmt, ...) \
  73. do { \
  74. sLOG(fmt, ##__VA_ARGS__); \
  75. printf(fmt, ##__VA_ARGS__); \
  76. } while(0)
  77. static struct ram_console_buffer *ram_console = NULL;
  78. static uint32_t ram_console_size;
  79. extern BOOT_ARGUMENT *g_boot_arg;
  80. static void ram_console_fatal(const char *str)
  81. {
  82. LOG("%s. FATAL:%s\n", MOD, str);
  83. while(1)
  84. ;
  85. }
  86. static void ram_console_memory_info_valid(struct ram_console_memory_info *memory_info)
  87. {
  88. if (memory_info->magic1 != MEM_MAGIC1 || memory_info->magic2 != MEM_MAGIC2) {
  89. LOG("%s. passed arg magic:[0x%x, 0x%x] mismatch\n", MOD, memory_info->magic1, memory_info->magic2);
  90. ram_console_fatal("illegal magic number");
  91. }
  92. }
  93. static void ram_console_atag_valid(void)
  94. {
  95. u32 sram_addr;
  96. u32 sram_size;
  97. u32 def_type;
  98. u32 memory_info_offset;
  99. if (g_boot_arg != NULL) {
  100. sram_addr = g_boot_arg->ram_console_sram_addr;
  101. sram_size = g_boot_arg->ram_console_sram_size;
  102. def_type = g_boot_arg->ram_console_def_type;
  103. memory_info_offset = g_boot_arg->ram_console_memory_info_offset;
  104. if (def_type != RAM_CONSOLE_DEF_SRAM && def_type != RAM_CONSOLE_DEF_DRAM)
  105. ram_console_fatal("unknown def type");
  106. if (sram_addr == 0 || sram_size == 0)
  107. ram_console_fatal("sram addr size zero");
  108. if (memory_info_offset <= sram_size)
  109. ram_console_fatal("memory offset invalid value");
  110. } else {
  111. ram_console_fatal("unexpected g_boot_arg null pointer");
  112. }
  113. }
  114. static struct ram_console_memory_info *ram_console_atag_memory_info(void)
  115. {
  116. u32 sram_addr;
  117. u32 memory_info_offset;
  118. struct ram_console_memory_info *memory_info = NULL;
  119. ram_console_atag_valid();
  120. sram_addr = g_boot_arg->ram_console_sram_addr;
  121. memory_info_offset = g_boot_arg->ram_console_memory_info_offset;
  122. memory_info = (struct ram_console_memory_info *)(sram_addr + memory_info_offset);
  123. ram_console_memory_info_valid(memory_info);
  124. return memory_info;
  125. }
  126. static void ram_console_ptr_init_by_atag(void)
  127. {
  128. struct ram_console_memory_info *memory_info = NULL;
  129. u32 sram_addr;
  130. u32 sram_size;
  131. u32 def_type;
  132. u32 memory_info_offset;
  133. if (g_boot_arg == NULL)
  134. ram_console_fatal("unexpected g_boot_arg null pointer");
  135. sram_addr = g_boot_arg->ram_console_sram_addr;
  136. sram_size = g_boot_arg->ram_console_sram_size;
  137. def_type = g_boot_arg->ram_console_def_type;
  138. memory_info_offset = g_boot_arg->ram_console_memory_info_offset;
  139. LOG("%s. boot_arg(PL2LK): sram_addr:0x%x, sram_size:0x%x, def_type:0x%x, memory_info_offset:0x%x\n", MOD, sram_addr, sram_size, def_type, memory_info_offset);
  140. memory_info = ram_console_atag_memory_info();
  141. if (def_type == RAM_CONSOLE_DEF_SRAM) {
  142. ram_console = (struct ram_console_buffer *)sram_addr;
  143. ram_console_size = sram_size;
  144. } else if (def_type == RAM_CONSOLE_DEF_DRAM) {
  145. ram_console = (struct ram_console_buffer *)memory_info->dram_addr;
  146. ram_console_size = memory_info->dram_size;
  147. #ifdef MTK_3LEVEL_PAGETABLE
  148. {
  149. uint32_t start = (uint32_t)ram_console;
  150. arch_mmu_map(ROUNDDOWN((uint64_t)start, PAGE_SIZE), ROUNDDOWN((uint32_t)start, PAGE_SIZE),
  151. MMU_MEMORY_TYPE_NORMAL_WRITE_BACK | MMU_MEMORY_AP_P_RW_U_NA, ROUNDUP(ram_console_size, PAGE_SIZE));
  152. }
  153. #endif
  154. } else {
  155. ram_console_fatal("unknown def type");
  156. }
  157. if (ram_console->sig != RAM_CONSOLE_SIG) {
  158. LOG("%s. %s(0x%x) sig %x mismatch\n", MOD, (def_type == RAM_CONSOLE_DEF_SRAM) ? "sram" : "dram", (unsigned int)ram_console, ram_console->sig);
  159. ram_console_fatal("sig mismatch");
  160. }
  161. }
  162. void ram_console_init(void)
  163. {
  164. int i;
  165. struct reboot_reason_lk *rr_lk;
  166. ram_console_ptr_init_by_atag();
  167. if (ram_console) {
  168. LOG("%s. start: %p, size: 0x%x\n", MOD, ram_console, ram_console_size);
  169. } else {
  170. LOG("%s. sig not match\n", MOD);
  171. return;
  172. }
  173. ram_console->off_lk = ram_console->off_lpl + ALIGN(ram_console->sz_pl, 64);
  174. ram_console->off_llk = ram_console->off_lk + ALIGN(sizeof(struct reboot_reason_lk), 64);
  175. ram_console->sz_lk = sizeof(struct reboot_reason_lk);
  176. if (ram_console->sz_lk == sizeof(struct reboot_reason_lk) && (ram_console->off_lk + ram_console->sz_lk == ram_console->off_llk)) {
  177. LOG("%s. lk last status: ", MOD);
  178. rr_lk = (void*)ram_console + ram_console->off_lk;
  179. for (i = 0; i < RAM_CONSOLE_LK_SIZE; i++) {
  180. LOG("0x%x ", rr_lk->last_func[i]);
  181. }
  182. LOG("\n");
  183. memcpy((void*)ram_console + ram_console->off_llk, (void*)ram_console + ram_console->off_lk, ram_console->sz_lk);
  184. } else {
  185. LOG("%s. lk size mismatch %x + %x != %x\n", MOD, ram_console->sz_lk, ram_console->off_lk, ram_console->off_llk);
  186. ram_console->sz_lk = sizeof(struct reboot_reason_lk);
  187. }
  188. ram_console->off_linux = ram_console->off_llk + ALIGN(ram_console->sz_lk, 64);
  189. }
  190. #define RE_BOOT_BY_WDT_SW 2
  191. #define RE_BOOT_NORMAL_BOOT 0
  192. #define RE_BOOT_BY_EINT 256/*we can find the definition from preloader ,this value should sync with preloader incase issue happened*/
  193. #define RE_BOOT_BY_SYSRST 512/*we can find the definition from preloader ,this value should sync with preloader incase issue happened*/
  194. #ifdef MTK_PMIC_FULL_RESET
  195. #define RE_BOOT_FULL_PMIC 0x800
  196. #endif
  197. #define U_VAR(type) rc_##type
  198. static unsigned int U_VAR(wdt_status), U_VAR(fiq_step), U_VAR(exp_type);
  199. static bool U_VAR(set_flag) = false;
  200. bool ram_console_reboot_by_mrdump_key(void)
  201. {
  202. unsigned int wdt_status;
  203. wdt_status = ((struct reboot_reason_pl*)((void*)ram_console + ram_console->off_pl))->wdt_status;
  204. return ((wdt_status & RE_BOOT_BY_EINT)|(wdt_status & RE_BOOT_BY_SYSRST))?true:false;
  205. }
  206. bool ram_console_should_restore(struct ram_console_buffer *tmp_ram_console)
  207. {
  208. unsigned int fiq_step, wdt_status, exp_type;
  209. if (U_VAR(set_flag) && tmp_ram_console && tmp_ram_console->off_linux &&
  210. (tmp_ram_console->off_linux == (tmp_ram_console->off_llk + ALIGN(tmp_ram_console->sz_lk, 64))) &&
  211. (tmp_ram_console->off_pl == sizeof(struct ram_console_buffer))) {
  212. wdt_status = ((struct reboot_reason_pl*)((void*)tmp_ram_console + tmp_ram_console->off_pl))->wdt_status;
  213. fiq_step = ((struct reboot_reason_kernel*)((void*)tmp_ram_console + tmp_ram_console->off_linux))->fiq_step;
  214. exp_type = RAM_CONSOLE_EXP_TYPE_DEC(((struct reboot_reason_kernel *)((void *)tmp_ram_console + tmp_ram_console->off_linux))->exp_type);
  215. if ((wdt_status != 0 && wdt_status != U_VAR(wdt_status)) ||
  216. (fiq_step != 0 && fiq_step != U_VAR(fiq_step)) ||
  217. (exp_type != 0 && wdt_status != U_VAR(exp_type))) {
  218. return true;
  219. }
  220. }
  221. return false;
  222. }
  223. #ifdef MTK_PMIC_FULL_RESET
  224. bool ram_console_reboot_by_cold_reset(void)
  225. {
  226. unsigned int wdt_status;
  227. wdt_status = ((struct reboot_reason_pl*)((void*)ram_console + ram_console->off_pl))->wdt_status;
  228. return (wdt_status & RE_BOOT_FULL_PMIC) ? true : false;
  229. }
  230. #endif
  231. bool ram_console_get_wdt_status(unsigned int *wdt_status)
  232. {
  233. if (wdt_status && U_VAR(set_flag)) {
  234. *wdt_status = U_VAR(wdt_status);
  235. return true;
  236. }
  237. return false;
  238. }
  239. bool ram_console_get_fiq_step(unsigned int *fiq_step)
  240. {
  241. if (fiq_step && U_VAR(set_flag)) {
  242. *fiq_step = U_VAR(fiq_step);
  243. return true;
  244. }
  245. return false;
  246. }
  247. bool ram_console_get_exp_type(unsigned int *exp_type)
  248. {
  249. if (exp_type && U_VAR(set_flag)) {
  250. *exp_type = U_VAR(exp_type);
  251. return true;
  252. }
  253. return false;
  254. }
  255. bool ram_console_set_exp_type(unsigned int exp_type)
  256. {
  257. bool ret = false;
  258. if (ram_console && ram_console->off_linux &&
  259. (ram_console->off_linux == (ram_console->off_llk + ALIGN(ram_console->sz_lk, 64))) &&
  260. (ram_console->off_pl == sizeof(struct ram_console_buffer))) {
  261. if (exp_type < 16) {
  262. exp_type = exp_type ^ RAM_CONSOLE_EXP_TYPE_MAGIC;
  263. ((struct reboot_reason_kernel*)((void*)ram_console + ram_console->off_linux))->exp_type = exp_type;
  264. ret = true;
  265. } else {
  266. LOG("%s. set exp type failed: off_linux:0x%x, off_llk:0x%x, off_pl:0x%x, exp type:%d\n", MOD, ram_console->off_linux, ram_console->off_llk, ram_console->off_pl, exp_type);
  267. }
  268. }
  269. return ret;
  270. }
  271. /*
  272. * struct last_reboot_reason is defined at [kernel/drivers/misc/mediatek/ram_console/mtk_ram_console.c]
  273. * if you need to access struct members in LK, this struct must be sync-ed with kernel code.
  274. */
  275. struct last_reboot_reason {
  276. uint32_t fiq_step;
  277. /* 0xaeedeadX: X=1 (HWT), X=2 (KE), X=3 (nested panic) */
  278. uint32_t exp_type;
  279. uint64_t kaslr_offset;
  280. uint64_t ram_console_buffer_addr;
  281. };
  282. static struct last_reboot_reason* krbr;
  283. bool ram_console_get_kaslr_offset(uint64_t* kaslr_offset)
  284. {
  285. if (krbr && U_VAR(set_flag)) {
  286. *kaslr_offset = krbr->kaslr_offset;
  287. return true;
  288. }
  289. return false;
  290. }
  291. bool ram_console_is_abnormal_boot(void)
  292. {
  293. unsigned int fiq_step, wdt_status, exp_type;
  294. int reinit_flag = 0;
  295. if (!ram_console) {
  296. ram_console_ptr_init_by_atag();
  297. reinit_flag = 1;
  298. }
  299. if (ram_console && ram_console->off_linux &&
  300. (ram_console->off_linux == (ram_console->off_llk + ALIGN(ram_console->sz_lk, 64))) &&
  301. (ram_console->off_pl == sizeof(struct ram_console_buffer))) {
  302. wdt_status = ((struct reboot_reason_pl*)((void*)ram_console + ram_console->off_pl))->wdt_status;
  303. krbr = ((struct last_reboot_reason*)((void*)ram_console + ram_console->off_linux));
  304. fiq_step = ((struct reboot_reason_kernel*)((void*)ram_console + ram_console->off_linux))->fiq_step;
  305. exp_type = ((struct reboot_reason_kernel*)((void*)ram_console + ram_console->off_linux))->exp_type;
  306. LOG("%s. wdt_status 0x%x, fiq_step 0x%x, exp_type 0x%x\n", MOD, wdt_status, fiq_step, RAM_CONSOLE_EXP_TYPE_DEC(exp_type));
  307. if (fiq_step != 0 && (exp_type ^ RAM_CONSOLE_EXP_TYPE_MAGIC) >= 16) {
  308. fiq_step = 0;
  309. ((struct reboot_reason_kernel*)((void*)ram_console + ram_console->off_linux))->fiq_step = fiq_step;
  310. }
  311. U_VAR(wdt_status) = wdt_status;
  312. U_VAR(fiq_step) = fiq_step;
  313. U_VAR(exp_type) = RAM_CONSOLE_EXP_TYPE_DEC(exp_type);
  314. U_VAR(set_flag) = true;
  315. LOG("%s. set reboot reason info done\n", MOD);
  316. #ifdef MTK_PMIC_FULL_RESET
  317. if ((fiq_step == 0 && (wdt_status == RE_BOOT_BY_WDT_SW || wdt_status == RE_BOOT_FULL_PMIC)) || (wdt_status == RE_BOOT_NORMAL_BOOT))
  318. #else
  319. if ((fiq_step == 0 && wdt_status == RE_BOOT_BY_WDT_SW) || (wdt_status == RE_BOOT_NORMAL_BOOT))
  320. #endif
  321. return false;
  322. else
  323. return true;
  324. } else {
  325. if (ram_console) {
  326. LOG("%s. set reboot reason info failed: off_linux:0x%x, off_llk:0x%x, off_pl:0x%x, reinit flag:%d\n", MOD, ram_console->off_linux, ram_console->off_llk, ram_console->off_pl, reinit_flag);
  327. } else {
  328. LOG("%s. ram console buffer NULL\n", MOD);
  329. }
  330. }
  331. return false;
  332. }
  333. void ram_console_lk_save(unsigned int val, int index)
  334. {
  335. struct reboot_reason_lk *rr_lk;
  336. if (ram_console && ram_console->off_lk < ram_console_size) {
  337. rr_lk = (void*)ram_console + ram_console->off_lk;
  338. if (index < RAM_CONSOLE_LK_SIZE)
  339. rr_lk->last_func[index] = val;
  340. }
  341. }
  342. /* default can be either sram or dram */
  343. void ram_console_addr_size(unsigned int *addr, unsigned int *size)
  344. {
  345. if (addr == NULL || size == NULL) {
  346. LOG("%s. get ram console default info args invalid\n", MOD);
  347. return;
  348. }
  349. *addr = (unsigned int)ram_console;
  350. *size = ram_console_size;
  351. }
  352. void ram_console_sram_addr_size(unsigned int *addr, unsigned int *size)
  353. {
  354. if (addr == NULL || size == NULL) {
  355. LOG("%s. get ram console sram info args invalid\n", MOD);
  356. return;
  357. }
  358. ram_console_atag_valid();
  359. *addr = g_boot_arg->ram_console_sram_addr;
  360. *size = g_boot_arg->ram_console_sram_size;
  361. }
  362. u32 ram_console_def_memory(void)
  363. {
  364. ram_console_atag_valid();
  365. return g_boot_arg->ram_console_def_type;
  366. }
  367. u32 ram_console_sram_offset(void)
  368. {
  369. ram_console_atag_valid();
  370. return g_boot_arg->ram_console_memory_info_offset;
  371. }
  372. void sram_plat_dbg_info_addr_size(unsigned int *addr, unsigned int *size)
  373. {
  374. struct ram_console_memory_info *memory_info = NULL;
  375. if (addr == NULL || size == NULL) {
  376. LOG("%s. get plat dbg info args invalid\n", MOD);
  377. return;
  378. }
  379. memory_info = ram_console_atag_memory_info();
  380. *addr = memory_info->sram_plat_dbg_info_addr;
  381. *size = memory_info->sram_plat_dbg_info_size;
  382. }
  383. void sram_log_store_addr_size(unsigned int *addr, unsigned int *size)
  384. {
  385. struct ram_console_memory_info *memory_info = NULL;
  386. if (addr == NULL || size == NULL) {
  387. LOG("%s. get log_store info args invalid\n", MOD);
  388. return;
  389. }
  390. memory_info = ram_console_atag_memory_info();
  391. *addr = memory_info->sram_log_store_addr;
  392. *size = memory_info->sram_log_store_size;
  393. }
  394. void sram_mrdump_addr_size(unsigned int *addr, unsigned int *size)
  395. {
  396. struct ram_console_memory_info *memory_info = NULL;
  397. if (addr == NULL || size == NULL) {
  398. LOG("%s. get mrdump info args invalid\n", MOD);
  399. return;
  400. }
  401. memory_info = ram_console_atag_memory_info();
  402. *addr = memory_info->mrdump_addr;
  403. *size = memory_info->mrdump_size;
  404. }
  405. void pstore_addr_size(unsigned int *addr, unsigned int *size)
  406. {
  407. struct ram_console_memory_info *memory_info = NULL;
  408. if (addr == NULL || size == NULL) {
  409. LOG("%s. get pstore info args invalid\n", MOD);
  410. return;
  411. }
  412. memory_info = ram_console_atag_memory_info();
  413. *addr = memory_info->pstore_addr;
  414. *size = memory_info->pstore_size;
  415. }
  416. void mrdump_mini_header_addr_size(unsigned int *addr, unsigned int *size)
  417. {
  418. struct ram_console_memory_info *memory_info = NULL;
  419. if (addr == NULL || size == NULL) {
  420. LOG("%s. get minirdump header info args invalid\n", MOD);
  421. return;
  422. }
  423. memory_info = ram_console_atag_memory_info();
  424. *addr = memory_info->mrdump_mini_header_addr;
  425. *size = memory_info->mrdump_mini_header_size;
  426. }
  427. void ram_console_dts_written(void *fdt)
  428. {
  429. unsigned int addr = 0;
  430. unsigned int size = 0;
  431. unsigned int def_type = 0;
  432. unsigned int memory_info_offset = 0;
  433. unsigned int *ptemp;
  434. unsigned int buf[4];
  435. int offset;
  436. int ret;
  437. offset = fdt_path_offset(fdt, "/chosen");
  438. if (offset < 0) {
  439. LOG("%s. get /chosen offset failed(%d)\n", MOD, offset);
  440. ram_console_fatal("get /chosen offset failed");
  441. return;
  442. }
  443. ptemp = (unsigned int *)buf;
  444. ram_console_sram_addr_size(&addr, &size);
  445. *ptemp = addr;
  446. *(ptemp + 1) = size;
  447. def_type = ram_console_def_memory();
  448. *(ptemp + 2) = def_type;
  449. memory_info_offset = ram_console_sram_offset();
  450. *(ptemp + 3) = memory_info_offset;
  451. LOG("%s. [0x%x,0x%x,0x%x,0x%x]\n", MOD, *ptemp, *(ptemp + 1),
  452. *(ptemp + 2), *(ptemp + 3));
  453. ret = fdt_setprop(fdt, offset, "ram_console", buf, (4 * sizeof(*ptemp)));
  454. if (ret)
  455. ram_console_fatal("dts written failed");
  456. sram_log_store_addr_size(&addr, &size);
  457. *ptemp = addr;
  458. *(ptemp + 1) = size;
  459. LOG("%s. log_store [0x%x,0x%x]\n", MOD, *ptemp, *(ptemp + 1));
  460. ret = fdt_setprop(fdt, offset, "log_store", buf, (2 * sizeof(*ptemp)));
  461. if (ret)
  462. ram_console_fatal("log_store dts written failed");
  463. }
  464. void ram_console_set_dump_step(unsigned int step)
  465. {
  466. if (ram_console) {
  467. ram_console->dump_step = step;
  468. }
  469. }
  470. int ram_console_get_dump_step()
  471. {
  472. if (ram_console)
  473. return ram_console->dump_step;
  474. else {
  475. LOG("%s. ram_console not ready\n", MOD);
  476. return 0;
  477. }
  478. }