BBSRAM: add another partition and store the last ulog path

This commit is contained in:
Beat Küng 2017-07-03 18:02:27 +02:00 committed by Lorenz Meier
parent 18ea5ec1f8
commit 1be089cf0c
15 changed files with 102 additions and 33 deletions

View File

@ -428,7 +428,7 @@ CONFIG_STM32_I2CTIMEOMS=10
CONFIG_STM32_I2CTIMEOTICKS=10
# CONFIG_STM32_I2C_DUTY16_9 is not set
# CONFIG_STM32_BBSRAM is not set
CONFIG_STM32_BBSRAM_FILES=4
CONFIG_STM32_BBSRAM_FILES=5
# CONFIG_STM32_SAVE_CRASHDUMP is not set
# CONFIG_STM32_HAVE_RTC_COUNTER is not set
# CONFIG_STM32_HAVE_RTC_SUBSECONDS is not set

View File

@ -529,7 +529,7 @@ CONFIG_STM32_I2CTIMEOMS=10
CONFIG_STM32_I2CTIMEOTICKS=10
# CONFIG_STM32_I2C_DUTY16_9 is not set
# CONFIG_STM32_BBSRAM is not set
CONFIG_STM32_BBSRAM_FILES=4
CONFIG_STM32_BBSRAM_FILES=5
# CONFIG_STM32_SAVE_CRASHDUMP is not set
# CONFIG_STM32_HAVE_RTC_COUNTER is not set
# CONFIG_STM32_HAVE_RTC_SUBSECONDS is not set

View File

@ -542,7 +542,7 @@ CONFIG_STM32_I2CTIMEOTICKS=10
#
CONFIG_SDIO_DMAPRIO=0x00010000
CONFIG_STM32_BBSRAM=y
CONFIG_STM32_BBSRAM_FILES=4
CONFIG_STM32_BBSRAM_FILES=5
CONFIG_STM32_SAVE_CRASHDUMP=y
# CONFIG_STM32_HAVE_RTC_COUNTER is not set
# CONFIG_STM32_HAVE_RTC_SUBSECONDS is not set

View File

@ -507,7 +507,7 @@ CONFIG_STM32_I2CTIMEOMS=10
CONFIG_STM32_I2CTIMEOTICKS=10
# CONFIG_STM32_I2C_DUTY16_9 is not set
CONFIG_STM32_BBSRAM=y
CONFIG_STM32_BBSRAM_FILES=4
CONFIG_STM32_BBSRAM_FILES=5
CONFIG_STM32_SAVE_CRASHDUMP=y
# CONFIG_STM32_HAVE_RTC_COUNTER is not set
# CONFIG_STM32_HAVE_RTC_SUBSECONDS is not set

View File

@ -551,7 +551,7 @@ CONFIG_STM32_I2CTIMEOTICKS=10
#
CONFIG_SDIO_DMAPRIO=0x00010000
CONFIG_STM32_BBSRAM=y
CONFIG_STM32_BBSRAM_FILES=4
CONFIG_STM32_BBSRAM_FILES=5
CONFIG_STM32_SAVE_CRASHDUMP=y
# CONFIG_STM32_HAVE_RTC_COUNTER is not set
# CONFIG_STM32_HAVE_RTC_SUBSECONDS is not set

View File

@ -518,7 +518,7 @@ CONFIG_STM32_I2CTIMEOMS=10
CONFIG_STM32_I2CTIMEOTICKS=10
# CONFIG_STM32_I2C_DUTY16_9 is not set
CONFIG_STM32_BBSRAM=y
CONFIG_STM32_BBSRAM_FILES=4
CONFIG_STM32_BBSRAM_FILES=5
CONFIG_STM32_SAVE_CRASHDUMP=y
# CONFIG_STM32_HAVE_RTC_COUNTER is not set
# CONFIG_STM32_HAVE_RTC_SUBSECONDS is not set

View File

@ -517,7 +517,7 @@ CONFIG_STM32_I2CTIMEOMS=10
CONFIG_STM32_I2CTIMEOTICKS=10
# CONFIG_STM32_I2C_DUTY16_9 is not set
# CONFIG_STM32_BBSRAM is not set
CONFIG_STM32_BBSRAM_FILES=4
CONFIG_STM32_BBSRAM_FILES=5
# CONFIG_STM32_SAVE_CRASHDUMP is not set
# CONFIG_STM32_HAVE_RTC_COUNTER is not set
# CONFIG_STM32_HAVE_RTC_SUBSECONDS is not set

View File

@ -542,7 +542,7 @@ CONFIG_STM32_I2CTIMEOTICKS=10
#
CONFIG_SDIO_DMAPRIO=0x00010000
CONFIG_STM32_BBSRAM=y
CONFIG_STM32_BBSRAM_FILES=4
CONFIG_STM32_BBSRAM_FILES=5
CONFIG_STM32_SAVE_CRASHDUMP=y
# CONFIG_STM32_HAVE_RTC_COUNTER is not set
# CONFIG_STM32_HAVE_RTC_SUBSECONDS is not set

View File

@ -542,7 +542,7 @@ CONFIG_STM32_I2CTIMEOTICKS=10
#
CONFIG_SDIO_DMAPRIO=0x00010000
CONFIG_STM32_BBSRAM=y
CONFIG_STM32_BBSRAM_FILES=4
CONFIG_STM32_BBSRAM_FILES=5
CONFIG_STM32_SAVE_CRASHDUMP=y
# CONFIG_STM32_HAVE_RTC_COUNTER is not set
# CONFIG_STM32_HAVE_RTC_SUBSECONDS is not set

View File

@ -535,7 +535,7 @@ CONFIG_STM32_I2CTIMEOTICKS=10
#
CONFIG_SDIO_DMAPRIO=0x00010000
CONFIG_STM32_BBSRAM=y
CONFIG_STM32_BBSRAM_FILES=4
CONFIG_STM32_BBSRAM_FILES=5
CONFIG_STM32_SAVE_CRASHDUMP=y
# CONFIG_STM32_HAVE_RTC_COUNTER is not set
# CONFIG_STM32_HAVE_RTC_SUBSECONDS is not set

View File

@ -546,7 +546,7 @@ CONFIG_STM32_I2CTIMEOTICKS=10
#
CONFIG_SDIO_DMAPRIO=0x00010000
CONFIG_STM32_BBSRAM=y
CONFIG_STM32_BBSRAM_FILES=4
CONFIG_STM32_BBSRAM_FILES=5
CONFIG_STM32_SAVE_CRASHDUMP=y
# CONFIG_STM32_HAVE_RTC_COUNTER is not set
# CONFIG_STM32_HAVE_RTC_SUBSECONDS is not set

View File

@ -524,7 +524,7 @@ CONFIG_STM32_I2CTIMEOMS=10
CONFIG_STM32_I2CTIMEOTICKS=10
# CONFIG_STM32_I2C_DUTY16_9 is not set
CONFIG_STM32_BBSRAM=y
CONFIG_STM32_BBSRAM_FILES=4
CONFIG_STM32_BBSRAM_FILES=5
CONFIG_STM32_SAVE_CRASHDUMP=y
# CONFIG_STM32_HAVE_RTC_COUNTER is not set
# CONFIG_STM32_HAVE_RTC_SUBSECONDS is not set

View File

@ -38,6 +38,9 @@
#include <mathlib/mathlib.h>
#include <px4_posix.h>
#ifdef __PX4_NUTTX
#include <systemlib/hardfault_log.h>
#endif /* __PX4_NUTTX */
namespace px4
{
@ -87,26 +90,37 @@ void LogWriterFile::start_log(const char *filename)
PX4_ERR("Can't open log file %s, errno: %d", filename, errno);
_should_run = false;
return;
}
} else {
if (_buffer == nullptr) {
_buffer = new uint8_t[_buffer_size];
if (_buffer == nullptr) {
_buffer = new uint8_t[_buffer_size];
if (_buffer == nullptr) {
PX4_ERR("Can't create log buffer");
::close(_fd);
_fd = -1;
_should_run = false;
return;
}
PX4_ERR("Can't create log buffer");
::close(_fd);
_fd = -1;
_should_run = false;
return;
}
PX4_INFO("Opened log file: %s", filename);
_should_run = true;
_running = true;
}
#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);
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;
_running = true;
// Clear buffer and counters
_head = 0;
_count = 0;

View File

@ -37,20 +37,25 @@
****************************************************************************/
#include <systemlib/px4_macros.h>
#include <stm32_bbsram.h>
#include <board_config.h>
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#define HARDFAULT_FILENO 3
#define HARDFAULT_PATH BBSRAM_PATH""STRINGIFY(HARDFAULT_FILENO)
#define HARDFAULT_REBOOT_FILENO 0
#define HARDFAULT_REBOOT_PATH BBSRAM_PATH""STRINGIFY(HARDFAULT_REBOOT_FILENO)
#define HARDFAULT_REBOOT_PATH BBSRAM_PATH "" STRINGIFY(HARDFAULT_REBOOT_FILENO)
#define HARDFAULT_ULOG_FILENO 3
#define HARDFAULT_ULOG_PATH BBSRAM_PATH "" STRINGIFY(HARDFAULT_ULOG_FILENO)
#define HARDFAULT_FILENO 4
#define HARDFAULT_PATH BBSRAM_PATH "" STRINGIFY(HARDFAULT_FILENO)
#define HARDFAULT_MAX_ULOG_FILE_LEN 64 /* must be large enough to store the full path to the log file */
#define BBSRAM_SIZE_FN0 (sizeof(int))
#define BBSRAM_SIZE_FN1 384 /* greater then 2.5 times the size of vehicle_status_s */
#define BBSRAM_SIZE_FN2 384 /* greater then 2.5 times the size of vehicle_status_s */
#define BBSRAM_SIZE_FN3 -1
#define BBSRAM_SIZE_FN3 HARDFAULT_MAX_ULOG_FILE_LEN
#define BBSRAM_SIZE_FN4 -1
/* The following guides in the amount of the user and interrupt stack
* data we can save. The amount of storage left will dictate the actual
@ -58,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))
#define BBSRAM_USED ((4*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
@ -77,8 +82,9 @@
#define BSRAM_FILE_SIZES { \
BBSRAM_SIZE_FN0, /* For Time stamp only */ \
BBSRAM_SIZE_FN1, /* For Current Flight Parameters Copy A */ \
BBSRAM_SIZE_FN2, /* For Current Flight Parameters Copy B*/ \
BBSRAM_SIZE_FN3, /* For the Panic Log use rest of space */ \
BBSRAM_SIZE_FN2, /* For Current Flight Parameters Copy B */ \
BBSRAM_SIZE_FN3, /* For the latest ULog file path */ \
BBSRAM_SIZE_FN4, /* For the Panic Log use rest of space */ \
0 /* End of table marker */ \
}
@ -350,4 +356,24 @@ 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

View File

@ -910,6 +910,35 @@ __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
****************************************************************************/