Skip to content

Commit bc438a7

Browse files
author
Memfault Inc
committed
Memfault Firmware SDK 0.30.3 (Build 433100)
1 parent 13f3a9b commit bc438a7

File tree

15 files changed

+337
-34
lines changed

15 files changed

+337
-34
lines changed

CHANGES.md

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,26 @@
1-
### Changes between Memfault SDK 0.30.2 and SDK 0.30.1 - April 12, 2022
1+
### Changes between Memfault SDK 0.30.3 and SDK 0.30.2 - April 25, 2022
22

33
#### :chart_with_upwards_trend: Improvements
44

5+
- Particle's Device OS port improvements:
6+
- A user initiated reboot will now be recorded as a User Shutdown instead of a
7+
Low Power reset
8+
- A custom hardware_version can now be specified using the `hardware_version`
9+
argument when initializing the Memfault library
10+
- Default hardware version now uses the `PLATFORM_NAME` macro instead of
11+
`PRODUCT_SERIES` macro
12+
- Zephyr port improvements
13+
- Exposed lower level APIs to Memfault's HTTP post implementation to allow
14+
easier custom handling. See
15+
[`ports/zephyr/include/memfault/ports/zephyr/http.h`](ports/zephyr/include/memfault/ports/zephyr/http.h)
16+
for more details
17+
18+
#### :house: Internal
19+
20+
- Misc README documentation improvements
21+
22+
### Changes between Memfault SDK 0.30.2 and SDK 0.30.1 - April 12, 2022
23+
524
- Fix a build regression on nRF Connect SDK v1.2 caused by the new Kconfig flag
625
`CONFIG_MEMFAULT_HTTP_USES_MBEDTLS`
726

VERSION

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
BUILD ID: 425870
2-
GIT COMMIT: 10b790b05
1+
BUILD ID: 433100
2+
GIT COMMIT: 558716463

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 = 30, .patch = 2 }
22+
#define MEMFAULT_SDK_VERSION { .major = 0, .minor = 30, .patch = 3 }
2323

2424
#ifdef __cplusplus
2525
}

ports/particle/src/memfault.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ static void prv_memfault_reboot_reason_get(sResetBootupInfo *info) {
287287
break;
288288
case RESET_REASON_POWER_DOWN:
289289
case RESET_REASON_POWER_MANAGEMENT:
290-
reset_reason = kMfltRebootReason_LowPower;
290+
reset_reason = kMfltRebootReason_UserShutdown;
291291
break;
292292
case RESET_REASON_POWER_BROWNOUT:
293293
reset_reason = kMfltRebootReason_BrownOutReset;
@@ -497,7 +497,7 @@ void memfault_platform_reboot_tracking_boot(void) {
497497
memfault_reboot_tracking_boot(s_reboot_tracking, &reset_reason);
498498
}
499499

500-
Memfault::Memfault(const uint16_t product_version, const char *build_metadata)
500+
Memfault::Memfault(const uint16_t product_version, const char *build_metadata, const char *hardware_version)
501501
: m_connected(false) {
502502

503503
System.enableFeature(FEATURE_RESET_INFO);
@@ -506,10 +506,15 @@ Memfault::Memfault(const uint16_t product_version, const char *build_metadata)
506506
System.on(cloud_status, &Memfault::handle_cloud_connectivity_event, this);
507507

508508
// Grab the revision of the particle board being used for a given product type.
509-
uint32_t hw_version_id = 0;
510-
hal_get_device_hw_version(&hw_version_id, NULL);
511-
snprintf(s_hardware_version, sizeof(s_hardware_version), "%s-rev%d",
512-
PRODUCT_SERIES, (int)hw_version_id);
509+
if (hardware_version == NULL) {
510+
// Use default hardware_version scheme
511+
uint32_t hw_version_id = 0;
512+
hal_get_device_hw_version(&hw_version_id, NULL);
513+
snprintf(s_hardware_version, sizeof(s_hardware_version), "%s-rev%d",
514+
MEMFAULT_EXPAND_AND_QUOTE(PLATFORM_NAME), (int)hw_version_id);
515+
} else {
516+
snprintf(s_hardware_version, sizeof(s_hardware_version), "%s", hardware_version);
517+
}
513518

514519
// Uniquely identifies a firmware version running on a device.
515520
//

ports/particle/src/memfault.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@ class Memfault {
2424
//! See https://mflt.io/particle-versioning for more details
2525
//! @param build_metadata Additional build metadata (such as a git short SHA or timestamp)
2626
//! to append to the "software_version" reported to Memfault.
27-
explicit Memfault(const uint16_t product_version = 0, const char *build_metadata = NULL);
27+
//! @param hardware_version When set, overrides the default strategy for reporting the
28+
//! hardware_version using the PLATFORM_NAME compiled against
29+
explicit Memfault(const uint16_t product_version = 0, const char *build_metadata = NULL,
30+
const char *hardware_version = NULL);
2831

2932
//! Should be called from your applications loop handler
3033
//!

ports/zephyr/README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,17 @@ within Zephyr and a different release, the port may work there as well
2020

2121
## Integrating SDK
2222

23-
1. Apply .patch in release directory to Zephyr Kernel
23+
1. Depending on Zephyr version, apply .patch in release directory to Zephyr
24+
Kernel. Be sure to use the patch matching the Zephyr version in use.
2425

2526
```
2627
$ cd $ZEPHYR_ROOT_DIR/
2728
$ git apply $MEMFAULT_SDK_ROOT/ports/zephyr/[v1.14|v2.0]/zephyr-integration.patch
2829
```
2930

31+
Note that `v2.x/coredump-support.patch` should be applied for Zephyr 2.2 and 2.3
32+
only.
33+
3034
2. Clone (or symlink) memfault-firmware-sdk in Zephyr Project
3135

3236
```

ports/zephyr/common/memfault_platform_http.c

Lines changed: 61 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -558,39 +558,84 @@ int memfault_zephyr_port_ota_update(const sMemfaultOtaUpdateHandler *handler) {
558558
}
559559

560560
int memfault_zephyr_port_post_data(void) {
561-
int rv = -1;
561+
sMemfaultHttpContext ctx = {0};
562562

563+
int rv = memfault_zephyr_port_http_open_socket(&ctx);
564+
if (rv < 0) {
565+
return rv;
566+
}
567+
568+
memfault_zephyr_port_http_upload_sdk_data(&ctx);
569+
570+
memfault_zephyr_port_http_close_socket(&ctx);
571+
572+
return 0;
573+
}
574+
575+
int memfault_zephyr_port_http_open_socket(sMemfaultHttpContext *ctx) {
563576
const char *host = MEMFAULT_HTTP_GET_CHUNKS_API_HOST();
564-
const int port = MEMFAULT_HTTP_GET_CHUNKS_API_PORT();
577+
const int port = MEMFAULT_HTTP_GET_CHUNKS_API_PORT();
565578

566-
struct addrinfo *res = NULL;
567-
const int sock_fd = prv_open_socket(&res, host, port);
568-
if (sock_fd < 0) {
569-
goto cleanup;
579+
memfault_zephyr_port_http_close_socket(ctx);
580+
581+
ctx->sock_fd = prv_open_socket(&(ctx->res), host, port);
582+
583+
if (ctx->sock_fd < 0) {
584+
memfault_zephyr_port_http_close_socket(ctx);
585+
return -1;
570586
}
571587

588+
return 0;
589+
}
590+
591+
void memfault_zephyr_port_http_close_socket(sMemfaultHttpContext *ctx) {
592+
if (ctx->sock_fd > 0) {
593+
close(ctx->sock_fd);
594+
}
595+
ctx->sock_fd = 0;
596+
597+
if (ctx->res != NULL) {
598+
freeaddrinfo(ctx->res);
599+
ctx->res = NULL;
600+
}
601+
}
602+
603+
bool memfault_zephyr_port_http_is_connected(sMemfaultHttpContext *ctx) { return ctx->sock_fd > 0; }
604+
605+
void memfault_zephyr_port_http_upload_sdk_data(sMemfaultHttpContext *ctx) {
572606
int max_messages_to_send = 5;
573607
#if CONFIG_MEMFAULT_HTTP_MAX_POST_SIZE && CONFIG_MEMFAULT_RAM_BACKED_COREDUMP
574608
// The largest data type we will send is a coredump. If CONFIG_MEMFAULT_HTTP_MAX_POST_SIZE
575609
// is being used, make sure we issue enough HTTP POSTS such that an entire coredump will be sent.
576-
max_messages_to_send = MEMFAULT_MAX(max_messages_to_send,
577-
CONFIG_MEMFAULT_RAM_BACKED_COREDUMP_SIZE / CONFIG_MEMFAULT_HTTP_MAX_POST_SIZE);
610+
max_messages_to_send =
611+
MEMFAULT_MAX(max_messages_to_send,
612+
CONFIG_MEMFAULT_RAM_BACKED_COREDUMP_SIZE / CONFIG_MEMFAULT_HTTP_MAX_POST_SIZE);
578613
#endif
579614

580615
while (max_messages_to_send-- > 0) {
581-
if (!prv_send_next_msg(sock_fd)) {
616+
if (!prv_send_next_msg(ctx->sock_fd)) {
582617
break;
583618
}
584-
if (!prv_wait_for_http_response(sock_fd)) {
619+
if (!prv_wait_for_http_response(ctx->sock_fd)) {
585620
break;
586621
}
587622
}
623+
}
588624

589-
close(sock_fd);
625+
int memfault_zephyr_port_http_post_chunk(sMemfaultHttpContext *ctx, void *p_data, size_t data_len) {
626+
if (!memfault_zephyr_port_http_is_connected(ctx)) {
627+
return -1;
628+
}
590629

591-
// if we got here, everything succeeded!
592-
rv = 0;
593-
cleanup:
594-
freeaddrinfo(res);
595-
return rv;
630+
memfault_http_start_chunk_post(prv_send_data, &(ctx->sock_fd), data_len);
631+
632+
if (!prv_try_send(ctx->sock_fd, p_data, data_len)) {
633+
return -1;
634+
}
635+
636+
if (!prv_wait_for_http_response(ctx->sock_fd)) {
637+
return -1;
638+
}
639+
640+
return 0;
596641
}

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

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
//! @brief
99
//! Zephyr specific http utility for interfacing with Memfault HTTP utilities
1010

11-
#include <stddef.h>
1211
#include <stdbool.h>
12+
#include <stddef.h>
1313

1414
#ifdef __cplusplus
1515
extern "C" {
@@ -56,7 +56,6 @@ typedef struct {
5656
bool (*handle_download_complete)(void *user_ctx);
5757
} sMemfaultOtaUpdateHandler;
5858

59-
6059
//! Handler which can be used to run OTA update using Memfault's Release Mgmt Infra
6160
//! For more details see:
6261
//! https://mflt.io/release-mgmt
@@ -91,6 +90,59 @@ int memfault_zephyr_port_get_download_url(char **download_url);
9190
//! Releases the memory returned from memfault_zephyr_port_get_download_url()
9291
int memfault_zephyr_port_release_download_url(char **download_url);
9392

93+
//!
94+
//! Utility functions for manually posting memfault data.
95+
96+
//! Context structure used to carry state information about the HTTP connection
97+
typedef struct {
98+
int sock_fd;
99+
struct addrinfo *res;
100+
} sMemfaultHttpContext;
101+
102+
//! Open a socket to the Memfault chunks upload server
103+
//!
104+
//! @param ctx If the socket is opened successfully, this will be populated with
105+
//! the connection state for the other HTTP functions below
106+
//!
107+
//! @note After use, memfault_zephyr_port_http_close_socket() must be called
108+
//! to close the socket and free any associated memory
109+
//!
110+
//! @return
111+
//! 0 : Success
112+
//! < 0 : Error
113+
int memfault_zephyr_port_http_open_socket(sMemfaultHttpContext *ctx);
114+
115+
//! Close a socket previously opened with
116+
//! memfault_zephyr_port_http_open_socket()
117+
void memfault_zephyr_port_http_close_socket(sMemfaultHttpContext *ctx);
118+
119+
//! Test if the socket is open
120+
bool memfault_zephyr_port_http_is_connected(sMemfaultHttpContext *ctx);
121+
122+
//! Identical to memfault_zephyr_port_post_data() but uses the already-opened
123+
//! socket to send data
124+
//!
125+
//! @param ctx Connection context previously opened with
126+
//! memfault_zephyr_port_http_open_socket()
127+
void memfault_zephyr_port_http_upload_sdk_data(sMemfaultHttpContext *ctx);
128+
129+
//! Similar to memfault_zephyr_port_http_upload_sdk_data(), but instead of using
130+
//! the SDK packetizer functions under the hood, send the data passed into this
131+
//! function.
132+
//!
133+
//! Typically this function is used to send data from pre-packetized data; for
134+
//! example, data that may have been stored outside of the Memfault SDK
135+
//! internally-managed buffers, or data coming from an external source (another
136+
//! chip running the Memfault SDK).
137+
//!
138+
//! @param ctx Connection context previously opened with
139+
//! memfault_zephyr_port_http_open_socket()
140+
//!
141+
//! @return
142+
//! 0 : Success
143+
//! < 0 : Error
144+
int memfault_zephyr_port_http_post_chunk(sMemfaultHttpContext *ctx, void *p_data, size_t data_len);
145+
94146
#ifdef __cplusplus
95147
}
96148
#endif

scripts/mflt-build-id/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "mflt-build-id"
3-
version = "0.0.4"
3+
version = "0.0.5"
44
description = "Memfault Build Id injector"
55
authors = ["Memfault Inc <[email protected]>"]
66
repository = "https://github.com/memfault/memfault-firmware-sdk"

scripts/mflt-build-id/setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@
1010
from distutils.core import setup
1111

1212
# This is a stub file generated so that `pip` can install this package in "editable mode".
13-
setup(name="mflt-build-id", packages=["mflt_build_id"], version="0.0.4", package_dir={"": "src"})
13+
setup(name="mflt-build-id", packages=["mflt_build_id"], version="0.0.5", package_dir={"": "src"})

0 commit comments

Comments
 (0)