Add hardfault log progmem flash backend

This commit is contained in:
Peter van der Perk
2022-12-30 12:09:05 +01:00
committed by Daniel Agar
parent ca9ae80b10
commit fa87375d0c
21 changed files with 1142 additions and 38 deletions
+1
View File
@@ -43,6 +43,7 @@ CONFIG_MODULES_VTOL_ATT_CONTROL=y
CONFIG_SYSTEMCMDS_ACTUATOR_TEST=y
CONFIG_SYSTEMCMDS_DMESG=y
CONFIG_SYSTEMCMDS_DUMPFILE=y
CONFIG_SYSTEMCMDS_HARDFAULT_LOG=y
CONFIG_SYSTEMCMDS_NETMAN=y
CONFIG_SYSTEMCMDS_NSHTERM=y
CONFIG_SYSTEMCMDS_PERF=y
@@ -71,6 +71,7 @@ CONFIG_ARMV7M_ICACHE=y
CONFIG_ARMV7M_MEMCPY=y
CONFIG_ARMV7M_USEBASEPRI=y
CONFIG_BOARDCTL_RESET=y
CONFIG_BOARD_CRASHDUMP=y
CONFIG_BOARD_LOOPSPERMSEC=14539
CONFIG_BUILTIN=y
CONFIG_DEBUG_BUSFAULT=y
@@ -247,6 +248,7 @@ CONFIG_S32K3XX_LPUART9=y
CONFIG_S32K3XX_LPUART_INVERT=y
CONFIG_S32K3XX_LPUART_SINGLEWIRE=y
CONFIG_S32K3XX_PROGMEM=y
CONFIG_S32K3XX_PROGMEM_SIZE=120
CONFIG_S32K3XX_QSPI=y
CONFIG_S32K3XX_WKPUINTS=y
CONFIG_SCHED_HPWORK=y
+18
View File
@@ -38,6 +38,7 @@ __BEGIN_DECLS
#include "hardware/s32k344_pinmux.h"
#include "s32k3xx_periphclocks.h"
#include "s32k3xx_pin.h"
#include "s32k3xx_progmem.h"
#include <arch/board/board.h>
/****************************************************************************
@@ -92,6 +93,23 @@ __BEGIN_DECLS
#define BOARD_ENABLE_CONSOLE_BUFFER
/*
* Hardfault log to progmem
*/
#define PROGMEM_CRASHDUMP 1
#define SAVE_CRASHDUMP 1
#define PROGMEM_DUMP_BASE ((CONFIG_S32K3XX_PROGMEM_SIZE * 1024) + S32K3XX_PROGMEM_START_ADDR)
#define PROGMEM_DUMP_SIZE ((DFLASH_SIZE - CONFIG_S32K3XX_PROGMEM_SIZE) * 1024)
#define PROGMEM_DUMP_ALIGNMENT (S32K3XX_PROGMEM_WRITE_SIZE)
#define PROGMEM_DUMP_UNIT_SIZE (S32K3XX_PROGMEM_DFLASH_WRITE_UNIT_SIZE)
#define PROGMEM_DUMP_HEADER_PAD (108)
#define PROGMEM_DUMP_ERASE_VALUE (0xFF)
#define PROGMEM_DUMP_STACK_SIZE (6656)
#define BOARD_CRASHDUMP_BSS 1
/* Reboot and ulog we store on a wear-level filesystem */
#define HARDFAULT_REBOOT_PATH "/mnt/progmem/reboot"
/****************************************************************************
* Public Data
****************************************************************************/
@@ -309,5 +309,7 @@ int s32k3xx_bringup(void)
# endif /* CONFIG_S32K3XX_FLEXCAN5 */
#endif /* CONFIG_NETDEV_LATEINIT */
board_hardfault_init(2, true);
return ret;
}
@@ -50,6 +50,7 @@ if(NOT PX4_BOARD MATCHES "io-v2")
px4_mtd.cpp
px4_24xxxx_mtd.c
px4_crypto.cpp
progmem_dump.c
)
# Kernel side & nuttx flat build common libraries
@@ -56,18 +56,14 @@
#include "nvic.h"
#include <syslog.h>
#if defined(CONFIG_STM32F7_BBSRAM) && defined(CONFIG_STM32F7_SAVE_CRASHDUMP)
# define HAS_BBSRAM CONFIG_STM32F7_BBSRAM
# define BBSRAM_FILE_COUNT CONFIG_STM32F7_BBSRAM_FILES
# define SAVE_CRASHDUMP CONFIG_STM32F7_SAVE_CRASHDUMP
#elif defined(CONFIG_STM32H7_BBSRAM) && defined(CONFIG_STM32H7_SAVE_CRASHDUMP)
# define HAS_BBSRAM CONFIG_STM32H7_BBSRAM
# define BBSRAM_FILE_COUNT CONFIG_STM32H7_BBSRAM_FILES
# define SAVE_CRASHDUMP CONFIG_STM32H7_SAVE_CRASHDUMP
#elif defined(CONFIG_STM32_BBSRAM) && defined(CONFIG_STM32_SAVE_CRASHDUMP)
# define HAS_BBSRAM CONFIG_STM32_BBSRAM
# define BBSRAM_FILE_COUNT CONFIG_STM32_BBSRAM_FILES
# define SAVE_CRASHDUMP CONFIG_STM32_SAVE_CRASHDUMP
#ifdef HAS_PROGMEM
#include <px4_platform/progmem_dump.h>
#endif
#ifdef HAS_BBSRAM
# define REBOOTS_COUNT 32000
#elif defined(HAS_PROGMEM)
# define REBOOTS_COUNT 32
#endif
int board_hardfault_init(int display_to_console, bool allow_prompt)
@@ -86,7 +82,21 @@ int board_hardfault_init(int display_to_console, bool allow_prompt)
stm32_bbsraminitialize(BBSRAM_PATH, filesizes);
#if defined(SAVE_CRASHDUMP)
#elif defined(HAS_PROGMEM)
/* NB. the use of the console requires the hrt running
* to poll the DMA
*/
/* Using progmem */
int filesizes[PROGMEM_FILE_COUNT + 1] = PROGMEM_FILE_SIZES;
progmem_dump_initialize(PROGMEM_PATH, filesizes);
#endif // HAS_PROGMEM
#if defined(SAVE_CRASHDUMP) && (defined(HAS_BBSRAM) || defined(HAS_PROGMEM))
/* Panic Logging in Battery Backed Up Files */
@@ -124,7 +134,7 @@ int board_hardfault_init(int display_to_console, bool allow_prompt)
return -EIO;
}
if (reboots >= 32000) {
if (reboots >= REBOOTS_COUNT) {
reboots = hardfault_increment_reboot("boot", true);
return -ENOSPC;
}
@@ -219,7 +229,6 @@ read:
} // outer if
#endif // SAVE_CRASHDUMP
#endif // HAS_BBSRAM
return hadCrash == OK ? 1 : 0;
}
@@ -230,11 +239,22 @@ static void copy_reverse(stack_word_t *dest, stack_word_t *src, int size)
}
}
#ifdef BOARD_CRASHDUMP_BSS
static uint32_t *__attribute__((noinline)) __ebss_addr(void)
{
return &_ebss;
}
#else
static uint32_t *__attribute__((noinline)) __sdata_addr(void)
{
return &_sdata;
}
#endif
__EXPORT void board_crashdump(uintptr_t currentsp, FAR void *tcb, FAR const char *filename, int lineno)
{
@@ -246,7 +266,11 @@ __EXPORT void board_crashdump(uintptr_t currentsp, FAR void *tcb, FAR const char
* Unfortunately this is hard to test. See dead below
*/
#ifdef BOARD_CRASHDUMP_BSS
fullcontext_s *pdump = (fullcontext_s *)(__ebss_addr() - sizeof(fullcontext_s));
#else
fullcontext_s *pdump = (fullcontext_s *)__sdata_addr();
#endif
(void)enter_critical_section();
@@ -378,14 +402,14 @@ __EXPORT void board_crashdump(uintptr_t currentsp, FAR void *tcb, FAR const char
char *dead = "Memory wiped - dump not saved!";
while (*dead) {
arm_lowputc(*dead++);
up_putc(*dead++);
}
} else if (rv == -ENOSPC) {
/* hard fault again */
arm_lowputc('!');
up_putc('!');
}
#endif /* BOARD_CRASHDUMP_RESET_ONLY */
@@ -0,0 +1,125 @@
/****************************************************************************
*
* Copyright (C) 2022 PX4 Development Team. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name PX4 nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <nuttx/fs/ioctl.h>
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#pragma once
#define PROGMEM_DUMP_GETDESC_IOCTL _DIOC(0x0000) /* Returns a progmem_s */
#define PROGMEM_DUMP_CLEAR_IOCTL _DIOC(0x0010) /* Erases flash sector */
/****************************************************************************
* Public Types
****************************************************************************/
#ifndef __ASSEMBLY__
struct progmem_s {
struct timespec lastwrite;
int fileno;
int len;
int flags;
};
/****************************************************************************
* Public Data
****************************************************************************/
#undef EXTERN
#if defined(__cplusplus)
# define EXTERN extern "C"
extern "C"
{
#else
# define EXTERN extern
#endif
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
/****************************************************************************
* Function: progmem_dump_initialize
*
* Description:
* Initialize the Progmem dump driver
*
* Input Parameters:
* devpath - the path to instantiate the files.
* sizes - Pointer to a any array of file sizes to create
* the last entry should be 0
* A size of -1 will use all the remaining spaces
*
* Returned Value:
* Number of files created on success; Negated errno on failure.
*
* Assumptions:
*
****************************************************************************/
int progmem_dump_initialize(char *devpath, int *sizes);
/****************************************************************************
* Function: progmem_dump_savepanic
*
* Description:
* Saves the panic context in a previously allocated BBSRAM file
*
* Parameters:
* fileno - the value returned by the ioctl PROGMEM_DUMP_GETDESC_IOCTL
* context - Pointer to a any array of bytes to save
* length - The length of the data pointed to byt context
*
* Returned Value:
* Length saved or negated errno.
*
* Assumptions:
*
****************************************************************************/
int progmem_dump_savepanic(int fileno, uint8_t *context, int length);
#undef EXTERN
#ifdef __cplusplus
}
#endif
#endif /* __ASSEMBLY__ */
File diff suppressed because it is too large Load Diff
@@ -41,7 +41,7 @@ __BEGIN_DECLS
// Fixme: using ??
#define PX4_BBSRAM_SIZE 2048
#define PX4_BBSRAM_GETDESC_IOCTL 0
#define PX4_HF_GETDESC_IOCTL 0
#define PX4_NUMBER_I2C_BUSES KINETIS_NI2C
#define GPIO_OUTPUT_SET GPIO_OUTPUT_ONE
@@ -40,7 +40,7 @@ __BEGIN_DECLS
#// Fixme: using ??
#define PX4_BBSRAM_SIZE 2048
#define PX4_BBSRAM_GETDESC_IOCTL 0
#define PX4_HF_GETDESC_IOCTL 0
#define PX4_NUMBER_I2C_BUSES 4
#define GPIO_OUTPUT_SET GPIO_OUTPUT_ONE
@@ -41,7 +41,7 @@ __BEGIN_DECLS
// Fixme: using ??
#define PX4_BBSRAM_SIZE 2048
#define PX4_BBSRAM_GETDESC_IOCTL 0
#define PX4_HF_GETDESC_IOCTL 0
#define PX4_NUMBER_I2C_BUSES 2
#define GPIO_OUTPUT_SET GPIO_OUTPUT_ONE
@@ -41,7 +41,7 @@ __BEGIN_DECLS
// Fixme: using ??
#define PX4_BBSRAM_SIZE 2048
#define PX4_BBSRAM_GETDESC_IOCTL 0
#define PX4_HF_GETDESC_IOCTL PROGMEM_DUMP_GETDESC_IOCTL
#define PX4_NUMBER_I2C_BUSES 2
#define GPIO_OUTPUT_SET GPIO_OUTPUT_ONE
@@ -93,6 +93,12 @@ __BEGIN_DECLS
#define PX4_BUS_OFFSET 1 /* s32k3xx buses are 0 based and adjustment is needed */
#define px4_savepanic(fileno, context, length) progmem_dump_savepanic(fileno, context, length)
#if defined(CONFIG_ARCH_HAVE_PROGMEM) && defined(CONFIG_BOARD_CRASHDUMP)
# define HAS_PROGMEM 1
#endif
#define px4_spibus_initialize(bus_num_1based) s32k3xx_lpspibus_initialize(PX4_BUS_NUMBER_FROM_PX4(bus_num_1based))
#define px4_i2cbus_initialize(bus_num_1based) s32k3xx_i2cbus_initialize(PX4_BUS_NUMBER_FROM_PX4(bus_num_1based))
@@ -12,7 +12,7 @@ __BEGIN_DECLS
// This will remove the errors of undefined PX4_BBSRAM_SIZE when logger module is activated.
// Fixme: using ??
#define PX4_BBSRAM_SIZE 2048
#define PX4_BBSRAM_GETDESC_IOCTL 0
#define PX4_HF_GETDESC_IOCTL 0
// RP2040 doesn't really have a cpu register with unique id.
// However, there is a function in pico-sdk which can provide
@@ -49,8 +49,6 @@ __BEGIN_DECLS
#define PX4_CPU_UUID_WORD32_FORMAT_SIZE (PX4_CPU_UUID_WORD32_LENGTH-1+(2*PX4_CPU_UUID_BYTE_LENGTH)+1)
#define PX4_CPU_MFGUID_FORMAT_SIZE ((2*PX4_CPU_MFGUID_BYTE_LENGTH)+1)
#define px4_savepanic(fileno, context, length) (0) // Turn off px4_savepanic for rp2040 as it is not implemented in nuttx
#define PX4_BUS_OFFSET 1 /* RP2040 buses are 0 based and adjustment is needed */
#define px4_spibus_initialize(bus_num_1based) rp2040_spibus_initialize(PX4_BUS_NUMBER_FROM_PX4(bus_num_1based))
@@ -43,7 +43,10 @@ __BEGIN_DECLS
#if defined(CONFIG_STM32_STM32F4XXX)
# include <stm32_bbsram.h>
# define PX4_BBSRAM_SIZE STM32_BBSRAM_SIZE
# define PX4_BBSRAM_GETDESC_IOCTL STM32_BBSRAM_GETDESC_IOCTL
# define PX4_HF_GETDESC_IOCTL STM32_BBSRAM_GETDESC_IOCTL
# define HAS_BBSRAM CONFIG_STM32_BBSRAM
# define BBSRAM_FILE_COUNT CONFIG_STM32_BBSRAM_FILES
# define SAVE_CRASHDUMP CONFIG_STM32_SAVE_CRASHDUMP
#endif
#define PX4_NUMBER_I2C_BUSES STM32_NI2C
#define PX4_ADC_INTERNAL_TEMP_SENSOR_CHANNEL 16
@@ -43,7 +43,10 @@ __BEGIN_DECLS
#if defined(CONFIG_STM32_STM32F4XXX)
# include <stm32_bbsram.h>
# define PX4_BBSRAM_SIZE STM32_BBSRAM_SIZE
# define PX4_BBSRAM_GETDESC_IOCTL STM32_BBSRAM_GETDESC_IOCTL
# define PX4_HF_GETDESC_IOCTL STM32_BBSRAM_GETDESC_IOCTL
# define HAS_BBSRAM CONFIG_STM32_BBSRAM
# define BBSRAM_FILE_COUNT CONFIG_STM32_BBSRAM_FILES
# define SAVE_CRASHDUMP CONFIG_STM32_SAVE_CRASHDUMP
#endif
#define PX4_NUMBER_I2C_BUSES STM32_NI2C
#define PX4_ADC_INTERNAL_TEMP_SENSOR_CHANNEL 16
@@ -43,7 +43,10 @@ __BEGIN_DECLS
#if defined(CONFIG_STM32_STM32F4XXX)
# include <stm32_bbsram.h>
# define PX4_BBSRAM_SIZE STM32_BBSRAM_SIZE
# define PX4_BBSRAM_GETDESC_IOCTL STM32_BBSRAM_GETDESC_IOCTL
# define PX4_HF_GETDESC_IOCTL STM32_BBSRAM_GETDESC_IOCTL
# define HAS_BBSRAM CONFIG_STM32_BBSRAM
# define BBSRAM_FILE_COUNT CONFIG_STM32_BBSRAM_FILES
# define SAVE_CRASHDUMP CONFIG_STM32_SAVE_CRASHDUMP
#endif
#define PX4_NUMBER_I2C_BUSES STM32_NI2C
#define PX4_ADC_INTERNAL_TEMP_SENSOR_CHANNEL 18
@@ -46,7 +46,10 @@ __BEGIN_DECLS
#if defined(CONFIG_STM32F7_BKPSRAM)
# include <stm32_bbsram.h>
# define PX4_BBSRAM_SIZE STM32F7_BBSRAM_SIZE
# define PX4_BBSRAM_GETDESC_IOCTL STM32F7_BBSRAM_GETDESC_IOCTL
# define PX4_HF_GETDESC_IOCTL STM32F7_BBSRAM_GETDESC_IOCTL
# define HAS_BBSRAM CONFIG_STM32F7_BBSRAM
# define BBSRAM_FILE_COUNT CONFIG_STM32F7_BBSRAM_FILES
# define SAVE_CRASHDUMP CONFIG_STM32F7_SAVE_CRASHDUMP
#endif // CONFIG_STM32F7_BKPSRAM
#define PX4_FLASH_BASE 0x08000000
#define PX4_NUMBER_I2C_BUSES STM32F7_NI2C
@@ -55,9 +55,12 @@ __BEGIN_DECLS
#include <arm_internal.h> //include up_systemreset() which is included on stm32.h
#include <stm32_bbsram.h>
#define PX4_BBSRAM_SIZE STM32H7_BBSRAM_SIZE
#define PX4_BBSRAM_GETDESC_IOCTL STM32H7_BBSRAM_GETDESC_IOCTL
#define PX4_HF_GETDESC_IOCTL STM32H7_BBSRAM_GETDESC_IOCTL
#define PX4_FLASH_BASE 0x08000000
#define PX4_NUMBER_I2C_BUSES STM32H7_NI2C
#define HAS_BBSRAM CONFIG_STM32H7_BBSRAM
#define BBSRAM_FILE_COUNT CONFIG_STM32H7_BBSRAM_FILES
#define SAVE_CRASHDUMP CONFIG_STM32H7_SAVE_CRASHDUMP
int stm32h7_flash_lock(size_t addr);
int stm32h7_flash_unlock(size_t addr);
+67
View File
@@ -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
+56 -8
View File
@@ -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) {