Skip to content

Commit 874eb93

Browse files
mikee47slaff
authored andcommitted
Add --nonet option to host emulator, fix default location for flash.bin (SmingHub#1824)
* Add `--nonet` option to emulator * Put default host flash.bin in same directory as executable
1 parent 1e9e9b0 commit 874eb93

File tree

4 files changed

+27
-7
lines changed

4 files changed

+27
-7
lines changed

Sming/Arch/Host/Components/hostlib/options.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@
4747
nullptr) \
4848
XX(flashsize, required_argument, "Change default flash size if file doesn't exist", "SIZE", \
4949
"Size of flash in bytes (e.g. 512K, 524288, 0x80000)", nullptr) \
50-
XX(initonly, no_argument, "Initialise only, do not start Sming", nullptr, nullptr, nullptr)
50+
XX(initonly, no_argument, "Initialise only, do not start Sming", nullptr, nullptr, nullptr) \
51+
XX(nonet, no_argument, "Skip network initialisation", nullptr, nullptr, nullptr)
5152

5253
enum option_tag_t {
5354
#define XX(tag, has_arg, desc, argname, arghelp, examples) opt_##tag,

Sming/Arch/Host/Components/hostlib/startup.cpp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,15 @@ int main(int argc, char* argv[])
110110
int pause;
111111
int exitpause;
112112
bool initonly;
113+
bool enable_network;
113114
UartServerConfig uart;
114115
FlashmemConfig flash;
115116
struct lwip_param lwip;
116117
} config = {
117118
.pause = -1,
118119
.exitpause = -1,
119120
.initonly = false,
121+
.enable_network = true,
120122
.uart =
121123
{
122124
.enableMask = 0,
@@ -187,6 +189,10 @@ int main(int argc, char* argv[])
187189
config.initonly = true;
188190
break;
189191

192+
case opt_nonet:
193+
config.enable_network = false;
194+
break;
195+
190196
default:;
191197
}
192198
}
@@ -209,9 +215,14 @@ int main(int argc, char* argv[])
209215
sockets_initialise();
210216
CUartServer::startup(config.uart);
211217

212-
bool lwip_initialised = host_lwip_init(&config.lwip);
213-
if(lwip_initialised) {
214-
host_wifi_lwip_init_complete();
218+
bool lwip_initialised = false;
219+
if(config.enable_network) {
220+
lwip_initialised = host_lwip_init(&config.lwip);
221+
if(lwip_initialised) {
222+
host_wifi_lwip_init_complete();
223+
}
224+
} else {
225+
hostmsg("Network initialisation skipped as requested");
215226
}
216227

217228
hostmsg("If required, you may start terminal application(s) now");

Sming/Arch/Host/Components/spi_flash/flashmem.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323

2424
static int flashFile = -1;
2525
static size_t flashFileSize = 0x400000U;
26-
static const char* flashFileName = "flash.bin";
26+
static char flashFileName[256];
27+
static const char* defaultFlashFileName = "flash.bin";
2728

2829
#define SPI_FLASH_SEC_SIZE 4096
2930

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

3839
bool host_flashmem_init(FlashmemConfig& config)
3940
{
40-
if(config.filename != NULL) {
41-
flashFileName = config.filename;
41+
if(config.filename != nullptr) {
42+
strcpy(flashFileName, config.filename);
4243
} else {
44+
getHostAppDir(flashFileName, sizeof(flashFileName));
45+
strcat(flashFileName, defaultFlashFileName);
4346
config.filename = flashFileName;
4447
}
48+
4549
flashFile = open(flashFileName, O_CREAT | O_RDWR | O_BINARY, 0644);
4650
if(flashFile < 0) {
4751
hostmsg("Error opening \"%s\"", flashFileName);

Sming/Arch/Host/README.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,10 @@ See :source:`Sming/Arch/Host/Core/DigitalHooks.h` for further details.
152152
Network
153153
~~~~~~~
154154

155+
.. note::
156+
157+
Network support is enabled by default. If you don't need it, use the ``--nonet`` option.
158+
155159
Linux
156160
^^^^^
157161

0 commit comments

Comments
 (0)