mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-15 23:53:33 +08:00
Add hardfault log progmem flash backend
This commit is contained in:
committed by
Daniel Agar
parent
ca9ae80b10
commit
fa87375d0c
@@ -36,11 +36,18 @@
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
#include <px4_platform_common/px4_config.h>
|
||||
#include <px4_arch/micro_hal.h>
|
||||
#include <systemlib/px4_macros.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
#if defined(HAS_BBSRAM)
|
||||
|
||||
#include <stm32_bbsram.h>
|
||||
typedef struct bbsramd_s dump_s;
|
||||
|
||||
#define HARDFAULT_REBOOT_FILENO 0
|
||||
#define HARDFAULT_REBOOT_PATH BBSRAM_PATH "" STRINGIFY(HARDFAULT_REBOOT_FILENO)
|
||||
#define HARDFAULT_ULOG_FILENO 3
|
||||
@@ -86,6 +93,66 @@
|
||||
BBSRAM_SIZE_FN4, /* For the Panic Log use rest of space */ \
|
||||
0 /* End of table marker */ \
|
||||
}
|
||||
#elif defined(HAS_PROGMEM)
|
||||
|
||||
typedef struct progmem_s dump_s;
|
||||
|
||||
#if CONFIG_ARCH_INTERRUPTSTACK <= 3
|
||||
# define PROGMEM_NUMBER_STACKS 1
|
||||
#else
|
||||
# define PROGMEM_NUMBER_STACKS 2
|
||||
#endif
|
||||
#define PROGMEM_DUMP_FIXED_ELEMENTS_SIZE (sizeof(info_s))
|
||||
#define PROGMEM_DUMP_LEFTOVER (PROGMEM_DUMP_STACK_SIZE-PROGMEM_DUMP_FIXED_ELEMENTS_SIZE)
|
||||
|
||||
#define CONFIG_ISTACK_SIZE (PROGMEM_DUMP_LEFTOVER/PROGMEM_NUMBER_STACKS/sizeof(stack_word_t))
|
||||
#define CONFIG_USTACK_SIZE (PROGMEM_DUMP_LEFTOVER/PROGMEM_NUMBER_STACKS/sizeof(stack_word_t))
|
||||
|
||||
#define HARDFAULT_ULOG_FILENO 2
|
||||
#define HARDFAULT_ULOG_PATH PROGMEM_PATH "" STRINGIFY(HARDFAULT_ULOG_FILENO)
|
||||
#define HARDFAULT_FILENO 3
|
||||
#define HARDFAULT_PATH PROGMEM_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 PROGMEM_SIZE_FN0 384 /* greater then 2.5 times the size of vehicle_status_s */
|
||||
#define PROGMEM_SIZE_FN1 384 /* greater then 2.5 times the size of vehicle_status_s */
|
||||
#define PROGMEM_SIZE_FN2 HARDFAULT_MAX_ULOG_FILE_LEN
|
||||
#define PROGMEM_SIZE_FN3 -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
|
||||
* number of entries of the user stack data saved. If it is too big
|
||||
* It will be truncated by the call to stm32_bbsram_savepanic
|
||||
*/
|
||||
|
||||
#define PROGMEM_USED ((5*PROGMEM_HEADER_SIZE)+(PROGMEM_SIZE_FN0+PROGMEM_SIZE_FN1+PROGMEM_SIZE_FN2+PROGMEM_SIZE_FN3))
|
||||
#define PROGMEM_REAMINING (PX4_PROGMEM_SIZE-PROGMEM_USED)
|
||||
#if CONFIG_ARCH_INTERRUPTSTACK <= 3
|
||||
# define PROGMEM_NUMBER_STACKS 1
|
||||
#else
|
||||
# define PROGMEM_NUMBER_STACKS 2
|
||||
#endif
|
||||
#define PROGMEM_FIXED_ELEMENTS_SIZE (sizeof(info_s))
|
||||
#define PROGMEM_LEFTOVER (PROGMEM_REAMINING-PROGMEM_FIXED_ELEMENTS_SIZE)
|
||||
|
||||
#define PROGMEM_FILE_COUNT 4
|
||||
/* The path to the Battery Backed up SRAM */
|
||||
#define PROGMEM_PATH "/mnt/hardfault"
|
||||
/* The sizes of the files to create (-1) use rest of BBSRAM memory */
|
||||
#define PROGMEM_FILE_SIZES { \
|
||||
PROGMEM_SIZE_FN0, /* For Current Flight Parameters Copy A */ \
|
||||
PROGMEM_SIZE_FN1, /* For Current Flight Parameters Copy B */ \
|
||||
PROGMEM_SIZE_FN2, /* For the latest ULog file path */ \
|
||||
PROGMEM_SIZE_FN3, /* For the Panic Log use rest of space */ \
|
||||
0 /* End of table marker */ \
|
||||
}
|
||||
#else /* HAS_PROGMEM */
|
||||
|
||||
#define CONFIG_ISTACK_SIZE 0
|
||||
#define CONFIG_USTACK_SIZE 0
|
||||
|
||||
#endif
|
||||
|
||||
/* For Assert keep this much of the file name*/
|
||||
#define MAX_FILE_PATH_LENGTH 40
|
||||
|
||||
@@ -54,12 +54,18 @@
|
||||
#include <errno.h>
|
||||
#include <debug.h>
|
||||
|
||||
#ifdef HAS_BBSRAM
|
||||
#include <stm32_bbsram.h>
|
||||
#endif
|
||||
|
||||
#include <systemlib/px4_macros.h>
|
||||
#include <systemlib/hardfault_log.h>
|
||||
#include <lib/version/version.h>
|
||||
|
||||
#ifdef HAS_PROGMEM
|
||||
#include <px4_platform/progmem_dump.h>
|
||||
#endif
|
||||
|
||||
#include "chip.h"
|
||||
|
||||
#if defined(CONSTRAINED_FLASH_NO_HELP)
|
||||
@@ -224,7 +230,7 @@ static void identify(const char *caller)
|
||||
/****************************************************************************
|
||||
* hardfault_get_desc
|
||||
****************************************************************************/
|
||||
static int hardfault_get_desc(char *caller, struct bbsramd_s *desc, bool silent)
|
||||
static int hardfault_get_desc(char *caller, dump_s *desc, bool silent)
|
||||
{
|
||||
int ret = -ENOENT;
|
||||
int fd = open(HARDFAULT_PATH, O_RDONLY);
|
||||
@@ -237,7 +243,7 @@ static int hardfault_get_desc(char *caller, struct bbsramd_s *desc, bool silent)
|
||||
|
||||
} else {
|
||||
ret = -EIO;
|
||||
int rv = ioctl(fd, PX4_BBSRAM_GETDESC_IOCTL, (unsigned long)((uintptr_t)desc));
|
||||
int rv = ioctl(fd, PX4_HF_GETDESC_IOCTL, (unsigned long)((uintptr_t)desc));
|
||||
|
||||
if (rv >= 0) {
|
||||
ret = fd;
|
||||
@@ -251,6 +257,39 @@ static int hardfault_get_desc(char *caller, struct bbsramd_s *desc, bool silent)
|
||||
return ret;
|
||||
}
|
||||
|
||||
#if HAS_PROGMEM
|
||||
/****************************************************************************
|
||||
* hardfault_clear
|
||||
****************************************************************************/
|
||||
static int hardfault_clear(char *caller, bool silent)
|
||||
{
|
||||
int ret = -ENOENT;
|
||||
int fd = open(HARDFAULT_PATH, O_RDONLY);
|
||||
int value = 1;
|
||||
|
||||
if (fd < 0) {
|
||||
if (!silent) {
|
||||
identify(caller);
|
||||
hfsyslog(LOG_INFO, "Failed to open Fault Log file to clear [%s] (%d)\n", HARDFAULT_PATH, fd);
|
||||
}
|
||||
|
||||
} else {
|
||||
ret = -EIO;
|
||||
int rv = ioctl(fd, PROGMEM_DUMP_CLEAR_IOCTL, (unsigned long)((uintptr_t)&value));
|
||||
|
||||
if (rv >= 0) {
|
||||
ret = fd;
|
||||
|
||||
} else {
|
||||
identify(caller);
|
||||
hfsyslog(LOG_INFO, "Failed to clear progmem sector (%d)\n", rv);
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* write_stack_detail
|
||||
****************************************************************************/
|
||||
@@ -518,7 +557,7 @@ static int write_user_stack_info(int fdout, info_s *pi, char *buffer,
|
||||
/****************************************************************************
|
||||
* write_dump_info
|
||||
****************************************************************************/
|
||||
static int write_dump_info(int fdout, info_s *info, struct bbsramd_s *desc,
|
||||
static int write_dump_info(int fdout, info_s *info, dump_s *desc,
|
||||
char *buffer, unsigned int sz)
|
||||
{
|
||||
char fmtbuff[ TIME_FMT_LEN + 1];
|
||||
@@ -859,7 +898,7 @@ static int hardfault_commit(char *caller)
|
||||
{
|
||||
int ret = -ENOENT;
|
||||
int state = -1;
|
||||
struct bbsramd_s desc;
|
||||
dump_s desc;
|
||||
char path[LOG_PATH_LEN + 1];
|
||||
ret = hardfault_get_desc(caller, &desc, false);
|
||||
|
||||
@@ -889,7 +928,7 @@ static int hardfault_commit(char *caller)
|
||||
if (fdout >= 0) {
|
||||
identify(caller);
|
||||
syslog(LOG_INFO, "Saving Fault Log file %s\n", path);
|
||||
ret = hardfault_write(caller, fdout, HARDFAULT_FILE_FORMAT, true);
|
||||
ret = hardfault_write(caller, fdout, HARDFAULT_FILE_FORMAT, false);
|
||||
identify(caller);
|
||||
hfsyslog(LOG_INFO, "Done saving Fault Log file\n");
|
||||
|
||||
@@ -916,6 +955,12 @@ static int hardfault_commit(char *caller)
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef HAS_PROGMEM
|
||||
// Clear flash sector to write new hardfault
|
||||
hardfault_clear(caller, false);
|
||||
#endif
|
||||
ret = hardfault_rearm(caller);
|
||||
|
||||
close(fdout);
|
||||
}
|
||||
}
|
||||
@@ -931,7 +976,7 @@ static int hardfault_commit(char *caller)
|
||||
* hardfault_dowrite
|
||||
****************************************************************************/
|
||||
static int hardfault_dowrite(char *caller, int infd, int outfd,
|
||||
struct bbsramd_s *desc, int format)
|
||||
dump_s *desc, int format)
|
||||
{
|
||||
int ret = -ENOMEM;
|
||||
char *line = zalloc(OUT_BUFFER_LEN);
|
||||
@@ -1056,7 +1101,7 @@ __EXPORT int hardfault_rearm(char *caller)
|
||||
__EXPORT int hardfault_check_status(char *caller)
|
||||
{
|
||||
int state = -1;
|
||||
struct bbsramd_s desc;
|
||||
dump_s desc;
|
||||
int ret = hardfault_get_desc(caller, &desc, true);
|
||||
|
||||
if (ret < 0) {
|
||||
@@ -1122,8 +1167,11 @@ __EXPORT int hardfault_increment_reboot(char *caller, bool reset)
|
||||
|
||||
if (!reset) {
|
||||
if (read(fd, &count, sizeof(count)) != sizeof(count)) {
|
||||
//Progmem could have an empty file hence we ignore this error
|
||||
#ifndef HAS_PROGMEM
|
||||
ret = -EIO;
|
||||
close(fd);
|
||||
#endif
|
||||
|
||||
} else {
|
||||
lseek(fd, 0, SEEK_SET);
|
||||
@@ -1155,7 +1203,7 @@ __EXPORT int hardfault_increment_reboot(char *caller, bool reset)
|
||||
|
||||
__EXPORT int hardfault_write(char *caller, int fd, int format, bool rearm)
|
||||
{
|
||||
struct bbsramd_s desc;
|
||||
dump_s desc;
|
||||
|
||||
switch (format) {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user