Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow runtime selection of storage backend #17736

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions Tools/ardupilotwaf/boards.py
Original file line number Diff line number Diff line change
Expand Up @@ -592,9 +592,6 @@ def configure_env(self, cfg, env):
cfg.fatal("Failed to find SFML Audio libraries")
env.CXXFLAGS += ['-DWITH_SITL_TONEALARM']

if cfg.options.sitl_flash_storage:
env.CXXFLAGS += ['-DSTORAGE_USE_FLASH=1']

if cfg.env.DEST_OS == 'cygwin':
env.LIB += [
'winmm',
Expand Down
25 changes: 25 additions & 0 deletions Tools/autotest/rover.py
Original file line number Diff line number Diff line change
Expand Up @@ -5677,6 +5677,27 @@ def MAV_CMD_DO_SET_MISSION_CURRENT(self, target_sysid=None, target_compid=1):
target_compid=target_compid,
want_result=mavutil.mavlink.MAV_RESULT_FAILED)

def FlashStorage(self):
self.set_parameter("LOG_BITMASK", 1)
self.reboot_sitl()

self.customise_SITL_commandline([
"--set-storage-posix-enabled", "0",
"--set-storage-flash-enabled", "1",
])
if self.get_parameter("LOG_BITMASK") == 1:
raise NotAchievedException("not using flash storage?")
self.set_parameter("LOG_BITMASK", 2)
self.reboot_sitl()
self.assert_parameter_value("LOG_BITMASK", 2)
self.set_parameter("LOG_BITMASK", 3)
self.reboot_sitl()
self.assert_parameter_value("LOG_BITMASK", 3)

self.customise_SITL_commandline([])
# make sure we're back at our original value:
self.assert_parameter_value("LOG_BITMASK", 1)

def tests(self):
'''return list of all tests'''
ret = super(AutoTestRover, self).tests()
Expand Down Expand Up @@ -5899,6 +5920,10 @@ def tests(self):
"Test end mission behavior",
self.test_end_mission_behavior),

("FlashStorage",
"Test flash storage (for parameters etc)",
self.FlashStorage),

("LogUpload",
"Upload logs",
self.log_upload),
Expand Down
6 changes: 3 additions & 3 deletions Tools/autotest/sim_vehicle.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,9 +320,6 @@ def do_build(opts, frame_options):
if opts.tonealarm:
cmd_configure.append("--enable-sfml-audio")

if opts.flash_storage:
cmd_configure.append("--sitl-flash-storage")

if opts.math_check_indexes:
cmd_configure.append("--enable-math-check-indexes")

Expand Down Expand Up @@ -671,6 +668,9 @@ def start_vehicle(binary, opts, stuff, spawns=None):
sys.exit(1)
path = ",".join(paths)
progress("Using defaults from (%s)" % (path,))
if opts.flash_storage:
cmd.append("--set-storage-flash-enabled 1")
cmd.append("--set-storage-posix-enabled 0")
if opts.add_param_file:
for file in opts.add_param_file:
if not os.path.isfile(file):
Expand Down
2 changes: 1 addition & 1 deletion Tools/completion/zsh/_waf
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ _waf() {
'--sitl-osd[Enable SITL OSD]' \
'--sitl-rgbled[Enable SITL RGBLed]' \
'--build-dates[Include build date in binaries]' \
'--sitl-flash-storage[Building SITL with flash storage emulation.]' \
'--sitl-flash-storage[Use flash storage emulation.]' \
'--upload[Upload applicable targets to a connected device]' \
'--board[Board name]:board:_waf_boards' \
'--target=[Target name]:target:_waf_targets' \
Expand Down
3 changes: 0 additions & 3 deletions libraries/AP_HAL/board/sitl.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@

#define AP_FLASHSTORAGE_TYPE 3

#if defined(STORAGE_USE_FLASH) && STORAGE_USE_FLASH==1

#if AP_FLASHSTORAGE_TYPE == 1
// emulate F1/F3 flash
#define HAL_STORAGE_SIZE 15360
Expand All @@ -33,7 +31,6 @@
#define HAL_FLASH_MIN_WRITE_SIZE 32
#define HAL_FLASH_ALLOW_UPDATE 0
#endif
#endif

#ifndef HAL_STORAGE_SIZE
#define HAL_STORAGE_SIZE 32768
Expand Down
13 changes: 13 additions & 0 deletions libraries/AP_HAL_SITL/HAL_SITL_Class.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,24 @@ class HAL_SITL : public AP_HAL::HAL {
void run(int argc, char * const argv[], Callbacks* callbacks) const override;
static void actually_reboot();

void set_storage_posix_enabled(bool _enabled) {
storage_posix_enabled = _enabled;
}
bool get_storage_posix_enabled() const { return storage_posix_enabled; }
void set_storage_flash_enabled(bool _enabled) {
storage_flash_enabled = _enabled;
}
bool get_storage_flash_enabled() const { return storage_flash_enabled; }

private:
HALSITL::SITL_State *_sitl_state;

void setup_signal_handlers() const;
static void exit_signal_handler(int);

bool storage_posix_enabled;
bool storage_flash_enabled;

};

#if HAL_NUM_CAN_IFACES
Expand Down
52 changes: 46 additions & 6 deletions libraries/AP_HAL_SITL/SITL_cmdline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "HAL_SITL_Class.h"
#include "UARTDriver.h"
#include <AP_HAL/utility/getopt_cpp.h>
#include <AP_HAL_SITL/Storage.h>
#include <AP_Logger/AP_Logger_SITL.h>
#include <AP_Param/AP_Param.h>

Expand Down Expand Up @@ -263,6 +264,12 @@ void SITL_State::_parse_command_line(int argc, char * const argv[])
CMDLINE_START_TIME,
CMDLINE_SYSID,
CMDLINE_SLAVE,
#if STORAGE_USE_FLASH
CMDLINE_SET_STORAGE_FLASH_ENABLED,
#endif
#if STORAGE_USE_POSIX
CMDLINE_SET_STORAGE_POSIX_ENABLED,
#endif
};

const struct GetOptLong::option options[] = {
Expand Down Expand Up @@ -311,6 +318,12 @@ void SITL_State::_parse_command_line(int argc, char * const argv[])
{"start-time", true, 0, CMDLINE_START_TIME},
{"sysid", true, 0, CMDLINE_SYSID},
{"slave", true, 0, CMDLINE_SLAVE},
#if STORAGE_USE_FLASH
{"set-storage-flash-enabled", true, 0, CMDLINE_SET_STORAGE_FLASH_ENABLED},
#endif
#if STORAGE_USE_POSIX
{"set-storage-posix-enabled", true, 0, CMDLINE_SET_STORAGE_POSIX_ENABLED},
#endif
{0, false, 0, 0}
};

Expand All @@ -319,6 +332,11 @@ void SITL_State::_parse_command_line(int argc, char * const argv[])
HALSITL::UARTDriver::_console = true;
}

// storage defaults are set here:
bool storage_posix_enabled = true;
bool storage_flash_enabled = false;
bool erase_all_storage = false;

if (asprintf(&autotest_dir, SKETCHBOOK "/Tools/autotest") <= 0) {
AP_HAL::panic("out of memory");
}
Expand All @@ -332,12 +350,7 @@ void SITL_State::_parse_command_line(int argc, char * const argv[])
while (!is_replay && (opt = gopt.getoption()) != -1) {
switch (opt) {
case 'w':
#if HAL_LOGGING_FILESYSTEM_ENABLED
AP_Param::erase_all();
#endif
#if HAL_LOGGING_SITL_ENABLED
unlink(AP_Logger_SITL::filename);
#endif
erase_all_storage = true;
break;
case 'u':
AP_Param::set_hide_disabled_groups(false);
Expand Down Expand Up @@ -463,6 +476,16 @@ void SITL_State::_parse_command_line(int argc, char * const argv[])
printf("Setting SYSID_THISMAV=%d\n", sysid);
break;
}
#if STORAGE_USE_POSIX
case CMDLINE_SET_STORAGE_POSIX_ENABLED:
storage_posix_enabled = atoi(gopt.optarg);
break;
#endif
#if STORAGE_USE_FLASH
case CMDLINE_SET_STORAGE_FLASH_ENABLED:
storage_flash_enabled = atoi(gopt.optarg);
break;
#endif
case 'h':
_usage();
exit(0);
Expand Down Expand Up @@ -522,11 +545,28 @@ void SITL_State::_parse_command_line(int argc, char * const argv[])
exit(1);
}

if (storage_posix_enabled && storage_flash_enabled) {
// this will change in the future!
printf("Only one of flash or posix storage may be selected");
exit(1);
}

if (AP::sitl()) {
// Set SITL start time.
AP::sitl()->start_time_UTC = start_time_UTC;
}

((HAL_SITL&)hal).set_storage_posix_enabled(storage_posix_enabled);
((HAL_SITL&)hal).set_storage_flash_enabled(storage_flash_enabled);

if (erase_all_storage) {
AP_Param::erase_all();
#if HAL_LOGGING_SITL_ENABLED
unlink(AP_Logger_SITL::filename);
#endif
unlink("flash.dat");
}

fprintf(stdout, "Starting sketch '%s'\n", SKETCH);

if (strcmp(SKETCH, "ArduCopter") == 0) {
Expand Down
Loading