更新日期: 2022/06/01 来源: https://gitee.com/weharmony/kernel_liteos_a_note
los_blackbox_system_adapter.c 文件参考

浏览源代码.

结构体

struct  FaultLogInfo
 

函数

static void SaveFaultLog (const char *filePath, const char *dataBuf, size_t bufSize, struct ErrorInfo *info)
 
static void WriteExcFile (UINT32 startAddr, UINT32 space, UINT32 rwFlag, char *buf)
 
static void RegisterExcInfoHook (void)
 
static int AllocLogBuffer (void)
 
static void Dump (const char *logDir, struct ErrorInfo *info)
 
static void Reset (struct ErrorInfo *info)
 
static int GetLastLogInfo (struct ErrorInfo *info)
 
static int SaveLastLog (const char *logDir, struct ErrorInfo *info)
 
static void BBoxTest (void)
 
int OsBBoxSystemAdapterInit (void)
 
 LOS_MODULE_INIT (OsBBoxSystemAdapterInit, LOS_INIT_LEVEL_PLATFORM)
 

变量

static char * g_logBuffer = NULL
 

函数说明

◆ AllocLogBuffer()

static int AllocLogBuffer ( void  )
static

在文件 los_blackbox_system_adapter.c96 行定义.

97{
98 if (LOSCFG_BLACKBOX_LOG_SIZE < sizeof(struct FaultLogInfo)) {
99 BBOX_PRINT_ERR("LOSCFG_BLACKBOX_LOG_SIZE [%d] is too short, it must be >= %u\n",
100 LOSCFG_BLACKBOX_LOG_SIZE, sizeof(struct FaultLogInfo));
101 return -1;
102 }
103
104 /*
105 * The physical memory pointed to by LOSCFG_BLACKBOX_RESERVE_MEM_ADDR is
106 * exclusive to blackbox and cannot be occupied by other modules during
107 * system running and cannot overlap with the memory area of other systems
108 * during startup.
109 */
110 g_logBuffer = (char *)MEM_CACHED_ADDR(LOSCFG_BLACKBOX_RESERVE_MEM_ADDR);
111 BBOX_PRINT_INFO("g_logBuffer: %p, len: 0x%x for blackbox!\n", g_logBuffer, (UINT32)LOSCFG_BLACKBOX_LOG_SIZE);
112
113 return (g_logBuffer != NULL) ? 0 : -1;
114}
static char * g_logBuffer
unsigned int UINT32
Definition: los_typedef.h:57
这是这个函数的调用关系图:

◆ BBoxTest()

static void BBoxTest ( void  )
static

在文件 los_blackbox_system_adapter.c219 行定义.

220{
221 struct ModuleOps ops = {
222 .module = "MODULE_TEST",
223 .Dump = NULL,
224 .Reset = NULL,
225 .GetLastLogInfo = NULL,
226 .SaveLastLog = NULL,
227 };
228
229 if (BBoxRegisterModuleOps(&ops) != 0) {
230 BBOX_PRINT_ERR("BBoxRegisterModuleOps failed!\n");
231 return;
232 }
233 BBoxNotifyError("EVENT_TEST1", "MODULE_TEST", "Test BBoxNotifyError111", 0);
234}
int BBoxNotifyError(const char event[EVENT_MAX_LEN], const char module[MODULE_MAX_LEN], const char errorDesc[ERROR_DESC_MAX_LEN], int needSysReset)
int BBoxRegisterModuleOps(struct ModuleOps *ops)
char module[MODULE_MAX_LEN]
Definition: los_blackbox.h:68
函数调用图:
这是这个函数的调用关系图:

◆ Dump()

static void Dump ( const char *  logDir,
struct ErrorInfo info 
)
static

在文件 los_blackbox_system_adapter.c116 行定义.

117{
118 struct FaultLogInfo *pLogInfo = NULL;
119
120 if (logDir == NULL || info == NULL) {
121 BBOX_PRINT_ERR("logDir: %p, info: %p!\n", logDir, info);
122 return;
123 }
124 if (g_logBuffer == NULL) {
125 BBOX_PRINT_ERR("g_logBuffer is NULL, alloc physical pages failed!\n");
126 return;
127 }
128
129 if (strcmp(info->event, EVENT_PANIC) == 0) {
130 pLogInfo = (struct FaultLogInfo *)g_logBuffer;
131 (void)memset_s(pLogInfo, sizeof(*pLogInfo), 0, sizeof(*pLogInfo));
132#ifdef LOSCFG_SAVE_EXCINFO
133 pLogInfo->len = GetExcInfoIndex();
134#else
135 pLogInfo->len = 0;
136#endif
137 (void)memcpy_s(&pLogInfo->flag, sizeof(pLogInfo->flag), LOG_FLAG, strlen(LOG_FLAG));
138 (void)memcpy_s(&pLogInfo->info, sizeof(pLogInfo->info), info, sizeof(*info));
139 DCacheFlushRange((UINTPTR)g_logBuffer, (UINTPTR)(g_logBuffer + LOSCFG_BLACKBOX_LOG_SIZE));
140 } else {
141#ifdef LOSCFG_SAVE_EXCINFO
142 SaveFaultLog(USER_FAULT_LOG_PATH, g_logBuffer + sizeof(struct FaultLogInfo),
143 Min(LOSCFG_BLACKBOX_LOG_SIZE - sizeof(struct FaultLogInfo), GetExcInfoIndex()), info);
144#else
145 SaveFaultLog(USER_FAULT_LOG_PATH, g_logBuffer + sizeof(struct FaultLogInfo), 0, info);
146#endif
147 }
148}
static void SaveFaultLog(const char *filePath, const char *dataBuf, size_t bufSize, struct ErrorInfo *info)
UINT32 GetExcInfoIndex(VOID)
获取异常信息索引位
Definition: los_excinfo.c:74
VOID DCacheFlushRange(UINT32 start, UINT32 end)
Definition: los_hw.c:170
unsigned long UINTPTR
Definition: los_typedef.h:68
char event[EVENT_MAX_LEN]
Definition: los_blackbox.h:62
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
函数调用图:
这是这个函数的调用关系图:

◆ GetLastLogInfo()

static int GetLastLogInfo ( struct ErrorInfo info)
static

在文件 los_blackbox_system_adapter.c164 行定义.

165{
166 struct FaultLogInfo *pLogInfo = NULL;
167
168 if (info == NULL) {
169 BBOX_PRINT_ERR("info is NULL!\n");
170 return -1;
171 }
172 if (g_logBuffer == NULL) {
173 BBOX_PRINT_ERR("g_logBuffer is NULL, alloc physical pages failed!\n");
174 return -1;
175 }
176
177 pLogInfo = (struct FaultLogInfo *)g_logBuffer;
178 if (memcmp(pLogInfo->flag, LOG_FLAG, strlen(LOG_FLAG)) == 0) {
179 (void)memcpy_s(info, sizeof(*info), &pLogInfo->info, sizeof(pLogInfo->info));
180 return 0;
181 }
182
183 return -1;
184}
int memcmp(const void *str1, const void *str2, size_t n)
Definition: memcmp.c:37
函数调用图:
这是这个函数的调用关系图:

◆ LOS_MODULE_INIT()

LOS_MODULE_INIT ( OsBBoxSystemAdapterInit  ,
LOS_INIT_LEVEL_PLATFORM   
)

◆ OsBBoxSystemAdapterInit()

int OsBBoxSystemAdapterInit ( void  )

在文件 los_blackbox_system_adapter.c237 行定义.

238{
239 struct ModuleOps ops = {
240 .module = MODULE_SYSTEM,
241 .Dump = Dump,
242 .Reset = Reset,
243 .GetLastLogInfo = GetLastLogInfo,
244 .SaveLastLog = SaveLastLog,
245 };
246
247 /* allocate buffer for kmsg */
248 if (AllocLogBuffer() == 0) {
250 if (BBoxRegisterModuleOps(&ops) != 0) {
251 BBOX_PRINT_ERR("BBoxRegisterModuleOps failed!\n");
252 g_logBuffer = NULL;
253 return LOS_NOK;
254 }
255 } else {
256 BBOX_PRINT_ERR("AllocLogBuffer failed!\n");
257 }
258
259#ifdef LOSCFG_BLACKBOX_TEST
260 BBoxTest();
261#endif
262
263 return LOS_OK;
264}
static int SaveLastLog(const char *logDir, struct ErrorInfo *info)
static int AllocLogBuffer(void)
static void BBoxTest(void)
static void Reset(struct ErrorInfo *info)
static void Dump(const char *logDir, struct ErrorInfo *info)
static int GetLastLogInfo(struct ErrorInfo *info)
static void RegisterExcInfoHook(void)
函数调用图:

◆ RegisterExcInfoHook()

static void RegisterExcInfoHook ( void  )
static

在文件 los_blackbox_system_adapter.c84 行定义.

85{
86 if (g_logBuffer != NULL) {
87#ifdef LOSCFG_SAVE_EXCINFO
88 LOS_ExcInfoRegHook(0, LOSCFG_BLACKBOX_LOG_SIZE - sizeof(struct FaultLogInfo),
89 g_logBuffer + sizeof(struct FaultLogInfo), WriteExcFile);
90#endif
91 } else {
92 BBOX_PRINT_ERR("Alloc mem failed!\n");
93 }
94}
VOID LOS_ExcInfoRegHook(UINT32 startAddr, UINT32 space, CHAR *buf, log_read_write_fn hook)
Register recording exception information function.
Definition: los_excinfo.c:122
static void WriteExcFile(UINT32 startAddr, UINT32 space, UINT32 rwFlag, char *buf)
函数调用图:
这是这个函数的调用关系图:

◆ Reset()

static void Reset ( struct ErrorInfo info)
static

在文件 los_blackbox_system_adapter.c150 行定义.

151{
152 if (info == NULL) {
153 BBOX_PRINT_ERR("info is NULL!\n");
154 return;
155 }
156
157 if (strcmp(info->event, EVENT_PANIC) != 0) {
158 BBOX_PRINT_INFO("[%s] starts uploading event [%s]\n", info->module, info->event);
159 (void)UploadEventByFile(USER_FAULT_LOG_PATH);
160 BBOX_PRINT_INFO("[%s] ends uploading event [%s]\n", info->module, info->event);
161 }
162}
int UploadEventByFile(const char *filePath)
char module[MODULE_MAX_LEN]
Definition: los_blackbox.h:63
函数调用图:
这是这个函数的调用关系图:

◆ SaveFaultLog()

static void SaveFaultLog ( const char *  filePath,
const char *  dataBuf,
size_t  bufSize,
struct ErrorInfo info 
)
static

在文件 los_blackbox_system_adapter.c68 行定义.

69{
70 (void)SaveBasicErrorInfo(filePath, info);
71 (void)FullWriteFile(filePath, dataBuf, bufSize, 1);
72}
int FullWriteFile(const char *filePath, const char *buf, size_t bufSize, int isAppend)
int SaveBasicErrorInfo(const char *filePath, const struct ErrorInfo *info)
函数调用图:
这是这个函数的调用关系图:

◆ SaveLastLog()

static int SaveLastLog ( const char *  logDir,
struct ErrorInfo info 
)
static

在文件 los_blackbox_system_adapter.c186 行定义.

187{
188#ifdef LOSCFG_FS_VFS
189 struct FaultLogInfo *pLogInfo = NULL;
190
191 if (logDir == NULL || info == NULL) {
192 BBOX_PRINT_ERR("logDir: %p, info: %p!\n", logDir, info);
193 return -1;
194 }
195 if (g_logBuffer == NULL) {
196 BBOX_PRINT_ERR("g_logBuffer is NULL, alloc physical pages failed!\n");
197 return -1;
198 }
199
200 pLogInfo = (struct FaultLogInfo *)g_logBuffer;
201 if (memcmp(pLogInfo->flag, LOG_FLAG, strlen(LOG_FLAG)) == 0) {
202 SaveFaultLog(KERNEL_FAULT_LOG_PATH, g_logBuffer + sizeof(*pLogInfo),
203 Min(LOSCFG_BLACKBOX_LOG_SIZE - sizeof(*pLogInfo), pLogInfo->len), info);
204 }
205 (void)memset_s(g_logBuffer, LOSCFG_BLACKBOX_LOG_SIZE, 0, LOSCFG_BLACKBOX_LOG_SIZE);
206 BBOX_PRINT_INFO("[%s] starts uploading event [%s]\n", info->module, info->event);
207 (void)UploadEventByFile(KERNEL_FAULT_LOG_PATH);
208 BBOX_PRINT_INFO("[%s] ends uploading event [%s]\n", info->module, info->event);
209 return 0;
210#else
211 (VOID)logDir;
212 (VOID)info;
213 BBOX_PRINT_ERR("LOSCFG_FS_VFS isn't defined!\n");
214 return -1;
215#endif
216}
函数调用图:
这是这个函数的调用关系图:

◆ WriteExcFile()

static void WriteExcFile ( UINT32  startAddr,
UINT32  space,
UINT32  rwFlag,
char *  buf 
)
static

在文件 los_blackbox_system_adapter.c75 行定义.

76{
77 (void)startAddr;
78 (void)space;
79 (void)rwFlag;
80 (void)buf;
81}
这是这个函数的调用关系图:

变量说明

◆ g_logBuffer

char* g_logBuffer = NULL
static

在文件 los_blackbox_system_adapter.c65 行定义.