Skip to content

Commit 73fab86

Browse files
author
Memfault Inc
committed
Memfault Firmware SDK 0.31.2 (Build 464682)
1 parent 14362a7 commit 73fab86

File tree

9 files changed

+133
-60
lines changed

9 files changed

+133
-60
lines changed

CHANGES.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
### Changes between Memfault SDK 0.31.2 and SDK 0.31.1 - June 24, 2022
2+
3+
#### :chart_with_upwards_trend: Improvements
4+
5+
- Fixed a :bug: in the
6+
[Zephyr port HTTP implementation](ports/zephyr/common/memfault_platform_http.c),
7+
where a socket file descriptor was leaked. This caused every HTTP operation
8+
after the first to fail on Zephyr platforms.
9+
- Added an update to improve the quality of stack traces when using
10+
`MEMFAULT_ASSERT` with the TI ARM Clang Compiler
11+
112
### Changes between Memfault SDK 0.31.1 and SDK 0.31.0 - June 16, 2022
213

314
#### :chart_with_upwards_trend: Improvements

VERSION

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
BUILD ID: 458093
2-
GIT COMMIT: b7d0794c4
1+
BUILD ID: 464682
2+
GIT COMMIT: 5b8557d55

components/include/memfault/panics/fault_handling.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,9 @@ MEMFAULT_NAKED_FUNC void MEMFAULT_EXC_HANDLER_WATCHDOG(void);
8282
//! @param lr The return address
8383
//! @see MEMFAULT_ASSERT_RECORD
8484
//! @see MEMFAULT_ASSERT
85-
#if defined(__CC_ARM)
86-
//! ARMCC will optimize away link register stores from callsites which makes it impossible for a
87-
//! reliable backtrace to be resolved so we don't use the NORETURN attribute
85+
#if defined(__CC_ARM) || (defined(__clang__) && defined(__ti__))
86+
//! ARMCC and tiarmclang will optimize away link register stores from callsites which makes it
87+
//! impossible for a reliable backtrace to be resolved so we don't use the NORETURN attribute
8888
#else
8989
MEMFAULT_NORETURN
9090
#endif
@@ -97,9 +97,9 @@ void memfault_fault_handling_assert(void *pc, void *lr);
9797
//! @param extra_info Additional information used by the assert handler
9898
//! @see MEMFAULT_ASSERT_RECORD
9999
//! @see MEMFAULT_ASSERT
100-
#if defined(__CC_ARM)
101-
//! ARMCC will optimize away link register stores from callsites which makes it impossible for a
102-
//! reliable backtrace to be resolved so we don't use the NORETURN attribute
100+
#if defined(__CC_ARM) || (defined(__clang__) && defined(__ti__))
101+
//! ARMCC and tiarmclang optimize away link register stores from callsites which makes it
102+
//! impossible for a reliable backtrace to be resolved so we don't use the NORETURN attribute
103103
#else
104104
MEMFAULT_NORETURN
105105
#endif

components/include/memfault/version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ typedef struct {
1919
uint8_t patch;
2020
} sMfltSdkVersion;
2121

22-
#define MEMFAULT_SDK_VERSION { .major = 0, .minor = 31, .patch = 1 }
22+
#define MEMFAULT_SDK_VERSION { .major = 0, .minor = 31, .patch = 2 }
2323

2424
#ifdef __cplusplus
2525
}

components/panics/src/memfault_fault_handling_arm.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -565,12 +565,24 @@ static void prv_fault_handling_assert(void *pc, void *lr, eMemfaultRebootReason
565565
MEMFAULT_NO_OPT
566566
void memfault_fault_handling_assert(void *pc, void *lr) {
567567
prv_fault_handling_assert(pc, lr, kMfltRebootReason_Assert);
568-
MEMFAULT_UNREACHABLE;
568+
569+
#if (defined(__clang__) && defined(__ti__))
570+
//! tiarmclang does not respect the no optimization request and will
571+
//! strip the pushing callee saved registers making it impossible to recover
572+
//! an accurate backtrace so we skip over providing the unreachable hint.
573+
#else
574+
MEMFAULT_UNREACHABLE;
575+
#endif
569576
}
570577
MEMFAULT_NO_OPT
571578
void memfault_fault_handling_assert_extra(void *pc, void *lr, sMemfaultAssertInfo *extra_info) {
572579
prv_fault_handling_assert(pc, lr, extra_info->assert_reason);
573-
MEMFAULT_UNREACHABLE;
580+
581+
#if (defined(__clang__) && defined(__ti__))
582+
//! See comment in memfault_fault_handling_assert for more context
583+
#else
584+
MEMFAULT_UNREACHABLE;
585+
#endif
574586
}
575587

576588
#endif /* MEMFAULT_COMPILER_ARM */

examples/zephyr/README.md

Lines changed: 50 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -26,55 +26,64 @@ Step-by-step instructions can be found in the
2626

2727
1. Clone the repo
2828

29-
```bash
30-
$ git clone [email protected]:zephyrproject-rtos/zephyr.git --branch v2.5-branch zephyr
31-
```
29+
```bash
30+
$ git clone [email protected]:zephyrproject-rtos/zephyr.git --branch v2.5-branch zephyr
31+
```
3232

3333
2. Create a virtual environment
3434

35-
```bash
36-
python3 -m venv .venv
37-
source .venv/bin/activate
38-
pip install -r zephyr/scripts/requirements.txt
39-
```
35+
```bash
36+
python3 -m venv .venv
37+
source .venv/bin/activate
38+
pip install -r zephyr/scripts/requirements.txt
39+
```
4040

4141
3. Initialize a new build environment:
4242

43-
```bash
44-
$ west init -l zephyr/
45-
$ west update
46-
```
43+
```bash
44+
$ west init -l zephyr/
45+
$ west update
46+
```
4747

4848
4. When using the STM32L4 discovery board, the following patch is also needed
4949
due to bugs in the stack:
5050

51-
```diff
52-
diff --git a/drivers/wifi/eswifi/Kconfig.eswifi b/drivers/wifi/eswifi/Kconfig.eswifi
53-
index 6468b98113..5f80c918cd 100644
54-
--- a/drivers/wifi/eswifi/Kconfig.eswifi
55-
+++ b/drivers/wifi/eswifi/Kconfig.eswifi
56-
@@ -9,7 +9,7 @@ menuconfig WIFI_ESWIFI
57-
select WIFI_OFFLOAD
58-
select NET_OFFLOAD
59-
select NET_SOCKETS
60-
- select NET_SOCKETS_OFFLOAD
61-
+ imply NET_SOCKETS_OFFLOAD
62-
select GPIO
63-
64-
if WIFI_ESWIFI
65-
diff --git a/drivers/wifi/eswifi/eswifi_socket.c b/drivers/wifi/eswifi/eswifi_socket.c
66-
index e31ca0eecd..119f55778d 100644
67-
--- a/drivers/wifi/eswifi/eswifi_socket.c
68-
+++ b/drivers/wifi/eswifi/eswifi_socket.c
69-
@@ -301,6 +301,6 @@ int __eswifi_socket_new(struct eswifi_dev *eswifi, int family, int type,
70-
k_delayed_work_init(&socket->read_work, eswifi_off_read_work);
71-
socket->usage = 1;
72-
LOG_DBG("Socket index %d", socket->index);
73-
-
74-
+ net_context_set_state(socket->context, NET_CONTEXT_CONNECTED);
75-
return socket->index;
76-
}
77-
```
51+
```diff
52+
diff --git a/drivers/wifi/eswifi/Kconfig.eswifi b/drivers/wifi/eswifi/Kconfig.eswifi
53+
index 6468b98113..5f80c918cd 100644
54+
--- a/drivers/wifi/eswifi/Kconfig.eswifi
55+
+++ b/drivers/wifi/eswifi/Kconfig.eswifi
56+
@@ -9,7 +9,7 @@ menuconfig WIFI_ESWIFI
57+
select WIFI_OFFLOAD
58+
select NET_OFFLOAD
59+
select NET_SOCKETS
60+
- select NET_SOCKETS_OFFLOAD
61+
+ imply NET_SOCKETS_OFFLOAD
62+
select GPIO
63+
64+
if WIFI_ESWIFI
65+
diff --git a/drivers/wifi/eswifi/eswifi_socket.c b/drivers/wifi/eswifi/eswifi_socket.c
66+
index e31ca0eecd..119f55778d 100644
67+
--- a/drivers/wifi/eswifi/eswifi_socket.c
68+
+++ b/drivers/wifi/eswifi/eswifi_socket.c
69+
@@ -301,6 +301,6 @@ int __eswifi_socket_new(struct eswifi_dev *eswifi, int family, int type,
70+
k_delayed_work_init(&socket->read_work, eswifi_off_read_work);
71+
socket->usage = 1;
72+
LOG_DBG("Socket index %d", socket->index);
73+
-
74+
+ net_context_set_state(socket->context, NET_CONTEXT_CONNECTED);
75+
return socket->index;
76+
}
77+
```
78+
79+
You can find this patch at
80+
[`stm32l4_disco_zephyr2.5_wifi.patch`](./stm32l4_disco_zephyr2.5_wifi.patch),
81+
which can be applied by this command (assuming the `zephyr` repo is in the
82+
current working directory):
83+
84+
```bash
85+
git -C zephyr apply < stm32l4_disco_zephyr2.5_wifi.patch
86+
```
7887

7988
### Memfault Project Key
8089

@@ -87,7 +96,7 @@ https://app.memfault.com/, navigate to the project you want to use and select
8796

8897
### Building
8998

90-
```
99+
```bash
91100
$ cd $MEMFAULT_SDK/examples/zephyr/
92101
$ west build -b disco_l475_iot1 apps/memfault_demo_app
93102
[...]
@@ -119,7 +128,7 @@ arm-none-eabi-gdb-py --eval-command="target remote localhost:2331" --ex="mon re
119128

120129
At this point, the application should be running and you can open a console:
121130

122-
```
131+
```bash
123132
$ miniterm.py /dev/cu.usbmodem* 115200 --raw
124133
*** Booting Zephyr OS build zephyr-v2.5.0-56-gec0aa8331a65 ***
125134
<inf> <mflt>: GNU Build ID: c20cef04e29e3ae7784002c3650d48f3a0b7b07d
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
From 4a4a13fa00ef0d04d9be239d145ddeb173ac72a1 Mon Sep 17 00:00:00 2001
2+
From: Memfault Inc <[email protected]>
3+
Date: Thu, 23 Jun 2022 10:45:20 -0400
4+
Subject: [PATCH] Patch for stm32l4_disco wifi on Zephyr 2.5.1
5+
6+
This patch is for Zephyr v2.5-branch
7+
(52e06334fbeabd5d764935c1fc47d7225216fff4), and fixes the
8+
eswifi driver for the Memfault demo app.
9+
---
10+
drivers/wifi/eswifi/Kconfig.eswifi | 2 +-
11+
drivers/wifi/eswifi/eswifi_socket.c | 1 +
12+
2 files changed, 2 insertions(+), 1 deletion(-)
13+
14+
diff --git a/drivers/wifi/eswifi/Kconfig.eswifi b/drivers/wifi/eswifi/Kconfig.eswifi
15+
index 6468b98113..5f80c918cd 100644
16+
--- a/drivers/wifi/eswifi/Kconfig.eswifi
17+
+++ b/drivers/wifi/eswifi/Kconfig.eswifi
18+
@@ -9,7 +9,7 @@ menuconfig WIFI_ESWIFI
19+
select WIFI_OFFLOAD
20+
select NET_OFFLOAD
21+
select NET_SOCKETS
22+
- select NET_SOCKETS_OFFLOAD
23+
+ imply NET_SOCKETS_OFFLOAD
24+
select GPIO
25+
26+
if WIFI_ESWIFI
27+
diff --git a/drivers/wifi/eswifi/eswifi_socket.c b/drivers/wifi/eswifi/eswifi_socket.c
28+
index e31ca0eecd..a3705535ab 100644
29+
--- a/drivers/wifi/eswifi/eswifi_socket.c
30+
+++ b/drivers/wifi/eswifi/eswifi_socket.c
31+
@@ -302,5 +302,6 @@ int __eswifi_socket_new(struct eswifi_dev *eswifi, int family, int type,
32+
socket->usage = 1;
33+
LOG_DBG("Socket index %d", socket->index);
34+
35+
+ net_context_set_state(socket->context, NET_CONTEXT_CONNECTED);
36+
return socket->index;
37+
}
38+
--
39+
2.36.1
40+

ports/zephyr/common/memfault_platform_http.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,8 @@ static bool prv_try_send(int sock_fd, const uint8_t *buf, size_t buf_len) {
191191
return true;
192192
}
193193

194-
static int prv_open_socket(struct addrinfo **res, const char *host, int port_num) {
195-
struct addrinfo hints = {
194+
static int prv_open_socket(struct zsock_addrinfo **res, const char *host, int port_num) {
195+
struct zsock_addrinfo hints = {
196196
.ai_family = AF_INET,
197197
.ai_socktype = SOCK_STREAM,
198198
};
@@ -559,6 +559,7 @@ int memfault_zephyr_port_ota_update(const sMemfaultOtaUpdateHandler *handler) {
559559

560560
int memfault_zephyr_port_post_data(void) {
561561
sMemfaultHttpContext ctx = {0};
562+
ctx.sock_fd = -1;
562563

563564
int rv = memfault_zephyr_port_http_open_socket(&ctx);
564565
if (rv < 0) {
@@ -589,18 +590,18 @@ int memfault_zephyr_port_http_open_socket(sMemfaultHttpContext *ctx) {
589590
}
590591

591592
void memfault_zephyr_port_http_close_socket(sMemfaultHttpContext *ctx) {
592-
if (ctx->sock_fd > 0) {
593+
if (ctx->sock_fd >= 0) {
593594
close(ctx->sock_fd);
594595
}
595-
ctx->sock_fd = 0;
596+
ctx->sock_fd = -1;
596597

597598
if (ctx->res != NULL) {
598599
freeaddrinfo(ctx->res);
599600
ctx->res = NULL;
600601
}
601602
}
602603

603-
bool memfault_zephyr_port_http_is_connected(sMemfaultHttpContext *ctx) { return ctx->sock_fd > 0; }
604+
bool memfault_zephyr_port_http_is_connected(sMemfaultHttpContext *ctx) { return ctx->sock_fd >= 0; }
604605

605606
void memfault_zephyr_port_http_upload_sdk_data(sMemfaultHttpContext *ctx) {
606607
int max_messages_to_send = 5;
@@ -630,11 +631,11 @@ int memfault_zephyr_port_http_post_chunk(sMemfaultHttpContext *ctx, void *p_data
630631
memfault_http_start_chunk_post(prv_send_data, &(ctx->sock_fd), data_len);
631632

632633
if (!prv_try_send(ctx->sock_fd, p_data, data_len)) {
633-
return -1;
634+
return -2;
634635
}
635636

636637
if (!prv_wait_for_http_response(ctx->sock_fd)) {
637-
return -1;
638+
return -3;
638639
}
639640

640641
return 0;

ports/zephyr/include/memfault/ports/zephyr/http.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ int memfault_zephyr_port_release_download_url(char **download_url);
9696
//! Context structure used to carry state information about the HTTP connection
9797
typedef struct {
9898
int sock_fd;
99-
struct addrinfo *res;
99+
struct zsock_addrinfo *res;
100100
} sMemfaultHttpContext;
101101

102102
//! Open a socket to the Memfault chunks upload server

0 commit comments

Comments
 (0)