Skip to content

Commit

Permalink
Add --nonet option to host emulator, fix default location for flash.b…
Browse files Browse the repository at this point in the history
…in (#1824)

* Add `--nonet` option to emulator

* Put default host flash.bin in same directory as executable
  • Loading branch information
mikee47 authored and slaff committed Aug 28, 2019
1 parent 1e9e9b0 commit 874eb93
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 7 deletions.
3 changes: 2 additions & 1 deletion Sming/Arch/Host/Components/hostlib/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@
nullptr) \
XX(flashsize, required_argument, "Change default flash size if file doesn't exist", "SIZE", \
"Size of flash in bytes (e.g. 512K, 524288, 0x80000)", nullptr) \
XX(initonly, no_argument, "Initialise only, do not start Sming", nullptr, nullptr, nullptr)
XX(initonly, no_argument, "Initialise only, do not start Sming", nullptr, nullptr, nullptr) \
XX(nonet, no_argument, "Skip network initialisation", nullptr, nullptr, nullptr)

enum option_tag_t {
#define XX(tag, has_arg, desc, argname, arghelp, examples) opt_##tag,
Expand Down
17 changes: 14 additions & 3 deletions Sming/Arch/Host/Components/hostlib/startup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,15 @@ int main(int argc, char* argv[])
int pause;
int exitpause;
bool initonly;
bool enable_network;
UartServerConfig uart;
FlashmemConfig flash;
struct lwip_param lwip;
} config = {
.pause = -1,
.exitpause = -1,
.initonly = false,
.enable_network = true,
.uart =
{
.enableMask = 0,
Expand Down Expand Up @@ -187,6 +189,10 @@ int main(int argc, char* argv[])
config.initonly = true;
break;

case opt_nonet:
config.enable_network = false;
break;

default:;
}
}
Expand All @@ -209,9 +215,14 @@ int main(int argc, char* argv[])
sockets_initialise();
CUartServer::startup(config.uart);

bool lwip_initialised = host_lwip_init(&config.lwip);
if(lwip_initialised) {
host_wifi_lwip_init_complete();
bool lwip_initialised = false;
if(config.enable_network) {
lwip_initialised = host_lwip_init(&config.lwip);
if(lwip_initialised) {
host_wifi_lwip_init_complete();
}
} else {
hostmsg("Network initialisation skipped as requested");
}

hostmsg("If required, you may start terminal application(s) now");
Expand Down
10 changes: 7 additions & 3 deletions Sming/Arch/Host/Components/spi_flash/flashmem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@

static int flashFile = -1;
static size_t flashFileSize = 0x400000U;
static const char* flashFileName = "flash.bin";
static char flashFileName[256];
static const char* defaultFlashFileName = "flash.bin";

#define SPI_FLASH_SEC_SIZE 4096

Expand All @@ -37,11 +38,14 @@ static const char* flashFileName = "flash.bin";

bool host_flashmem_init(FlashmemConfig& config)
{
if(config.filename != NULL) {
flashFileName = config.filename;
if(config.filename != nullptr) {
strcpy(flashFileName, config.filename);
} else {
getHostAppDir(flashFileName, sizeof(flashFileName));
strcat(flashFileName, defaultFlashFileName);
config.filename = flashFileName;
}

flashFile = open(flashFileName, O_CREAT | O_RDWR | O_BINARY, 0644);
if(flashFile < 0) {
hostmsg("Error opening \"%s\"", flashFileName);
Expand Down
4 changes: 4 additions & 0 deletions Sming/Arch/Host/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,10 @@ See :source:`Sming/Arch/Host/Core/DigitalHooks.h` for further details.
Network
~~~~~~~

.. note::

Network support is enabled by default. If you don't need it, use the ``--nonet`` option.

Linux
^^^^^

Expand Down

0 comments on commit 874eb93

Please sign in to comment.