Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions lib/libc/stdio/lib_lowoutstream.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@

#include "lib_internal.h"

#ifdef CONFIG_LOWLOG_DUMP
#include <tinyara/log_dump/lowlog_dump.h>
#endif
/****************************************************************************
* Private Functions
****************************************************************************/
Expand All @@ -76,6 +79,9 @@
static void lowoutstream_putc(FAR struct lib_outstream_s *this, int ch)
{
DEBUGASSERT(this);
#if defined(__KERNEL__) && defined(CONFIG_LOWLOG_DUMP)
lowlog_dump_save_ch(ch);
#endif
#if defined(CONFIG_BUILD_FLAT) || (defined(CONFIG_BUILD_PROTECTED) && defined(__KERNEL__))
if (up_putc(ch) != EOF) {
this->nput++;
Expand Down
4 changes: 4 additions & 0 deletions os/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,10 @@ menu "Binary manager"
source kernel/binary_manager/Kconfig
endmenu

menu "Lowlog dump"
source kernel/log_dump/Kconfig
endmenu

menu "Task Monitor"
source kernel/task_monitor/Kconfig
endmenu
Expand Down
66 changes: 66 additions & 0 deletions os/include/tinyara/log_dump/lowlog_dump.h
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
10 changes: 10 additions & 0 deletions os/kernel/binary_manager/binary_manager_recovery.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
****************************************************************************/
Expand Down Expand Up @@ -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);
Copy link
Contributor

@ewoodev ewoodev Aug 25, 2025

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.

/* Do not overwrite reboot reason here */ 
boardctl(BOARDIOC_RESET, EXIT_SUCCESS);

#endif
#endif
/* Create loader to reload binary */
ret = binary_manager_execute_loader(LOADCMD_RELOAD, bin_idx);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need to make option to system reboot here.

Expand Down
50 changes: 50 additions & 0 deletions os/kernel/log_dump/Kconfig
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

7 changes: 7 additions & 0 deletions os/kernel/log_dump/Make.defs
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,10 @@ DEPPATH += --dep-path log_dump
VPATH += :log_dump

endif

ifeq ($(CONFIG_LOWLOG_DUMP),y)

CSRCS += lowlog_dump_read.c lowlog_dump_ch.c lowlog_dump_save.c
CSRCS += lowlog_dump_resume.c lowlog_dump_pause.c

endif # CONFIG_LOWLOG_DUMP
71 changes: 71 additions & 0 deletions os/kernel/log_dump/lowlog_dump.h
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
Copy link
Contributor

Choose a reason for hiding this comment

The 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 */
104 changes: 104 additions & 0 deletions os/kernel/log_dump/lowlog_dump_ch.c
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
Copy link
Contributor

Choose a reason for hiding this comment

The 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.
this is because we need to call the start function to all asset occurrence codes in order to turn on log storage in case of asset occurrence.

However, for this to work properly, the g_lowlog buffer must be implemented as a ring buffer.
This is already full due to boot log, so it will not be able to save the assert log.

Suggested change
if (lowlog_dump_get_store_flag() && g_lowlog_index < CONFIG_LOWLOG_DUMP_BUF_SIZE) {
g_lowlog[g_lowlog_index++] = ch;
}
if (lowlog_dump_get_store_flag()) {
g_lowlog[g_lowlog_tail] = ch;
g_lowlog_tail = (g_lowlog_tail + 1) & BUFFER_MASK;
if (g_lowlog_tail == g_lowlog_head) {
g_lowlog_head = (g_lowlog_head + 1) & BUFFER_MASK;
}
}

}

Loading