-
Notifications
You must be signed in to change notification settings - Fork 618
os/kernel/crashlog_writer: Add crash log flash save #6899
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
319bc2f
ebd15e6
ce9c49f
5abfde1
6f83078
e424bf6
c618e14
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| /**************************************************************************** | ||
| * | ||
| * Copyright 2025 Samsung Electronics All Rights Reserved. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, | ||
| * either express or implied. See the License for the specific | ||
| * language governing permissions and limitations under the License. | ||
| * | ||
| ****************************************************************************/ | ||
|
|
||
| #ifndef __LOWLOG_DUMP_H__ | ||
| #define __LOWLOG_DUMP_H__ | ||
|
|
||
| /**************************************************************************** | ||
| * Included Files | ||
| ****************************************************************************/ | ||
| /************************************************************************************* | ||
| * Description: | ||
| * resume saving lldbg to buf. | ||
| * | ||
| *************************************************************************************/ | ||
| void lowlog_dump_resume(void); | ||
|
|
||
| /************************************************************************************* | ||
| * Description: | ||
| * pause saving lldbg to buf. | ||
| * | ||
| *************************************************************************************/ | ||
| void lowlog_dump_pause(void); | ||
|
|
||
| /**************************************************************************** | ||
| * Description: | ||
| * This is used to store logs that are output via lldbg() during a user crash situation into a buffer. | ||
| * | ||
| ****************************************************************************/ | ||
| void lowlog_dump_save_ch(char ch); | ||
|
|
||
| /**************************************************************************** | ||
| * Description: | ||
| * Saves the crash log to a file. | ||
| * | ||
| ****************************************************************************/ | ||
| int lowlog_dump_save(); | ||
|
|
||
| /************************************************************************************* | ||
| * Description: | ||
| * Reads a log from a file and stores it in a buffer. If the log is compresed, it is | ||
| * decompressed before being stored. | ||
| *************************************************************************************/ | ||
| int lowlog_dump_read(char *filename, char *buf, int buf_size); | ||
|
|
||
| /************************************************************************************* | ||
| * Description: | ||
| * Reads the most recent log from a file and stores it in a buffer. If the log is compresed, it is | ||
| * decompressed before being stored. | ||
| *************************************************************************************/ | ||
| int lowlog_dump_read_recent(char *buf, int buf_size); | ||
| #endif |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -42,6 +42,10 @@ | |
| #include "semaphore/semaphore.h" | ||
| #include "binary_manager_internal.h" | ||
|
|
||
| #ifdef CONFIG_LOWLOG_DUMP | ||
| #include <tinyara/log_dump/lowlog_dump.h> | ||
| #endif | ||
|
|
||
| /**************************************************************************** | ||
| * Pre-processor Definitions | ||
| ****************************************************************************/ | ||
|
|
@@ -345,6 +349,12 @@ void binary_manager_recovery(int bin_idx) | |
| bmlldbg("Failed to deactivate binary, bin idx %d\n", bin_idx); | ||
| goto reboot_board; | ||
| } | ||
| #endif | ||
| #ifdef CONFIG_LOWLOG_DUMP | ||
| lowlog_dump_save(); | ||
| #ifdef CONFIG_LOWLOG_DUMP_REBOOT | ||
| binary_manager_reset_board(REBOOT_SYSTEM_BINARY_RECOVERYFAIL); | ||
| #endif | ||
| #endif | ||
| /* Create loader to reload binary */ | ||
| ret = binary_manager_execute_loader(LOADCMD_RELOAD, bin_idx); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we need to make option to system reboot here. |
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| # | ||
| # For a description of the syntax of this configuration file, | ||
| # see kconfig-language at https://www.kernel.org/doc/Documentation/kbuild/kconfig-language.txt | ||
| # | ||
|
|
||
|
|
||
| config LOWLOG_DUMP | ||
| bool "enable lowlog dump" | ||
| default n | ||
| depends on BINMGR_RECOVERY | ||
| ---help--- | ||
| This saves the lowlog. | ||
|
|
||
| if LOWLOG_DUMP | ||
|
|
||
| config LOWLOG_DUMP_COMPRESS | ||
| bool "LOWLOG_DUMP_COMPRESS" | ||
| default y | ||
| ---help--- | ||
| Controls whether compression is applied. | ||
| if the value is n compression is not performed. | ||
|
|
||
|
|
||
| config LOWLOG_DUMP_BUF_SIZE | ||
| int "LOWLOG_DUMP_BUF_SIZE" | ||
| default 8192 | ||
| ---help--- | ||
| Determines the size of the buffer where crash logs will be stored. | ||
| The low log is stored in the data section. | ||
|
|
||
| config LOWLOG_DUMP_REBOOT | ||
| bool "REBOOT_AFTER_SAVING_LOG" | ||
| default y | ||
| ---help--- | ||
| Determines whether to reboot after saving the low log. | ||
|
|
||
| config LOWLOG_DUMP_MAX_FILES | ||
| int "LOWLOG_DUMP_MAX_FILES" | ||
| default 5 | ||
| ---help--- | ||
| Determine the maximum number of low log files to be stored. | ||
|
|
||
| config LOWLOG_DUMP_RECORD_TIME | ||
| bool "LOWLOG_DUMP_RECORD_TIME" | ||
| default n | ||
| ---help--- | ||
| Measure and record the time it takes to save the crash log to a file. | ||
|
|
||
| endif # LOWLOG_DUMP | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| /**************************************************************************** | ||
| * | ||
| * Copyright 2025 Samsung Electronics All Rights Reserved. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, | ||
| * either express or implied. See the License for the specific | ||
| * language governing permissions and limitations under the License. | ||
| * | ||
| ****************************************************************************/ | ||
|
|
||
| #ifndef __SCHED_LOWLOG_DUMP_H | ||
| #define __SCHED_LOWLOG_DUMP_H | ||
|
|
||
| /**************************************************************************** | ||
| * Included Files | ||
| ****************************************************************************/ | ||
|
|
||
| #include <tinyara/config.h> | ||
|
|
||
| #ifdef CONFIG_LOWLOG_DUMP | ||
|
|
||
| #include <stdint.h> | ||
| #include <stdlib.h> | ||
| #include <unistd.h> | ||
| #include <string.h> | ||
| #include <errno.h> | ||
| #include <debug.h> | ||
|
Comment on lines
+30
to
+35
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please remove unnecessary including header |
||
|
|
||
| #include <tinyara/clock.h> | ||
| #include <tinyara/log_dump/lowlog_dump.h> | ||
| #include <dirent.h> | ||
| #include <ctype.h> | ||
| #include <fcntl.h> | ||
|
|
||
| /**************************************************************************** | ||
| * Pre-processor Definitions | ||
| ****************************************************************************/ | ||
| #define DIR_PATH "/mnt/lowlog_dump" | ||
| #define MAX_FILENAME_LEN 64 | ||
| #define PRE_FILENAME_UNCOMP "lowlog_dump" | ||
| #define PRE_FILENAME_COMP "lowlog_dump_comp" | ||
| #define REQUIRED_HEAP_FOR_COMPRESS 400000 | ||
| /**************************************************************************** | ||
| * Private Type Declarations | ||
| ****************************************************************************/ | ||
| typedef struct { | ||
| int number; | ||
| char name[MAX_FILENAME_LEN]; | ||
| } FileEntry; | ||
|
|
||
| /**************************************************************************** | ||
| * Function Prototypes | ||
| ****************************************************************************/ | ||
| void lowlog_dump_init(void); | ||
| void lowlog_dump_init_flag(void); | ||
| void lowlog_dump_init_buf(void); | ||
| char *lowlog_dump_get_buf(void); | ||
| int lowlog_dump_is_valid_filename(const char *name, int *out_number); | ||
| int lowlog_dump_get_size(void); | ||
| int lowlog_dump_set_store_flag(int flag); | ||
|
|
||
| #endif /* CONFIG_LOWLOG_DUMP */ | ||
| #endif /* __SCHED_LOWLOG_DUMP_H */ | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,104 @@ | ||||||||||||||||||||||||
| /**************************************************************************** | ||||||||||||||||||||||||
| * | ||||||||||||||||||||||||
| * Copyright 2025 Samsung Electronics All Rights Reserved. | ||||||||||||||||||||||||
| * | ||||||||||||||||||||||||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||||||||||||||||||||||||
| * you may not use this file except in compliance with the License. | ||||||||||||||||||||||||
| * You may obtain a copy of the License at | ||||||||||||||||||||||||
| * | ||||||||||||||||||||||||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||||||||||||||||||||||||
| * | ||||||||||||||||||||||||
| * Unless required by applicable law or agreed to in writing, | ||||||||||||||||||||||||
| * software distributed under the License is distributed on an | ||||||||||||||||||||||||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, | ||||||||||||||||||||||||
| * either express or implied. See the License for the specific | ||||||||||||||||||||||||
| * language governing permissions and limitations under the License. | ||||||||||||||||||||||||
| * | ||||||||||||||||||||||||
| ****************************************************************************/ | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| /**************************************************************************** | ||||||||||||||||||||||||
| * Included Files | ||||||||||||||||||||||||
| ****************************************************************************/ | ||||||||||||||||||||||||
| #include <tinyara/config.h> | ||||||||||||||||||||||||
| #include <tinyara/compression.h> | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| #include <stdint.h> | ||||||||||||||||||||||||
| #include <stdlib.h> | ||||||||||||||||||||||||
| #include <unistd.h> | ||||||||||||||||||||||||
| #include <string.h> | ||||||||||||||||||||||||
| #include <errno.h> | ||||||||||||||||||||||||
| #include <debug.h> | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| #include <tinyara/clock.h> | ||||||||||||||||||||||||
| #include "lowlog_dump.h" | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| /**************************************************************************** | ||||||||||||||||||||||||
| * Public Variables | ||||||||||||||||||||||||
| ****************************************************************************/ | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| /**************************************************************************** | ||||||||||||||||||||||||
| * Private Variables | ||||||||||||||||||||||||
| ****************************************************************************/ | ||||||||||||||||||||||||
| static char g_lowlog[CONFIG_LOWLOG_DUMP_BUF_SIZE]; | ||||||||||||||||||||||||
| int g_lowlog_index = 0; | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| /**************************************************************************** | ||||||||||||||||||||||||
| * Private Functions | ||||||||||||||||||||||||
| ****************************************************************************/ | ||||||||||||||||||||||||
| /************************************************************************************* | ||||||||||||||||||||||||
| * Name: lowlog_dump_get_size | ||||||||||||||||||||||||
| * | ||||||||||||||||||||||||
| * Description: | ||||||||||||||||||||||||
| * Gets the size (in bytes) of the log currently stored in the buffer. | ||||||||||||||||||||||||
| * | ||||||||||||||||||||||||
| *************************************************************************************/ | ||||||||||||||||||||||||
| int lowlog_dump_get_size() | ||||||||||||||||||||||||
| { | ||||||||||||||||||||||||
| return g_lowlog_index; | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| /************************************************************************************* | ||||||||||||||||||||||||
| * Name: lowlog_dump_init_buf | ||||||||||||||||||||||||
| * | ||||||||||||||||||||||||
| * Description: | ||||||||||||||||||||||||
| * init global buf | ||||||||||||||||||||||||
| * | ||||||||||||||||||||||||
| *************************************************************************************/ | ||||||||||||||||||||||||
| //TODO : It may be necessary to remove this function. | ||||||||||||||||||||||||
| void lowlog_dump_init_buf() | ||||||||||||||||||||||||
| { | ||||||||||||||||||||||||
| for (int i = 0; i < CONFIG_LOWLOG_DUMP_BUF_SIZE; i++) { | ||||||||||||||||||||||||
| g_lowlog[i] = '\0'; | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| g_lowlog_index = 0; | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| /************************************************************************************* | ||||||||||||||||||||||||
| * Name: lowlog_dump_get_buf | ||||||||||||||||||||||||
| * | ||||||||||||||||||||||||
| * Description: | ||||||||||||||||||||||||
| * return lowlog buf | ||||||||||||||||||||||||
| * | ||||||||||||||||||||||||
| *************************************************************************************/ | ||||||||||||||||||||||||
| char *lowlog_dump_get_buf() | ||||||||||||||||||||||||
| { | ||||||||||||||||||||||||
| return g_lowlog; | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| /**************************************************************************** | ||||||||||||||||||||||||
| * Public Functions | ||||||||||||||||||||||||
| ****************************************************************************/ | ||||||||||||||||||||||||
| /************************************************************************************* | ||||||||||||||||||||||||
| * Name: crashlog_writer_crashlog_to_buffer | ||||||||||||||||||||||||
| * | ||||||||||||||||||||||||
| * Description: | ||||||||||||||||||||||||
| * Stores the crash log into the buffer. | ||||||||||||||||||||||||
| * This is used to store logs that are output via lldbg() during a user crash situation into a buffer. | ||||||||||||||||||||||||
| *************************************************************************************/ | ||||||||||||||||||||||||
| void lowlog_dump_save_ch(char ch) | ||||||||||||||||||||||||
| { | ||||||||||||||||||||||||
| if (lowlog_dump_get_store_flag() && g_lowlog_index < CONFIG_LOWLOG_DUMP_BUF_SIZE) { | ||||||||||||||||||||||||
| g_lowlog[g_lowlog_index++] = ch; | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
Comment on lines
+100
to
+102
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the previous review, we decided to turn on the log save from the start of booting. However, for this to work properly, the g_lowlog buffer must be implemented as a ring buffer.
Suggested change
|
||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reboot Reason should not be overwritten here.
in the time, we already writed reason reason about cause of crash.