From d846035f3e7d2dae973d31e373bfb66b09782709 Mon Sep 17 00:00:00 2001 From: YOUR_NAME Date: Thu, 29 Apr 2021 16:04:33 +0800 Subject: [PATCH] feature:the feature of saving system exception information to the storage medium is separated from the shell module. Change-Id: Id56939001d70bb92d9cc02bd7c9f55ca8b61cf5b --- Kconfig | 7 ++++ arch/arm/arm/src/los_exc.c | 39 +++++++++++++----- kernel/base/misc/mempt_shellcmd.c | 12 +++--- kernel/base/misc/task_shellcmd.c | 2 +- kernel/common/los_config.h | 2 +- kernel/common/los_excinfo.c | 33 +++++++++++++++- kernel/common/los_excinfo_pri.h | 2 +- kernel/common/los_printf.c | 4 +- shell/Kconfig | 7 ---- shell/full/src/cmds/excinfo_shell.c | 61 ----------------------------- 10 files changed, 79 insertions(+), 90 deletions(-) delete mode 100644 shell/full/src/cmds/excinfo_shell.c diff --git a/Kconfig b/Kconfig index ccf86320..fbf80924 100644 --- a/Kconfig +++ b/Kconfig @@ -165,6 +165,7 @@ config THUMB default n help Answer Y to build thumb version. This will make LiteOS smaller. + config PLATFORM_DVFS bool "Enable Dvfs" default n @@ -173,6 +174,12 @@ config PLATFORM_DVFS Answer Y to enable LiteOS support dynamic voltage and frequency scaling feature for low power consumption. +config SAVE_EXCINFO + bool "Enable Saving Exception Information" + default n + help + Answer Y to enable LiteOS support saving exception information to storage medium. + config DEBUG_VERSION bool "Enable a Debug Version" default n diff --git a/arch/arm/arm/src/los_exc.c b/arch/arm/arm/src/los_exc.c index dd94396d..7b047fcd 100644 --- a/arch/arm/arm/src/los_exc.c +++ b/arch/arm/arm/src/los_exc.c @@ -34,7 +34,7 @@ #include "los_printf_pri.h" #include "los_task_pri.h" #include "los_hw_pri.h" -#ifdef LOSCFG_SHELL_EXCINFO +#ifdef LOSCFG_SAVE_EXCINFO #include "los_excinfo_pri.h" #endif #ifdef LOSCFG_EXC_INTERACTION @@ -576,7 +576,7 @@ STATIC VOID OsUserExcHandle(ExcContext *excBufAddr) #endif #endif -#ifdef LOSCFG_SHELL_EXCINFO +#ifdef LOSCFG_SAVE_EXCINFO OsProcessExitCodeCoreDumpSet(runProcess); #endif OsProcessExitCodeSignalSet(runProcess, SIGUSR2); @@ -1086,6 +1086,22 @@ LITE_OS_SEC_TEXT_INIT STATIC VOID OsPrintExcHead(UINT32 far) } } +#ifdef LOSCFG_SAVE_EXCINFO +STATIC VOID OsSysStateSave(UINT32 *intCount, UINT32 *lockCount) +{ + *intCount = g_intCount[ArchCurrCpuid()]; + *lockCount = OsPercpuGet()->taskLockCnt; + g_intCount[ArchCurrCpuid()] = 0; + OsPercpuGet()->taskLockCnt = 0; +} + +STATIC VOID OsSysStateRestore(UINT32 intCount, UINT32 lockCount) +{ + g_intCount[ArchCurrCpuid()] = intCount; + OsPercpuGet()->taskLockCnt = lockCount; +} +#endif + /* * Description : EXC handler entry * Input : excType --- exc type @@ -1093,6 +1109,11 @@ LITE_OS_SEC_TEXT_INIT STATIC VOID OsPrintExcHead(UINT32 far) */ LITE_OS_SEC_TEXT_INIT VOID OsExcHandleEntry(UINT32 excType, ExcContext *excBufAddr, UINT32 far, UINT32 fsr) { +#ifdef LOSCFG_SAVE_EXCINFO + UINT32 intCount; + UINT32 lockCount; +#endif + /* Task scheduling is not allowed during exception handling */ OsPercpuGet()->taskLockCnt++; @@ -1106,18 +1127,18 @@ LITE_OS_SEC_TEXT_INIT VOID OsExcHandleEntry(UINT32 excType, ExcContext *excBufAd OsAllCpuStatusOutput(); #endif -#ifdef LOSCFG_SHELL_EXCINFO +#ifdef LOSCFG_SAVE_EXCINFO log_read_write_fn func = GetExcInfoRW(); #endif if (g_excHook != NULL) { if (g_curNestCount[ArchCurrCpuid()] == 1) { -#ifdef LOSCFG_SHELL_EXCINFO +#ifdef LOSCFG_SAVE_EXCINFO if (func != NULL) { SetExcInfoIndex(0); - g_intCount[ArchCurrCpuid()] = 0; + OsSysStateSave(&intCount, &lockCount); OsRecordExcInfoTime(); - g_intCount[ArchCurrCpuid()] = 1; + OsSysStateRestore(intCount, lockCount); } #endif g_excHook(excType, excBufAddr, far, fsr); @@ -1125,12 +1146,12 @@ LITE_OS_SEC_TEXT_INIT VOID OsExcHandleEntry(UINT32 excType, ExcContext *excBufAd OsCallStackInfo(); } -#ifdef LOSCFG_SHELL_EXCINFO +#ifdef LOSCFG_SAVE_EXCINFO if (func != NULL) { PrintExcInfo("Be sure flash space bigger than GetExcInfoIndex():0x%x\n", GetExcInfoIndex()); - g_intCount[ArchCurrCpuid()] = 0; + OsSysStateSave(&intCount, &lockCount); func(GetRecordAddr(), GetRecordSpace(), 0, GetExcInfoBuf()); - g_intCount[ArchCurrCpuid()] = 1; + OsSysStateRestore(intCount, lockCount); } #endif } diff --git a/kernel/base/misc/mempt_shellcmd.c b/kernel/base/misc/mempt_shellcmd.c index 50322068..333d5b28 100644 --- a/kernel/base/misc/mempt_shellcmd.c +++ b/kernel/base/misc/mempt_shellcmd.c @@ -31,7 +31,7 @@ #include "stdlib.h" #include "los_memory_pri.h" -#ifdef LOSCFG_SHELL_EXCINFO +#ifdef LOSCFG_SAVE_EXCINFO #include "los_excinfo_pri.h" #endif #ifdef LOSCFG_SHELL @@ -64,7 +64,7 @@ VOID OsDumpMemByte(size_t length, UINTPTR addr) while (dataLen) { if (IS_ALIGNED(count, sizeof(CHAR *))) { PRINTK("\n 0x%lx :", alignAddr); -#ifdef LOSCFG_SHELL_EXCINFO +#ifdef LOSCFG_SAVE_EXCINFO WriteExcInfoToBuf("\n 0x%lx :", alignAddr); #endif } @@ -73,7 +73,7 @@ VOID OsDumpMemByte(size_t length, UINTPTR addr) #else PRINTK("%0+8lx ", *alignAddr); #endif -#ifdef LOSCFG_SHELL_EXCINFO +#ifdef LOSCFG_SAVE_EXCINFO #ifdef __LP64__ WriteExcInfoToBuf("0x%0+16x ", *alignAddr); #else @@ -85,7 +85,7 @@ VOID OsDumpMemByte(size_t length, UINTPTR addr) count++; } PRINTK("\n"); -#ifdef LOSCFG_SHELL_EXCINFO +#ifdef LOSCFG_SAVE_EXCINFO WriteExcInfoToBuf("\n"); #endif @@ -101,14 +101,14 @@ LITE_OS_SEC_TEXT_MINOR UINT32 OsShellCmdMemCheck(INT32 argc, const CHAR *argv[]) if (LOS_MemIntegrityCheck(m_aucSysMem1) == LOS_OK) { PRINTK("system memcheck over, all passed!\n"); -#ifdef LOSCFG_SHELL_EXCINFO +#ifdef LOSCFG_SAVE_EXCINFO WriteExcInfoToBuf("system memcheck over, all passed!\n"); #endif } #ifdef LOSCFG_EXC_INTERACTION if (LOS_MemIntegrityCheck(m_aucSysMem0) == LOS_OK) { PRINTK("exc interaction memcheck over, all passed!\n"); -#ifdef LOSCFG_SHELL_EXCINFO +#ifdef LOSCFG_SAVE_EXCINFO WriteExcInfoToBuf("exc interaction memcheck over, all passed!\n"); #endif } diff --git a/kernel/base/misc/task_shellcmd.c b/kernel/base/misc/task_shellcmd.c index 7c918e1c..49671f7d 100644 --- a/kernel/base/misc/task_shellcmd.c +++ b/kernel/base/misc/task_shellcmd.c @@ -43,7 +43,7 @@ #ifdef LOSCFG_KERNEL_CPUP #include "los_cpup_pri.h" #endif -#ifdef LOSCFG_SHELL_EXCINFO +#ifdef LOSCFG_SAVE_EXCINFO #include "los_excinfo_pri.h" #endif #include "los_process_pri.h" diff --git a/kernel/common/los_config.h b/kernel/common/los_config.h index a59581c1..7b9cb0ad 100644 --- a/kernel/common/los_config.h +++ b/kernel/common/los_config.h @@ -398,7 +398,7 @@ extern UINT32 __heap_end; #endif /****************************** exception information configuration ******************************/ -#ifdef LOSCFG_SHELL_EXCINFO +#ifdef LOSCFG_SAVE_EXCINFO /** * @ingroup los_config * the size of space for recording exception information diff --git a/kernel/common/los_excinfo.c b/kernel/common/los_excinfo.c index 422600a2..92ec6404 100644 --- a/kernel/common/los_excinfo.c +++ b/kernel/common/los_excinfo.c @@ -34,9 +34,11 @@ #ifdef LOSCFG_FS_VFS #include "fs/fs.h" #endif +#ifdef LOSCFG_SHELL +#include "shcmd.h" +#endif - -#ifdef LOSCFG_SHELL_EXCINFO +#ifdef LOSCFG_SAVE_EXCINFO STATIC log_read_write_fn g_excInfoRW = NULL; /* the hook of read-writing exception information */ STATIC CHAR *g_excInfoBuf = NULL; /* pointer to the buffer for storing the exception information */ STATIC UINT32 g_excInfoIndex = 0xFFFFFFFF; /* the index of the buffer for storing the exception information */ @@ -164,5 +166,32 @@ VOID OsRecordExcInfoTime(VOID) #endif } +#ifdef LOSCFG_SHELL +INT32 OsShellCmdReadExcInfo(INT32 argc, CHAR **argv) +{ + UINT32 recordSpace = GetRecordSpace(); + + (VOID)argc; + (VOID)argv; + + CHAR *buf = (CHAR*)LOS_MemAlloc((void *)OS_SYS_MEM_ADDR, recordSpace + 1); + if (buf == NULL) { + return LOS_NOK; + } + (void)memset_s(buf, recordSpace + 1, 0, recordSpace + 1); + + log_read_write_fn hook = GetExcInfoRW(); + if (hook != NULL) { + hook(GetRecordAddr(), recordSpace, 1, buf); + } + PRINTK("%s\n", buf); + (VOID)LOS_MemFree((void *)OS_SYS_MEM_ADDR, buf); + buf = NULL; + return LOS_OK; +} + +SHELLCMD_ENTRY(readExcInfo_shellcmd, CMD_TYPE_EX, "excInfo", 0, (CmdCallBackFunc)OsShellCmdReadExcInfo); +#endif + #endif diff --git a/kernel/common/los_excinfo_pri.h b/kernel/common/los_excinfo_pri.h index 24f0d043..ba68d5f4 100644 --- a/kernel/common/los_excinfo_pri.h +++ b/kernel/common/los_excinfo_pri.h @@ -40,7 +40,7 @@ extern "C" { #endif /* __cplusplus */ #endif /* __cplusplus */ -#ifdef LOSCFG_SHELL_EXCINFO +#ifdef LOSCFG_SAVE_EXCINFO extern VOID SetExcInfoRW(log_read_write_fn func); extern log_read_write_fn GetExcInfoRW(VOID); extern VOID SetExcInfoBuf(CHAR *buf); diff --git a/kernel/common/los_printf.c b/kernel/common/los_printf.c index 567348ff..b5d2a002 100644 --- a/kernel/common/los_printf.c +++ b/kernel/common/los_printf.c @@ -42,7 +42,7 @@ #ifdef LOSCFG_SHELL_DMESG #include "dmesg_pri.h" #endif -#ifdef LOSCFG_SHELL_EXCINFO +#ifdef LOSCFG_SAVE_EXCINFO #include "los_excinfo_pri.h" #endif #include "los_exc_pri.h" @@ -250,7 +250,7 @@ VOID PrintExcInfo(const CHAR *fmt, ...) va_start(ap, fmt); /* uart output without print-spinlock */ OsVprintf(fmt, ap, EXC_OUTPUT); -#ifdef LOSCFG_SHELL_EXCINFO +#ifdef LOSCFG_SAVE_EXCINFO WriteExcBufVa(fmt, ap); #endif va_end(ap); diff --git a/shell/Kconfig b/shell/Kconfig index b37c5918..641c740a 100644 --- a/shell/Kconfig +++ b/shell/Kconfig @@ -22,11 +22,4 @@ config SHELL_DMESG help Answer Y to enable LiteOS support shell dmesg. -config SHELL_EXCINFO - bool "Enable Shell excInfo" - default n - depends on DEBUG_VERSION && SHELL - help - Answer Y to enable LiteOS support shell excInfo. - endmenu diff --git a/shell/full/src/cmds/excinfo_shell.c b/shell/full/src/cmds/excinfo_shell.c deleted file mode 100644 index 85f3959c..00000000 --- a/shell/full/src/cmds/excinfo_shell.c +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. - * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of - * conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list - * of conditions and the following disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used - * to endorse or promote products derived from this software without specific prior written - * permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "shcmd.h" -#include "los_memory.h" -#ifdef LOSCFG_SHELL_EXCINFO -#include "los_excinfo_pri.h" - - -INT32 osShellCmdReadExcInfo(INT32 argc, CHAR **argv) -{ - UINT32 recordSpace = GetRecordSpace(); - - (VOID)argc; - (VOID)argv; - - CHAR *buf = (CHAR*)LOS_MemAlloc((void *)OS_SYS_MEM_ADDR, recordSpace + 1); - if (buf == NULL) { - return LOS_NOK; - } - (void)memset_s(buf, recordSpace + 1, 0, recordSpace + 1); - - log_read_write_fn hook = GetExcInfoRW(); - if (hook != NULL) { - hook(GetRecordAddr(), recordSpace, 1, buf); - } - PRINTK("%s\n", buf); - (VOID)LOS_MemFree((void *)OS_SYS_MEM_ADDR, buf); - buf = NULL; - return LOS_OK; -} -SHELLCMD_ENTRY(readExcInfo_shellcmd, CMD_TYPE_EX, "excInfo", 0, (CmdCallBackFunc)osShellCmdReadExcInfo); -#endif