mirror of
https://github.com/cesanta/mongoose.git
synced 2026-12-04 21:58:22 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
010fd33858 | ||
|
|
f3189519d8 | ||
|
|
f03c00a516 | ||
|
|
d7a756a24a | ||
|
|
24f5519463 |
No files matched your search
+53
-9
@@ -5397,7 +5397,7 @@ static void http_cb(struct mg_connection *c, int ev, void *ev_data) {
|
|||||||
while (c->pfn_data == NULL && ofs < c->recv.len) {
|
while (c->pfn_data == NULL && ofs < c->recv.len) {
|
||||||
const char *buf = (char *) c->recv.buf + ofs;
|
const char *buf = (char *) c->recv.buf + ofs;
|
||||||
int n = mg_http_parse(buf, c->recv.len - ofs, &hm);
|
int n = mg_http_parse(buf, c->recv.len - ofs, &hm);
|
||||||
struct mg_str *te; // Transfer - encoding header
|
struct mg_str *hcl, *te; // Content-Length and Transfer-encoding headers
|
||||||
bool is_chunked = false, is_http_1_0 = false;
|
bool is_chunked = false, is_http_1_0 = false;
|
||||||
size_t old_len = c->recv.len;
|
size_t old_len = c->recv.len;
|
||||||
if (n < 0) {
|
if (n < 0) {
|
||||||
@@ -5417,8 +5417,11 @@ static void http_cb(struct mg_connection *c, int ev, void *ev_data) {
|
|||||||
c->pfn = NULL;
|
c->pfn = NULL;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (ev == MG_EV_CLOSE) { // If client did not set Content-Length
|
hcl = mg_http_get_header(&hm, "Content-Length");
|
||||||
hm.message.len = c->recv.len - ofs; // and closes now, deliver MSG
|
if (ev == MG_EV_CLOSE && (hcl == NULL || c->is_client)) {
|
||||||
|
// - a server responded to HEAD with optional Content-Length (no body)
|
||||||
|
// - a client sent no Content-Length and closed --> deliver MSG
|
||||||
|
hm.message.len = c->recv.len - ofs;
|
||||||
hm.body.len = hm.message.len - (size_t) (hm.body.buf - hm.message.buf);
|
hm.body.len = hm.message.len - (size_t) (hm.body.buf - hm.message.buf);
|
||||||
}
|
}
|
||||||
is_http_1_0 =
|
is_http_1_0 =
|
||||||
@@ -5432,7 +5435,7 @@ static void http_cb(struct mg_connection *c, int ev, void *ev_data) {
|
|||||||
mg_error(c, "Invalid Transfer-Encoding"); // See #2460
|
mg_error(c, "Invalid Transfer-Encoding"); // See #2460
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else if (mg_http_get_header(&hm, "Content-length") == NULL) {
|
} else if (hcl == NULL) {
|
||||||
// #2593: HTTP packets must contain either Transfer-Encoding or
|
// #2593: HTTP packets must contain either Transfer-Encoding or
|
||||||
// Content-length
|
// Content-length
|
||||||
bool is_response = mg_ncasecmp(hm.method.buf, "HTTP/", 5) == 0;
|
bool is_response = mg_ncasecmp(hm.method.buf, "HTTP/", 5) == 0;
|
||||||
@@ -8591,9 +8594,8 @@ int mg_mqtt_parse(const uint8_t *buf, size_t len, uint8_t version,
|
|||||||
m->ack = p[1];
|
m->ack = p[1];
|
||||||
p += 2;
|
p += 2;
|
||||||
if (version == 5) {
|
if (version == 5) {
|
||||||
if (p >= end) return MQTT_MALFORMED;
|
|
||||||
len_len = (uint32_t) decode_varint(p, (size_t) (end - p), &tmp);
|
len_len = (uint32_t) decode_varint(p, (size_t) (end - p), &tmp);
|
||||||
if (!len_len) return MQTT_MALFORMED;
|
if (len_len == 0) return MQTT_MALFORMED;
|
||||||
m->props_size = (size_t) tmp;
|
m->props_size = (size_t) tmp;
|
||||||
m->props_start = (size_t) (p + len_len - buf);
|
m->props_start = (size_t) (p + len_len - buf);
|
||||||
p += len_len + m->props_size;
|
p += len_len + m->props_size;
|
||||||
@@ -8624,9 +8626,9 @@ int mg_mqtt_parse(const uint8_t *buf, size_t len, uint8_t version,
|
|||||||
p += 2;
|
p += 2;
|
||||||
}
|
}
|
||||||
if (p > end) return MQTT_MALFORMED;
|
if (p > end) return MQTT_MALFORMED;
|
||||||
if (version == 5 && p + 2 < end) {
|
if (version == 5) {
|
||||||
len_len = (uint32_t) decode_varint(p, (size_t) (end - p), &tmp);
|
len_len = (uint32_t) decode_varint(p, (size_t) (end - p), &tmp);
|
||||||
if (!len_len) return MQTT_MALFORMED;
|
if (len_len == 0) return MQTT_MALFORMED;
|
||||||
m->props_size = (size_t) tmp;
|
m->props_size = (size_t) tmp;
|
||||||
m->props_start = (size_t) (p + len_len - buf);
|
m->props_start = (size_t) (p + len_len - buf);
|
||||||
p += len_len + m->props_size;
|
p += len_len + m->props_size;
|
||||||
@@ -12733,7 +12735,11 @@ struct mg_flexspi_nor_driver_interface {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if MG_OTA <= MG_OTA_RT1064
|
#if MG_OTA <= MG_OTA_RT1064
|
||||||
|
#if MG_OTA == MG_OTA_RT1064
|
||||||
|
#define MG_FLEXSPI_BASE 0x402A4000
|
||||||
|
#else
|
||||||
#define MG_FLEXSPI_BASE 0x402A8000
|
#define MG_FLEXSPI_BASE 0x402A8000
|
||||||
|
#endif
|
||||||
#define flexspi_nor \
|
#define flexspi_nor \
|
||||||
(*((struct mg_flexspi_nor_driver_interface **) (*(uint32_t *) 0x0020001c + \
|
(*((struct mg_flexspi_nor_driver_interface **) (*(uint32_t *) 0x0020001c + \
|
||||||
16)))
|
16)))
|
||||||
@@ -12898,9 +12904,45 @@ MG_IRAM static bool mg_imxrt_erase(void *addr) {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
MG_IRAM static void flash_sync(void *addr, size_t len) {
|
||||||
|
// Include any sectors erased while programming their first page
|
||||||
|
size_t ss = s_mg_flash_imxrt.secsz, es = ss;
|
||||||
|
#if MG_IMXRT_PARAM_SECTOR_COUNT > 0
|
||||||
|
ss = flash_sector_size(addr);
|
||||||
|
es = flash_sector_size((void *) ((uintptr_t) addr + len - 1));
|
||||||
|
#endif
|
||||||
|
uintptr_t start = MG_ROUND_DOWN((uintptr_t) addr, ss);
|
||||||
|
uintptr_t end = MG_ROUND_UP((uintptr_t) addr + len, es);
|
||||||
|
|
||||||
|
MG_DSB();
|
||||||
|
// Reset the FlexSPI AHB read buffers and IP FIFOs, even with CPU caches off
|
||||||
|
while ((MG_REG(MG_FLEXSPI_BASE + 0xe0) & 3U) != 3U) (void) 0; // STS0
|
||||||
|
MG_REG(MG_FLEXSPI_BASE) |= MG_BIT(0); // MCR0 SWRESET
|
||||||
|
while (MG_REG(MG_FLEXSPI_BASE) & MG_BIT(0)) (void) 0;
|
||||||
|
|
||||||
|
#if MG_OTA == MG_OTA_RT1180
|
||||||
|
uintptr_t cache = 0x44400000; // XCACHE_PC (CM33)
|
||||||
|
if (MG_REG(cache) & MG_BIT(0)) { // CCR ENCACHE
|
||||||
|
// CLCR: invalidate by physical address. Cache lines are 16 bytes
|
||||||
|
MG_SET_BITS(MG_REG(cache + 4), 3U << 24, MG_BIT(24) | MG_BIT(26));
|
||||||
|
for (; start < end; start += 16) {
|
||||||
|
MG_REG(cache + 8) = (uint32_t) start | MG_BIT(0); // CSAR: address | LGO
|
||||||
|
while (MG_REG(cache + 8) & MG_BIT(0)) (void) 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
if (MG_REG(0xe000ed14) & MG_BIT(16)) { // CM7 SCB CCR: D-cache enabled
|
||||||
|
for (; start < end; start += 32) {
|
||||||
|
MG_REG(0xe000ef5c) = (uint32_t) start; // DCIMVAC
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
MG_DSB();
|
||||||
|
}
|
||||||
|
|
||||||
MG_IRAM static bool mg_imxrt_write(void *addr, const void *buf, size_t len) {
|
MG_IRAM static bool mg_imxrt_write(void *addr, const void *buf, size_t len) {
|
||||||
struct mg_flexspi_nor_config config, *config_ptr = &config;
|
struct mg_flexspi_nor_config config, *config_ptr = &config;
|
||||||
bool ok = false;
|
bool ok = false, sync = false;
|
||||||
// Interrupts must be disabled before calls to ROM API in RT1020 and 1060
|
// Interrupts must be disabled before calls to ROM API in RT1020 and 1060
|
||||||
MG_ARM_DISABLE_IRQ();
|
MG_ARM_DISABLE_IRQ();
|
||||||
if (flexspi_nor_get_config(&config_ptr) != 0) goto fwxit;
|
if (flexspi_nor_get_config(&config_ptr) != 0) goto fwxit;
|
||||||
@@ -12921,6 +12963,7 @@ MG_IRAM static bool mg_imxrt_write(void *addr, const void *buf, size_t len) {
|
|||||||
ok = true;
|
ok = true;
|
||||||
|
|
||||||
while (ok && src < end) {
|
while (ok && src < end) {
|
||||||
|
sync = true; // Erase/program may modify flash even on failure
|
||||||
if (flash_page_start(dst) && flash_erase(config_ptr, dst) == false) {
|
if (flash_page_start(dst) && flash_erase(config_ptr, dst) == false) {
|
||||||
ok = false;
|
ok = false;
|
||||||
break;
|
break;
|
||||||
@@ -12962,6 +13005,7 @@ MG_IRAM static bool mg_imxrt_write(void *addr, const void *buf, size_t len) {
|
|||||||
}
|
}
|
||||||
MG_DEBUG(("Flash write %lu bytes @ %p: %s.", len, dst, ok ? "ok" : "fail"));
|
MG_DEBUG(("Flash write %lu bytes @ %p: %s.", len, dst, ok ? "ok" : "fail"));
|
||||||
fwxit:
|
fwxit:
|
||||||
|
if (sync) flash_sync(addr, len);
|
||||||
if (!s_flash_irq_disabled) MG_ARM_ENABLE_IRQ();
|
if (!s_flash_irq_disabled) MG_ARM_ENABLE_IRQ();
|
||||||
return ok;
|
return ok;
|
||||||
}
|
}
|
||||||
|
|||||||
+7
-4
@@ -1152,7 +1152,7 @@ static void http_cb(struct mg_connection *c, int ev, void *ev_data) {
|
|||||||
while (c->pfn_data == NULL && ofs < c->recv.len) {
|
while (c->pfn_data == NULL && ofs < c->recv.len) {
|
||||||
const char *buf = (char *) c->recv.buf + ofs;
|
const char *buf = (char *) c->recv.buf + ofs;
|
||||||
int n = mg_http_parse(buf, c->recv.len - ofs, &hm);
|
int n = mg_http_parse(buf, c->recv.len - ofs, &hm);
|
||||||
struct mg_str *te; // Transfer - encoding header
|
struct mg_str *hcl, *te; // Content-Length and Transfer-encoding headers
|
||||||
bool is_chunked = false, is_http_1_0 = false;
|
bool is_chunked = false, is_http_1_0 = false;
|
||||||
size_t old_len = c->recv.len;
|
size_t old_len = c->recv.len;
|
||||||
if (n < 0) {
|
if (n < 0) {
|
||||||
@@ -1172,8 +1172,11 @@ static void http_cb(struct mg_connection *c, int ev, void *ev_data) {
|
|||||||
c->pfn = NULL;
|
c->pfn = NULL;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (ev == MG_EV_CLOSE) { // If client did not set Content-Length
|
hcl = mg_http_get_header(&hm, "Content-Length");
|
||||||
hm.message.len = c->recv.len - ofs; // and closes now, deliver MSG
|
if (ev == MG_EV_CLOSE && (hcl == NULL || c->is_client)) {
|
||||||
|
// - a server responded to HEAD with optional Content-Length (no body)
|
||||||
|
// - a client sent no Content-Length and closed --> deliver MSG
|
||||||
|
hm.message.len = c->recv.len - ofs;
|
||||||
hm.body.len = hm.message.len - (size_t) (hm.body.buf - hm.message.buf);
|
hm.body.len = hm.message.len - (size_t) (hm.body.buf - hm.message.buf);
|
||||||
}
|
}
|
||||||
is_http_1_0 =
|
is_http_1_0 =
|
||||||
@@ -1187,7 +1190,7 @@ static void http_cb(struct mg_connection *c, int ev, void *ev_data) {
|
|||||||
mg_error(c, "Invalid Transfer-Encoding"); // See #2460
|
mg_error(c, "Invalid Transfer-Encoding"); // See #2460
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else if (mg_http_get_header(&hm, "Content-length") == NULL) {
|
} else if (hcl == NULL) {
|
||||||
// #2593: HTTP packets must contain either Transfer-Encoding or
|
// #2593: HTTP packets must contain either Transfer-Encoding or
|
||||||
// Content-length
|
// Content-length
|
||||||
bool is_response = mg_ncasecmp(hm.method.buf, "HTTP/", 5) == 0;
|
bool is_response = mg_ncasecmp(hm.method.buf, "HTTP/", 5) == 0;
|
||||||
|
|||||||
+3
-4
@@ -440,9 +440,8 @@ int mg_mqtt_parse(const uint8_t *buf, size_t len, uint8_t version,
|
|||||||
m->ack = p[1];
|
m->ack = p[1];
|
||||||
p += 2;
|
p += 2;
|
||||||
if (version == 5) {
|
if (version == 5) {
|
||||||
if (p >= end) return MQTT_MALFORMED;
|
|
||||||
len_len = (uint32_t) decode_varint(p, (size_t) (end - p), &tmp);
|
len_len = (uint32_t) decode_varint(p, (size_t) (end - p), &tmp);
|
||||||
if (!len_len) return MQTT_MALFORMED;
|
if (len_len == 0) return MQTT_MALFORMED;
|
||||||
m->props_size = (size_t) tmp;
|
m->props_size = (size_t) tmp;
|
||||||
m->props_start = (size_t) (p + len_len - buf);
|
m->props_start = (size_t) (p + len_len - buf);
|
||||||
p += len_len + m->props_size;
|
p += len_len + m->props_size;
|
||||||
@@ -473,9 +472,9 @@ int mg_mqtt_parse(const uint8_t *buf, size_t len, uint8_t version,
|
|||||||
p += 2;
|
p += 2;
|
||||||
}
|
}
|
||||||
if (p > end) return MQTT_MALFORMED;
|
if (p > end) return MQTT_MALFORMED;
|
||||||
if (version == 5 && p + 2 < end) {
|
if (version == 5) {
|
||||||
len_len = (uint32_t) decode_varint(p, (size_t) (end - p), &tmp);
|
len_len = (uint32_t) decode_varint(p, (size_t) (end - p), &tmp);
|
||||||
if (!len_len) return MQTT_MALFORMED;
|
if (len_len == 0) return MQTT_MALFORMED;
|
||||||
m->props_size = (size_t) tmp;
|
m->props_size = (size_t) tmp;
|
||||||
m->props_start = (size_t) (p + len_len - buf);
|
m->props_start = (size_t) (p + len_len - buf);
|
||||||
p += len_len + m->props_size;
|
p += len_len + m->props_size;
|
||||||
|
|||||||
+43
-1
@@ -411,7 +411,11 @@ struct mg_flexspi_nor_driver_interface {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if MG_OTA <= MG_OTA_RT1064
|
#if MG_OTA <= MG_OTA_RT1064
|
||||||
|
#if MG_OTA == MG_OTA_RT1064
|
||||||
|
#define MG_FLEXSPI_BASE 0x402A4000
|
||||||
|
#else
|
||||||
#define MG_FLEXSPI_BASE 0x402A8000
|
#define MG_FLEXSPI_BASE 0x402A8000
|
||||||
|
#endif
|
||||||
#define flexspi_nor \
|
#define flexspi_nor \
|
||||||
(*((struct mg_flexspi_nor_driver_interface **) (*(uint32_t *) 0x0020001c + \
|
(*((struct mg_flexspi_nor_driver_interface **) (*(uint32_t *) 0x0020001c + \
|
||||||
16)))
|
16)))
|
||||||
@@ -576,9 +580,45 @@ MG_IRAM static bool mg_imxrt_erase(void *addr) {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
MG_IRAM static void flash_sync(void *addr, size_t len) {
|
||||||
|
// Include any sectors erased while programming their first page
|
||||||
|
size_t ss = s_mg_flash_imxrt.secsz, es = ss;
|
||||||
|
#if MG_IMXRT_PARAM_SECTOR_COUNT > 0
|
||||||
|
ss = flash_sector_size(addr);
|
||||||
|
es = flash_sector_size((void *) ((uintptr_t) addr + len - 1));
|
||||||
|
#endif
|
||||||
|
uintptr_t start = MG_ROUND_DOWN((uintptr_t) addr, ss);
|
||||||
|
uintptr_t end = MG_ROUND_UP((uintptr_t) addr + len, es);
|
||||||
|
|
||||||
|
MG_DSB();
|
||||||
|
// Reset the FlexSPI AHB read buffers and IP FIFOs, even with CPU caches off
|
||||||
|
while ((MG_REG(MG_FLEXSPI_BASE + 0xe0) & 3U) != 3U) (void) 0; // STS0
|
||||||
|
MG_REG(MG_FLEXSPI_BASE) |= MG_BIT(0); // MCR0 SWRESET
|
||||||
|
while (MG_REG(MG_FLEXSPI_BASE) & MG_BIT(0)) (void) 0;
|
||||||
|
|
||||||
|
#if MG_OTA == MG_OTA_RT1180
|
||||||
|
uintptr_t cache = 0x44400000; // XCACHE_PC (CM33)
|
||||||
|
if (MG_REG(cache) & MG_BIT(0)) { // CCR ENCACHE
|
||||||
|
// CLCR: invalidate by physical address. Cache lines are 16 bytes
|
||||||
|
MG_SET_BITS(MG_REG(cache + 4), 3U << 24, MG_BIT(24) | MG_BIT(26));
|
||||||
|
for (; start < end; start += 16) {
|
||||||
|
MG_REG(cache + 8) = (uint32_t) start | MG_BIT(0); // CSAR: address | LGO
|
||||||
|
while (MG_REG(cache + 8) & MG_BIT(0)) (void) 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
if (MG_REG(0xe000ed14) & MG_BIT(16)) { // CM7 SCB CCR: D-cache enabled
|
||||||
|
for (; start < end; start += 32) {
|
||||||
|
MG_REG(0xe000ef5c) = (uint32_t) start; // DCIMVAC
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
MG_DSB();
|
||||||
|
}
|
||||||
|
|
||||||
MG_IRAM static bool mg_imxrt_write(void *addr, const void *buf, size_t len) {
|
MG_IRAM static bool mg_imxrt_write(void *addr, const void *buf, size_t len) {
|
||||||
struct mg_flexspi_nor_config config, *config_ptr = &config;
|
struct mg_flexspi_nor_config config, *config_ptr = &config;
|
||||||
bool ok = false;
|
bool ok = false, sync = false;
|
||||||
// Interrupts must be disabled before calls to ROM API in RT1020 and 1060
|
// Interrupts must be disabled before calls to ROM API in RT1020 and 1060
|
||||||
MG_ARM_DISABLE_IRQ();
|
MG_ARM_DISABLE_IRQ();
|
||||||
if (flexspi_nor_get_config(&config_ptr) != 0) goto fwxit;
|
if (flexspi_nor_get_config(&config_ptr) != 0) goto fwxit;
|
||||||
@@ -599,6 +639,7 @@ MG_IRAM static bool mg_imxrt_write(void *addr, const void *buf, size_t len) {
|
|||||||
ok = true;
|
ok = true;
|
||||||
|
|
||||||
while (ok && src < end) {
|
while (ok && src < end) {
|
||||||
|
sync = true; // Erase/program may modify flash even on failure
|
||||||
if (flash_page_start(dst) && flash_erase(config_ptr, dst) == false) {
|
if (flash_page_start(dst) && flash_erase(config_ptr, dst) == false) {
|
||||||
ok = false;
|
ok = false;
|
||||||
break;
|
break;
|
||||||
@@ -640,6 +681,7 @@ MG_IRAM static bool mg_imxrt_write(void *addr, const void *buf, size_t len) {
|
|||||||
}
|
}
|
||||||
MG_DEBUG(("Flash write %lu bytes @ %p: %s.", len, dst, ok ? "ok" : "fail"));
|
MG_DEBUG(("Flash write %lu bytes @ %p: %s.", len, dst, ok ? "ok" : "fail"));
|
||||||
fwxit:
|
fwxit:
|
||||||
|
if (sync) flash_sync(addr, len);
|
||||||
if (!s_flash_irq_disabled) MG_ARM_ENABLE_IRQ();
|
if (!s_flash_irq_disabled) MG_ARM_ENABLE_IRQ();
|
||||||
return ok;
|
return ok;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -817,6 +817,12 @@ static void test_mqtt_parse(void) {
|
|||||||
struct mg_mqtt_prop prop;
|
struct mg_mqtt_prop prop;
|
||||||
// MQTT5 PUBLISH with Subscription Identifier = 5
|
// MQTT5 PUBLISH with Subscription Identifier = 5
|
||||||
const uint8_t sub_id_pkt[] = {0x30, 0x06, 0x00, 0x01, 'x', 0x02, 0x0B, 0x05};
|
const uint8_t sub_id_pkt[] = {0x30, 0x06, 0x00, 0x01, 'x', 0x02, 0x0B, 0x05};
|
||||||
|
// MQTT5 PUBLISH with no properties and no payload
|
||||||
|
const uint8_t pub_empty[] = {0x30, 0x04, 0x00, 0x01, 'x', 0x00};
|
||||||
|
// MQTT5 PUBLISH with no properties and a one-byte payload
|
||||||
|
const uint8_t pub_byte[] = {0x30, 0x05, 0x00, 0x01, 'x', 0x00, 'y'};
|
||||||
|
// MQTT5 PUBLISH without its mandatory Property Length
|
||||||
|
const uint8_t pub_no_props[] = {0x30, 0x03, 0x00, 0x01, 'x'};
|
||||||
// MQTT5 CONNACK with Server Keep Alive = 60
|
// MQTT5 CONNACK with Server Keep Alive = 60
|
||||||
const uint8_t connack_pkt[] = {0x20, 0x06, 0x00, 0x00, 0x03, 0x13, 0x00, 0x3C};
|
const uint8_t connack_pkt[] = {0x20, 0x06, 0x00, 0x00, 0x03, 0x13, 0x00, 0x3C};
|
||||||
|
|
||||||
@@ -825,6 +831,13 @@ static void test_mqtt_parse(void) {
|
|||||||
ASSERT(mg_mqtt_parse(sub_id_pkt, sizeof(sub_id_pkt), 5, &mm) == MQTT_OK);
|
ASSERT(mg_mqtt_parse(sub_id_pkt, sizeof(sub_id_pkt), 5, &mm) == MQTT_OK);
|
||||||
mg_mqtt_next_prop(&mm, &prop, 0);
|
mg_mqtt_next_prop(&mm, &prop, 0);
|
||||||
|
|
||||||
|
ASSERT(mg_mqtt_parse(pub_empty, sizeof(pub_empty), 5, &mm) == MQTT_OK);
|
||||||
|
ASSERT(mm.props_size == 0 && mm.data.len == 0);
|
||||||
|
ASSERT(mg_mqtt_parse(pub_byte, sizeof(pub_byte), 5, &mm) == MQTT_OK);
|
||||||
|
ASSERT(mm.props_size == 0 && mm.data.len == 1 && mm.data.buf[0] == 'y');
|
||||||
|
ASSERT(mg_mqtt_parse(pub_no_props, sizeof(pub_no_props), 5, &mm) ==
|
||||||
|
MQTT_MALFORMED);
|
||||||
|
|
||||||
ASSERT(mg_mqtt_parse(connack_pkt, sizeof(connack_pkt), 5, &mm) == MQTT_OK);
|
ASSERT(mg_mqtt_parse(connack_pkt, sizeof(connack_pkt), 5, &mm) == MQTT_OK);
|
||||||
ASSERT(mm.ack == 0);
|
ASSERT(mm.ack == 0);
|
||||||
ASSERT(mg_mqtt_next_prop(&mm, &prop, 0) > 0);
|
ASSERT(mg_mqtt_next_prop(&mm, &prop, 0) > 0);
|
||||||
@@ -1277,6 +1290,9 @@ static void test_http_server(void) {
|
|||||||
"POST /body HTTP/1.1\r\n"
|
"POST /body HTTP/1.1\r\n"
|
||||||
"Content-Length: 4\r\n\r\nkuku") == 200);
|
"Content-Length: 4\r\n\r\nkuku") == 200);
|
||||||
ASSERT(cmpbody(buf, "kuku") == 0);
|
ASSERT(cmpbody(buf, "kuku") == 0);
|
||||||
|
ASSERT(fetch(&mgr, buf, url, "%s",
|
||||||
|
"POST /body HTTP/1.1\r\n"
|
||||||
|
"Content-Length: 4\r\n\r\nku") == 0);
|
||||||
|
|
||||||
ASSERT(fetch(&mgr, buf, url, "GET /ssi HTTP/1.1\r\n\r\n") == 301);
|
ASSERT(fetch(&mgr, buf, url, "GET /ssi HTTP/1.1\r\n\r\n") == 301);
|
||||||
ASSERT(fetch(&mgr, buf, url, "GET /ssi/ HTTP/1.1\r\n\r\n") == 200);
|
ASSERT(fetch(&mgr, buf, url, "GET /ssi/ HTTP/1.1\r\n\r\n") == 200);
|
||||||
|
|||||||
@@ -1,18 +1,21 @@
|
|||||||
# Environment setup: https://mongoose.ws/documentation/tutorials/tools/
|
# Environment setup: https://mongoose.ws/documentation/tutorials/tools/
|
||||||
|
|
||||||
|
MGDIR = ../../../..
|
||||||
|
|
||||||
CFLAGS = -W -Wall -Wextra -Werror -Wundef -Wshadow -Wdouble-promotion
|
CFLAGS = -W -Wall -Wextra -Werror -Wundef -Wshadow -Wdouble-promotion
|
||||||
CFLAGS += -Wformat-truncation -fno-common -Wno-conversion -Wno-sign-conversion
|
CFLAGS += -Wformat-truncation -fno-common -Wno-conversion -Wno-sign-conversion
|
||||||
CFLAGS += -g3 -Os -ffunction-sections -fdata-sections
|
CFLAGS += -g3 -Os -ffunction-sections -fdata-sections
|
||||||
CFLAGS += -Wno-cast-function-type -Wno-old-style-declaration
|
CFLAGS += -Wno-cast-function-type -Wno-old-style-declaration
|
||||||
CFLAGS += -Wno-unused-parameter -Wno-unused-function
|
CFLAGS += -Wno-unused-parameter -Wno-unused-function
|
||||||
CFLAGS += -I. -Imongoose -Icmsis_core/CMSIS/Core/Include/
|
CFLAGS += -I. -I$(MGDIR) -Ilittlefs -Icmsis_core/CMSIS/Core/Include/
|
||||||
CFLAGS += -Icmsis_rt1186/devices/MIMXRT1186/ -Icmsis_rt1186/devices/MIMXRT1186/periph/ -Icmsis_rt1186/devices/MIMXRT1186/drivers/
|
CFLAGS += -Icmsis_rt1186/devices/MIMXRT1186/ -Icmsis_rt1186/devices/MIMXRT1186/periph/ -Icmsis_rt1186/devices/MIMXRT1186/drivers/
|
||||||
CFLAGS += -DCPU_MIMXRT1186CVJ8C_cm33 -DCPU_MIMXRT1186CVJ8C -DMIMXRT1186_cm33_SERIES
|
CFLAGS += -DCPU_MIMXRT1186CVJ8C_cm33 -DCPU_MIMXRT1186CVJ8C -DMIMXRT1186_cm33_SERIES
|
||||||
CFLAGS += -DXIP_EXTERNAL_FLASH=1 -DXIP_BOOT_HEADER_ENABLE=1
|
CFLAGS += -DXIP_EXTERNAL_FLASH=1 -DXIP_BOOT_HEADER_ENABLE=1
|
||||||
CFLAGS += -mcpu=cortex-m33 -mthumb -mfpu=fpv5-sp-d16 -mfloat-abi=hard $(CFLAGS_EXTRA)
|
CFLAGS += -mcpu=cortex-m33 -mthumb -mfpu=fpv5-sp-d16 -mfloat-abi=hard $(CFLAGS_EXTRA)
|
||||||
LDFLAGS ?= -Tlink.ld -nostdlib -nostartfiles --specs=nano.specs -lc -lgcc -Wl,--gc-sections
|
LDFLAGS ?= -Tlink.ld -nostdlib -nostartfiles --specs=nano.specs -lc -lgcc -Wl,--gc-sections
|
||||||
|
|
||||||
SOURCES = main.c hal.c flash_image.c mongoose/mongoose.c
|
SOURCES = main.c hal.c flash_image.c $(MGDIR)/mongoose.c
|
||||||
|
SOURCES += littlefs/lfs.c littlefs/lfs_util.c
|
||||||
SOURCES += cmsis_rt1186/devices/MIMXRT1186/gcc/startup_MIMXRT1186_cm33.S
|
SOURCES += cmsis_rt1186/devices/MIMXRT1186/gcc/startup_MIMXRT1186_cm33.S
|
||||||
SOURCES += cmsis_rt1186/devices/MIMXRT1186/drivers/fsl_clock.c
|
SOURCES += cmsis_rt1186/devices/MIMXRT1186/drivers/fsl_clock.c
|
||||||
SOURCES += cmsis_rt1186/devices/MIMXRT1186/drivers/fsl_pmu.c
|
SOURCES += cmsis_rt1186/devices/MIMXRT1186/drivers/fsl_pmu.c
|
||||||
@@ -23,17 +26,16 @@ SOURCES += cmsis_rt1186/devices/MIMXRT1186/drivers/fsl_trdc.c
|
|||||||
|
|
||||||
CFLAGS += -D__ATOLLIC__ -D__STARTUP_CLEAR_BSS -DMG_HAL_DISABLE_RANDOM -DMG_HAL_ENABLE_PHY_STRAP
|
CFLAGS += -D__ATOLLIC__ -D__STARTUP_CLEAR_BSS -DMG_HAL_DISABLE_RANDOM -DMG_HAL_ENABLE_PHY_STRAP
|
||||||
|
|
||||||
all build: firmware.bin
|
# Disabled for littlefs/lfs.c
|
||||||
|
CFLAGS += -Wno-shadow
|
||||||
|
|
||||||
mongoose/mongoose.c mongoose/mongoose.h:
|
all build: firmware.bin
|
||||||
mkdir -p mongoose
|
|
||||||
cp ../../../../mongoose.[ch] mongoose/
|
|
||||||
|
|
||||||
firmware.bin: firmware.elf
|
firmware.bin: firmware.elf
|
||||||
arm-none-eabi-objcopy -O binary $< $@
|
arm-none-eabi-objcopy -O binary $< $@
|
||||||
arm-none-eabi-size --format=berkeley $<
|
arm-none-eabi-size --format=berkeley $<
|
||||||
|
|
||||||
firmware.elf: cmsis_core cmsis_rt1186 $(SOURCES) $(wildcard *.h) link.ld Makefile
|
firmware.elf: cmsis_core cmsis_rt1186 littlefs sys/dirent.h $(SOURCES) $(MGDIR)/mongoose.h $(wildcard *.h) link.ld Makefile
|
||||||
arm-none-eabi-gcc $(SOURCES) $(CFLAGS) $(LDFLAGS) -o $@
|
arm-none-eabi-gcc $(SOURCES) $(CFLAGS) $(LDFLAGS) -o $@
|
||||||
|
|
||||||
cmsis_core:
|
cmsis_core:
|
||||||
@@ -44,9 +46,13 @@ cmsis_rt1186:
|
|||||||
unzip -q NXP.MIMXRT1186_DFP.26.06.00.pack -d $@
|
unzip -q NXP.MIMXRT1186_DFP.26.06.00.pack -d $@
|
||||||
rm NXP.MIMXRT1186_DFP.26.06.00.pack
|
rm NXP.MIMXRT1186_DFP.26.06.00.pack
|
||||||
|
|
||||||
|
littlefs/lfs.c littlefs/lfs_util.c: littlefs
|
||||||
|
littlefs:
|
||||||
|
git clone -q -c advice.detachedHead=false --depth 1 -b v2.11.3 https://github.com/littlefs-project/littlefs $@
|
||||||
|
|
||||||
# Show all symbols sorted by size
|
# Show all symbols sorted by size
|
||||||
show_symbols_sorted_by_size: firmware.bin
|
show_symbols_sorted_by_size: firmware.bin
|
||||||
arm-none-eabi-readelf -sW firmware.elf | sed 1,3d | sed 's,^.*: ,,' | tr -s ' ' | cut -d ' ' -f 2,7 | sort -nk1 | grep -v '^0 '
|
arm-none-eabi-readelf -sW firmware.elf | sed 1,3d | sed 's,^.*: ,,' | tr -s ' ' | cut -d ' ' -f 2,7 | sort -nk1 | grep -v '^0 '
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -rf firmware.* cmsis_* mongoose/mongoose.*
|
rm -rf firmware.* cmsis_* mongoose/mongoose.* littlefs
|
||||||
@@ -74,6 +74,14 @@ static void http_ev_handler(struct mg_connection *c, int ev, void *ev_data) {
|
|||||||
struct mg_http_message *hm = (struct mg_http_message *) ev_data;
|
struct mg_http_message *hm = (struct mg_http_message *) ev_data;
|
||||||
if (mg_match(hm->uri, mg_str("/api/tick"), NULL)) {
|
if (mg_match(hm->uri, mg_str("/api/tick"), NULL)) {
|
||||||
mg_http_reply(c, 200, "", "{%m:%llu}\n", MG_ESC("tick"), hal_get_tick());
|
mg_http_reply(c, 200, "", "{%m:%llu}\n", MG_ESC("tick"), hal_get_tick());
|
||||||
|
} else if (mg_match(hm->uri, mg_str("/files/#"), NULL)) {
|
||||||
|
struct mg_http_serve_opts opts = {
|
||||||
|
.root_dir = "/files/=/fs/",
|
||||||
|
.enable_delete = true,
|
||||||
|
.enable_upload = true,
|
||||||
|
.enable_dir_listing = true,
|
||||||
|
};
|
||||||
|
mg_http_serve_dir(c, hm, &opts);
|
||||||
} else if (mg_match(hm->uri, mg_str("/api/crash"), NULL)) {
|
} else if (mg_match(hm->uri, mg_str("/api/crash"), NULL)) {
|
||||||
__asm volatile("udf #0"); // Trigger HardFault
|
__asm volatile("udf #0"); // Trigger HardFault
|
||||||
} else {
|
} else {
|
||||||
@@ -108,6 +116,18 @@ int main(void) {
|
|||||||
MG_INFO(("RAM used: %zu, free: %zu", hal_ram_used(), hal_ram_free()));
|
MG_INFO(("RAM used: %zu, free: %zu", hal_ram_used(), hal_ram_free()));
|
||||||
MG_INFO(("Crash record: %M", mg_print_crash_record));
|
MG_INFO(("Crash record: %M", mg_print_crash_record));
|
||||||
|
|
||||||
|
// Create directory for Web file manager. Will be mapped to /files/ URL
|
||||||
|
if (!mg_lfs_init(MG_LFS_SIZE)) {
|
||||||
|
MG_ERROR(("LittleFS initialisation failed"));
|
||||||
|
} else {
|
||||||
|
mkdir("/fs", 0755);
|
||||||
|
MG_INFO(("File manager operations:"));
|
||||||
|
MG_INFO(("Upload: curl IP/files/NAME --data-binary @FILE"));
|
||||||
|
MG_INFO(("Delete: curl IP/files/NAME -X DELETE"));
|
||||||
|
MG_INFO(("Show: curl IP/files/NAME"));
|
||||||
|
MG_INFO(("List: curl IP/files/"));
|
||||||
|
}
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
mg_mgr_poll(&mgr, 0);
|
mg_mgr_poll(&mgr, 0);
|
||||||
blink_task();
|
blink_task();
|
||||||
|
|||||||
@@ -3,6 +3,12 @@
|
|||||||
#define MG_ENABLE_TCPIP 1
|
#define MG_ENABLE_TCPIP 1
|
||||||
#define MG_ENABLE_DRIVER_NETC 1
|
#define MG_ENABLE_DRIVER_NETC 1
|
||||||
#define MG_OTA MG_OTA_RT1180
|
#define MG_OTA MG_OTA_RT1180
|
||||||
|
|
||||||
|
#define MG_ENABLE_LFS 1
|
||||||
|
#define MG_LFS_SIZE (128 * 1024) // Multiple of the 4 KiB flash sector size
|
||||||
|
#define MG_LFS_BUF_SIZE 256 // Match the RT1180 flash write alignment
|
||||||
|
// LittleFS shares the OTA staging area; files may be lost after an update.
|
||||||
|
|
||||||
// Keep the Mongoose PHY address aligned with NETC switch link binding
|
// Keep the Mongoose PHY address aligned with NETC switch link binding
|
||||||
#include "board_config.h"
|
#include "board_config.h"
|
||||||
#define MG_TCPIP_PHY_ADDR BOARD_ETH_PHY_ADDR
|
#define MG_TCPIP_PHY_ADDR BOARD_ETH_PHY_ADDR
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
// LittleFS provides directory types in mongoose.h instead of newlib's stub.
|
||||||
@@ -1,30 +1,32 @@
|
|||||||
# Environment setup: https://mongoose.ws/documentation/tutorials/tools/
|
# Environment setup: https://mongoose.ws/documentation/tutorials/tools/
|
||||||
|
|
||||||
|
MGDIR = ../../../..
|
||||||
|
|
||||||
CFLAGS = -W -Wall -Wextra -Werror -Wundef -Wshadow -Wdouble-promotion
|
CFLAGS = -W -Wall -Wextra -Werror -Wundef -Wshadow -Wdouble-promotion
|
||||||
CFLAGS += -Wformat-truncation -fno-common -Wno-conversion -Wno-sign-conversion
|
CFLAGS += -Wformat-truncation -fno-common -Wno-conversion -Wno-sign-conversion
|
||||||
CFLAGS += -g3 -Os -ffunction-sections -fdata-sections
|
CFLAGS += -g3 -Os -ffunction-sections -fdata-sections
|
||||||
CFLAGS += -Wno-cast-function-type
|
CFLAGS += -Wno-cast-function-type
|
||||||
CFLAGS += -I. -Imongoose -Icmsis_core/CMSIS/Core/Include/ -DCPU_MIMXRT1062DVL6B
|
CFLAGS += -I. -I$(MGDIR) -Ilittlefs -Icmsis_core/CMSIS/Core/Include/ -DCPU_MIMXRT1062DVL6B
|
||||||
CFLAGS += -Icmsis_rt1060/devices/MIMXRT1062/ -Icmsis_rt1060/devices/MIMXRT1062/periph/ -Icmsis_rt1060/devices/MIMXRT1062/drivers/
|
CFLAGS += -Icmsis_rt1060/devices/MIMXRT1062/ -Icmsis_rt1060/devices/MIMXRT1062/periph/ -Icmsis_rt1060/devices/MIMXRT1062/drivers/
|
||||||
CFLAGS += -mcpu=cortex-m7 -mthumb -mfloat-abi=hard -mfpu=fpv5-sp-d16 $(CFLAGS_EXTRA)
|
CFLAGS += -mcpu=cortex-m7 -mthumb -mfloat-abi=hard -mfpu=fpv5-sp-d16 $(CFLAGS_EXTRA)
|
||||||
LDFLAGS ?= -Tlink.ld -nostdlib -nostartfiles --specs nano.specs -lc -lgcc -Wl,--gc-sections
|
LDFLAGS ?= -Tlink.ld -nostdlib -nostartfiles --specs nano.specs -lc -lgcc -Wl,--gc-sections
|
||||||
|
|
||||||
SOURCES = main.c hal.c flash_image.c mongoose/mongoose.c
|
SOURCES = main.c hal.c flash_image.c $(MGDIR)/mongoose.c
|
||||||
|
SOURCES += littlefs/lfs.c littlefs/lfs_util.c
|
||||||
SOURCES += cmsis_rt1060/devices/MIMXRT1062/gcc/startup_MIMXRT1062.S
|
SOURCES += cmsis_rt1060/devices/MIMXRT1062/gcc/startup_MIMXRT1062.S
|
||||||
|
|
||||||
CFLAGS += -D__ATOLLIC__ -D__STARTUP_CLEAR_BSS # Make startup code work as expected
|
CFLAGS += -D__ATOLLIC__ -D__STARTUP_CLEAR_BSS # Make startup code work as expected
|
||||||
|
|
||||||
all build: firmware.bin
|
# Disabled for littlefs/lfs.c
|
||||||
|
CFLAGS += -Wno-shadow
|
||||||
|
|
||||||
mongoose/mongoose.c mongoose/mongoose.h:
|
all build: firmware.bin
|
||||||
mkdir -p mongoose/
|
|
||||||
cp ../../../../mongoose.[ch] mongoose/
|
|
||||||
|
|
||||||
firmware.bin: firmware.elf
|
firmware.bin: firmware.elf
|
||||||
arm-none-eabi-objcopy -O binary $< $@
|
arm-none-eabi-objcopy -O binary $< $@
|
||||||
arm-none-eabi-size --format=berkeley $<
|
arm-none-eabi-size --format=berkeley $<
|
||||||
|
|
||||||
firmware.elf: cmsis_core cmsis_rt1060 $(SOURCES) $(wildcard *.h) link.ld Makefile
|
firmware.elf: cmsis_core cmsis_rt1060 littlefs sys/dirent.h $(SOURCES) $(MGDIR)/mongoose.h $(wildcard *.h) link.ld Makefile
|
||||||
arm-none-eabi-gcc $(SOURCES) $(CFLAGS) $(LDFLAGS) -o $@
|
arm-none-eabi-gcc $(SOURCES) $(CFLAGS) $(LDFLAGS) -o $@
|
||||||
|
|
||||||
cmsis_core:
|
cmsis_core:
|
||||||
@@ -35,9 +37,13 @@ cmsis_rt1060:
|
|||||||
unzip -q NXP.MIMXRT1062_DFP.26.06.00.pack -d $@
|
unzip -q NXP.MIMXRT1062_DFP.26.06.00.pack -d $@
|
||||||
rm NXP.MIMXRT1062_DFP.26.06.00.pack
|
rm NXP.MIMXRT1062_DFP.26.06.00.pack
|
||||||
|
|
||||||
|
littlefs/lfs.c littlefs/lfs_util.c: littlefs
|
||||||
|
littlefs:
|
||||||
|
git clone -q -c advice.detachedHead=false --depth 1 -b v2.11.3 https://github.com/littlefs-project/littlefs $@
|
||||||
|
|
||||||
# Show all symbols sorted by size
|
# Show all symbols sorted by size
|
||||||
show_symbols_sorted_by_size: firmware.bin
|
show_symbols_sorted_by_size: firmware.bin
|
||||||
arm-none-eabi-readelf -sW firmware.elf | sed 1,3d | sed 's,^.*: ,,' | tr -s ' ' | cut -d ' ' -f 2,7 | sort -nk1 | grep -v '^0 '
|
arm-none-eabi-readelf -sW firmware.elf | sed 1,3d | sed 's,^.*: ,,' | tr -s ' ' | cut -d ' ' -f 2,7 | sort -nk1 | grep -v '^0 '
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -rf firmware.* cmsis_* mongoose/mongoose.*
|
rm -rf firmware.* cmsis_* mongoose/mongoose.* littlefs
|
||||||
@@ -70,6 +70,14 @@ static void http_ev_handler(struct mg_connection *c, int ev, void *ev_data) {
|
|||||||
struct mg_http_message *hm = (struct mg_http_message *) ev_data;
|
struct mg_http_message *hm = (struct mg_http_message *) ev_data;
|
||||||
if (mg_match(hm->uri, mg_str("/api/tick"), NULL)) {
|
if (mg_match(hm->uri, mg_str("/api/tick"), NULL)) {
|
||||||
mg_http_reply(c, 200, "", "{%m:%llu}\n", MG_ESC("tick"), hal_get_tick());
|
mg_http_reply(c, 200, "", "{%m:%llu}\n", MG_ESC("tick"), hal_get_tick());
|
||||||
|
} else if (mg_match(hm->uri, mg_str("/files/#"), NULL)) {
|
||||||
|
struct mg_http_serve_opts opts = {
|
||||||
|
.root_dir = "/files/=/fs/",
|
||||||
|
.enable_delete = true,
|
||||||
|
.enable_upload = true,
|
||||||
|
.enable_dir_listing = true,
|
||||||
|
};
|
||||||
|
mg_http_serve_dir(c, hm, &opts);
|
||||||
} else if (mg_match(hm->uri, mg_str("/api/crash"), NULL)) {
|
} else if (mg_match(hm->uri, mg_str("/api/crash"), NULL)) {
|
||||||
__asm volatile("udf #0"); // Trigger HardFault
|
__asm volatile("udf #0"); // Trigger HardFault
|
||||||
} else {
|
} else {
|
||||||
@@ -102,6 +110,18 @@ int main(void) {
|
|||||||
MG_INFO(("RAM used: %zu, free: %zu", hal_ram_used(), hal_ram_free()));
|
MG_INFO(("RAM used: %zu, free: %zu", hal_ram_used(), hal_ram_free()));
|
||||||
MG_INFO(("Crash record: %M", mg_print_crash_record));
|
MG_INFO(("Crash record: %M", mg_print_crash_record));
|
||||||
|
|
||||||
|
// Create directory for Web file manager. Will be mapped to /files/ URL
|
||||||
|
if (!mg_lfs_init(MG_LFS_SIZE)) {
|
||||||
|
MG_ERROR(("LittleFS initialisation failed"));
|
||||||
|
} else {
|
||||||
|
mkdir("/fs", 0755);
|
||||||
|
MG_INFO(("File manager operations:"));
|
||||||
|
MG_INFO(("Upload: curl IP/files/NAME --data-binary @FILE"));
|
||||||
|
MG_INFO(("Delete: curl IP/files/NAME -X DELETE"));
|
||||||
|
MG_INFO(("Show: curl IP/files/NAME"));
|
||||||
|
MG_INFO(("List: curl IP/files/"));
|
||||||
|
}
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
mg_mgr_poll(&mgr, 0);
|
mg_mgr_poll(&mgr, 0);
|
||||||
blink_task();
|
blink_task();
|
||||||
|
|||||||
@@ -5,6 +5,11 @@
|
|||||||
#define MG_TLS MG_TLS_BUILTIN
|
#define MG_TLS MG_TLS_BUILTIN
|
||||||
#define MG_OTA MG_OTA_RT1060
|
#define MG_OTA MG_OTA_RT1060
|
||||||
|
|
||||||
|
#define MG_ENABLE_LFS 1
|
||||||
|
#define MG_LFS_SIZE (128 * 1024) // Multiple of the 4 KiB flash sector size
|
||||||
|
#define MG_LFS_BUF_SIZE 256 // Match the RT1060 flash write alignment
|
||||||
|
// LittleFS shares the OTA staging area; files may be lost after an update
|
||||||
|
|
||||||
#define MG_ENABLE_TCPIP 1
|
#define MG_ENABLE_TCPIP 1
|
||||||
#define MG_ENABLE_DRIVER_IMXRT10 1
|
#define MG_ENABLE_DRIVER_IMXRT10 1
|
||||||
#define MG_IO_SIZE 256
|
#define MG_IO_SIZE 256
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
// LittleFS provides directory types in mongoose.h instead of newlib's stub.
|
||||||
@@ -1,16 +1,19 @@
|
|||||||
# Environment setup: https://mongoose.ws/documentation/tutorials/tools/
|
# Environment setup: https://mongoose.ws/documentation/tutorials/tools/
|
||||||
|
|
||||||
|
MGDIR = ../../../..
|
||||||
|
|
||||||
CFLAGS = -W -Wall -Wextra -Werror -Wundef -Wshadow -Wdouble-promotion
|
CFLAGS = -W -Wall -Wextra -Werror -Wundef -Wshadow -Wdouble-promotion
|
||||||
CFLAGS += -Wformat-truncation -fno-common -Wno-conversion -Wno-sign-conversion
|
CFLAGS += -Wformat-truncation -fno-common -Wno-conversion -Wno-sign-conversion
|
||||||
CFLAGS += -g3 -Os -ffunction-sections -fdata-sections
|
CFLAGS += -g3 -Os -ffunction-sections -fdata-sections
|
||||||
CFLAGS += -Wno-cast-function-type
|
CFLAGS += -Wno-cast-function-type
|
||||||
CFLAGS += -I. -Imongoose -Icmsis_core/CMSIS/Core/Include/ -DCPU_MIMXRT1176DVMAA_cm7
|
CFLAGS += -I. -I$(MGDIR) -Ilittlefs -Icmsis_core/CMSIS/Core/Include/ -DCPU_MIMXRT1176DVMAA_cm7
|
||||||
CFLAGS += -Icmsis_rt1170/devices/MIMXRT1176/ -Icmsis_rt1170/devices/MIMXRT1176/periph/ -Icmsis_rt1170/devices/MIMXRT1176/drivers/
|
CFLAGS += -Icmsis_rt1170/devices/MIMXRT1176/ -Icmsis_rt1170/devices/MIMXRT1176/periph/ -Icmsis_rt1170/devices/MIMXRT1176/drivers/
|
||||||
CFLAGS += -mcpu=cortex-m7 -mthumb -mfloat-abi=hard -mfpu=fpv5-d16 $(CFLAGS_EXTRA)
|
CFLAGS += -mcpu=cortex-m7 -mthumb -mfloat-abi=hard -mfpu=fpv5-d16 $(CFLAGS_EXTRA)
|
||||||
CFLAGS += -Wno-unused-parameter # NXP support files
|
CFLAGS += -Wno-unused-parameter # NXP support files
|
||||||
LDFLAGS ?= -Tlink.ld -nostdlib -nostartfiles --specs nano.specs -lc -lgcc -Wl,--gc-sections
|
LDFLAGS ?= -Tlink.ld -nostdlib -nostartfiles --specs nano.specs -lc -lgcc -Wl,--gc-sections
|
||||||
|
|
||||||
SOURCES = main.c hal.c flash_image.c mongoose/mongoose.c
|
SOURCES = main.c hal.c flash_image.c $(MGDIR)/mongoose.c
|
||||||
|
SOURCES += littlefs/lfs.c littlefs/lfs_util.c
|
||||||
SOURCES += cmsis_rt1170/devices/MIMXRT1176/gcc/startup_MIMXRT1176_cm7.S
|
SOURCES += cmsis_rt1170/devices/MIMXRT1176/gcc/startup_MIMXRT1176_cm7.S
|
||||||
SOURCES += cmsis_rt1170/devices/MIMXRT1176/drivers/fsl_clock.c
|
SOURCES += cmsis_rt1170/devices/MIMXRT1176/drivers/fsl_clock.c
|
||||||
SOURCES += cmsis_rt1170/devices/MIMXRT1176/drivers/fsl_anatop_ai.c
|
SOURCES += cmsis_rt1170/devices/MIMXRT1176/drivers/fsl_anatop_ai.c
|
||||||
@@ -20,17 +23,16 @@ SOURCES += cmsis_rt1170/devices/MIMXRT1176/drivers/fsl_common_arm.c
|
|||||||
|
|
||||||
CFLAGS += -D__ATOLLIC__ -D__STARTUP_CLEAR_BSS # Make startup code work as expected
|
CFLAGS += -D__ATOLLIC__ -D__STARTUP_CLEAR_BSS # Make startup code work as expected
|
||||||
|
|
||||||
all build: firmware.bin
|
# Disabled for littlefs/lfs.c
|
||||||
|
CFLAGS += -Wno-shadow
|
||||||
|
|
||||||
mongoose/mongoose.c mongoose/mongoose.h:
|
all build: firmware.bin
|
||||||
mkdir -p mongoose
|
|
||||||
cp ../../../../mongoose.[ch] mongoose/
|
|
||||||
|
|
||||||
firmware.bin: firmware.elf
|
firmware.bin: firmware.elf
|
||||||
arm-none-eabi-objcopy -O binary $< $@
|
arm-none-eabi-objcopy -O binary $< $@
|
||||||
arm-none-eabi-size --format=berkeley $<
|
arm-none-eabi-size --format=berkeley $<
|
||||||
|
|
||||||
firmware.elf: cmsis_core cmsis_rt1170 $(SOURCES) $(wildcard *.h) link.ld Makefile
|
firmware.elf: cmsis_core cmsis_rt1170 littlefs sys/dirent.h $(SOURCES) $(MGDIR)/mongoose.h $(wildcard *.h) link.ld Makefile
|
||||||
arm-none-eabi-gcc $(SOURCES) $(CFLAGS) $(LDFLAGS) -o $@
|
arm-none-eabi-gcc $(SOURCES) $(CFLAGS) $(LDFLAGS) -o $@
|
||||||
|
|
||||||
cmsis_core:
|
cmsis_core:
|
||||||
@@ -41,9 +43,13 @@ cmsis_rt1170:
|
|||||||
unzip -q NXP.MIMXRT1176_DFP.26.06.00.pack -d $@
|
unzip -q NXP.MIMXRT1176_DFP.26.06.00.pack -d $@
|
||||||
rm NXP.MIMXRT1176_DFP.26.06.00.pack
|
rm NXP.MIMXRT1176_DFP.26.06.00.pack
|
||||||
|
|
||||||
|
littlefs/lfs.c littlefs/lfs_util.c: littlefs
|
||||||
|
littlefs:
|
||||||
|
git clone -q -c advice.detachedHead=false --depth 1 -b v2.11.3 https://github.com/littlefs-project/littlefs $@
|
||||||
|
|
||||||
# Show all symbols sorted by size
|
# Show all symbols sorted by size
|
||||||
show_symbols_sorted_by_size: firmware.bin
|
show_symbols_sorted_by_size: firmware.bin
|
||||||
arm-none-eabi-readelf -sW firmware.elf | sed 1,3d | sed 's,^.*: ,,' | tr -s ' ' | cut -d ' ' -f 2,7 | sort -nk1 | grep -v '^0 '
|
arm-none-eabi-readelf -sW firmware.elf | sed 1,3d | sed 's,^.*: ,,' | tr -s ' ' | cut -d ' ' -f 2,7 | sort -nk1 | grep -v '^0 '
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -rf firmware.* cmsis_* mongoose/mongoose.*
|
rm -rf firmware.* cmsis_* mongoose/mongoose.* littlefs
|
||||||
@@ -74,6 +74,14 @@ static void http_ev_handler(struct mg_connection *c, int ev, void *ev_data) {
|
|||||||
struct mg_http_message *hm = (struct mg_http_message *) ev_data;
|
struct mg_http_message *hm = (struct mg_http_message *) ev_data;
|
||||||
if (mg_match(hm->uri, mg_str("/api/tick"), NULL)) {
|
if (mg_match(hm->uri, mg_str("/api/tick"), NULL)) {
|
||||||
mg_http_reply(c, 200, "", "{%m:%llu}\n", MG_ESC("tick"), hal_get_tick());
|
mg_http_reply(c, 200, "", "{%m:%llu}\n", MG_ESC("tick"), hal_get_tick());
|
||||||
|
} else if (mg_match(hm->uri, mg_str("/files/#"), NULL)) {
|
||||||
|
struct mg_http_serve_opts opts = {
|
||||||
|
.root_dir = "/files/=/fs/",
|
||||||
|
.enable_delete = true,
|
||||||
|
.enable_upload = true,
|
||||||
|
.enable_dir_listing = true,
|
||||||
|
};
|
||||||
|
mg_http_serve_dir(c, hm, &opts);
|
||||||
} else if (mg_match(hm->uri, mg_str("/api/crash"), NULL)) {
|
} else if (mg_match(hm->uri, mg_str("/api/crash"), NULL)) {
|
||||||
__asm volatile("udf #0"); // Trigger HardFault
|
__asm volatile("udf #0"); // Trigger HardFault
|
||||||
} else {
|
} else {
|
||||||
@@ -108,6 +116,18 @@ int main(void) {
|
|||||||
MG_INFO(("RAM used: %zu, free: %zu", hal_ram_used(), hal_ram_free()));
|
MG_INFO(("RAM used: %zu, free: %zu", hal_ram_used(), hal_ram_free()));
|
||||||
MG_INFO(("Crash record: %M", mg_print_crash_record));
|
MG_INFO(("Crash record: %M", mg_print_crash_record));
|
||||||
|
|
||||||
|
// Create directory for Web file manager. Will be mapped to /files/ URL
|
||||||
|
if (!mg_lfs_init(MG_LFS_SIZE)) {
|
||||||
|
MG_ERROR(("LittleFS initialisation failed"));
|
||||||
|
} else {
|
||||||
|
mkdir("/fs", 0755);
|
||||||
|
MG_INFO(("File manager operations:"));
|
||||||
|
MG_INFO(("Upload: curl IP/files/NAME --data-binary @FILE"));
|
||||||
|
MG_INFO(("Delete: curl IP/files/NAME -X DELETE"));
|
||||||
|
MG_INFO(("Show: curl IP/files/NAME"));
|
||||||
|
MG_INFO(("List: curl IP/files/"));
|
||||||
|
}
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
mg_mgr_poll(&mgr, 0);
|
mg_mgr_poll(&mgr, 0);
|
||||||
blink_task();
|
blink_task();
|
||||||
|
|||||||
@@ -9,6 +9,12 @@
|
|||||||
#define MG_IO_SIZE 256
|
#define MG_IO_SIZE 256
|
||||||
#define MG_ENABLE_CUSTOM_MILLIS 1
|
#define MG_ENABLE_CUSTOM_MILLIS 1
|
||||||
#define MG_OTA MG_OTA_RT1170
|
#define MG_OTA MG_OTA_RT1170
|
||||||
|
|
||||||
|
#define MG_ENABLE_LFS 1
|
||||||
|
#define MG_LFS_SIZE (128 * 1024) // Multiple of the 4 KiB flash sector size
|
||||||
|
#define MG_LFS_BUF_SIZE 256 // Match the RT1170 flash write alignment
|
||||||
|
// LittleFS shares the OTA staging area; files may be lost after an update
|
||||||
|
|
||||||
// #define MG_ENABLE_TCPIP_PRINT_DEBUG_STATS 1
|
// #define MG_ENABLE_TCPIP_PRINT_DEBUG_STATS 1
|
||||||
#define MG_TCPIP_PHY_ADDR 3
|
#define MG_TCPIP_PHY_ADDR 3
|
||||||
#define MG_DRIVER_MDC_CR 24
|
#define MG_DRIVER_MDC_CR 24
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
// LittleFS provides directory types in mongoose.h instead of newlib's stub.
|
||||||
Reference in new issue
Block a user