diff --git a/flight/pios/posix/libraries/yaffs2/yaffscfg2k.c b/flight/pios/posix/libraries/yaffs2/yaffscfg2k.c index 695f99e15..05ed8fd6e 100644 --- a/flight/pios/posix/libraries/yaffs2/yaffscfg2k.c +++ b/flight/pios/posix/libraries/yaffs2/yaffscfg2k.c @@ -26,12 +26,25 @@ #include +#include -unsigned yaffs_trace_mask = - YAFFS_TRACE_ERROR | - YAFFS_TRACE_BUG | - YAFFS_TRACE_ALWAYS | - 0; + +#include "pios.h" +#include "pios_trace.h" +#include "pios_stdio.h" + +#include +#include "pios_flashfs.h" /* API for flash filesystem */ +#include "pios_flashfs_logfs_priv.h" + +#include + + +unsigned yaffs_trace_mask = 0; + //YAFFS_TRACE_ERROR | + //YAFFS_TRACE_BUG | + //YAFFS_TRACE_ALWAYS | + //0; int random_seed; int simulate_power_failure = 0; @@ -56,13 +69,71 @@ int yaffs_start_up(void) return 0; } -#include "pios.h" -#include "pios_trace.h" -#include "pios_stdio.h" -#include -#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 @@ -94,6 +165,11 @@ int32_t PIOS_FLASHFS_Logfs_Init( // as multiple instances yaffs_nor_install_drv(devicename); + + sigset_t sigset; + sigemptyset(&sigset); + yaffsSigSetup(yaffsSigHandler); + // Attempt to mount the device retval = pios_mount(devicename); if (retval < 0) { diff --git a/flight/pios/posix/libraries/yaffs2/ynorsim.c b/flight/pios/posix/libraries/yaffs2/ynorsim.c index 38a4632e8..654fdc773 100644 --- a/flight/pios/posix/libraries/yaffs2/ynorsim.c +++ b/flight/pios/posix/libraries/yaffs2/ynorsim.c @@ -19,6 +19,8 @@ #include #include +#include "pios_trace.h" + #define YNORSIM_FNAME "emfile-nor" /* 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) { int h; - + pios_trace(PIOS_TRACE_TEST, "ynorsim_save_image"); h = open(sim->fname, O_RDWR | O_CREAT | O_TRUNC, S_IREAD | S_IWRITE); write(h, sim->word, sim->file_size); close(h); @@ -80,7 +82,7 @@ static void ynorsim_save_image(struct nor_sim *sim) static void ynorsim_restore_image(struct nor_sim *sim) { int h; - + pios_trace(PIOS_TRACE_TEST, "ynorsim_restore_image"); h = open(sim->fname, O_RDONLY, S_IREAD | S_IWRITE); memset(sim->word, 0xFF, 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) { /* Todo... bit flipping */ + pios_trace(PIOS_TRACE_TEST, "ynorsim_erase"); memset(addr, 0xFF, sim->block_size_bytes); }