1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-04-19 23:22:16 +03:00

emulation on host: option for FS persistence location (#7424)

* fix warnings
* emulation on host: option -P to change FS persistence location
* exit on SIGTERM too, with SIGINT
This commit is contained in:
david gauchard 2020-07-03 19:10:08 +02:00 committed by GitHub
parent f1651fba89
commit cc1cc0b2ce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 49 additions and 18 deletions

View File

@ -153,6 +153,7 @@ DEBUG += -DDEBUG_ESP_SSL -DDEBUG_ESP_TLS_MEM -DDEBUG_ESP_HTTP_CLIENT -DDEBUG_ESP
endif endif
FLAGS += $(DEBUG) -Wall $(OPTZ) -fno-common -g $(M32) FLAGS += $(DEBUG) -Wall $(OPTZ) -fno-common -g $(M32)
FLAGS += -fstack-check -fstack-protector-all
FLAGS += -DHTTPCLIENT_1_1_COMPATIBLE=0 FLAGS += -DHTTPCLIENT_1_1_COMPATIBLE=0
FLAGS += -DLWIP_IPV6=0 FLAGS += -DLWIP_IPV6=0
FLAGS += -DHOST_MOCK=1 FLAGS += -DHOST_MOCK=1

View File

@ -49,6 +49,7 @@ bool ignore_sigint = false;
bool restore_tty = false; bool restore_tty = false;
bool mockdebug = false; bool mockdebug = false;
int mock_port_shifter = MOCK_PORT_SHIFTER; int mock_port_shifter = MOCK_PORT_SHIFTER;
const char* fspath = nullptr;
#define STDIN STDIN_FILENO #define STDIN STDIN_FILENO
@ -120,19 +121,24 @@ void help (const char* argv0, int exitcode)
printf( printf(
"%s - compiled with esp8266/arduino emulator\n" "%s - compiled with esp8266/arduino emulator\n"
"options:\n" "options:\n"
" -h\n" "\t-h\n"
" -i <interface> - use this interface for IP address\n" "\tnetwork:\n"
" -l - bind tcp/udp servers to interface only (not 0.0.0.0)\n" "\t-i <interface> - use this interface for IP address\n"
" -s - port shifter (default: %d, when root: 0)\n" "\t-l - bind tcp/udp servers to interface only (not 0.0.0.0)\n"
" -c - ignore CTRL-C (send it via Serial)\n" "\t-s - port shifter (default: %d, when root: 0)\n"
" -f - no throttle (possibly 100%%CPU)\n" "\tterminal:\n"
" -b - blocking tty/mocked-uart (default: not blocking tty)\n" "\t-b - blocking tty/mocked-uart (default: not blocking tty)\n"
" -S - spiffs size in KBytes (default: %zd)\n" "\t-T - show timestamp on output\n"
" -L - littlefs size in KBytes (default: %zd)\n" "\tFS:\n"
"\t-P - path for fs-persistent files (default: %s-)\n"
"\t-S - spiffs size in KBytes (default: %zd)\n"
"\t-L - littlefs size in KBytes (default: %zd)\n"
"\t (spiffs, littlefs: negative value will force mismatched size)\n" "\t (spiffs, littlefs: negative value will force mismatched size)\n"
" -T - show timestamp on output\n" "\tgeneral:\n"
" -v - verbose\n" "\t-c - ignore CTRL-C (send it via Serial)\n"
, argv0, MOCK_PORT_SHIFTER, spiffs_kb, littlefs_kb); "\t-f - no throttle (possibly 100%%CPU)\n"
"\t-v - verbose\n"
, argv0, MOCK_PORT_SHIFTER, argv0, spiffs_kb, littlefs_kb);
exit(exitcode); exit(exitcode);
} }
@ -146,6 +152,7 @@ static struct option options[] =
{ "verbose", no_argument, NULL, 'v' }, { "verbose", no_argument, NULL, 'v' },
{ "timestamp", no_argument, NULL, 'T' }, { "timestamp", no_argument, NULL, 'T' },
{ "interface", required_argument, NULL, 'i' }, { "interface", required_argument, NULL, 'i' },
{ "fspath", required_argument, NULL, 'P' },
{ "spiffskb", required_argument, NULL, 'S' }, { "spiffskb", required_argument, NULL, 'S' },
{ "littlefskb", required_argument, NULL, 'L' }, { "littlefskb", required_argument, NULL, 'L' },
{ "portshifter", required_argument, NULL, 's' }, { "portshifter", required_argument, NULL, 's' },
@ -158,6 +165,23 @@ void cleanup ()
mock_stop_uart(); mock_stop_uart();
} }
void make_fs_filename (String& name, const char* fspath, const char* argv0)
{
name.clear();
if (fspath)
{
int lastSlash = -1;
for (int i = 0; argv0[i]; i++)
if (argv0[i] == '/')
lastSlash = i;
name = fspath;
name += '/';
name += &argv0[lastSlash + 1];
}
else
name = argv0;
}
void control_c (int sig) void control_c (int sig)
{ {
(void)sig; (void)sig;
@ -177,6 +201,7 @@ int main (int argc, char* const argv [])
blocking_uart = false; // global blocking_uart = false; // global
signal(SIGINT, control_c); signal(SIGINT, control_c);
signal(SIGTERM, control_c);
if (geteuid() == 0) if (geteuid() == 0)
mock_port_shifter = 0; mock_port_shifter = 0;
else else
@ -184,7 +209,7 @@ int main (int argc, char* const argv [])
for (;;) for (;;)
{ {
int n = getopt_long(argc, argv, "hlcfbvTi:S:s:L:", options, NULL); int n = getopt_long(argc, argv, "hlcfbvTi:S:s:L:P:", options, NULL);
if (n < 0) if (n < 0)
break; break;
switch (n) switch (n)
@ -213,6 +238,9 @@ int main (int argc, char* const argv [])
case 'L': case 'L':
littlefs_kb = atoi(optarg); littlefs_kb = atoi(optarg);
break; break;
case 'P':
fspath = optarg;
break;
case 'b': case 'b':
blocking_uart = true; blocking_uart = true;
break; break;
@ -231,7 +259,8 @@ int main (int argc, char* const argv [])
if (spiffs_kb) if (spiffs_kb)
{ {
String name = argv[0]; String name;
make_fs_filename(name, fspath, argv[0]);
name += "-spiffs"; name += "-spiffs";
name += String(spiffs_kb > 0? spiffs_kb: -spiffs_kb, DEC); name += String(spiffs_kb > 0? spiffs_kb: -spiffs_kb, DEC);
name += "KB"; name += "KB";
@ -240,7 +269,8 @@ int main (int argc, char* const argv [])
if (littlefs_kb) if (littlefs_kb)
{ {
String name = argv[0]; String name;
make_fs_filename(name, fspath, argv[0]);
name += "-littlefs"; name += "-littlefs";
name += String(littlefs_kb > 0? littlefs_kb: -littlefs_kb, DEC); name += String(littlefs_kb > 0? littlefs_kb: -littlefs_kb, DEC);
name += "KB"; name += "KB";

View File

@ -90,8 +90,8 @@ bool mockUDPListen (int sock, uint32_t dstaddr, uint16_t port, uint32_t mcast)
else else
mockverbose("UDP server on port %d (sock=%d)\n", mockport, sock); mockverbose("UDP server on port %d (sock=%d)\n", mockport, sock);
if (!mcast) if (!mcast)
mcast = inet_addr("224.0.0.1"); // all hosts group mcast = inet_addr("224.0.0.1"); // all hosts group
if (mcast) if (mcast)
{ {
// https://web.cs.wpi.edu/~claypool/courses/4514-B99/samples/multicast.c // https://web.cs.wpi.edu/~claypool/courses/4514-B99/samples/multicast.c
@ -121,7 +121,7 @@ bool mockUDPListen (int sock, uint32_t dstaddr, uint16_t port, uint32_t mcast)
return false; return false;
} }
else else
mockverbose("joined multicast group addr %08lx\n", ntohl(mcast)); mockverbose("joined multicast group addr %08lx\n", (long)ntohl(mcast));
} }
return true; return true;