mirror of
https://github.com/cesanta/mongoose.git
synced 2026-12-04 21:58:22 +00:00
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d597b89bd4 |
No files matched your search
+38
-75
@@ -9527,6 +9527,7 @@ static const struct mg_addr ip6_allnodes = {
|
|||||||
static const uint8_t locpx[8] = {0xfe, 0x80, 0, 0, 0, 0, 0, 0};
|
static const uint8_t locpx[8] = {0xfe, 0x80, 0, 0, 0, 0, 0, 0};
|
||||||
|
|
||||||
#define MG_IP6MATCH(a, b) (a[0] == b[0] && a[1] == b[1])
|
#define MG_IP6MATCH(a, b) (a[0] == b[0] && a[1] == b[1])
|
||||||
|
#define MG_IP6UNSPEC(a) (a[0] == 0 && a[1] == 0)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static void settmout(struct mg_connection *c, uint8_t type) {
|
static void settmout(struct mg_connection *c, uint8_t type) {
|
||||||
@@ -10081,9 +10082,9 @@ static void rx_ndp_ns(struct mg_tcpip_if *ifp, struct pkt *pkt) {
|
|||||||
// - use solicited node multicast to resolve a l2 address (l2_addr = NULL)
|
// - use solicited node multicast to resolve a l2 address (l2_addr = NULL)
|
||||||
// - use unicast to verify presence (l2_addr = neighbor l2 address)
|
// - use unicast to verify presence (l2_addr = neighbor l2 address)
|
||||||
static void tx_ndp_ns(struct mg_tcpip_if *ifp, uint64_t *ip_dst,
|
static void tx_ndp_ns(struct mg_tcpip_if *ifp, uint64_t *ip_dst,
|
||||||
uint8_t *l2_addr) {
|
uint8_t *l2_addr, bool ll) {
|
||||||
|
uint64_t *ip_src = ll ? ifp->ip6ll : ifp->ip6;
|
||||||
uint8_t payload[4 + 16 + 16]; // NOTE(): 16 --> optional len upto 2 hw addr
|
uint8_t payload[4 + 16 + 16]; // NOTE(): 16 --> optional len upto 2 hw addr
|
||||||
uint64_t ip_unspec[2] = {0, 0};
|
|
||||||
size_t payload_len = 20;
|
size_t payload_len = 20;
|
||||||
bool mcast = (l2_addr == NULL);
|
bool mcast = (l2_addr == NULL);
|
||||||
uint64_t ip_mcast[2] = {0, 0};
|
uint64_t ip_mcast[2] = {0, 0};
|
||||||
@@ -10103,14 +10104,12 @@ static void tx_ndp_ns(struct mg_tcpip_if *ifp, uint64_t *ip_dst,
|
|||||||
l2 = mg_l2_mapip(ifp->l2type, MG_TCPIP_L2ADDR_MCAST6, &ipd);
|
l2 = mg_l2_mapip(ifp->l2type, MG_TCPIP_L2ADDR_MCAST6, &ipd);
|
||||||
}
|
}
|
||||||
payload_len = 20;
|
payload_len = 20;
|
||||||
// TODO(robertc2000): using only link-local IP addr for now
|
if (!MG_IP6UNSPEC(ip_src)) {
|
||||||
// We might consider to add an option to use either link-local or global IP
|
|
||||||
if (!MG_IP6MATCH(ifp->ip6ll, ip_unspec)) {
|
|
||||||
payload[20] = 1; // 4.6.1, source hwaddr; option length in 8-byte units
|
payload[20] = 1; // 4.6.1, source hwaddr; option length in 8-byte units
|
||||||
payload[21] = mg_l2_ip6put(ifp->l2type, ifp->mac, payload + 22);
|
payload[21] = mg_l2_ip6put(ifp->l2type, ifp->mac, payload + 22);
|
||||||
payload_len += 8 * payload[21];
|
payload_len += 8 * payload[21];
|
||||||
}
|
}
|
||||||
tx_icmp6(ifp, l2, ifp->ip6ll, mcast ? ip_mcast : ip_dst, 135, 0, payload,
|
tx_icmp6(ifp, l2, ip_src, mcast ? ip_mcast : ip_dst, 135, 0, payload,
|
||||||
payload_len);
|
payload_len);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -10118,11 +10117,10 @@ static void tx_ndp_ns(struct mg_tcpip_if *ifp, uint64_t *ip_dst,
|
|||||||
static void tx_ndp_rs(struct mg_tcpip_if *ifp) {
|
static void tx_ndp_rs(struct mg_tcpip_if *ifp) {
|
||||||
uint8_t payload[4 + 16]; // reserved + optional len upto 2 hw addr NOTE()
|
uint8_t payload[4 + 16]; // reserved + optional len upto 2 hw addr NOTE()
|
||||||
size_t payload_len = 4;
|
size_t payload_len = 4;
|
||||||
uint64_t ip_unspec[2] = {0, 0};
|
|
||||||
|
|
||||||
memset(payload, 0, sizeof(payload));
|
memset(payload, 0, sizeof(payload));
|
||||||
|
|
||||||
if (!MG_IP6MATCH(ifp->ip6ll, ip_unspec)) {
|
if (!MG_IP6UNSPEC(ifp->ip6ll)) {
|
||||||
payload[4] = 1; // 4.6.1, source hwaddr; option length in 8-byte units
|
payload[4] = 1; // 4.6.1, source hwaddr; option length in 8-byte units
|
||||||
payload[5] = mg_l2_ip6put(ifp->l2type, ifp->mac, payload + 6);
|
payload[5] = mg_l2_ip6put(ifp->l2type, ifp->mac, payload + 6);
|
||||||
payload_len += 8 * payload[5];
|
payload_len += 8 * payload[5];
|
||||||
@@ -10291,7 +10289,7 @@ static void onstate6change(struct mg_tcpip_if *ifp) {
|
|||||||
(struct mg_addr *) &ip6_allnodes),
|
(struct mg_addr *) &ip6_allnodes),
|
||||||
ifp->ip6ll, (uint64_t *) ip6_allnodes.addr.ip6, false,
|
ifp->ip6ll, (uint64_t *) ip6_allnodes.addr.ip6, false,
|
||||||
ifp->mac);
|
ifp->mac);
|
||||||
if (ifp->ip6[0] != 0 && ifp->ip6[1] != 0)
|
if (!MG_IP6UNSPEC(ifp->ip6))
|
||||||
tx_ndp_na(ifp, // RFC-9131 4.1
|
tx_ndp_na(ifp, // RFC-9131 4.1
|
||||||
mg_l2_mapip(ifp->l2type, MG_TCPIP_L2ADDR_MCAST6,
|
mg_l2_mapip(ifp->l2type, MG_TCPIP_L2ADDR_MCAST6,
|
||||||
(struct mg_addr *) &ip6_allrouters),
|
(struct mg_addr *) &ip6_allrouters),
|
||||||
@@ -10306,9 +10304,9 @@ static void onstate6change(struct mg_tcpip_if *ifp) {
|
|||||||
ifp->is_ip6_changed = false;
|
ifp->is_ip6_changed = false;
|
||||||
}
|
}
|
||||||
} else if (ifp->state6 == MG_TCPIP_STATE_IP) {
|
} else if (ifp->state6 == MG_TCPIP_STATE_IP) {
|
||||||
if ((ifp->gw6[0] != 0 || ifp->gw6[1] != 0) &&
|
if (!MG_IP6UNSPEC(ifp->gw6) &&
|
||||||
(ifp->l2type != MG_TCPIP_L2_PPP && ifp->l2type != MG_TCPIP_L2_PPPoE))
|
(ifp->l2type != MG_TCPIP_L2_PPP && ifp->l2type != MG_TCPIP_L2_PPPoE))
|
||||||
tx_ndp_ns(ifp, ifp->gw6, NULL); // unsolicited GW hwaddr resolution
|
tx_ndp_ns(ifp, ifp->gw6, NULL, true); // unsolicited GW hwaddr resolution
|
||||||
} else if (ifp->state6 == MG_TCPIP_STATE_UP) {
|
} else if (ifp->state6 == MG_TCPIP_STATE_UP) {
|
||||||
MG_INFO(("IP: %M", mg_print_ip6, &ifp->ip6ll));
|
MG_INFO(("IP: %M", mg_print_ip6, &ifp->ip6ll));
|
||||||
}
|
}
|
||||||
@@ -10521,13 +10519,14 @@ static struct mg_connection *accept_conn(struct mg_connection *lsn,
|
|||||||
struct pkt *pkt, uint16_t mss) {
|
struct pkt *pkt, uint16_t mss) {
|
||||||
struct connstate *s;
|
struct connstate *s;
|
||||||
uint8_t *l2addr;
|
uint8_t *l2addr;
|
||||||
|
struct mg_tcpip_if *ifp = lsn->mgr->ifp;
|
||||||
struct mg_connection *c = mg_alloc_conn(lsn->mgr);
|
struct mg_connection *c = mg_alloc_conn(lsn->mgr);
|
||||||
if (c == NULL) {
|
if (c == NULL) {
|
||||||
MG_ERROR(("OOM"));
|
MG_ERROR(("OOM"));
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
s = (struct connstate *) (c + 1);
|
s = (struct connstate *) (c + 1);
|
||||||
s->retransmit = lsn->mgr->ifp->enable_tcp_retransmit;
|
s->retransmit = ifp->enable_tcp_retransmit;
|
||||||
s->txq.align = MG_TCPIP_TXQ_ALIGN;
|
s->txq.align = MG_TCPIP_TXQ_ALIGN;
|
||||||
s->dmss = mss; // from options in client SYN
|
s->dmss = mss; // from options in client SYN
|
||||||
s->seq = mg_ntohl(pkt->tcp->ack), s->ack = mg_ntohl(pkt->tcp->seq);
|
s->seq = mg_ntohl(pkt->tcp->ack), s->ack = mg_ntohl(pkt->tcp->seq);
|
||||||
@@ -10536,19 +10535,21 @@ static struct mg_connection *accept_conn(struct mg_connection *lsn,
|
|||||||
if (lsn->loc.is_ip6) {
|
if (lsn->loc.is_ip6) {
|
||||||
c->rem.addr.ip6[0] = pkt->ip6->src[0],
|
c->rem.addr.ip6[0] = pkt->ip6->src[0],
|
||||||
c->rem.addr.ip6[1] = pkt->ip6->src[1], c->rem.is_ip6 = true;
|
c->rem.addr.ip6[1] = pkt->ip6->src[1], c->rem.is_ip6 = true;
|
||||||
c->loc.addr.ip6[0] = c->mgr->ifp->ip6[0],
|
if (pkt->ip6->dst[0] == ifp->ip6ll[0]) { // link-local prefix
|
||||||
c->loc.addr.ip6[1] = c->mgr->ifp->ip6[1], c->loc.is_ip6 = true;
|
c->loc.addr.ip6[0] = ifp->ip6ll[0], c->loc.addr.ip6[1] = ifp->ip6ll[1];
|
||||||
// TODO(): compare lsn to link-local, or rem as link-local: use ll instead
|
} else {
|
||||||
|
c->loc.addr.ip6[0] = ifp->ip6[0], c->loc.addr.ip6[1] = ifp->ip6[1];
|
||||||
|
}
|
||||||
|
c->loc.is_ip6 = true;
|
||||||
} else
|
} else
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
c->rem.addr.ip4 = pkt->ip->src;
|
c->rem.addr.ip4 = pkt->ip->src;
|
||||||
c->loc.addr.ip4 = c->mgr->ifp->ip;
|
c->loc.addr.ip4 = ifp->ip;
|
||||||
}
|
}
|
||||||
c->rem.port = pkt->tcp->sport;
|
c->rem.port = pkt->tcp->sport;
|
||||||
c->loc.port = lsn->loc.port;
|
c->loc.port = lsn->loc.port;
|
||||||
if ((l2addr = get_return_l2addr(lsn->mgr->ifp, &c->rem, false, pkt)) ==
|
if ((l2addr = get_return_l2addr(ifp, &c->rem, false, pkt)) == NULL) {
|
||||||
NULL) {
|
|
||||||
mg_free(c); // safety net for lousy networks, not actually needed
|
mg_free(c); // safety net for lousy networks, not actually needed
|
||||||
return NULL; // as path has already been checked at SYN (sending SYN+ACK)
|
return NULL; // as path has already been checked at SYN (sending SYN+ACK)
|
||||||
}
|
}
|
||||||
@@ -10606,10 +10607,14 @@ static bool udp_send(struct mg_connection *c, const void *buf, size_t len) {
|
|||||||
struct mg_addr ips;
|
struct mg_addr ips;
|
||||||
memset(&ips, 0, sizeof(ips));
|
memset(&ips, 0, sizeof(ips));
|
||||||
#if MG_ENABLE_IPV6
|
#if MG_ENABLE_IPV6
|
||||||
if (c->loc.is_ip6) {
|
if (c->loc.is_ip6) { // At [::] infer link-local from peer
|
||||||
ips.addr.ip6[0] = ifp->ip6[0], ips.addr.ip6[1] = ifp->ip6[1],
|
if (MG_IP6UNSPEC(c->loc.addr.ip6) ? c->rem.addr.ip6[0] == ifp->ip6ll[0]
|
||||||
|
: c->loc.addr.ip6[0] == ifp->ip6ll[0]) {
|
||||||
|
ips.addr.ip6[0] = ifp->ip6ll[0], ips.addr.ip6[1] = ifp->ip6ll[1];
|
||||||
|
} else {
|
||||||
|
ips.addr.ip6[0] = ifp->ip6[0], ips.addr.ip6[1] = ifp->ip6[1];
|
||||||
|
}
|
||||||
ips.is_ip6 = true;
|
ips.is_ip6 = true;
|
||||||
// TODO(): detect link-local (c->rem) and use it
|
|
||||||
} else
|
} else
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
@@ -11270,14 +11275,14 @@ static void mg_ip6_link(struct mg_tcpip_if *ifp, bool drv_up, bool l2_up) {
|
|||||||
bool cur_drv = (ifp->state6 != MG_TCPIP_STATE_DOWN);
|
bool cur_drv = (ifp->state6 != MG_TCPIP_STATE_DOWN);
|
||||||
bool cur_l2 = (ifp->state6 >= MG_TCPIP_STATE_UP);
|
bool cur_l2 = (ifp->state6 >= MG_TCPIP_STATE_UP);
|
||||||
if (drv_up != cur_drv || l2_up != cur_l2) { // link/L2 state has changed
|
if (drv_up != cur_drv || l2_up != cur_l2) { // link/L2 state has changed
|
||||||
if (ifp->l2type == MG_TCPIP_L2_ETH && l2_up && ifp->ip6ll[0] == 0 &&
|
if (ifp->l2type == MG_TCPIP_L2_ETH && l2_up &&
|
||||||
ifp->ip6ll[1] == 0) { // gen ll address
|
MG_IP6UNSPEC(ifp->ip6ll)) { // gen ll address
|
||||||
mg_l2_genip6(ifp->l2type, ifp->ip6ll, 64, ifp->mac);
|
mg_l2_genip6(ifp->l2type, ifp->ip6ll, 64, ifp->mac);
|
||||||
memcpy(ifp->ip6ll, locpx, 8); // RFC-4291 2.5.6; RFC-2464 5
|
memcpy(ifp->ip6ll, locpx, 8); // RFC-4291 2.5.6; RFC-2464 5
|
||||||
} // just got our link local address if we didn't have one.
|
} // just got our link local address if we didn't have one.
|
||||||
// If static configuration is used, global addresses,
|
// If static configuration is used, global addresses,
|
||||||
// prefix length, and gw are already filled at this point.
|
// prefix length, and gw are already filled at this point.
|
||||||
if (ifp->ip6[0] == 0 && ifp->ip6[1] == 0) ifp->enable_slaac = true;
|
if (MG_IP6UNSPEC(ifp->ip6)) ifp->enable_slaac = true;
|
||||||
if (!l2_up && ifp->enable_slaac) ifp->ip6[0] = ifp->ip6[1] = 0;
|
if (!l2_up && ifp->enable_slaac) ifp->ip6[0] = ifp->ip6[1] = 0;
|
||||||
ifp->state6 = !drv_up ? MG_TCPIP_STATE_DOWN
|
ifp->state6 = !drv_up ? MG_TCPIP_STATE_DOWN
|
||||||
: !l2_up ? MG_TCPIP_STATE_LINK_UP
|
: !l2_up ? MG_TCPIP_STATE_LINK_UP
|
||||||
@@ -11338,8 +11343,8 @@ static void mg_tcpip_poll(struct mg_tcpip_if *ifp, uint64_t now) {
|
|||||||
onstate6change(ifp);
|
onstate6change(ifp);
|
||||||
}
|
}
|
||||||
if (expired_1000ms && ifp->state6 == MG_TCPIP_STATE_READY && !ifp->gw6_ready &&
|
if (expired_1000ms && ifp->state6 == MG_TCPIP_STATE_READY && !ifp->gw6_ready &&
|
||||||
(ifp->gw6[0] != 0 || ifp->gw6[1] != 0))
|
!MG_IP6UNSPEC(ifp->gw6))
|
||||||
tx_ndp_ns(ifp, ifp->gw6, NULL); // retry GW hwaddr resolution
|
tx_ndp_ns(ifp, ifp->gw6, NULL, true); // retry GW hwaddr resolution
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
{ // poll driver and let L2 do its work, if any
|
{ // poll driver and let L2 do its work, if any
|
||||||
@@ -11518,13 +11523,12 @@ void mg_connect_resolved(struct mg_connection *c) {
|
|||||||
} // otherwise retain an existing bound port
|
} // otherwise retain an existing bound port
|
||||||
#if MG_ENABLE_IPV6
|
#if MG_ENABLE_IPV6
|
||||||
if (c->rem.is_ip6) {
|
if (c->rem.is_ip6) {
|
||||||
if (c->loc.addr.ip6[0] == 0 && c->loc.addr.ip6[1] == 0 &&
|
bool any = MG_IP6UNSPEC(c->loc.addr.ip6);
|
||||||
c->rem.addr.ip6[0] == ifp->ip6ll[0]) { // same local LAN, use ll
|
if (any && c->rem.addr.ip6[0] == ifp->ip6ll[0]) { // same local LAN, use ll
|
||||||
c->loc.addr.ip6[0] = ifp->ip6ll[0], c->loc.addr.ip6[1] = ifp->ip6ll[1];
|
c->loc.addr.ip6[0] = ifp->ip6ll[0], c->loc.addr.ip6[1] = ifp->ip6ll[1];
|
||||||
} else if (c->loc.addr.ip6[0] == 0 && c->loc.addr.ip6[1] == 0) {
|
} else if (any) { // Use global address
|
||||||
// Use global address
|
|
||||||
c->loc.addr.ip6[0] = ifp->ip6[0], c->loc.addr.ip6[1] = ifp->ip6[1];
|
c->loc.addr.ip6[0] = ifp->ip6[0], c->loc.addr.ip6[1] = ifp->ip6[1];
|
||||||
} // otherwise retain an existing bound address
|
} // otherwise retain an existing bound address
|
||||||
c->loc.is_ip6 = true;
|
c->loc.is_ip6 = true;
|
||||||
} else
|
} else
|
||||||
#endif
|
#endif
|
||||||
@@ -11546,7 +11550,8 @@ void mg_connect_resolved(struct mg_connection *c) {
|
|||||||
&& !MG_IP6MATCH(c->rem.addr.ip6, ifp->gw6))) { // and not gw
|
&& !MG_IP6MATCH(c->rem.addr.ip6, ifp->gw6))) { // and not gw
|
||||||
// If we're in the same LAN, fire a Neighbor Solicitation
|
// If we're in the same LAN, fire a Neighbor Solicitation
|
||||||
MG_DEBUG(("%lu NS lookup...", c->id));
|
MG_DEBUG(("%lu NS lookup...", c->id));
|
||||||
tx_ndp_ns(ifp, c->rem.addr.ip6, NULL); // RFC-4861 4.3, requesting
|
tx_ndp_ns(ifp, c->rem.addr.ip6, NULL,
|
||||||
|
c->loc.addr.ip6[0] == ifp->ip6ll[0]); // RFC-4861 4.3, request
|
||||||
settmout(c, MIP_TTYPE_ARP);
|
settmout(c, MIP_TTYPE_ARP);
|
||||||
c->is_arplooking = 1;
|
c->is_arplooking = 1;
|
||||||
} else if (ifp->gw6_ready) {
|
} else if (ifp->gw6_ready) {
|
||||||
@@ -12735,11 +12740,7 @@ 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)))
|
||||||
@@ -12904,45 +12905,9 @@ 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, sync = false;
|
bool ok = 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;
|
||||||
@@ -12963,7 +12928,6 @@ 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;
|
||||||
@@ -13005,7 +12969,6 @@ 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;
|
||||||
}
|
}
|
||||||
|
|||||||
+37
-32
@@ -380,6 +380,7 @@ static const struct mg_addr ip6_allnodes = {
|
|||||||
static const uint8_t locpx[8] = {0xfe, 0x80, 0, 0, 0, 0, 0, 0};
|
static const uint8_t locpx[8] = {0xfe, 0x80, 0, 0, 0, 0, 0, 0};
|
||||||
|
|
||||||
#define MG_IP6MATCH(a, b) (a[0] == b[0] && a[1] == b[1])
|
#define MG_IP6MATCH(a, b) (a[0] == b[0] && a[1] == b[1])
|
||||||
|
#define MG_IP6UNSPEC(a) (a[0] == 0 && a[1] == 0)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static void settmout(struct mg_connection *c, uint8_t type) {
|
static void settmout(struct mg_connection *c, uint8_t type) {
|
||||||
@@ -934,9 +935,9 @@ static void rx_ndp_ns(struct mg_tcpip_if *ifp, struct pkt *pkt) {
|
|||||||
// - use solicited node multicast to resolve a l2 address (l2_addr = NULL)
|
// - use solicited node multicast to resolve a l2 address (l2_addr = NULL)
|
||||||
// - use unicast to verify presence (l2_addr = neighbor l2 address)
|
// - use unicast to verify presence (l2_addr = neighbor l2 address)
|
||||||
static void tx_ndp_ns(struct mg_tcpip_if *ifp, uint64_t *ip_dst,
|
static void tx_ndp_ns(struct mg_tcpip_if *ifp, uint64_t *ip_dst,
|
||||||
uint8_t *l2_addr) {
|
uint8_t *l2_addr, bool ll) {
|
||||||
|
uint64_t *ip_src = ll ? ifp->ip6ll : ifp->ip6;
|
||||||
uint8_t payload[4 + 16 + 16]; // NOTE(): 16 --> optional len upto 2 hw addr
|
uint8_t payload[4 + 16 + 16]; // NOTE(): 16 --> optional len upto 2 hw addr
|
||||||
uint64_t ip_unspec[2] = {0, 0};
|
|
||||||
size_t payload_len = 20;
|
size_t payload_len = 20;
|
||||||
bool mcast = (l2_addr == NULL);
|
bool mcast = (l2_addr == NULL);
|
||||||
uint64_t ip_mcast[2] = {0, 0};
|
uint64_t ip_mcast[2] = {0, 0};
|
||||||
@@ -956,14 +957,12 @@ static void tx_ndp_ns(struct mg_tcpip_if *ifp, uint64_t *ip_dst,
|
|||||||
l2 = mg_l2_mapip(ifp->l2type, MG_TCPIP_L2ADDR_MCAST6, &ipd);
|
l2 = mg_l2_mapip(ifp->l2type, MG_TCPIP_L2ADDR_MCAST6, &ipd);
|
||||||
}
|
}
|
||||||
payload_len = 20;
|
payload_len = 20;
|
||||||
// TODO(robertc2000): using only link-local IP addr for now
|
if (!MG_IP6UNSPEC(ip_src)) {
|
||||||
// We might consider to add an option to use either link-local or global IP
|
|
||||||
if (!MG_IP6MATCH(ifp->ip6ll, ip_unspec)) {
|
|
||||||
payload[20] = 1; // 4.6.1, source hwaddr; option length in 8-byte units
|
payload[20] = 1; // 4.6.1, source hwaddr; option length in 8-byte units
|
||||||
payload[21] = mg_l2_ip6put(ifp->l2type, ifp->mac, payload + 22);
|
payload[21] = mg_l2_ip6put(ifp->l2type, ifp->mac, payload + 22);
|
||||||
payload_len += 8 * payload[21];
|
payload_len += 8 * payload[21];
|
||||||
}
|
}
|
||||||
tx_icmp6(ifp, l2, ifp->ip6ll, mcast ? ip_mcast : ip_dst, 135, 0, payload,
|
tx_icmp6(ifp, l2, ip_src, mcast ? ip_mcast : ip_dst, 135, 0, payload,
|
||||||
payload_len);
|
payload_len);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -971,11 +970,10 @@ static void tx_ndp_ns(struct mg_tcpip_if *ifp, uint64_t *ip_dst,
|
|||||||
static void tx_ndp_rs(struct mg_tcpip_if *ifp) {
|
static void tx_ndp_rs(struct mg_tcpip_if *ifp) {
|
||||||
uint8_t payload[4 + 16]; // reserved + optional len upto 2 hw addr NOTE()
|
uint8_t payload[4 + 16]; // reserved + optional len upto 2 hw addr NOTE()
|
||||||
size_t payload_len = 4;
|
size_t payload_len = 4;
|
||||||
uint64_t ip_unspec[2] = {0, 0};
|
|
||||||
|
|
||||||
memset(payload, 0, sizeof(payload));
|
memset(payload, 0, sizeof(payload));
|
||||||
|
|
||||||
if (!MG_IP6MATCH(ifp->ip6ll, ip_unspec)) {
|
if (!MG_IP6UNSPEC(ifp->ip6ll)) {
|
||||||
payload[4] = 1; // 4.6.1, source hwaddr; option length in 8-byte units
|
payload[4] = 1; // 4.6.1, source hwaddr; option length in 8-byte units
|
||||||
payload[5] = mg_l2_ip6put(ifp->l2type, ifp->mac, payload + 6);
|
payload[5] = mg_l2_ip6put(ifp->l2type, ifp->mac, payload + 6);
|
||||||
payload_len += 8 * payload[5];
|
payload_len += 8 * payload[5];
|
||||||
@@ -1144,7 +1142,7 @@ static void onstate6change(struct mg_tcpip_if *ifp) {
|
|||||||
(struct mg_addr *) &ip6_allnodes),
|
(struct mg_addr *) &ip6_allnodes),
|
||||||
ifp->ip6ll, (uint64_t *) ip6_allnodes.addr.ip6, false,
|
ifp->ip6ll, (uint64_t *) ip6_allnodes.addr.ip6, false,
|
||||||
ifp->mac);
|
ifp->mac);
|
||||||
if (ifp->ip6[0] != 0 && ifp->ip6[1] != 0)
|
if (!MG_IP6UNSPEC(ifp->ip6))
|
||||||
tx_ndp_na(ifp, // RFC-9131 4.1
|
tx_ndp_na(ifp, // RFC-9131 4.1
|
||||||
mg_l2_mapip(ifp->l2type, MG_TCPIP_L2ADDR_MCAST6,
|
mg_l2_mapip(ifp->l2type, MG_TCPIP_L2ADDR_MCAST6,
|
||||||
(struct mg_addr *) &ip6_allrouters),
|
(struct mg_addr *) &ip6_allrouters),
|
||||||
@@ -1159,9 +1157,9 @@ static void onstate6change(struct mg_tcpip_if *ifp) {
|
|||||||
ifp->is_ip6_changed = false;
|
ifp->is_ip6_changed = false;
|
||||||
}
|
}
|
||||||
} else if (ifp->state6 == MG_TCPIP_STATE_IP) {
|
} else if (ifp->state6 == MG_TCPIP_STATE_IP) {
|
||||||
if ((ifp->gw6[0] != 0 || ifp->gw6[1] != 0) &&
|
if (!MG_IP6UNSPEC(ifp->gw6) &&
|
||||||
(ifp->l2type != MG_TCPIP_L2_PPP && ifp->l2type != MG_TCPIP_L2_PPPoE))
|
(ifp->l2type != MG_TCPIP_L2_PPP && ifp->l2type != MG_TCPIP_L2_PPPoE))
|
||||||
tx_ndp_ns(ifp, ifp->gw6, NULL); // unsolicited GW hwaddr resolution
|
tx_ndp_ns(ifp, ifp->gw6, NULL, true); // unsolicited GW hwaddr resolution
|
||||||
} else if (ifp->state6 == MG_TCPIP_STATE_UP) {
|
} else if (ifp->state6 == MG_TCPIP_STATE_UP) {
|
||||||
MG_INFO(("IP: %M", mg_print_ip6, &ifp->ip6ll));
|
MG_INFO(("IP: %M", mg_print_ip6, &ifp->ip6ll));
|
||||||
}
|
}
|
||||||
@@ -1374,13 +1372,14 @@ static struct mg_connection *accept_conn(struct mg_connection *lsn,
|
|||||||
struct pkt *pkt, uint16_t mss) {
|
struct pkt *pkt, uint16_t mss) {
|
||||||
struct connstate *s;
|
struct connstate *s;
|
||||||
uint8_t *l2addr;
|
uint8_t *l2addr;
|
||||||
|
struct mg_tcpip_if *ifp = lsn->mgr->ifp;
|
||||||
struct mg_connection *c = mg_alloc_conn(lsn->mgr);
|
struct mg_connection *c = mg_alloc_conn(lsn->mgr);
|
||||||
if (c == NULL) {
|
if (c == NULL) {
|
||||||
MG_ERROR(("OOM"));
|
MG_ERROR(("OOM"));
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
s = (struct connstate *) (c + 1);
|
s = (struct connstate *) (c + 1);
|
||||||
s->retransmit = lsn->mgr->ifp->enable_tcp_retransmit;
|
s->retransmit = ifp->enable_tcp_retransmit;
|
||||||
s->txq.align = MG_TCPIP_TXQ_ALIGN;
|
s->txq.align = MG_TCPIP_TXQ_ALIGN;
|
||||||
s->dmss = mss; // from options in client SYN
|
s->dmss = mss; // from options in client SYN
|
||||||
s->seq = mg_ntohl(pkt->tcp->ack), s->ack = mg_ntohl(pkt->tcp->seq);
|
s->seq = mg_ntohl(pkt->tcp->ack), s->ack = mg_ntohl(pkt->tcp->seq);
|
||||||
@@ -1389,19 +1388,21 @@ static struct mg_connection *accept_conn(struct mg_connection *lsn,
|
|||||||
if (lsn->loc.is_ip6) {
|
if (lsn->loc.is_ip6) {
|
||||||
c->rem.addr.ip6[0] = pkt->ip6->src[0],
|
c->rem.addr.ip6[0] = pkt->ip6->src[0],
|
||||||
c->rem.addr.ip6[1] = pkt->ip6->src[1], c->rem.is_ip6 = true;
|
c->rem.addr.ip6[1] = pkt->ip6->src[1], c->rem.is_ip6 = true;
|
||||||
c->loc.addr.ip6[0] = c->mgr->ifp->ip6[0],
|
if (pkt->ip6->dst[0] == ifp->ip6ll[0]) { // link-local prefix
|
||||||
c->loc.addr.ip6[1] = c->mgr->ifp->ip6[1], c->loc.is_ip6 = true;
|
c->loc.addr.ip6[0] = ifp->ip6ll[0], c->loc.addr.ip6[1] = ifp->ip6ll[1];
|
||||||
// TODO(): compare lsn to link-local, or rem as link-local: use ll instead
|
} else {
|
||||||
|
c->loc.addr.ip6[0] = ifp->ip6[0], c->loc.addr.ip6[1] = ifp->ip6[1];
|
||||||
|
}
|
||||||
|
c->loc.is_ip6 = true;
|
||||||
} else
|
} else
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
c->rem.addr.ip4 = pkt->ip->src;
|
c->rem.addr.ip4 = pkt->ip->src;
|
||||||
c->loc.addr.ip4 = c->mgr->ifp->ip;
|
c->loc.addr.ip4 = ifp->ip;
|
||||||
}
|
}
|
||||||
c->rem.port = pkt->tcp->sport;
|
c->rem.port = pkt->tcp->sport;
|
||||||
c->loc.port = lsn->loc.port;
|
c->loc.port = lsn->loc.port;
|
||||||
if ((l2addr = get_return_l2addr(lsn->mgr->ifp, &c->rem, false, pkt)) ==
|
if ((l2addr = get_return_l2addr(ifp, &c->rem, false, pkt)) == NULL) {
|
||||||
NULL) {
|
|
||||||
mg_free(c); // safety net for lousy networks, not actually needed
|
mg_free(c); // safety net for lousy networks, not actually needed
|
||||||
return NULL; // as path has already been checked at SYN (sending SYN+ACK)
|
return NULL; // as path has already been checked at SYN (sending SYN+ACK)
|
||||||
}
|
}
|
||||||
@@ -1459,10 +1460,14 @@ static bool udp_send(struct mg_connection *c, const void *buf, size_t len) {
|
|||||||
struct mg_addr ips;
|
struct mg_addr ips;
|
||||||
memset(&ips, 0, sizeof(ips));
|
memset(&ips, 0, sizeof(ips));
|
||||||
#if MG_ENABLE_IPV6
|
#if MG_ENABLE_IPV6
|
||||||
if (c->loc.is_ip6) {
|
if (c->loc.is_ip6) { // At [::] infer link-local from peer
|
||||||
ips.addr.ip6[0] = ifp->ip6[0], ips.addr.ip6[1] = ifp->ip6[1],
|
if (MG_IP6UNSPEC(c->loc.addr.ip6) ? c->rem.addr.ip6[0] == ifp->ip6ll[0]
|
||||||
|
: c->loc.addr.ip6[0] == ifp->ip6ll[0]) {
|
||||||
|
ips.addr.ip6[0] = ifp->ip6ll[0], ips.addr.ip6[1] = ifp->ip6ll[1];
|
||||||
|
} else {
|
||||||
|
ips.addr.ip6[0] = ifp->ip6[0], ips.addr.ip6[1] = ifp->ip6[1];
|
||||||
|
}
|
||||||
ips.is_ip6 = true;
|
ips.is_ip6 = true;
|
||||||
// TODO(): detect link-local (c->rem) and use it
|
|
||||||
} else
|
} else
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
@@ -2123,14 +2128,14 @@ static void mg_ip6_link(struct mg_tcpip_if *ifp, bool drv_up, bool l2_up) {
|
|||||||
bool cur_drv = (ifp->state6 != MG_TCPIP_STATE_DOWN);
|
bool cur_drv = (ifp->state6 != MG_TCPIP_STATE_DOWN);
|
||||||
bool cur_l2 = (ifp->state6 >= MG_TCPIP_STATE_UP);
|
bool cur_l2 = (ifp->state6 >= MG_TCPIP_STATE_UP);
|
||||||
if (drv_up != cur_drv || l2_up != cur_l2) { // link/L2 state has changed
|
if (drv_up != cur_drv || l2_up != cur_l2) { // link/L2 state has changed
|
||||||
if (ifp->l2type == MG_TCPIP_L2_ETH && l2_up && ifp->ip6ll[0] == 0 &&
|
if (ifp->l2type == MG_TCPIP_L2_ETH && l2_up &&
|
||||||
ifp->ip6ll[1] == 0) { // gen ll address
|
MG_IP6UNSPEC(ifp->ip6ll)) { // gen ll address
|
||||||
mg_l2_genip6(ifp->l2type, ifp->ip6ll, 64, ifp->mac);
|
mg_l2_genip6(ifp->l2type, ifp->ip6ll, 64, ifp->mac);
|
||||||
memcpy(ifp->ip6ll, locpx, 8); // RFC-4291 2.5.6; RFC-2464 5
|
memcpy(ifp->ip6ll, locpx, 8); // RFC-4291 2.5.6; RFC-2464 5
|
||||||
} // just got our link local address if we didn't have one.
|
} // just got our link local address if we didn't have one.
|
||||||
// If static configuration is used, global addresses,
|
// If static configuration is used, global addresses,
|
||||||
// prefix length, and gw are already filled at this point.
|
// prefix length, and gw are already filled at this point.
|
||||||
if (ifp->ip6[0] == 0 && ifp->ip6[1] == 0) ifp->enable_slaac = true;
|
if (MG_IP6UNSPEC(ifp->ip6)) ifp->enable_slaac = true;
|
||||||
if (!l2_up && ifp->enable_slaac) ifp->ip6[0] = ifp->ip6[1] = 0;
|
if (!l2_up && ifp->enable_slaac) ifp->ip6[0] = ifp->ip6[1] = 0;
|
||||||
ifp->state6 = !drv_up ? MG_TCPIP_STATE_DOWN
|
ifp->state6 = !drv_up ? MG_TCPIP_STATE_DOWN
|
||||||
: !l2_up ? MG_TCPIP_STATE_LINK_UP
|
: !l2_up ? MG_TCPIP_STATE_LINK_UP
|
||||||
@@ -2191,8 +2196,8 @@ static void mg_tcpip_poll(struct mg_tcpip_if *ifp, uint64_t now) {
|
|||||||
onstate6change(ifp);
|
onstate6change(ifp);
|
||||||
}
|
}
|
||||||
if (expired_1000ms && ifp->state6 == MG_TCPIP_STATE_READY && !ifp->gw6_ready &&
|
if (expired_1000ms && ifp->state6 == MG_TCPIP_STATE_READY && !ifp->gw6_ready &&
|
||||||
(ifp->gw6[0] != 0 || ifp->gw6[1] != 0))
|
!MG_IP6UNSPEC(ifp->gw6))
|
||||||
tx_ndp_ns(ifp, ifp->gw6, NULL); // retry GW hwaddr resolution
|
tx_ndp_ns(ifp, ifp->gw6, NULL, true); // retry GW hwaddr resolution
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
{ // poll driver and let L2 do its work, if any
|
{ // poll driver and let L2 do its work, if any
|
||||||
@@ -2371,13 +2376,12 @@ void mg_connect_resolved(struct mg_connection *c) {
|
|||||||
} // otherwise retain an existing bound port
|
} // otherwise retain an existing bound port
|
||||||
#if MG_ENABLE_IPV6
|
#if MG_ENABLE_IPV6
|
||||||
if (c->rem.is_ip6) {
|
if (c->rem.is_ip6) {
|
||||||
if (c->loc.addr.ip6[0] == 0 && c->loc.addr.ip6[1] == 0 &&
|
bool any = MG_IP6UNSPEC(c->loc.addr.ip6);
|
||||||
c->rem.addr.ip6[0] == ifp->ip6ll[0]) { // same local LAN, use ll
|
if (any && c->rem.addr.ip6[0] == ifp->ip6ll[0]) { // same local LAN, use ll
|
||||||
c->loc.addr.ip6[0] = ifp->ip6ll[0], c->loc.addr.ip6[1] = ifp->ip6ll[1];
|
c->loc.addr.ip6[0] = ifp->ip6ll[0], c->loc.addr.ip6[1] = ifp->ip6ll[1];
|
||||||
} else if (c->loc.addr.ip6[0] == 0 && c->loc.addr.ip6[1] == 0) {
|
} else if (any) { // Use global address
|
||||||
// Use global address
|
|
||||||
c->loc.addr.ip6[0] = ifp->ip6[0], c->loc.addr.ip6[1] = ifp->ip6[1];
|
c->loc.addr.ip6[0] = ifp->ip6[0], c->loc.addr.ip6[1] = ifp->ip6[1];
|
||||||
} // otherwise retain an existing bound address
|
} // otherwise retain an existing bound address
|
||||||
c->loc.is_ip6 = true;
|
c->loc.is_ip6 = true;
|
||||||
} else
|
} else
|
||||||
#endif
|
#endif
|
||||||
@@ -2399,7 +2403,8 @@ void mg_connect_resolved(struct mg_connection *c) {
|
|||||||
&& !MG_IP6MATCH(c->rem.addr.ip6, ifp->gw6))) { // and not gw
|
&& !MG_IP6MATCH(c->rem.addr.ip6, ifp->gw6))) { // and not gw
|
||||||
// If we're in the same LAN, fire a Neighbor Solicitation
|
// If we're in the same LAN, fire a Neighbor Solicitation
|
||||||
MG_DEBUG(("%lu NS lookup...", c->id));
|
MG_DEBUG(("%lu NS lookup...", c->id));
|
||||||
tx_ndp_ns(ifp, c->rem.addr.ip6, NULL); // RFC-4861 4.3, requesting
|
tx_ndp_ns(ifp, c->rem.addr.ip6, NULL,
|
||||||
|
c->loc.addr.ip6[0] == ifp->ip6ll[0]); // RFC-4861 4.3, request
|
||||||
settmout(c, MIP_TTYPE_ARP);
|
settmout(c, MIP_TTYPE_ARP);
|
||||||
c->is_arplooking = 1;
|
c->is_arplooking = 1;
|
||||||
} else if (ifp->gw6_ready) {
|
} else if (ifp->gw6_ready) {
|
||||||
|
|||||||
+1
-43
@@ -411,11 +411,7 @@ 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)))
|
||||||
@@ -580,45 +576,9 @@ 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, sync = false;
|
bool ok = 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;
|
||||||
@@ -639,7 +599,6 @@ 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;
|
||||||
@@ -681,7 +640,6 @@ 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;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -328,6 +328,8 @@ static void init_tests(struct mg_mgr *mgr, struct eth *e, struct ipp *ipp,
|
|||||||
mif->driver_data = &s_driver_data;
|
mif->driver_data = &s_driver_data;
|
||||||
#if MG_ENABLE_IPV6
|
#if MG_ENABLE_IPV6
|
||||||
if (ipp->ip6 != NULL) {
|
if (ipp->ip6 != NULL) {
|
||||||
|
mif->ip6ll[0] = mg_htonll(0xfe80000000000000);
|
||||||
|
mif->ip6ll[1] = mg_htonll(1);
|
||||||
mif->ip6[0] = mg_htonll(0x100000000000000);
|
mif->ip6[0] = mg_htonll(0x100000000000000);
|
||||||
mif->prefix[0] = 1;
|
mif->prefix[0] = 1;
|
||||||
mif->prefix_len = 64;
|
mif->prefix_len = 64;
|
||||||
@@ -664,6 +666,16 @@ static void test_tcp_basics(bool ipv6) {
|
|||||||
ASSERT((t->ack == mg_htonl(1002)));
|
ASSERT((t->ack == mg_htonl(1002)));
|
||||||
// make sure it is closed
|
// make sure it is closed
|
||||||
ASSERT(mgr.conns->next == NULL); // only one connection: the listener
|
ASSERT(mgr.conns->next == NULL); // only one connection: the listener
|
||||||
|
#if MG_ENABLE_IPV6
|
||||||
|
// Test we use link-local address for link-local peers
|
||||||
|
if (ipv6) {
|
||||||
|
ip6.src[0] = mif.ip6ll[0], ip6.src[1] = mg_htonll(2);
|
||||||
|
ip6.dst[0] = mif.ip6ll[0], ip6.dst[1] = mif.ip6ll[1];
|
||||||
|
init_tcp_handshake(&e, &ipp, &mgr);
|
||||||
|
ASSERT(mgr.conns->loc.addr.ip6[0] == mif.ip6ll[0] &&
|
||||||
|
mgr.conns->loc.addr.ip6[1] == mif.ip6ll[1]);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
s_driver_data.len = 0;
|
s_driver_data.len = 0;
|
||||||
mg_mgr_free(&mgr);
|
mg_mgr_free(&mgr);
|
||||||
@@ -1513,6 +1525,18 @@ static void test_udp(bool ipv6) {
|
|||||||
ASSERT((uint8_t) (((i6->ver & 15) << 2) | (i6->label[0] >> 6)) ==
|
ASSERT((uint8_t) (((i6->ver & 15) << 2) | (i6->label[0] >> 6)) ==
|
||||||
MG_DSCP_AF(4, 1));
|
MG_DSCP_AF(4, 1));
|
||||||
ASSERT(udp6csum_ok(i6, u));
|
ASSERT(udp6csum_ok(i6, u));
|
||||||
|
#if MG_ENABLE_IPV6
|
||||||
|
// Test we use link-local address for link-local peers
|
||||||
|
mgr.conns->recv.len = 0;
|
||||||
|
ip6.src[0] = mif.ip6ll[0], ip6.src[1] = mg_htonll(2);
|
||||||
|
ip6.dst[0] = mif.ip6ll[0], ip6.dst[1] = mif.ip6ll[1];
|
||||||
|
s_driver_data.len = 0;
|
||||||
|
create_udp_dat(&e, &ipp, 1, 888, 2);
|
||||||
|
mg_mgr_poll(&mgr, 0);
|
||||||
|
ASSERT(received_response(&s_driver_data));
|
||||||
|
ASSERT(i6->src[0] == mif.ip6ll[0] && i6->src[1] == mif.ip6ll[1] &&
|
||||||
|
i6->dst[0] == ip6.src[0] && i6->dst[1] == ip6.src[1]);
|
||||||
|
#endif
|
||||||
} else {
|
} else {
|
||||||
ASSERT(i->src == mg_htonl(0x1000000) && i->dst == mg_htonl(0x2000000));
|
ASSERT(i->src == mg_htonl(0x1000000) && i->dst == mg_htonl(0x2000000));
|
||||||
ASSERT(i->tos == (MG_DSCP_AF(4, 1) << 2));
|
ASSERT(i->tos == (MG_DSCP_AF(4, 1) << 2));
|
||||||
|
|||||||
@@ -1,21 +1,18 @@
|
|||||||
# 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. -I$(MGDIR) -Ilittlefs -Icmsis_core/CMSIS/Core/Include/
|
CFLAGS += -I. -Imongoose -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 $(MGDIR)/mongoose.c
|
SOURCES = main.c hal.c flash_image.c mongoose/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
|
||||||
@@ -26,16 +23,17 @@ 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
|
||||||
|
|
||||||
# Disabled for littlefs/lfs.c
|
|
||||||
CFLAGS += -Wno-shadow
|
|
||||||
|
|
||||||
all build: firmware.bin
|
all build: firmware.bin
|
||||||
|
|
||||||
|
mongoose/mongoose.c mongoose/mongoose.h:
|
||||||
|
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 littlefs sys/dirent.h $(SOURCES) $(MGDIR)/mongoose.h $(wildcard *.h) link.ld Makefile
|
firmware.elf: cmsis_core cmsis_rt1186 $(SOURCES) $(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:
|
||||||
@@ -46,13 +44,9 @@ 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.* littlefs
|
rm -rf firmware.* cmsis_* mongoose/mongoose.*
|
||||||
@@ -74,14 +74,6 @@ 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 {
|
||||||
@@ -116,18 +108,6 @@ 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,12 +3,6 @@
|
|||||||
#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
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
// LittleFS provides directory types in mongoose.h instead of newlib's stub.
|
|
||||||
@@ -1,32 +1,30 @@
|
|||||||
# 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. -I$(MGDIR) -Ilittlefs -Icmsis_core/CMSIS/Core/Include/ -DCPU_MIMXRT1062DVL6B
|
CFLAGS += -I. -Imongoose -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 $(MGDIR)/mongoose.c
|
SOURCES = main.c hal.c flash_image.c mongoose/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
|
||||||
|
|
||||||
# Disabled for littlefs/lfs.c
|
|
||||||
CFLAGS += -Wno-shadow
|
|
||||||
|
|
||||||
all build: firmware.bin
|
all build: firmware.bin
|
||||||
|
|
||||||
|
mongoose/mongoose.c mongoose/mongoose.h:
|
||||||
|
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 littlefs sys/dirent.h $(SOURCES) $(MGDIR)/mongoose.h $(wildcard *.h) link.ld Makefile
|
firmware.elf: cmsis_core cmsis_rt1060 $(SOURCES) $(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:
|
||||||
@@ -37,13 +35,9 @@ 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.* littlefs
|
rm -rf firmware.* cmsis_* mongoose/mongoose.*
|
||||||
@@ -70,14 +70,6 @@ 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 {
|
||||||
@@ -110,18 +102,6 @@ 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,11 +5,6 @@
|
|||||||
#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
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
// LittleFS provides directory types in mongoose.h instead of newlib's stub.
|
|
||||||
@@ -1,19 +1,16 @@
|
|||||||
# 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. -I$(MGDIR) -Ilittlefs -Icmsis_core/CMSIS/Core/Include/ -DCPU_MIMXRT1176DVMAA_cm7
|
CFLAGS += -I. -Imongoose -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 $(MGDIR)/mongoose.c
|
SOURCES = main.c hal.c flash_image.c mongoose/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
|
||||||
@@ -23,16 +20,17 @@ 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
|
||||||
|
|
||||||
# Disabled for littlefs/lfs.c
|
|
||||||
CFLAGS += -Wno-shadow
|
|
||||||
|
|
||||||
all build: firmware.bin
|
all build: firmware.bin
|
||||||
|
|
||||||
|
mongoose/mongoose.c mongoose/mongoose.h:
|
||||||
|
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 littlefs sys/dirent.h $(SOURCES) $(MGDIR)/mongoose.h $(wildcard *.h) link.ld Makefile
|
firmware.elf: cmsis_core cmsis_rt1170 $(SOURCES) $(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:
|
||||||
@@ -43,13 +41,9 @@ 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.* littlefs
|
rm -rf firmware.* cmsis_* mongoose/mongoose.*
|
||||||
@@ -74,14 +74,6 @@ 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 {
|
||||||
@@ -116,18 +108,6 @@ 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,12 +9,6 @@
|
|||||||
#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
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
// LittleFS provides directory types in mongoose.h instead of newlib's stub.
|
|
||||||
Reference in new issue
Block a user