49#include "sys/reboot.h"
52#define LOG_WAIT_TIMES 10
53#define LOG_PART_WAIT_TIME 1000
73 const char event[EVENT_MAX_LEN],
74 const char module[MODULE_MAX_LEN],
78 BBOX_PRINT_ERR(
"info: %p, event: %p, module: %p, errorDesc: %p!\n", info,
event,
module,
errorDesc);
82 (
void)memset_s(info,
sizeof(*info), 0,
sizeof(*info));
84 BBOX_PRINT_ERR(
"info->event is not enough or strncpy_s failed!\n");
87 BBOX_PRINT_ERR(
"info->module is not enough or strncpy_s failed!\n");
91 BBOX_PRINT_ERR(
"info->errorDesc is not enough or strncpy_s failed!\n");
98 BBOX_PRINT_INFO(
"wait for log part [%s] begin!\n", LOSCFG_BLACKBOX_LOG_PART_MOUNT_POINT);
102 BBOX_PRINT_INFO(
"wait for log part [%s] end!\n", LOSCFG_BLACKBOX_LOG_PART_MOUNT_POINT);
109 BBOX_PRINT_INFO(
"wait for log part [%s] begin!\n", LOSCFG_BLACKBOX_LOG_PART_MOUNT_POINT);
110 while (i++ < LOG_WAIT_TIMES) {
113 BBOX_PRINT_INFO(
"wait for log part [%s] end!\n", LOSCFG_BLACKBOX_LOG_PART_MOUNT_POINT);
121 if (info == NULL || ops == NULL) {
122 BBOX_PRINT_ERR(
"info: %p, ops: %p!\n", info, ops);
126 LOS_DL_LIST_FOR_EACH_ENTRY(*ops, &g_opsList,
BBoxOps, opsList) {
127 if (*ops != NULL && strcmp((*ops)->ops.module, info->
module) == 0) {
133 BBOX_PRINT_ERR(
"[%s] hasn't been registered!\n", info->
module);
141 if (info == NULL || ops == NULL) {
142 BBOX_PRINT_ERR(
"info: %p, ops: %p!\n", info, ops);
147 BBOX_PRINT_INFO(
"[%s] starts dumping log!\n", ops->
ops.
module);
148 ops->
ops.
Dump(LOSCFG_BLACKBOX_LOG_ROOT_PATH, info);
149 BBOX_PRINT_INFO(
"[%s] ends dumping log!\n", ops->
ops.
module);
152 BBOX_PRINT_INFO(
"[%s] starts resetting!\n", ops->
ops.
module);
154 BBOX_PRINT_INFO(
"[%s] ends resetting!\n", ops->
ops.
module);
165 BBOX_PRINT_ERR(
"LOS_MemAlloc failed!\n");
170 BBOX_PRINT_ERR(
"Request g_opsListSem failed!\n");
177 BBOX_PRINT_ERR(
"Create log dir [%s] failed!\n", LOSCFG_BLACKBOX_LOG_ROOT_PATH);
180 LOS_DL_LIST_FOR_EACH_ENTRY(ops, &g_opsList,
BBoxOps, opsList) {
182 BBOX_PRINT_ERR(
"ops: NULL, please check it!\n");
186 (
void)memset_s(info,
sizeof(*info), 0,
sizeof(*info));
188 BBOX_PRINT_ERR(
"[%s] failed to get log info!\n", ops->
ops.
module);
191 BBOX_PRINT_INFO(
"[%s] starts saving log!\n", ops->
ops.
module);
193 BBOX_PRINT_ERR(
"[%s] failed to save log!\n", ops->
ops.
module);
195 BBOX_PRINT_INFO(
"[%s] ends saving log!\n", ops->
ops.
module);
196 BBOX_PRINT_INFO(
"[%s] starts uploading event [%s]\n", info->
module, info->
event);
200 BBOX_PRINT_INFO(
"LOSCFG_FS_VFS isn't defined!\n");
202 BBOX_PRINT_INFO(
"[%s] ends uploading event [%s]\n", info->
module, info->
event);
205 BBOX_PRINT_ERR(
"module [%s], GetLastLogInfo: %p, SaveLastLog: %p!\n",
218 BBOX_PRINT_ERR(
"info is NULL!\n");
223 BBOX_PRINT_ERR(
"Request g_opsListSem failed!\n");
232 BBOX_PRINT_ERR(
"Create log dir [%s] failed!\n", LOSCFG_BLACKBOX_LOG_ROOT_PATH);
238 BBOX_PRINT_INFO(
"[%s] starts uploading event [%s]\n", info->
module, info->
event);
242 BBOX_PRINT_INFO(
"LOSCFG_FS_VFS isn't defined!\n");
244 BBOX_PRINT_INFO(
"[%s] ends uploading event [%s]\n", info->
module, info->
event);
255 BBOX_PRINT_ERR(
"Request g_tempErrInfoSem failed!\n");
259 BBOX_PRINT_ERR(
"g_tempErrInfo is NULL!\n");
275 BBOX_PRINT_ERR(
"info is NULL!\n");
284 BBOX_PRINT_INFO(
"SysReboot, ret: %d\n", ret);
288 const char module[MODULE_MAX_LEN],
289 const char errorDesc[ERROR_DESC_MAX_LEN])
296 BBOX_PRINT_ERR(
"Request g_tempErrInfoSem failed!\n");
305 const char *logDir = (
const char *)uwParam1;
316 BBOX_PRINT_ERR(
"Request g_tempErrLogSaveSem failed!\n");
324#ifdef LOSCFG_BLACKBOX_DEBUG
329 BBOX_PRINT_INFO(
"The following modules have been registered!\n");
334 BBOX_PRINT_INFO(
"module: %s, Dump: %p, Reset: %p, GetLastLogInfo: %p, SaveLastLog: %p\n",
346 BBOX_PRINT_ERR(
"BlackBox isn't initialized successfully!\n");
350 BBOX_PRINT_ERR(
"ops is NULL!\n");
355 if (newOps == NULL) {
356 BBOX_PRINT_ERR(
"LOS_MemAlloc failed!\n");
359 (
void)memset_s(newOps,
sizeof(*newOps), 0,
sizeof(*newOps));
360 if (memcpy_s(&newOps->
ops,
sizeof(newOps->
ops),
ops,
sizeof(*
ops)) != EOK) {
361 BBOX_PRINT_ERR(
"newOps->ops is not enough or memcpy_s failed!\n");
366 BBOX_PRINT_ERR(
"Request g_opsListSem failed!\n");
379 BBOX_PRINT_ERR(
"module [%s] has been registered!\n",
ops->
module);
389 BBOX_PRINT_INFO(
"module [%s] is registered successfully!\n",
ops->
module);
390#ifdef LOSCFG_BLACKBOX_DEBUG
398 const char module[MODULE_MAX_LEN],
399 const char errorDesc[ERROR_DESC_MAX_LEN],
402 if (event == NULL || module == NULL || errorDesc == NULL) {
403 BBOX_PRINT_ERR(
"event: %p, module: %p, errorDesc: %p!\n", event, module, errorDesc);
407 BBOX_PRINT_ERR(
"BlackBox isn't initialized successfully!\n");
411 if (needSysReset == 0) {
417 BBOX_PRINT_ERR(
"LOS_MemAlloc failed!\n");
434 BBOX_PRINT_ERR(
"Create g_opsListSem failed!\n");
438 BBOX_PRINT_ERR(
"Create g_tempErrInfoSem failed!\n");
442 BBOX_PRINT_ERR(
"Create g_tempErrLogSaveSem failed!\n");
448 BBOX_PRINT_ERR(
"LOS_MemAlloc failed!\n");
452 (
void)memset_s(&taskParam,
sizeof(taskParam), 0,
sizeof(taskParam));
455 taskParam.
uwStackSize = LOSCFG_BASE_CORE_TSK_DEFAULT_STACK_SIZE;
456 taskParam.
pcName =
"SaveErrorLog";
457 taskParam.
usTaskPrio = LOSCFG_BASE_CORE_TSK_DEFAULT_PRIO;
458 taskParam.
uwResved = LOS_TASK_STATUS_DETACHED;
459#ifdef LOSCFG_KERNEL_SMP
LITE_OS_SEC_TEXT_MINOR VOID LOS_Msleep(UINT32 msecs)
Sleep the current task.
LITE_OS_SEC_ALW_INLINE STATIC INLINE VOID LOS_ListInit(LOS_DL_LIST *list)
LITE_OS_SEC_ALW_INLINE STATIC INLINE VOID LOS_ListTailInsert(LOS_DL_LIST *list, LOS_DL_LIST *node)
Insert a node to the tail of a doubly linked list.
LITE_OS_SEC_ALW_INLINE STATIC INLINE BOOL LOS_ListEmpty(LOS_DL_LIST *list)
Identify whether a specified doubly linked list is empty. | 判断链表是否为空
VOID * LOS_MemAlloc(VOID *pool, UINT32 size)
从指定内存池中申请size长度的内存,注意这可不是从内核堆空间中申请内存
UINT8 * m_aucSysMem1
系统动态内存池地址的起始地址 @note_thinking 能否不要用 0,1来命名核心变量 ???
UINT32 LOS_MemFree(VOID *pool, VOID *ptr)
释放从指定动态内存中申请的内存
LITE_OS_SEC_TEXT_INIT UINT32 LOS_BinarySemCreate(UINT16 count, UINT32 *semHandle)
对外接口 创建二值信号量,其计数值最大为1,可以当互斥锁用
LITE_OS_SEC_TEXT UINT32 LOS_SemPost(UINT32 semHandle)
对外接口 释放指定的信号量
LITE_OS_SEC_TEXT UINT32 LOS_SemPend(UINT32 semHandle, UINT32 timeout)
对外接口 申请指定的信号量,并设置超时时间
LITE_OS_SEC_TEXT_INIT UINT32 LOS_SemDelete(UINT32 semHandle)
对外接口 删除指定的信号量,参数就是 semID
LITE_OS_SEC_TEXT_INIT UINT32 LOS_TaskCreate(UINT32 *taskID, TSK_INIT_PARAM_S *initParam)
创建任务,并使该任务进入ready状态,如果就绪队列中没有更高优先级的任务,则运行该任务
VOID *(* TSK_ENTRY_FUNC)(UINTPTR param1, UINTPTR param2, UINTPTR param3, UINTPTR param4)
Define the type of a task entrance function.
bool IsLogPartReady(void)
int SaveBasicErrorInfo(const char *filePath, const struct ErrorInfo *info)
int CreateLogDir(const char *dirPath)
static void SaveTempErrorLog(void)
int BBoxNotifyError(const char event[EVENT_MAX_LEN], const char module[MODULE_MAX_LEN], const char errorDesc[ERROR_DESC_MAX_LEN], int needSysReset)
static void SaveLogWithReset(struct ErrorInfo *info)
int BBoxRegisterModuleOps(struct ModuleOps *ops)
static void SaveLastLog(const char *logDir)
LOS_MODULE_INIT(OsBBoxDriverInit, LOS_INIT_LEVEL_ARCH)
static void SaveTempErrorInfo(const char event[EVENT_MAX_LEN], const char module[MODULE_MAX_LEN], const char errorDesc[ERROR_DESC_MAX_LEN])
struct ErrorInfo * g_tempErrInfo
static UINT32 g_tempErrInfoSem
static void SaveLogWithoutReset(struct ErrorInfo *info)
static int SaveErrorLog(UINTPTR uwParam1, UINTPTR uwParam2, UINTPTR uwParam3, UINTPTR uwParam4)
static LOS_DL_LIST_HEAD(g_opsList)
static UINT32 g_opsListSem
static void FormatErrorInfo(struct ErrorInfo *info, const char event[EVENT_MAX_LEN], const char module[MODULE_MAX_LEN], const char errorDesc[ERROR_DESC_MAX_LEN])
static bool FindModuleOps(struct ErrorInfo *info, BBoxOps **ops)
static void PrintModuleOps(void)
static void InvokeModuleOps(struct ErrorInfo *info, const BBoxOps *ops)
static UINT32 g_tempErrLogSaveSem
int OsBBoxDriverInit(void)
static void WaitForLogPart(void)
static bool g_bboxInitSucc
int UploadEventByFile(const char *filePath)
STATIC INLINE UINT32 ArchCurrCpuid(VOID)
char errorDesc[ERROR_DESC_MAX_LEN]
char module[MODULE_MAX_LEN]
char event[EVENT_MAX_LEN]
void(* Reset)(struct ErrorInfo *info)
void(* Dump)(const char *logDir, struct ErrorInfo *info)
char module[MODULE_MAX_LEN]
int(* SaveLastLog)(const char *logDir, struct ErrorInfo *info)
int(* GetLastLogInfo)(struct ErrorInfo *info)
TSK_ENTRY_FUNC pfnTaskEntry
ARG_NUM_3 ARG_NUM_1 ARG_NUM_2 ARG_NUM_2 ARG_NUM_3 ARG_NUM_1 ARG_NUM_4 ARG_NUM_2 ARG_NUM_2 ARG_NUM_5 ARG_NUM_2 ARG_NUM_0 ARG_NUM_2 ARG_NUM_1 ARG_NUM_2 ARG_NUM_3 ARG_NUM_7 ARG_NUM_2 ARG_NUM_3 ARG_NUM_2 ARG_NUM_4 ARG_NUM_5 ARG_NUM_6 ARG_NUM_3 ARG_NUM_5 ARG_NUM_7 ARG_NUM_1 ARG_NUM_4 ARG_NUM_5 ARG_NUM_4 ARG_NUM_7 ARG_NUM_2 ARG_NUM_3 ARG_NUM_7 ARG_NUM_7 ARG_NUM_3 ARG_NUM_3 ARG_NUM_3 ARG_NUM_7 ARG_NUM_3 ARG_NUM_2 char ARG_NUM_2 ARG_NUM_1 ARG_NUM_0 ARG_NUM_0 SysReboot
ARG_NUM_3 ARG_NUM_1 ARG_NUM_2 ARG_NUM_2 ARG_NUM_3 ARG_NUM_1 ARG_NUM_4 ARG_NUM_2 ARG_NUM_2 ARG_NUM_5 ARG_NUM_2 void