diff --git a/libraries/AP_HAL_PX4/Storage.cpp b/libraries/AP_HAL_PX4/Storage.cpp index fb0df6d77a..70246884e8 100644 --- a/libraries/AP_HAL_PX4/Storage.cpp +++ b/libraries/AP_HAL_PX4/Storage.cpp @@ -21,13 +21,8 @@ using namespace PX4; // name the storage file after the sketch so you can use the same sd // card for ArduCopter and ArduPlane #define STORAGE_DIR "/fs/microsd/APM" -#define OLD_STORAGE_FILE STORAGE_DIR "/" SKETCHNAME ".stg" -#define OLD_STORAGE_FILE_BAK STORAGE_DIR "/" SKETCHNAME ".bak" //#define SAVE_STORAGE_FILE STORAGE_DIR "/" SKETCHNAME ".sav" #define MTD_PARAMS_FILE "/fs/mtd" -#define MTD_SIGNATURE 0x14012014 -#define MTD_SIGNATURE_OFFSET (8192-4) -#define STORAGE_RENAME_OLD_FILE 0 extern const AP_HAL::HAL& hal; @@ -38,89 +33,6 @@ PX4Storage::PX4Storage(void) : { } -/* - get signature from bytes at offset MTD_SIGNATURE_OFFSET -*/ -uint32_t PX4Storage::_mtd_signature(void) -{ - int mtd_fd = open(MTD_PARAMS_FILE, O_RDONLY); - if (mtd_fd == -1) { - AP_HAL::panic("Failed to open " MTD_PARAMS_FILE); - } - uint32_t v; - if (lseek(mtd_fd, MTD_SIGNATURE_OFFSET, SEEK_SET) != MTD_SIGNATURE_OFFSET) { - AP_HAL::panic("Failed to seek in " MTD_PARAMS_FILE); - } - bus_lock(true); - if (read(mtd_fd, &v, sizeof(v)) != sizeof(v)) { - AP_HAL::panic("Failed to read signature from " MTD_PARAMS_FILE); - } - bus_lock(false); - close(mtd_fd); - return v; -} - -/* - put signature bytes at offset MTD_SIGNATURE_OFFSET -*/ -void PX4Storage::_mtd_write_signature(void) -{ - int mtd_fd = open(MTD_PARAMS_FILE, O_WRONLY); - if (mtd_fd == -1) { - AP_HAL::panic("Failed to open " MTD_PARAMS_FILE); - } - uint32_t v = MTD_SIGNATURE; - if (lseek(mtd_fd, MTD_SIGNATURE_OFFSET, SEEK_SET) != MTD_SIGNATURE_OFFSET) { - AP_HAL::panic("Failed to seek in " MTD_PARAMS_FILE); - } - bus_lock(true); - if (write(mtd_fd, &v, sizeof(v)) != sizeof(v)) { - AP_HAL::panic("Failed to write signature in " MTD_PARAMS_FILE); - } - bus_lock(false); - close(mtd_fd); -} - -/* - upgrade from microSD to MTD (FRAM) -*/ -void PX4Storage::_upgrade_to_mtd(void) -{ - // the MTD is completely uninitialised - try to get a - // copy from OLD_STORAGE_FILE - int old_fd = open(OLD_STORAGE_FILE, O_RDONLY); - if (old_fd == -1) { - ::printf("Failed to open %s\n", OLD_STORAGE_FILE); - return; - } - - int mtd_fd = open(MTD_PARAMS_FILE, O_WRONLY); - if (mtd_fd == -1) { - AP_HAL::panic("Unable to open MTD for upgrade"); - } - - if (::read(old_fd, _buffer, sizeof(_buffer)) != sizeof(_buffer)) { - close(old_fd); - close(mtd_fd); - ::printf("Failed to read %s\n", OLD_STORAGE_FILE); - return; - } - close(old_fd); - ssize_t ret; - bus_lock(true); - if ((ret=::write(mtd_fd, _buffer, sizeof(_buffer))) != sizeof(_buffer)) { - ::printf("mtd write of %u bytes returned %d errno=%d\n", sizeof(_buffer), ret, errno); - AP_HAL::panic("Unable to write MTD for upgrade"); - } - bus_lock(false); - close(mtd_fd); -#if STORAGE_RENAME_OLD_FILE - rename(OLD_STORAGE_FILE, OLD_STORAGE_FILE_BAK); -#endif - ::printf("Upgraded MTD from %s\n", OLD_STORAGE_FILE); -} - - void PX4Storage::_storage_open(void) { if (_initialised) { @@ -135,26 +47,6 @@ void PX4Storage::_storage_open(void) AP_HAL::panic("Failed to find " MTD_PARAMS_FILE); } - /* - cope with upgrading from OLD_STORAGE_FILE to MTD - */ - bool good_signature = (_mtd_signature() == MTD_SIGNATURE); - if (stat(OLD_STORAGE_FILE, &st) == 0) { - if (good_signature) { -#if STORAGE_RENAME_OLD_FILE - rename(OLD_STORAGE_FILE, OLD_STORAGE_FILE_BAK); -#endif - } else { - _upgrade_to_mtd(); - } - } - - // we write the signature every time, even if it already is - // good, as this gives us a way to detect if the MTD device is - // functional. It is better to panic now than to fail to save - // parameters in flight - _mtd_write_signature(); - _dirty_mask.clearall(); int fd = open(MTD_PARAMS_FILE, O_RDONLY); diff --git a/libraries/AP_HAL_PX4/Storage.h b/libraries/AP_HAL_PX4/Storage.h index 6c64ab251e..9d1c3c4b2a 100644 --- a/libraries/AP_HAL_PX4/Storage.h +++ b/libraries/AP_HAL_PX4/Storage.h @@ -30,9 +30,6 @@ private: Bitmask _dirty_mask{PX4_STORAGE_NUM_LINES}; perf_counter_t _perf_storage; perf_counter_t _perf_errors; - void _upgrade_to_mtd(void); - uint32_t _mtd_signature(void); - void _mtd_write_signature(void); #if defined (CONFIG_ARCH_BOARD_PX4FMU_V4) irqstate_t irq_state;