[Feature]add MT2731_MP2_MR2_SVN388 baseline version
Change-Id: Ief04314834b31e27effab435d3ca8ba33b499059
diff --git a/src/bsp/lk/lib/aee/include/KEHeader.h b/src/bsp/lk/lib/aee/include/KEHeader.h
new file mode 100644
index 0000000..b61f8e5
--- /dev/null
+++ b/src/bsp/lk/lib/aee/include/KEHeader.h
@@ -0,0 +1,140 @@
+/*
+ * Copyright (c) 2018 MediaTek Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include <sys/types.h>
+
+#define AEE_IPANIC_PLABLE "expdb"
+
+
+#define AEE_IPANIC_MAGIC 0xaee0dead
+#define AEE_IPANIC_PHDR_VERSION 0x10
+#define IPANIC_NR_SECTIONS 64
+#if (AEE_IPANIC_PHDR_VERSION >= 0x10)
+#define IPANIC_USERSPACE_READ 1
+#endif
+
+/***************************************************************/
+/* #define MRDUMP_MINI_NR_SECTION 40 */
+/* #define MRDUMP_MINI_SECTION_SIZE (32 * 1024) */
+/* #define MRDUMP_MINI_NR_MISC 20 */
+/***************************************************************/
+
+struct mrdump_mini_misc_data32 {
+ unsigned int vaddr;
+ unsigned int paddr;
+ unsigned int start;
+ unsigned int size;
+};
+
+struct mrdump_mini_misc_data64 {
+ unsigned long long vaddr;
+ unsigned long long paddr;
+ unsigned long long start;
+ unsigned long long size;
+};
+
+/**********************************************/
+/* struct mrdump_mini_elf_misc { */
+/* struct elf_note note; */
+/* char name[16]; */
+/* struct mrdump_mini_misc_data data; */
+/* }; */
+/**********************************************/
+
+/**********************************************************/
+/* struct mrdump_mini_elf_header { */
+/* struct elfhdr ehdr; */
+/* struct elf_phdr phdrs[MRDUMP_MINI_NR_SECTION]; */
+/* struct { */
+/* struct elf_note note; */
+/* char name[12]; */
+/* struct elf_prpsinfo data; */
+/* } psinfo; */
+/* struct { */
+/* struct elf_note note; */
+/* char name[12]; */
+/* struct elf_prstatus data; */
+/* } prstatus[3]; */
+/* struct { */
+/* struct elf_note note; */
+/* char name[20]; */
+/* struct mrdump_mini_misc_data data; */
+/* } misc[MRDUMP_MINI_NR_MISC]; */
+/* }; */
+/**********************************************************/
+
+//#define PAGE_SIZE 4096
+/***********************************************************************************************************/
+/* #define MRDUMP_MINI_HEADER_SIZE ALIGN(sizeof(struct mrdump_mini_elf_header), PAGE_SIZE) */
+/* #define MRDUMP_MINI_DATA_SIZE (MRDUMP_MINI_NR_SECTION * MRDUMP_MINI_SECTION_SIZE) */
+/* #define MRDUMP_MINI_BUF_SIZE (MRDUMP_MINI_HEADER_SIZE + MRDUMP_MINI_DATA_SIZE) */
+/***********************************************************************************************************/
+
+// ipanic partation
+struct ipanic_data_header {
+ u32 type; /* data type(0-31) */
+ u32 valid; /* set to 1 when dump succeded */
+ u32 offset; /* offset in EXPDB partition */
+ u32 used; /* valid data size */
+ u32 total; /* allocated partition size */
+ u32 encrypt; /* data encrypted */
+ u32 raw; /* raw data or plain text */
+ u32 compact; /* data and header in same block, to save space */
+ u8 name[32];
+};
+
+struct ipanic_header {
+ u32 magic;
+ u32 version; /* ipanic version */
+ u32 size; /* ipanic_header size */
+ u32 datas; /* bitmap of data sections dumped */
+ u32 dhblk; /* data header blk size, 0 if no dup data headers */
+ u32 blksize;
+ u32 partsize; /* expdb partition totoal size */
+ u32 bufsize;
+ u64 buf;
+ struct ipanic_data_header data_hdr[IPANIC_NR_SECTIONS];
+};
+
+#define IPANIC_MMPROFILE_LIMIT 0x220000
+
+typedef enum {
+ IPANIC_DT_HEADER = 0 ,
+ IPANIC_DT_KERNEL_LOG = 1 ,
+ IPANIC_DT_WDT_LOG ,
+ IPANIC_DT_WQ_LOG ,
+ IPANIC_DT_CURRENT_TSK = 6 ,
+ IPANIC_DT_OOPS_LOG ,
+ IPANIC_DT_MINI_RDUMP = 8 ,
+ IPANIC_DT_MMPROFILE ,
+ IPANIC_DT_MAIN_LOG ,
+ IPANIC_DT_SYSTEM_LOG ,
+ IPANIC_DT_EVENTS_LOG ,
+ IPANIC_DT_RADIO_LOG ,
+ IPANIC_DT_LAST_LOG ,
+ IPANIC_DT_RAM_DUMP = 28 ,
+ IPANIC_DT_SHUTDOWN_LOG = 30 ,
+ IPANIC_DT_RESERVED31 = 31 ,
+} IPANIC_DT;
+
+int kedump_get_data_info(int index, char **name, u32 *offset, u32 *size);
diff --git a/src/bsp/lk/lib/aee/include/aee.h b/src/bsp/lk/lib/aee/include/aee.h
new file mode 100644
index 0000000..f9c164f
--- /dev/null
+++ b/src/bsp/lk/lib/aee/include/aee.h
@@ -0,0 +1,108 @@
+/*
+ * Copyright (c) 2018 MediaTek Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#if !defined (__AEE_H__)
+#define __AEE_H__
+
+#include <mrdump.h>
+#include <stdbool.h>
+#include <stdarg.h>
+#include <stdint.h>
+#include <sys/types.h>
+#include "KEHeader.h"
+
+typedef enum {
+ AEE_MODE_MTK_ENG = 1,
+ AEE_MODE_MTK_USER,
+ AEE_MODE_CUSTOMER_ENG,
+ AEE_MODE_CUSTOMER_USER
+} AEE_MODE;
+
+typedef enum {
+ AEE_REBOOT_MODE_NORMAL = 0,
+ AEE_REBOOT_MODE_KERNEL_OOPS,
+ AEE_REBOOT_MODE_KERNEL_PANIC,
+ AEE_REBOOT_MODE_NESTED_EXCEPTION,
+ AEE_REBOOT_MODE_WDT,
+ AEE_REBOOT_MODE_EXCEPTION_KDUMP,
+ AEE_REBOOT_MODE_MRDUMP_KEY,
+ AEE_REBOOT_MODE_GZ_KE,
+ AEE_REBOOT_MODE_GZ_WDT,
+ AEE_REBOOT_MODE_HANG_DETECT,
+} AEE_REBOOT_MODE;
+
+enum {
+ REBOOT_REASON_REBOOT = 0,
+ REBOOT_REASON_WATCHDOG,
+ REBOOT_REASON_KERNEL_PANIC,
+ REBOOT_REASON_2S_REBOOT,
+ REBOOT_REASON_DM_VERITY_CORRUPTION
+};
+
+#define IPANIC_OOPS_HEADER_PROCESS_NAME_LENGTH 256
+#define IPANIC_OOPS_HEADER_BACKTRACE_LENGTH 3840
+
+struct ipanic_oops_header {
+ char process_path[IPANIC_OOPS_HEADER_PROCESS_NAME_LENGTH];
+ char backtrace[IPANIC_OOPS_HEADER_BACKTRACE_LENGTH];
+};
+
+extern uint32_t g_aee_mode;
+
+const char *mrdump_mode2string(uint8_t mode);
+
+struct mrdump_control_block *aee_mrdump_get_params(void);
+struct mrdump_control_block *mrdump_cb_addr(void);
+int mrdump_cb_size(void);
+
+void aee_mrdump_flush_cblock(struct mrdump_control_block *bufp);
+
+void voprintf(char type, const char *msg, va_list ap);
+void voprintf_verbose(const char *msg, ...);
+void voprintf_debug(const char *msg, ...);
+void voprintf_info(const char *msg, ...);
+void voprintf_warning(const char *msg, ...);
+void voprintf_error(const char *msg, ...);
+void vo_show_progress(int sizeM);
+
+void mrdump_status_none(const char *fmt, ...);
+void mrdump_status_ok(const char *fmt, ...);
+void mrdump_status_error(const char *fmt, ...);
+
+struct aee_timer {
+ unsigned int acc_ms;
+
+ unsigned int start_ms;
+};
+
+void aee_timer_init(struct aee_timer *t);
+void aee_timer_start(struct aee_timer *t);
+void aee_timer_stop(struct aee_timer *t);
+
+/* FIXME: move to platform/mtk_wdt.h */
+extern void mtk_wdt_restart(void);
+extern ulong get_timer_masked (void);
+extern uint32_t memory_size(void);
+bool ram_console_reboot_by_mrdump_key(void)__attribute__((weak));
+
+#endif
diff --git a/src/bsp/lk/lib/aee/include/dev/aee_platform_debug.h b/src/bsp/lk/lib/aee/include/dev/aee_platform_debug.h
new file mode 100644
index 0000000..99ff07c
--- /dev/null
+++ b/src/bsp/lk/lib/aee/include/dev/aee_platform_debug.h
@@ -0,0 +1,108 @@
+/*
+ * Copyright (c) 2018 MediaTek Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+#if !defined(__AEE_PLATFORM_DEBUG_H__)
+#define __AEE_PLATFORM_DEBUG_H__
+
+#include <boot_args.h>
+#include <sys/types.h>
+
+typedef unsigned long long u64;
+typedef unsigned long long (*CALLBACK)(void *data, unsigned long sz);
+
+/* extern global variable */
+extern BOOT_ARGUMENT *g_boot_arg;
+
+enum {
+ AEE_PLAT_DFD20,
+ AEE_PLAT_DRAM,
+ AEE_PLAT_CPU_BUS,
+ AEE_PLAT_SPM_DATA,
+ AEE_PLAT_SPM_SRAM_DATA,
+ AEE_PLAT_ATF_LAST_LOG,
+ AEE_PLAT_ATF_CRASH_REPORT,
+ AEE_PLAT_ATF_RAW_LOG,
+ AEE_PLAT_ATF_RDUMP_LOG,
+ AEE_PLAT_HVFS,
+#ifdef MTK_TINYSYS_SSPM_SUPPORT
+ AEE_PLAT_SSPM_COREDUMP,
+ AEE_PLAT_SSPM_DATA,
+ AEE_PLAT_SSPM_XFILE,
+ AEE_PLAT_SSPM_LAST_LOG,
+#endif
+ AEE_PLAT_PLLK_LAST_LOG,
+ AEE_PLAT_LOG_DUR_LKDUMP,
+ AEE_PLAT_MCDI_DATA,
+ AEE_PLAT_SCP_COREDUMP,
+ AEE_PLAT_DEBUG_NUM
+};
+
+/* function pointers */
+extern unsigned int (* plat_dfd20_get)(u64 offset, int *len, CALLBACK dev_write);
+extern unsigned int (* plat_dram_get)(u64 offset, int *len, CALLBACK dev_write);
+extern unsigned int (* plat_cpu_bus_get)(u64 offset, int *len, CALLBACK dev_write);
+extern unsigned int (* plat_spm_data_get)(u64 offset, int *len, CALLBACK dev_write);
+extern unsigned int (* plat_spm_sram_data_get)(u64 offset, int *len, CALLBACK dev_write);
+extern unsigned int (* plat_hvfs_get)(u64 offset, int *len, CALLBACK dev_write);
+#ifdef MTK_TINYSYS_SSPM_SUPPORT
+extern unsigned int (* plat_sspm_coredump_get)(u64 offset, int *len, CALLBACK dev_write);
+extern unsigned int (* plat_sspm_data_get)(u64 offset, int *len, CALLBACK dev_write);
+extern unsigned int (* plat_sspm_xfile_get)(u64 offset, int *len, CALLBACK dev_write);
+extern unsigned int (* plat_sspm_log_get)(u64 offset, int *len, CALLBACK dev_write);
+#endif
+extern unsigned int (* plat_pllk_last_log_get)(u64 offset, int *len, CALLBACK dev_write);
+extern unsigned int (* plat_dur_lkdump_get)(u64 offset, int *len, CALLBACK dev_write);
+extern unsigned int (* plat_mcdi_get)(u64 offset, int *len, CALLBACK dev_write);
+#ifdef MTK_TINYSYS_SCP_SUPPORT
+extern unsigned int (* plat_scp_coredump_get)(u64 offset, int *len, CALLBACK dev_write);
+#endif
+
+/* DRAM KLOG at MRDUMP area of expdb, offset from bottom = 3145728 - 16384 = 3129344 */
+#define MRDUMP_EXPDB_BOTTOM_OFFSET 2097152
+#define MRDUMP_EXPDB_DRAM_KLOG_OFFSET 3129344
+
+/* common api */
+unsigned int kedump_plat_savelog(int condition, u64 offset, int *len, CALLBACK dev_write);
+
+extern void arch_clean_cache_range(addr_t start, size_t len);
+//extern part_dev_t *mt_part_get_device(void);
+
+/* common interface for platform */
+void mrdump_write_log(u64 offset_dst, void *data, int len);
+void mrdump_read_log(void *data, int len, u64 offset);
+
+int lkdump_debug_init(void);
+/* common interface from platform */
+int platform_debug_init(void);
+void platform_lastpc_postinit(void);
+
+extern struct aee_db_file_info* get_file_info(void);
+
+/* db filename and max size */
+struct aee_db_file_info {
+ char filename[32];
+ unsigned int filesize;
+ unsigned int step;
+};
+
+#endif /* __AEE_PLATFORM_DEBUG_H__ */
+
diff --git a/src/bsp/lk/lib/aee/include/elf.h b/src/bsp/lk/lib/aee/include/elf.h
new file mode 100644
index 0000000..d76bd7f
--- /dev/null
+++ b/src/bsp/lk/lib/aee/include/elf.h
@@ -0,0 +1,225 @@
+/*
+ * Copyright (c) 2018 MediaTek Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+/****************************************************************************
+ ****************************************************************************
+ ***
+ *** This header was automatically generated from a Linux kernel header
+ *** of the same name, to make information necessary for userspace to
+ *** call into the kernel available to libc. It contains only constants,
+ *** structures, and macros generated from the original header, and thus,
+ *** contains no copyrightable information.
+ ***
+ *** To edit the content of this header, modify the corresponding
+ *** source file (e.g. under external/kernel-headers/original/) then
+ *** run bionic/libc/kernel/tools/update_all.py
+ ***
+ *** Any manual change here will be lost the next time this script will
+ *** be run. You've been warned!
+ ***
+ ****************************************************************************
+ ****************************************************************************/
+#ifndef _UAPI_LINUX_ELF_H
+#define _UAPI_LINUX_ELF_H
+
+typedef short __s16;
+typedef int __s32;
+typedef long long __s64;
+typedef unsigned short __u16;
+typedef unsigned int __u32;
+typedef unsigned long long __u64;
+
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+typedef __u32 Elf32_Addr;
+typedef __u16 Elf32_Half;
+typedef __u32 Elf32_Off;
+typedef __s32 Elf32_Sword;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+typedef __u32 Elf32_Word;
+typedef __u64 Elf64_Addr;
+typedef __u16 Elf64_Half;
+typedef __s16 Elf64_SHalf;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+typedef __u64 Elf64_Off;
+typedef __s32 Elf64_Sword;
+typedef __u32 Elf64_Word;
+typedef __u64 Elf64_Xword;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+typedef __s64 Elf64_Sxword;
+#define PT_NULL 0
+#define PT_LOAD 1
+#define PT_DYNAMIC 2
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define PT_INTERP 3
+#define PT_NOTE 4
+#define PT_SHLIB 5
+#define PT_PHDR 6
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define PT_TLS 7
+
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define ET_NONE 0
+#define ET_REL 1
+#define ET_EXEC 2
+#define ET_DYN 3
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define ET_CORE 4
+#define ET_LOPROC 0xff00
+#define ET_HIPROC 0xffff
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+
+
+#define EI_NIDENT 16
+
+typedef struct elf32_hdr {
+ /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ unsigned char e_ident[EI_NIDENT];
+ Elf32_Half e_type;
+ Elf32_Half e_machine;
+ Elf32_Word e_version;
+ /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ Elf32_Addr e_entry;
+ Elf32_Off e_phoff;
+ Elf32_Off e_shoff;
+ Elf32_Word e_flags;
+ /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ Elf32_Half e_ehsize;
+ Elf32_Half e_phentsize;
+ Elf32_Half e_phnum;
+ Elf32_Half e_shentsize;
+ /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ Elf32_Half e_shnum;
+ Elf32_Half e_shstrndx;
+} Elf32_Ehdr;
+typedef struct elf64_hdr {
+ /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ unsigned char e_ident[EI_NIDENT];
+ Elf64_Half e_type;
+ Elf64_Half e_machine;
+ Elf64_Word e_version;
+ /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ Elf64_Addr e_entry;
+ Elf64_Off e_phoff;
+ Elf64_Off e_shoff;
+ Elf64_Word e_flags;
+ /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ Elf64_Half e_ehsize;
+ Elf64_Half e_phentsize;
+ Elf64_Half e_phnum;
+ Elf64_Half e_shentsize;
+ /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ Elf64_Half e_shnum;
+ Elf64_Half e_shstrndx;
+} Elf64_Ehdr;
+#define PF_R 0x4
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define PF_W 0x2
+#define PF_X 0x1
+typedef struct elf32_phdr {
+ Elf32_Word p_type;
+ /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ Elf32_Off p_offset;
+ Elf32_Addr p_vaddr;
+ Elf32_Addr p_paddr;
+ Elf32_Word p_filesz;
+ /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ Elf32_Word p_memsz;
+ Elf32_Word p_flags;
+ Elf32_Word p_align;
+} Elf32_Phdr;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+typedef struct elf64_phdr {
+ Elf64_Word p_type;
+ Elf64_Word p_flags;
+ Elf64_Off p_offset;
+ /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ Elf64_Addr p_vaddr;
+ Elf64_Addr p_paddr;
+ Elf64_Xword p_filesz;
+ Elf64_Xword p_memsz;
+ /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ Elf64_Xword p_align;
+} Elf64_Phdr;
+
+#define EI_MAG0 0
+#define EI_MAG1 1
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define EI_MAG2 2
+#define EI_MAG3 3
+#define EI_CLASS 4
+#define EI_DATA 5
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define EI_VERSION 6
+#define EI_OSABI 7
+#define EI_PAD 8
+#define ELFMAG0 0x7f
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define ELFMAG1 'E'
+#define ELFMAG2 'L'
+#define ELFMAG3 'F'
+#define ELFMAG "\177ELF"
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define SELFMAG 4
+#define ELFCLASSNONE 0
+#define ELFCLASS32 1
+#define ELFCLASS64 2
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define ELFCLASSNUM 3
+#define ELFDATANONE 0
+#define ELFDATA2LSB 1
+#define ELFDATA2MSB 2
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define EV_NONE 0
+#define EV_CURRENT 1
+#define EV_NUM 2
+#define ELFOSABI_NONE 0
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define ELFOSABI_LINUX 3
+#ifndef ELF_OSABI
+#define ELF_OSABI ELFOSABI_NONE
+#endif
+
+#define NT_PRSTATUS 1
+#define NT_PRFPREG 2
+#define NT_PRPSINFO 3
+#define NT_TASKSTRUCT 4
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define NT_AUXV 6
+
+/* Note header in a PT_NOTE section */
+typedef struct elf32_note {
+ Elf32_Word n_namesz;
+ /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ Elf32_Word n_descsz;
+ Elf32_Word n_type;
+} Elf32_Nhdr;
+typedef struct elf64_note {
+ /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ Elf64_Word n_namesz;
+ Elf64_Word n_descsz;
+ Elf64_Word n_type;
+} Elf64_Nhdr;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define EM_AARCH64 183
+#define EM_ARM 40
+#endif
diff --git a/src/bsp/lk/lib/aee/include/emi_info_v1.h b/src/bsp/lk/lib/aee/include/emi_info_v1.h
new file mode 100644
index 0000000..f300fa9
--- /dev/null
+++ b/src/bsp/lk/lib/aee/include/emi_info_v1.h
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2018 MediaTek Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef __EMI_INFO_H__
+#define __EMI_INFO_H__
+
+#include <mt_emi_mpu.h>
+
+typedef struct {
+ unsigned int dram_type;
+ unsigned int ch_num;
+ unsigned int rk_num;
+ unsigned long long rank_size[MAX_RK];
+} emi_info_t;
+
+#endif
diff --git a/src/bsp/lk/lib/aee/include/env.h b/src/bsp/lk/lib/aee/include/env.h
new file mode 100644
index 0000000..73f57b6
--- /dev/null
+++ b/src/bsp/lk/lib/aee/include/env.h
@@ -0,0 +1,54 @@
+/*
+ * Copyright (c) 2018 MediaTek Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef __ENV_H__
+#define __ENV_H__
+
+#ifdef MTK_COMBO_NAND_SUPPORT
+extern unsigned int mtk_nand_erasesize(void);
+#define CFG_ENV_SIZE 0x8000 //(32KB)
+#define CFG_ENV_OFFSET mtk_nand_erasesize()
+#else
+#define CFG_ENV_SIZE 0x4000 //(16KB)
+#define CFG_ENV_OFFSET 0x20000 //(128KB)
+#endif
+
+#define CFG_ENV_DATA_SIZE (CFG_ENV_SIZE-sizeof(g_env.checksum)-sizeof(g_env.sig)-sizeof(g_env.sig_1))
+#define CFG_ENV_DATA_OFFSET (sizeof(g_env.sig))
+#define CFG_ENV_SIG_1_OFFSET (CFG_ENV_SIZE - sizeof(g_env.checksum)-sizeof(g_env.sig_1))
+#define CFG_ENV_CHECKSUM_OFFSET (CFG_ENV_SIZE - sizeof(g_env.checksum))
+
+#define ENV_SIG "ENV_v1"
+
+typedef struct env_struct {
+ char sig[8]; // "ENV_v1"
+ char *env_data;
+ char sig_1[8]; //"ENV_v1"
+ int checksum; // checksum for env_data
+} env_t;
+
+extern void env_init(void);
+extern char *get_env(char *name);
+extern int set_env(char *name,char *value);
+extern void print_env(void);
+#endif
diff --git a/src/bsp/lk/lib/aee/include/kdump.h b/src/bsp/lk/lib/aee/include/kdump.h
new file mode 100644
index 0000000..43d346f
--- /dev/null
+++ b/src/bsp/lk/lib/aee/include/kdump.h
@@ -0,0 +1,266 @@
+/*
+ * Copyright (c) 2018 MediaTek Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#if !defined(__KDUMP_H__)
+#define __KDUMP_H__
+
+#include <compiler.h>
+#include <libfdt.h>
+#include <mrdump.h>
+#include <platform/mt_reg_base.h>
+#include <stdint.h>
+
+#ifdef MTK_MRDUMP_SRAM_CB
+#include <platform/mtk_mrdump.h>
+#endif
+
+#define MRDUMP_DEV_UNKNOWN 0
+#define MRDUMP_DEV_NONE 1
+#define MRDUMP_DEV_NULL 2
+#define MRDUMP_DEV_ISTORAGE_EXT4 3
+#define MRDUMP_DEV_ISTORAGE_VFAT 4
+#define MRDUMP_DEV_USB 5
+
+#define MRDUMP_GO_DUMP "MRDUMP08"
+
+/* for dts */
+#ifdef CFG_DTB_EARLY_LOADER_SUPPORT
+
+struct mrdump_reserve_args {
+ uint32_t hi_addr;
+ uint32_t lo_addr;
+ uint32_t hi_size;
+ uint32_t lo_size;
+};
+
+#endif
+
+/*
+ * for ext4 and f2fs, InfoLBA (header), version 2
+ * v1: support allocate size > 4G
+ * v2: support timestamp
+ */
+#define MRDUMP_PAF_VERSION 0x0002
+
+#define MRDUMP_PAF_INFO_LBA 4
+#define MRDUMP_PAF_ADDR_LBA 8
+#define MRDUMP_PAF_ALLOCSIZE 12
+#define MRDUMP_PAF_COREDUMPSIZE 20
+#define MRDUMP_PAF_TIMESTAMP 28
+#define MRDUMP_PAF_CRC32 36
+#define MRDUMP_LBA_DATAONLY MRDUMP_PAF_CRC32
+#define MRDUMP_PAF_TOTAL_SIZE 40
+
+#define KZIP_ENTRY_MAX 30
+#define LOCALHEADERMAGIC 0x04034b50UL
+#define CENTRALHEADERMAGIC 0x02014b50UL
+#define ZIP64ENDOFCENTRALDIRMAGIC 0x06064b50UL
+#define ZIP64ENDOFCENTRALDIRLOCATORMAGIC 0x07064b50UL
+#define ENDOFCENTRALDIRMAGIC 0x06054b50UL
+
+#define KDUMP_CORE_HEADER_SIZE 2 * 4096
+
+struct kzip_entry {
+ char *filename;
+ int level;
+ uint64_t localheader_offset;
+ uint64_t comp_size;
+ uint64_t uncomp_size;
+ uint32_t crc32;
+};
+
+struct kzip_file {
+ uint32_t reported_size;
+ uint32_t wdk_kick_size;
+ uint64_t current_size;
+
+ uint32_t entries_num;
+ struct kzip_entry zentries[KZIP_ENTRY_MAX];
+ void *handle;
+
+ int (*write_cb)(void *handle, void *buf, int size);
+};
+
+#define MEM_NO_MAP 0
+#define MEM_DO_MAP 1
+#define EXPDB_FILE 2
+struct kzip_addlist {
+ uint64_t address;
+ uint64_t size;
+ int type;
+};
+
+#define MRDUMP_CPU_MAX 12
+
+#define MRDUMP_ENABLE_COOKIE 0x590d2ba3
+
+typedef uint32_t arm32_gregset_t[18];
+typedef uint64_t arm64_gregset_t[34];
+
+struct arm32_ctrl_regs {
+ uint32_t sctlr;
+ uint64_t ttbcr;
+ uint64_t ttbr0;
+ uint64_t ttbr1;
+};
+
+struct arm64_ctrl_regs {
+ uint32_t sctlr_el1;
+ uint32_t sctlr_el2;
+ uint32_t sctlr_el3;
+
+ uint64_t tcr_el1;
+ uint64_t tcr_el2;
+ uint64_t tcr_el3;
+
+ uint64_t ttbr0_el1;
+ uint64_t ttbr0_el2;
+ uint64_t ttbr0_el3;
+
+ uint64_t ttbr1_el1;
+
+ uint64_t sp_el[4];
+};
+
+struct mrdump_crash_record {
+ int reboot_mode;
+
+ char msg[128];
+
+ uint32_t fault_cpu;
+
+ union {
+ arm32_gregset_t arm32_regs;
+ arm64_gregset_t arm64_regs;
+ } cpu_regs[MRDUMP_CPU_MAX];
+
+ union {
+ struct arm32_ctrl_regs arm32_creg;
+ struct arm64_ctrl_regs arm64_creg;
+ } cpu_creg[MRDUMP_CPU_MAX];
+};
+
+struct mrdump_ksyms_param {
+ char tag[4];
+ uint32_t flag;
+ uint32_t crc;
+ uint64_t start_addr;
+ uint32_t size;
+ uint32_t addresses_off;
+ uint32_t num_syms_off;
+ uint32_t names_off;
+ uint32_t markers_off;
+ uint32_t token_table_off;
+ uint32_t token_index_off;
+} __attribute__((packed));
+
+struct mrdump_machdesc {
+ uint32_t nr_cpus;
+
+ uint64_t page_offset;
+ uint64_t high_memory;
+
+ uint64_t kimage_vaddr;
+ uint64_t dram_start;
+ uint64_t dram_end;
+ uint64_t kimage_stext;
+ uint64_t kimage_etext;
+ uint64_t kimage_stext_real;
+ uint64_t kimage_voffset;
+ uint64_t kimage_sdata;
+ uint64_t kimage_edata;
+
+ uint64_t vmalloc_start;
+ uint64_t vmalloc_end;
+
+ uint64_t modules_start;
+ uint64_t modules_end;
+
+ uint64_t phys_offset;
+ uint64_t master_page_table;
+
+ uint64_t memmap;
+
+ uint64_t dfdmem_pa; // Reserved for DFD 3.0+
+
+ struct mrdump_ksyms_param kallsyms;
+};
+
+struct __attribute__((__packed__)) mrdump_cblock_result {
+ char sig[9];
+ char status[128];
+ char log_buf[2048];
+};
+
+struct mrdump_control_block {
+ char sig[8];
+
+ struct mrdump_machdesc machdesc;
+ uint32_t machdesc_crc;
+
+ uint32_t enabled;
+ uint32_t output_fs_lbaooo;
+
+ struct mrdump_crash_record crash_record;
+};
+
+struct kzip_file *kzip_open(void *handle, int (*write_cb)(void *handle, void *p, int size));
+bool kzip_add_file(struct kzip_file *zf, const struct kzip_addlist *addlist, const char *zfilename);
+bool kzip_close(struct kzip_file *zf);
+
+struct mrdump_dev;
+
+struct mrdump_dev *mrdump_dev_emmc_vfat(void);
+struct mrdump_dev *mrdump_dev_emmc_ext4(void);
+struct mrdump_dev *mrdump_dev_sdcard(void);
+
+int kdump_null_output(const struct mrdump_control_block *kparams,
+ const struct kzip_addlist *memlist);
+int mrdump_ext4_output(const struct mrdump_control_block *mrdump_cb,
+ const struct kzip_addlist *memlist, struct mrdump_dev *mrdump_dev);
+int mrdump_vfat_output(const struct mrdump_control_block *mrdump_cb,
+ const struct kzip_addlist *memlist, struct mrdump_dev *mrdump_dev);
+int kdump_usb_output(const struct mrdump_control_block *mrdump_cb,
+ const struct kzip_addlist *memlist);
+
+void kdump_core_header_init(const struct mrdump_control_block *kparams,
+ const struct kzip_addlist *memlist);
+void kdump_core32_header_init(const struct mrdump_control_block *kparams,
+ const struct kzip_addlist *memlist);
+void kdump_core64_header_init(const struct mrdump_control_block *kparams,
+ const struct kzip_addlist *memlist);
+
+void mrdump_setup_cblock(void);
+void mrdump_setup_version(void);
+void mrdump_setup_boot_reason(void);
+
+extern u64 physical_memory_size(void);
+extern void mtk_wdt_disable(void);
+extern void mtk_wdt_init(void);
+extern void mrdump_read_expdb(void *data, int len, u64 offset_src);
+
+#ifdef MTK_3LEVEL_PAGETABLE
+vaddr_t scratch_addr(void);
+#endif
+
+#endif
diff --git a/src/bsp/lk/lib/aee/include/kdump_sdhc.h b/src/bsp/lk/lib/aee/include/kdump_sdhc.h
new file mode 100644
index 0000000..8a28943
--- /dev/null
+++ b/src/bsp/lk/lib/aee/include/kdump_sdhc.h
@@ -0,0 +1,121 @@
+/*
+ * Copyright (c) 2018 MediaTek Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#if !defined(__KDUMP_SDHC_H__)
+#define __KDUMP_SDHC_H__
+
+#include <lib/bio.h>
+#include <stdbool.h>
+
+#define MaxFindFileClusNum 100
+
+typedef enum {
+ WRITE_FILE_DIRECT = 0,
+ FORMAT_BEF_WRITE = 1
+} FileWriteType;
+
+
+typedef enum FileSysType {
+ FAT_16 = 0,
+ FAT_32 = 1
+} FATType;
+
+typedef struct {
+ uint32_t BPB_BytsPerSec;
+ uint32_t BPB_SecPerClus;
+ uint32_t BPB_RsvdSecCnt;
+ uint32_t BPB_NumFATs;
+ uint32_t BPB_FATSz;
+ uint32_t BPB_RootEntCnt;
+ uint32_t BPB_RootClus;
+ uint32_t BPB_TotSec;
+ FATType FileSysType;
+ uint32_t BootStartSec;
+ uint32_t FATStartSec;
+ uint32_t RootDirStartSec;
+ uint32_t ClusStartSec;
+} FAT_Para;
+
+
+
+typedef struct {
+ uint8_t name[11]; // file name
+ uint8_t attr; // file attribute bits (system, hidden, etc.)
+ uint8_t NTflags; // ???
+ uint8_t createdTimeMsec; // ??? (milliseconds needs 11 bits for 0-2000)
+ uint16_t createdTime; // time of file creation
+ uint16_t createdDate; // date of file creation
+ uint16_t lastAccessDate; // date of last file access
+ uint16_t clusFirstHigh; // high word of first cluster
+ uint16_t time; // time of last file change
+ uint16_t date; // date of last file change
+ uint16_t clusFirst; // low word of first cluster
+ uint32_t size; // file size in bytes
+} DirEntry;
+
+typedef struct {
+ uint8_t seqNum; // sequence number
+ uint8_t name1[10]; // name characters (five UTF-16 characters)
+ uint8_t attr; // attributes (always 0x0F)
+ uint8_t NTflags; // reserved (alwyas 0x00)
+ uint8_t checksum; // checksum of DOS file name
+ uint8_t name2[12]; // name characters (six UTF-16 characters)
+ uint16_t clusFirst; // word of first cluster (always 0x0000)
+ uint8_t name3[4]; // name characters (2 UTF-16 characters)
+} LfnEntry;
+
+#define FAT_BUFSIZE 65536
+
+typedef struct {
+ uint8_t FileBuffer[FAT_BUFSIZE]; // File cluster cache, assume maximum cluster size is 64KB
+ uint8_t FATBuffer[512]; // FAT cache
+ uint32_t BufferLen; // data cached length in FileBuffer
+ uint32_t TotalLen; // File total length
+ uint32_t PrevClusterNum; // Prev cluster number
+ uint32_t CurrClusterNum; // Current cluster number
+ uint32_t FATSector; // Current FAT sector number
+ uint32_t CheckSum; // File write content checksum
+ bool DiskFull;
+} FileHandler;
+
+
+struct mrdump_dev {
+ const char *name;
+ void *handle;
+ bdev_t *bdev;
+
+ bool (*read)(struct mrdump_dev *dev, uint64_t sector_addr, uint8_t *pdBuf, int32_t blockLen);
+ bool (*write)(struct mrdump_dev *dev, uint64_t sector_addr, uint8_t *pdBuf, int32_t blockLen);
+};
+
+static inline int mrdump_dev_read(struct mrdump_dev *dev, uint32_t sector_addr, uint8_t *pdBuf, int32_t blockLen)
+{
+ return dev->read(dev, sector_addr, pdBuf, blockLen);
+}
+
+static inline int mrdump_dev_write(struct mrdump_dev *dev, uint32_t sector_addr, uint8_t *pdBuf, int32_t blockLen)
+{
+ return dev->write(dev, sector_addr, pdBuf, blockLen);
+}
+
+#endif
diff --git a/src/bsp/lk/lib/aee/include/mrdump.h b/src/bsp/lk/lib/aee/include/mrdump.h
new file mode 100644
index 0000000..f676197
--- /dev/null
+++ b/src/bsp/lk/lib/aee/include/mrdump.h
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2018 MediaTek Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#if !defined (__MRDUMP_H__)
+#define __MRDUMP_H__
+
+#include <sys/types.h>
+
+#define AEE_MRDUMP_LK_RSV_SIZE 0x100000
+#define AEE_MRDUMP_DDR_RSV_READY 0x9502
+
+void aee_reserve_memory(char *str, ...);
+int mrdump_detection(void);
+
+void mrdump_reboot(void);
+int mrdump_run2(void);
+
+int check_ram_console_is_abnormal_boot(void) __attribute__((weak));
+
+/* extern functions */
+int usb_write_with_timeout(void *buf, unsigned len, lk_time_t timeout);
+int usb_read_with_timeout(void *_buf, unsigned len, lk_time_t timeout);
+
+#endif
diff --git a/src/bsp/lk/lib/aee/include/mrdump_elf.h b/src/bsp/lk/lib/aee/include/mrdump_elf.h
new file mode 100644
index 0000000..8448fa0
--- /dev/null
+++ b/src/bsp/lk/lib/aee/include/mrdump_elf.h
@@ -0,0 +1,118 @@
+/*
+ * Copyright (c) 2018 MediaTek Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#if !defined(__KDUMP_ELF_H__)
+#define __KDUMP_ELF_H__
+
+#include <stdint.h>
+#include "mrdump_elf_common.h"
+
+#define ELF_ARM_NGREGS 18
+typedef uint32_t elf_arm_gregset_t[ELF_ARM_NGREGS];
+
+typedef struct elf32_hdr {
+ unsigned char e_ident[EI_NIDENT];
+ Elf32_Half e_type;
+ Elf32_Half e_machine;
+ Elf32_Word e_version;
+ Elf32_Addr e_entry;
+ Elf32_Off e_phoff;
+ Elf32_Off e_shoff;
+ Elf32_Word e_flags;
+ Elf32_Half e_ehsize;
+ Elf32_Half e_phentsize;
+ Elf32_Half e_phnum;
+ Elf32_Half e_shentsize;
+ Elf32_Half e_shnum;
+ Elf32_Half e_shstrndx;
+} Elf64_Ehdr;
+
+typedef struct elf32_phdr {
+ Elf32_Word p_type;
+ Elf32_Off p_offset;
+ Elf32_Addr p_vaddr;
+ Elf32_Addr p_paddr;
+ Elf32_Word p_filesz;
+ Elf32_Word p_memsz;
+ Elf32_Word p_flags;
+ Elf32_Word p_align;
+} Elf32_Phdr;
+
+typedef struct elf_note {
+ Elf32_Word n_namesz; /* Name size */
+ Elf32_Word n_descsz; /* Content size */
+ Elf32_Word n_type; /* Content type */
+} Elf_Nhdr;
+
+struct elf32_timeval {
+ int32_t tv_sec;
+ int32_t tv_usec;
+};
+
+struct elf_siginfo {
+ int32_t si_signo;
+ int32_t si_code;
+ int32_t si_errno;
+};
+
+struct elf32_arm_prstatus {
+ struct elf_siginfo pr_info;
+ short pr_cursig;
+ uint32_t pr_sigpend;
+ uint32_t pr_sighold;
+
+ int32_t pr_pid;
+ int32_t pr_ppid;
+ int32_t pr_pgrp;
+
+ int32_t pr_sid;
+ struct elf32_timeval pr_utime;
+ struct elf32_timeval pr_stime;
+ struct elf32_timeval pr_cutime;
+ struct elf32_timeval pr_cstime;
+
+ elf_arm_gregset_t pr_reg;
+
+ int32_t pr_fpvalid;
+};
+
+struct elf32_prpsinfo {
+ char pr_state;
+ char pr_sname;
+ char pr_zomb;
+ char pr_nice;
+ uint32_t pr_flag;
+
+ uint16_t pr_uid;
+ uint16_t pr_gid;
+
+ int32_t pr_pid;
+ int32_t pr_ppid;
+ int32_t pr_pgrp;
+ int32_t pr_sid;
+
+ char pr_fname[16];
+ char pr_psargs[ELF_PRARGSZ];
+};
+
+#endif /* __KDUMP_ELF_H__ */
diff --git a/src/bsp/lk/lib/aee/include/mrdump_elf64.h b/src/bsp/lk/lib/aee/include/mrdump_elf64.h
new file mode 100644
index 0000000..4ab22a6
--- /dev/null
+++ b/src/bsp/lk/lib/aee/include/mrdump_elf64.h
@@ -0,0 +1,118 @@
+/*
+ * Copyright (c) 2018 MediaTek Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#if !defined(__MRDUMP_ELF64_H__)
+#define __MRDUMP_ELF64_H__
+
+#include <stdint.h>
+#include "mrdump_elf_common.h"
+
+#define ELF_ARM64_NGREGS 34
+typedef uint64_t elf_arm64_gregset_t[ELF_ARM64_NGREGS];
+
+typedef struct elf64_hdr {
+ unsigned char e_ident[EI_NIDENT];
+ Elf64_Half e_type;
+ Elf64_Half e_machine;
+ Elf64_Word e_version;
+ Elf64_Addr e_entry;
+ Elf64_Off e_phoff;
+ Elf64_Off e_shoff;
+ Elf64_Word e_flags;
+ Elf64_Half e_ehsize;
+ Elf64_Half e_phentsize;
+ Elf64_Half e_phnum;
+ Elf64_Half e_shentsize;
+ Elf64_Half e_shnum;
+ Elf64_Half e_shstrndx;
+} Elf64_ehdr;
+
+typedef struct elf64_phdr {
+ Elf64_Word p_type;
+ Elf64_Word p_flags;
+ Elf64_Off p_offset;
+ Elf64_Addr p_vaddr;
+ Elf64_Addr p_paddr;
+ Elf64_Xword p_filesz;
+ Elf64_Xword p_memsz;
+ Elf64_Xword p_align;
+} Elf64_phdr;
+
+typedef struct elf64_note {
+ Elf64_Word n_namesz; /* Name size */
+ Elf64_Word n_descsz; /* Content size */
+ Elf64_Word n_type; /* Content type */
+} Elf64_nhdr;
+
+struct elf_timeval64 {
+ int64_t tv_sec;
+ int64_t tv_usec;
+};
+
+struct elf_siginfo {
+ int64_t si_signo;
+ int64_t si_code;
+ int64_t si_errno;
+};
+
+struct elf_arm64_prstatus64 {
+ struct elf_siginfo pr_info;
+ short pr_cursig;
+ uint64_t pr_sigpend;
+ uint64_t pr_sighold;
+
+ int32_t pr_pid;
+ int32_t pr_ppid;
+ int32_t pr_pgrp;
+
+ int32_t pr_sid;
+ struct elf_timeval64 pr_utime;
+ struct elf_timeval64 pr_stime;
+ struct elf_timeval64 pr_cutime;
+ struct elf_timeval64 pr_cstime;
+
+ elf_arm64_gregset_t pr_reg;
+
+ int64_t pr_fpvalid;
+};
+
+struct elf_prpsinfo64 {
+ char pr_state;
+ char pr_sname;
+ char pr_zomb;
+ char pr_nice;
+ uint64_t pr_flag;
+
+ uint32_t pr_uid;
+ uint32_t pr_gid;
+
+ int32_t pr_pid;
+ int32_t pr_ppid;
+ int32_t pr_pgrp;
+ int32_t pr_sid;
+
+ char pr_fname[16];
+ char pr_psargs[ELF_PRARGSZ];
+};
+
+#endif /* __MRDUMP_ELF64_H__ */
diff --git a/src/bsp/lk/lib/aee/include/mrdump_elf_common.h b/src/bsp/lk/lib/aee/include/mrdump_elf_common.h
new file mode 100644
index 0000000..10d9d23
--- /dev/null
+++ b/src/bsp/lk/lib/aee/include/mrdump_elf_common.h
@@ -0,0 +1,144 @@
+/*
+ * Copyright (c) 2018 MediaTek Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#if !defined(__MRDUMP_ELF_COMMON_H__)
+#define __MRDUMP_ELF_COMMON_H__
+
+#define ELFMAG "\177ELF"
+#define SELFMAG 4
+
+#define CORE_STR "CORE"
+
+#ifndef ELF_CORE_EFLAGS
+#define ELF_CORE_EFLAGS 0
+#endif
+
+#define EI_NIDENT 16
+
+#define EI_CLASS 4
+#define EI_DATA 5
+#define EI_VERSION 6
+#define EI_OSABI 7
+#define EI_PAD 8
+
+#define EM_ARM 40
+#define EM_AARCH64 183
+
+#define ET_CORE 4
+
+#define PT_LOAD 1
+#define PT_NOTE 4
+
+#define ELFCLASS32 1
+#define ELFCLASS64 2
+
+#define NT_PRSTATUS 1
+#define NT_PRFPREG 2
+#define NT_PRPSINFO 3
+/* MRDUMP support note type */
+#define NT_MRDUMP_MACHDESC 0xAEE0
+#define NT_MRDUMP_CBLOCK 0xBEEF
+
+
+#define PF_R 0x4
+#define PF_W 0x2
+#define PF_X 0x1
+
+#define ELFOSABI_NONE 0
+
+#define EV_CURRENT 1
+
+#define ELFDATA2LSB 1
+
+#define ELF_PRARGSZ 80
+
+#define MRDUMP_TYPE_FULL_MEMORY 0
+#define MRDUMP_TYPE_KERNEL_1 1
+#define MRDUMP_TYPE_KERNEL_2 2
+
+#define MRDUMP_TYPE_MASK 0x3
+
+typedef uint32_t Elf32_Addr;
+typedef uint16_t Elf32_Half;
+typedef uint32_t Elf32_Off;
+typedef int32_t Elf32_Sword;
+typedef uint32_t Elf32_Word;
+
+typedef uint64_t Elf64_Addr;
+typedef uint16_t Elf64_Half;
+typedef uint64_t Elf64_Off;
+typedef uint32_t Elf64_Word;
+typedef uint64_t Elf64_Xword;
+
+static inline void mrdump_elf_setup_eident(unsigned char e_ident[EI_NIDENT], unsigned char elfclasz)
+{
+ dprintf(CRITICAL, "%s before memcpy\n", __func__);
+ memcpy(e_ident, ELFMAG, SELFMAG);
+ dprintf(CRITICAL, "%s after memcpy\n", __func__);
+ e_ident[EI_CLASS] = elfclasz;
+ e_ident[EI_DATA] = ELFDATA2LSB;
+ e_ident[EI_VERSION] = EV_CURRENT;
+ e_ident[EI_OSABI] = ELFOSABI_NONE;
+ memset(e_ident+EI_PAD, 0, EI_NIDENT-EI_PAD);
+}
+
+#define mrdump_elf_setup_elfhdr(elfp, machid, elfhdr_t, elfphdr_t, phdrcount) \
+ elfp->e_type = ET_CORE; \
+ elfp->e_machine = machid; \
+ elfp->e_version = EV_CURRENT; \
+ elfp->e_entry = 0; \
+ elfp->e_phoff = sizeof(elfhdr_t); \
+ elfp->e_shoff = 0; \
+ elfp->e_flags = ELF_CORE_EFLAGS; \
+ elfp->e_ehsize = sizeof(elfhdr_t); \
+ elfp->e_phentsize = sizeof(elfphdr_t); \
+ elfp->e_phnum = phdrcount; \
+ elfp->e_shentsize = 0; \
+ elfp->e_shnum = 0; \
+ elfp->e_shstrndx = 0; \
+
+
+struct __attribute__((__packed__)) elf_mrdump_machdesc {
+ uint32_t flags;
+ uint32_t nr_cpus;
+
+ uint64_t phys_offset;
+ uint64_t total_memory;
+
+ uint64_t page_offset;
+ uint64_t high_memory;
+
+ uint64_t kimage_vaddr;
+
+ uint64_t modules_start;
+ uint64_t modules_end;
+
+ uint64_t vmalloc_start;
+ uint64_t vmalloc_end;
+
+ uint64_t master_page_table;
+
+ uint64_t dfdmem_pa;
+};
+
+#endif
diff --git a/src/bsp/lk/lib/aee/include/mt_emi_mpu.h b/src/bsp/lk/lib/aee/include/mt_emi_mpu.h
new file mode 100644
index 0000000..a91b13c
--- /dev/null
+++ b/src/bsp/lk/lib/aee/include/mt_emi_mpu.h
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2018 MediaTek Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef __MT_EMI_MPU_H__
+#define __MT_EMI_MPU_H__
+
+#define EMI_MPU_ALIGN_BITS 16
+#define EMI_MPU_DOMAIN_NUM 16
+#define EMI_MPU_REGION_NUM 32
+
+#define MAX_CH 2
+#define MAX_RK 2
+
+//#include <emi_mpu_v1.h>
+#include <emi_info_v1.h>
+
+#endif /* __MT_EMI_MPU_H__ */
diff --git a/src/bsp/lk/lib/aee/include/partition.h b/src/bsp/lk/lib/aee/include/partition.h
new file mode 100644
index 0000000..1760b68
--- /dev/null
+++ b/src/bsp/lk/lib/aee/include/partition.h
@@ -0,0 +1,64 @@
+/*
+ * Copyright (c) 2018 MediaTek Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef __PARTITION_H__
+#define __PARTITION_H__
+
+#include <platform/mmc_core.h>
+
+#define BIMG_HEADER_SZ (0x800)
+#define MKIMG_HEADER_SZ (0x200)
+
+#define PART_HDR_DATA_SIZE 512
+
+#define PART_KERNEL "KERNEL"
+#define PART_ROOTFS "ROOTFS"
+
+#define PART_MAGIC 0x58881688
+#define PART_EXT_MAGIC 0x58891689
+#define PART_MAX_COUNT 128
+#define PART_PRELOADER_SIZE (0x400)
+
+#define FRP_NAME "frp"
+
+typedef union {
+ struct {
+ unsigned int magic; /* partition magic */
+ unsigned int dsize; /* partition data size */
+ char name[32]; /* partition name */
+ unsigned int maddr; /* partition memory address */
+ unsigned int mode; /* maddr is counted from the beginning or end of RAM */
+ /* extension */
+ unsigned int ext_magic; /* always EXT_MAGIC */
+ unsigned int hdr_size; /* header size is 512 bytes currently, but may extend in the future */
+ unsigned int hdr_version; /* see HDR_VERSION */
+ unsigned int img_type; /* please refer to #define beginning with IMG_TYPE_ */
+ unsigned int img_list_end; /* end of image list? 0: this image is followed by another image 1: end */
+ unsigned int align_size; /* image size alignment setting in bytes, 16 by default for AES encryption */
+ unsigned int dsize_extend; /* high word of image size for 64 bit address support */
+ unsigned int maddr_extend; /* high word of image load address in RAM for 64 bit address support */
+ } info;
+ unsigned char data[PART_HDR_DATA_SIZE];
+} part_hdr_t;
+#endif /* __PARTITION_H__ */
+
diff --git a/src/bsp/lk/lib/aee/include/plat_dbg_info.h b/src/bsp/lk/lib/aee/include/plat_dbg_info.h
new file mode 100644
index 0000000..5bb704a
--- /dev/null
+++ b/src/bsp/lk/lib/aee/include/plat_dbg_info.h
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2018 MediaTek Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef __PLAT_DBG_INFO_H__
+#define __PLAT_DBG_INFO_H__
+
+#define INFO_TYPE_MAX 3
+
+typedef struct {
+ unsigned int key;
+ unsigned int base;
+ unsigned int size;
+} dbg_info_in_bootargs;
+
+unsigned int get_dbg_info_base(unsigned int key);
+unsigned int get_dbg_info_size(unsigned int key);
+
+#endif
+
diff --git a/src/bsp/lk/lib/aee/include/ram_console.h b/src/bsp/lk/lib/aee/include/ram_console.h
new file mode 100644
index 0000000..689a434
--- /dev/null
+++ b/src/bsp/lk/lib/aee/include/ram_console.h
@@ -0,0 +1,50 @@
+/*
+ * Copyright (c) 2018 MediaTek Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef __RAM_CONSOLE_H__
+#define __RAM_CONSOLE_H__
+
+#include <kernel/vm.h>
+#include <platform/ram_console_def.h>
+#include <ram_console_common.h>
+
+#define SZLOG 8192
+char logbuf[SZLOG];
+int sLOG(const char *fmt, ...);
+
+#define LOG(fmt, ...) \
+ do { \
+ sLOG(fmt, ##__VA_ARGS__); \
+ _dprintf(fmt, ##__VA_ARGS__); \
+ } while (0)
+
+#define LOGD(fmt, ...) \
+ sLOG(fmt, ##__VA_ARGS__)
+
+#if WITH_KERNEL_VM
+ #define PA_TO_VA(pa) paddr_to_kvaddr(pa)
+#else
+ #define PA_TO_VA(pa) pa
+#endif
+
+#endif // #ifndef __RAM_CONSOLE_H__
diff --git a/src/bsp/lk/lib/aee/include/ram_console_common.h b/src/bsp/lk/lib/aee/include/ram_console_common.h
new file mode 100644
index 0000000..700701e
--- /dev/null
+++ b/src/bsp/lk/lib/aee/include/ram_console_common.h
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 2018 MediaTek Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef __RAM_CONSOLE_COMMON_H__
+#define __RAM_CONSOLE_COMMON_H__
+
+enum AEE_EXP_TYPE_NUM {
+ AEE_EXP_TYPE_HWT = 1,
+ AEE_EXP_TYPE_KE = 2,
+ AEE_EXP_TYPE_NESTED_PANIC = 3,
+ AEE_EXP_TYPE_SMART_RESET = 4,
+ AEE_EXP_TYPE_HANG_DETECT = 5,
+ AEE_EXP_TYPE_LK_CRASH = 6,
+ AEE_EXP_TYPE_DM_VERITY_CORRUPTION = 7,
+};
+
+#define RAM_CONSOLE_EXP_TYPE_MAGIC 0xaeedead0
+#define RAM_CONSOLE_EXP_TYPE_DEC(exp_type) \
+ ((exp_type ^ RAM_CONSOLE_EXP_TYPE_MAGIC) < 16 ? exp_type ^ RAM_CONSOLE_EXP_TYPE_MAGIC : exp_type)
+
+void ram_console_init(void);
+int ram_console_get_wdt_status(unsigned int *);
+int ram_console_get_fiq_step(unsigned int *);
+int ram_console_get_exp_type(unsigned int *);
+int ram_console_set_exp_type(unsigned int exp_type);
+int ram_console_is_abnormal_boot(void);
+void ram_console_lk_save(unsigned int val, int index);
+void ram_console_reboot_reason_save(u32 rgu_status);
+void pl_ram_console_init(void);
+
+void ram_console_addr_size(unsigned long *addr, unsigned long *size);
+void ram_console_set_dump_step(unsigned int step);
+int ram_console_get_dump_step(void);
+bool ram_console_should_restore(unsigned char *ram_console_ptr);
+#ifdef MTK_PMIC_FULL_RESET
+bool ram_console_reboot_by_cold_reset(void);
+#endif
+#endif // #ifndef __RAM_CONSOLE_COMMON_H__
+