1 /* 2 * Copyright (c) 2021-2021 Huawei Device Co., Ltd. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without modification, 5 * are permitted provided that the following conditions are met: 6 * 7 * 1. Redistributions of source code must retain the above copyright notice, this list of 8 * conditions and the following disclaimer. 9 * 10 * 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 * of conditions and the following disclaimer in the documentation and/or other materials 12 * provided with the distribution. 13 * 14 * 3. Neither the name of the copyright holder nor the names of its contributors may be used 15 * to endorse or promote products derived from this software without specific prior written 16 * permission. 17 * 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 20 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 22 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 23 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 25 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 26 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 27 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 28 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 */ 30 31 #ifndef LOS_BLACKBOX_H 32 #define LOS_BLACKBOX_H 33 34 #include "stdarg.h" 35 #include "los_typedef.h" 36 37 #ifdef __cplusplus 38 #if __cplusplus 39 extern "C" { 40 #endif /* __cplusplus */ 41 #endif /* __cplusplus */ 42 43 #define PATH_MAX_LEN 256 44 #define EVENT_MAX_LEN 32 45 #define MODULE_MAX_LEN 32 46 #define ERROR_DESC_MAX_LEN 512 47 #define KERNEL_FAULT_LOG_PATH LOSCFG_BLACKBOX_LOG_ROOT_PATH "/kernel_fault.log" 48 #define USER_FAULT_LOG_PATH LOSCFG_BLACKBOX_LOG_ROOT_PATH "/user_fault.log" 49 50 #define MODULE_SYSTEM "SYSTEM" 51 #define EVENT_SYSREBOOT "SYSREBOOT" 52 #define EVENT_LONGPRESS "LONGPRESS" 53 #define EVENT_COMBINATIONKEY "COMBINATIONKEY" 54 #define EVENT_SUBSYSREBOOT "SUBSYSREBOOT" 55 #define EVENT_POWEROFF "POWEROFF" 56 #define EVENT_PANIC "PANIC" 57 #define EVENT_SYS_WATCHDOG "SYSWATCHDOG" 58 #define EVENT_HUNGTASK "HUNGTASK" 59 #define EVENT_BOOTFAIL "BOOTFAIL" 60 61 struct ErrorInfo { 62 char event[EVENT_MAX_LEN]; 63 char module[MODULE_MAX_LEN]; 64 char errorDesc[ERROR_DESC_MAX_LEN]; 65 }; 66 67 struct ModuleOps { 68 char module[MODULE_MAX_LEN]; 69 void (*Dump)(const char *logDir, struct ErrorInfo *info); 70 void (*Reset)(struct ErrorInfo *info); 71 int (*GetLastLogInfo)(struct ErrorInfo *info); 72 int (*SaveLastLog)(const char *logDir, struct ErrorInfo *info); 73 }; 74 75 int BBoxRegisterModuleOps(struct ModuleOps *ops); 76 int BBoxNotifyError(const char event[EVENT_MAX_LEN], 77 const char module[MODULE_MAX_LEN], 78 const char errorDesc[ERROR_DESC_MAX_LEN], 79 int needSysReset); 80 int OsBBoxDriverInit(void); 81 82 #ifdef __cplusplus 83 #if __cplusplus 84 } 85 #endif /* __cplusplus */ 86 #endif /* __cplusplus */ 87 88 #endif