Skip to content

Commit

Permalink
Memfault Firmware SDK 0.30.3 (Build 433100)
Browse files Browse the repository at this point in the history
  • Loading branch information
Memfault Inc committed Apr 25, 2022
1 parent 13f3a9b commit bc438a7
Show file tree
Hide file tree
Showing 15 changed files with 337 additions and 34 deletions.
21 changes: 20 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,26 @@
### Changes between Memfault SDK 0.30.2 and SDK 0.30.1 - April 12, 2022
### Changes between Memfault SDK 0.30.3 and SDK 0.30.2 - April 25, 2022

#### :chart_with_upwards_trend: Improvements

- Particle's Device OS port improvements:
- A user initiated reboot will now be recorded as a User Shutdown instead of a
Low Power reset
- A custom hardware_version can now be specified using the `hardware_version`
argument when initializing the Memfault library
- Default hardware version now uses the `PLATFORM_NAME` macro instead of
`PRODUCT_SERIES` macro
- Zephyr port improvements
- Exposed lower level APIs to Memfault's HTTP post implementation to allow
easier custom handling. See
[`ports/zephyr/include/memfault/ports/zephyr/http.h`](ports/zephyr/include/memfault/ports/zephyr/http.h)
for more details

#### :house: Internal

- Misc README documentation improvements

### Changes between Memfault SDK 0.30.2 and SDK 0.30.1 - April 12, 2022

- Fix a build regression on nRF Connect SDK v1.2 caused by the new Kconfig flag
`CONFIG_MEMFAULT_HTTP_USES_MBEDTLS`

Expand Down
4 changes: 2 additions & 2 deletions VERSION
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
BUILD ID: 425870
GIT COMMIT: 10b790b05
BUILD ID: 433100
GIT COMMIT: 558716463
2 changes: 1 addition & 1 deletion components/include/memfault/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ typedef struct {
uint8_t patch;
} sMfltSdkVersion;

#define MEMFAULT_SDK_VERSION { .major = 0, .minor = 30, .patch = 2 }
#define MEMFAULT_SDK_VERSION { .major = 0, .minor = 30, .patch = 3 }

#ifdef __cplusplus
}
Expand Down
17 changes: 11 additions & 6 deletions ports/particle/src/memfault.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ static void prv_memfault_reboot_reason_get(sResetBootupInfo *info) {
break;
case RESET_REASON_POWER_DOWN:
case RESET_REASON_POWER_MANAGEMENT:
reset_reason = kMfltRebootReason_LowPower;
reset_reason = kMfltRebootReason_UserShutdown;
break;
case RESET_REASON_POWER_BROWNOUT:
reset_reason = kMfltRebootReason_BrownOutReset;
Expand Down Expand Up @@ -497,7 +497,7 @@ void memfault_platform_reboot_tracking_boot(void) {
memfault_reboot_tracking_boot(s_reboot_tracking, &reset_reason);
}

Memfault::Memfault(const uint16_t product_version, const char *build_metadata)
Memfault::Memfault(const uint16_t product_version, const char *build_metadata, const char *hardware_version)
: m_connected(false) {

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

// Grab the revision of the particle board being used for a given product type.
uint32_t hw_version_id = 0;
hal_get_device_hw_version(&hw_version_id, NULL);
snprintf(s_hardware_version, sizeof(s_hardware_version), "%s-rev%d",
PRODUCT_SERIES, (int)hw_version_id);
if (hardware_version == NULL) {
// Use default hardware_version scheme
uint32_t hw_version_id = 0;
hal_get_device_hw_version(&hw_version_id, NULL);
snprintf(s_hardware_version, sizeof(s_hardware_version), "%s-rev%d",
MEMFAULT_EXPAND_AND_QUOTE(PLATFORM_NAME), (int)hw_version_id);
} else {
snprintf(s_hardware_version, sizeof(s_hardware_version), "%s", hardware_version);
}

// Uniquely identifies a firmware version running on a device.
//
Expand Down
5 changes: 4 additions & 1 deletion ports/particle/src/memfault.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ class Memfault {
//! See https://mflt.io/particle-versioning for more details
//! @param build_metadata Additional build metadata (such as a git short SHA or timestamp)
//! to append to the "software_version" reported to Memfault.
explicit Memfault(const uint16_t product_version = 0, const char *build_metadata = NULL);
//! @param hardware_version When set, overrides the default strategy for reporting the
//! hardware_version using the PLATFORM_NAME compiled against
explicit Memfault(const uint16_t product_version = 0, const char *build_metadata = NULL,
const char *hardware_version = NULL);

//! Should be called from your applications loop handler
//!
Expand Down
6 changes: 5 additions & 1 deletion ports/zephyr/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,17 @@ within Zephyr and a different release, the port may work there as well

## Integrating SDK

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

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

Note that `v2.x/coredump-support.patch` should be applied for Zephyr 2.2 and 2.3
only.

2. Clone (or symlink) memfault-firmware-sdk in Zephyr Project

```
Expand Down
77 changes: 61 additions & 16 deletions ports/zephyr/common/memfault_platform_http.c
Original file line number Diff line number Diff line change
Expand Up @@ -558,39 +558,84 @@ int memfault_zephyr_port_ota_update(const sMemfaultOtaUpdateHandler *handler) {
}

int memfault_zephyr_port_post_data(void) {
int rv = -1;
sMemfaultHttpContext ctx = {0};

int rv = memfault_zephyr_port_http_open_socket(&ctx);
if (rv < 0) {
return rv;
}

memfault_zephyr_port_http_upload_sdk_data(&ctx);

memfault_zephyr_port_http_close_socket(&ctx);

return 0;
}

int memfault_zephyr_port_http_open_socket(sMemfaultHttpContext *ctx) {
const char *host = MEMFAULT_HTTP_GET_CHUNKS_API_HOST();
const int port = MEMFAULT_HTTP_GET_CHUNKS_API_PORT();
const int port = MEMFAULT_HTTP_GET_CHUNKS_API_PORT();

struct addrinfo *res = NULL;
const int sock_fd = prv_open_socket(&res, host, port);
if (sock_fd < 0) {
goto cleanup;
memfault_zephyr_port_http_close_socket(ctx);

ctx->sock_fd = prv_open_socket(&(ctx->res), host, port);

if (ctx->sock_fd < 0) {
memfault_zephyr_port_http_close_socket(ctx);
return -1;
}

return 0;
}

void memfault_zephyr_port_http_close_socket(sMemfaultHttpContext *ctx) {
if (ctx->sock_fd > 0) {
close(ctx->sock_fd);
}
ctx->sock_fd = 0;

if (ctx->res != NULL) {
freeaddrinfo(ctx->res);
ctx->res = NULL;
}
}

bool memfault_zephyr_port_http_is_connected(sMemfaultHttpContext *ctx) { return ctx->sock_fd > 0; }

void memfault_zephyr_port_http_upload_sdk_data(sMemfaultHttpContext *ctx) {
int max_messages_to_send = 5;
#if CONFIG_MEMFAULT_HTTP_MAX_POST_SIZE && CONFIG_MEMFAULT_RAM_BACKED_COREDUMP
// The largest data type we will send is a coredump. If CONFIG_MEMFAULT_HTTP_MAX_POST_SIZE
// is being used, make sure we issue enough HTTP POSTS such that an entire coredump will be sent.
max_messages_to_send = MEMFAULT_MAX(max_messages_to_send,
CONFIG_MEMFAULT_RAM_BACKED_COREDUMP_SIZE / CONFIG_MEMFAULT_HTTP_MAX_POST_SIZE);
max_messages_to_send =
MEMFAULT_MAX(max_messages_to_send,
CONFIG_MEMFAULT_RAM_BACKED_COREDUMP_SIZE / CONFIG_MEMFAULT_HTTP_MAX_POST_SIZE);
#endif

while (max_messages_to_send-- > 0) {
if (!prv_send_next_msg(sock_fd)) {
if (!prv_send_next_msg(ctx->sock_fd)) {
break;
}
if (!prv_wait_for_http_response(sock_fd)) {
if (!prv_wait_for_http_response(ctx->sock_fd)) {
break;
}
}
}

close(sock_fd);
int memfault_zephyr_port_http_post_chunk(sMemfaultHttpContext *ctx, void *p_data, size_t data_len) {
if (!memfault_zephyr_port_http_is_connected(ctx)) {
return -1;
}

// if we got here, everything succeeded!
rv = 0;
cleanup:
freeaddrinfo(res);
return rv;
memfault_http_start_chunk_post(prv_send_data, &(ctx->sock_fd), data_len);

if (!prv_try_send(ctx->sock_fd, p_data, data_len)) {
return -1;
}

if (!prv_wait_for_http_response(ctx->sock_fd)) {
return -1;
}

return 0;
}
56 changes: 54 additions & 2 deletions ports/zephyr/include/memfault/ports/zephyr/http.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
//! @brief
//! Zephyr specific http utility for interfacing with Memfault HTTP utilities

#include <stddef.h>
#include <stdbool.h>
#include <stddef.h>

#ifdef __cplusplus
extern "C" {
Expand Down Expand Up @@ -56,7 +56,6 @@ typedef struct {
bool (*handle_download_complete)(void *user_ctx);
} sMemfaultOtaUpdateHandler;


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

//!
//! Utility functions for manually posting memfault data.

//! Context structure used to carry state information about the HTTP connection
typedef struct {
int sock_fd;
struct addrinfo *res;
} sMemfaultHttpContext;

//! Open a socket to the Memfault chunks upload server
//!
//! @param ctx If the socket is opened successfully, this will be populated with
//! the connection state for the other HTTP functions below
//!
//! @note After use, memfault_zephyr_port_http_close_socket() must be called
//! to close the socket and free any associated memory
//!
//! @return
//! 0 : Success
//! < 0 : Error
int memfault_zephyr_port_http_open_socket(sMemfaultHttpContext *ctx);

//! Close a socket previously opened with
//! memfault_zephyr_port_http_open_socket()
void memfault_zephyr_port_http_close_socket(sMemfaultHttpContext *ctx);

//! Test if the socket is open
bool memfault_zephyr_port_http_is_connected(sMemfaultHttpContext *ctx);

//! Identical to memfault_zephyr_port_post_data() but uses the already-opened
//! socket to send data
//!
//! @param ctx Connection context previously opened with
//! memfault_zephyr_port_http_open_socket()
void memfault_zephyr_port_http_upload_sdk_data(sMemfaultHttpContext *ctx);

//! Similar to memfault_zephyr_port_http_upload_sdk_data(), but instead of using
//! the SDK packetizer functions under the hood, send the data passed into this
//! function.
//!
//! Typically this function is used to send data from pre-packetized data; for
//! example, data that may have been stored outside of the Memfault SDK
//! internally-managed buffers, or data coming from an external source (another
//! chip running the Memfault SDK).
//!
//! @param ctx Connection context previously opened with
//! memfault_zephyr_port_http_open_socket()
//!
//! @return
//! 0 : Success
//! < 0 : Error
int memfault_zephyr_port_http_post_chunk(sMemfaultHttpContext *ctx, void *p_data, size_t data_len);

#ifdef __cplusplus
}
#endif
2 changes: 1 addition & 1 deletion scripts/mflt-build-id/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "mflt-build-id"
version = "0.0.4"
version = "0.0.5"
description = "Memfault Build Id injector"
authors = ["Memfault Inc <[email protected]>"]
repository = "https://github.com/memfault/memfault-firmware-sdk"
Expand Down
2 changes: 1 addition & 1 deletion scripts/mflt-build-id/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@
from distutils.core import setup

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

0 comments on commit bc438a7

Please sign in to comment.