mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-01-18 03:52:11 +01:00
Added signal handler that on ctrl-c will unmount the yaffs device(s) and save to the em-norsim file
This commit is contained in:
parent
942945850b
commit
c6aa4ed1d6
@ -26,12 +26,25 @@
|
|||||||
|
|
||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#include <signal.h>
|
||||||
|
|
||||||
unsigned yaffs_trace_mask =
|
|
||||||
YAFFS_TRACE_ERROR |
|
#include "pios.h"
|
||||||
YAFFS_TRACE_BUG |
|
#include "pios_trace.h"
|
||||||
YAFFS_TRACE_ALWAYS |
|
#include "pios_stdio.h"
|
||||||
0;
|
|
||||||
|
#include <openpilot.h>
|
||||||
|
#include "pios_flashfs.h" /* API for flash filesystem */
|
||||||
|
#include "pios_flashfs_logfs_priv.h"
|
||||||
|
|
||||||
|
#include <pios_stdio.h>
|
||||||
|
|
||||||
|
|
||||||
|
unsigned yaffs_trace_mask = 0;
|
||||||
|
//YAFFS_TRACE_ERROR |
|
||||||
|
//YAFFS_TRACE_BUG |
|
||||||
|
//YAFFS_TRACE_ALWAYS |
|
||||||
|
//0;
|
||||||
|
|
||||||
int random_seed;
|
int random_seed;
|
||||||
int simulate_power_failure = 0;
|
int simulate_power_failure = 0;
|
||||||
@ -56,13 +69,71 @@ int yaffs_start_up(void)
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#include "pios.h"
|
|
||||||
#include "pios_trace.h"
|
|
||||||
#include "pios_stdio.h"
|
|
||||||
|
|
||||||
#include <openpilot.h>
|
|
||||||
#include "pios_flashfs.h" /* API for flash filesystem */
|
|
||||||
#include "pios_flashfs_logfs_priv.h"
|
void yaffsSigHandler ( int sig)
|
||||||
|
{
|
||||||
|
char devicename[8];
|
||||||
|
int fs_id;
|
||||||
|
|
||||||
|
pios_trace(PIOS_TRACE_TEST, "yaffsSigHandler sig=%d", sig);
|
||||||
|
switch (sig)
|
||||||
|
{
|
||||||
|
case SIGALRM:
|
||||||
|
case SIGQUIT:
|
||||||
|
case SIGTERM:
|
||||||
|
case SIGKILL:
|
||||||
|
case SIGINT:
|
||||||
|
case SIGUSR1:
|
||||||
|
case SIGUSR2:
|
||||||
|
|
||||||
|
for (fs_id =0; fs_id < pios_flash_device_count; fs_id++)
|
||||||
|
{
|
||||||
|
snprintf(devicename,6, "/dev%01u", (unsigned) fs_id);
|
||||||
|
|
||||||
|
pios_umount((const char *)devicename);
|
||||||
|
|
||||||
|
}
|
||||||
|
pios_flash_device_count=0;
|
||||||
|
exit(1);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void yaffsSigSetup
|
||||||
|
(
|
||||||
|
void (*sighandler)(int sig)
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//sigset_t block_sigusr;
|
||||||
|
struct sigaction sa;
|
||||||
|
|
||||||
|
sigemptyset(&sa.sa_mask);
|
||||||
|
sa.sa_flags = 0;
|
||||||
|
sa.sa_handler = sighandler;
|
||||||
|
if (sigaction(SIGQUIT, &sa, NULL)) return;
|
||||||
|
|
||||||
|
|
||||||
|
sigemptyset(&sa.sa_mask);
|
||||||
|
sa.sa_flags = 0;
|
||||||
|
sa.sa_handler = sighandler;
|
||||||
|
if (sigaction(SIGINT , &sa, NULL)) return;
|
||||||
|
|
||||||
|
|
||||||
|
sigemptyset(&sa.sa_mask);
|
||||||
|
sa.sa_flags = 0;
|
||||||
|
sa.sa_handler = sighandler;
|
||||||
|
if (sigaction(SIGTERM, &sa, NULL)) return;
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Initialize the flash object setting FS. Each call creates a yaffs device
|
* @brief Initialize the flash object setting FS. Each call creates a yaffs device
|
||||||
@ -94,6 +165,11 @@ int32_t PIOS_FLASHFS_Logfs_Init(
|
|||||||
// as multiple instances
|
// as multiple instances
|
||||||
yaffs_nor_install_drv(devicename);
|
yaffs_nor_install_drv(devicename);
|
||||||
|
|
||||||
|
|
||||||
|
sigset_t sigset;
|
||||||
|
sigemptyset(&sigset);
|
||||||
|
yaffsSigSetup(yaffsSigHandler);
|
||||||
|
|
||||||
// Attempt to mount the device
|
// Attempt to mount the device
|
||||||
retval = pios_mount(devicename);
|
retval = pios_mount(devicename);
|
||||||
if (retval < 0) {
|
if (retval < 0) {
|
||||||
|
@ -19,6 +19,8 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
|
#include "pios_trace.h"
|
||||||
|
|
||||||
#define YNORSIM_FNAME "emfile-nor"
|
#define YNORSIM_FNAME "emfile-nor"
|
||||||
|
|
||||||
/* Set YNORSIM_BIT_CHANGES to a a value from 1..30 to
|
/* Set YNORSIM_BIT_CHANGES to a a value from 1..30 to
|
||||||
@ -71,7 +73,7 @@ static void NorError(struct nor_sim *sim)
|
|||||||
static void ynorsim_save_image(struct nor_sim *sim)
|
static void ynorsim_save_image(struct nor_sim *sim)
|
||||||
{
|
{
|
||||||
int h;
|
int h;
|
||||||
|
pios_trace(PIOS_TRACE_TEST, "ynorsim_save_image");
|
||||||
h = open(sim->fname, O_RDWR | O_CREAT | O_TRUNC, S_IREAD | S_IWRITE);
|
h = open(sim->fname, O_RDWR | O_CREAT | O_TRUNC, S_IREAD | S_IWRITE);
|
||||||
write(h, sim->word, sim->file_size);
|
write(h, sim->word, sim->file_size);
|
||||||
close(h);
|
close(h);
|
||||||
@ -80,7 +82,7 @@ static void ynorsim_save_image(struct nor_sim *sim)
|
|||||||
static void ynorsim_restore_image(struct nor_sim *sim)
|
static void ynorsim_restore_image(struct nor_sim *sim)
|
||||||
{
|
{
|
||||||
int h;
|
int h;
|
||||||
|
pios_trace(PIOS_TRACE_TEST, "ynorsim_restore_image");
|
||||||
h = open(sim->fname, O_RDONLY, S_IREAD | S_IWRITE);
|
h = open(sim->fname, O_RDONLY, S_IREAD | S_IWRITE);
|
||||||
memset(sim->word, 0xFF, sim->file_size);
|
memset(sim->word, 0xFF, sim->file_size);
|
||||||
read(h, sim->word, sim->file_size);
|
read(h, sim->word, sim->file_size);
|
||||||
@ -169,6 +171,7 @@ void ynorsim_wr32(struct nor_sim *sim, u32 * addr, u32 * buf, int nwords)
|
|||||||
void ynorsim_erase(struct nor_sim *sim, u32 * addr)
|
void ynorsim_erase(struct nor_sim *sim, u32 * addr)
|
||||||
{
|
{
|
||||||
/* Todo... bit flipping */
|
/* Todo... bit flipping */
|
||||||
|
pios_trace(PIOS_TRACE_TEST, "ynorsim_erase");
|
||||||
memset(addr, 0xFF, sim->block_size_bytes);
|
memset(addr, 0xFF, sim->block_size_bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user