mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-04-29 13:04:07 +08:00
hardfault_log: move hardfault_store_ulog_filename to logger module
This commit is contained in:
parent
eac657f4b3
commit
209f220288
@ -104,18 +104,16 @@ void LogWriterFile::start_log(const char *filename)
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef __PX4_NUTTX
|
||||
// register the current file with the hardfault handler: if the system crashes,
|
||||
// the hardfault handler will append the crash log to that file on the next reboot.
|
||||
// Note that we don't deregister it when closing the log, so that crashes after disarming
|
||||
// are appended as well (the same holds for crashes before arming, which can be a bit misleading)
|
||||
int ret = hardfault_store_ulog_filename(filename);
|
||||
int ret = hardfault_store_filename(filename);
|
||||
|
||||
if (ret) {
|
||||
PX4_ERR("Failed to register ULog file to the hardfault handler (%i)", ret);
|
||||
}
|
||||
|
||||
#endif /* __PX4_NUTTX */
|
||||
|
||||
PX4_INFO("Opened log file: %s", filename);
|
||||
_should_run = true;
|
||||
@ -128,6 +126,38 @@ void LogWriterFile::start_log(const char *filename)
|
||||
notify();
|
||||
}
|
||||
|
||||
int LogWriterFile::hardfault_store_filename(const char *log_file)
|
||||
{
|
||||
#ifdef __PX4_NUTTX
|
||||
int fd = open(HARDFAULT_ULOG_PATH, O_TRUNC | O_WRONLY | O_CREAT);
|
||||
|
||||
if (fd < 0) {
|
||||
return -errno;
|
||||
}
|
||||
|
||||
int n = strlen(log_file);
|
||||
|
||||
if (n >= HARDFAULT_MAX_ULOG_FILE_LEN) {
|
||||
PX4_ERR("ULog file name too long (%s, %i>=%i)\n", log_file, n, HARDFAULT_MAX_ULOG_FILE_LEN);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (n + 1 != ::write(fd, log_file, n + 1)) {
|
||||
close(fd);
|
||||
return -errno;
|
||||
}
|
||||
|
||||
int ret = close(fd);
|
||||
|
||||
if (ret != 0) {
|
||||
return -errno;
|
||||
}
|
||||
|
||||
#endif /* __PX4_NUTTX */
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void LogWriterFile::stop_log()
|
||||
{
|
||||
_should_run = false;
|
||||
|
||||
@ -125,6 +125,14 @@ private:
|
||||
_count -= n;
|
||||
}
|
||||
|
||||
/**
|
||||
* permanently store the ulog file name for the hardfault crash handler, so that it can
|
||||
* append crash logs to the last ulog file.
|
||||
* @param log_file path to the log file
|
||||
* @return 0 on success, <0 errno otherwise
|
||||
*/
|
||||
int hardfault_store_filename(const char *log_file);
|
||||
|
||||
/**
|
||||
* write w/o waiting/blocking
|
||||
*/
|
||||
|
||||
@ -63,7 +63,7 @@
|
||||
* It will be truncated by the call to stm32_bbsram_savepanic
|
||||
*/
|
||||
#define BBSRAM_HEADER_SIZE 20 /* This is an assumption */
|
||||
#define BBSRAM_USED ((4*BBSRAM_HEADER_SIZE)+(BBSRAM_SIZE_FN0+BBSRAM_SIZE_FN1+BBSRAM_SIZE_FN2+BBSRAM_SIZE_FN3))
|
||||
#define BBSRAM_USED ((5*BBSRAM_HEADER_SIZE)+(BBSRAM_SIZE_FN0+BBSRAM_SIZE_FN1+BBSRAM_SIZE_FN2+BBSRAM_SIZE_FN3))
|
||||
#define BBSRAM_REAMINING (PX4_BBSRAM_SIZE-BBSRAM_USED)
|
||||
#if CONFIG_ARCH_INTERRUPTSTACK <= 3
|
||||
# define BBSRAM_NUMBER_STACKS 1
|
||||
@ -356,24 +356,4 @@ int hardfault_rearm(char *caller) weak_function;
|
||||
****************************************************************************/
|
||||
int hardfault_increment_reboot(char *caller, bool reset) weak_function;
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* Name: hardfault_store_ulog_filename
|
||||
*
|
||||
* Description:
|
||||
* Permanently store the current ulog file name. A crash dump will
|
||||
* be appended to this file (must be ULog).
|
||||
*
|
||||
*
|
||||
* Inputs:
|
||||
* - log_file: full path to the log file
|
||||
*
|
||||
* Returned Value:
|
||||
*
|
||||
* OK or errno
|
||||
*
|
||||
*
|
||||
****************************************************************************/
|
||||
int hardfault_store_ulog_filename(const char *log_file);
|
||||
|
||||
__END_DECLS
|
||||
|
||||
@ -583,7 +583,7 @@ static int write_user_stack(int fdin, int fdout, info_s *pi, char *buffer,
|
||||
}
|
||||
|
||||
/**
|
||||
* Append hardfault data to the stored ULog file (stored in BBSRAM).
|
||||
* Append hardfault data to the stored ULog file (the log path is stored in BBSRAM).
|
||||
* @param caller
|
||||
* @param fdin file descriptor for plain-text hardhault log to read from
|
||||
* @return 0 on success, -errno otherwise
|
||||
@ -609,6 +609,7 @@ static int hardfault_append_to_ulog(const char *caller, int fdin)
|
||||
}
|
||||
|
||||
if (read(fd, ulog_file_name, HARDFAULT_MAX_ULOG_FILE_LEN) != HARDFAULT_MAX_ULOG_FILE_LEN) {
|
||||
close(fd);
|
||||
return -errno;
|
||||
}
|
||||
|
||||
@ -1121,35 +1122,6 @@ __EXPORT int hardfault_write(char *caller, int fd, int format, bool rearm)
|
||||
return ret;
|
||||
}
|
||||
|
||||
int hardfault_store_ulog_filename(const char *log_file)
|
||||
{
|
||||
int fd = open(HARDFAULT_ULOG_PATH, O_TRUNC | O_WRONLY | O_CREAT);
|
||||
|
||||
if (fd < 0) {
|
||||
return -errno;
|
||||
}
|
||||
|
||||
int n = strlen(log_file);
|
||||
|
||||
if (n >= HARDFAULT_MAX_ULOG_FILE_LEN) {
|
||||
syslog(LOG_INFO, "ULog file name too long (%s, %i>=%i)\n", log_file, n, HARDFAULT_MAX_ULOG_FILE_LEN);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (n + 1 != write(fd, log_file, n + 1)) {
|
||||
close(fd);
|
||||
return -errno;
|
||||
}
|
||||
|
||||
int ret = close(fd);
|
||||
|
||||
if (ret != 0) {
|
||||
return -errno;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: hardfault_log_main
|
||||
****************************************************************************/
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user