Skip to content

Commit

Permalink
Simplify version management
Browse files Browse the repository at this point in the history
  • Loading branch information
noahp committed Aug 5, 2024
1 parent 39dc3a7 commit abe7fe3
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 55 deletions.
18 changes: 0 additions & 18 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,3 @@ project(wifi)
FILE(GLOB app_sources src/*.c)
target_sources(app PRIVATE ${app_sources})
zephyr_include_directories(config)

# Generate a git hash that's used as part of the software_version, eg
# 1.0.0+12345678. Permit overriding at command line for CI builds.
if (NOT DEFINED ZEPHYR_MEMFAULT_EXAMPLE_GIT_SHA1)
EXECUTE_PROCESS(
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMAND git rev-parse --short HEAD
RESULT_VARIABLE commit_sha1
OUTPUT_VARIABLE ZEPHYR_MEMFAULT_EXAMPLE_GIT_SHA1
OUTPUT_STRIP_TRAILING_WHITESPACE
COMMAND_ERROR_IS_FATAL ANY
)
endif()

zephyr_compile_definitions(
ZEPHYR_MEMFAULT_EXAMPLE_GIT_SHA1=\"${ZEPHYR_MEMFAULT_EXAMPLE_GIT_SHA1}\"
)
# zephyr_ld_options(-Wl,--fatal-warnings)
10 changes: 4 additions & 6 deletions Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@
# This is loaded when building this directory with west.
menu "Memfault Example Application Configuration"

config MEMFAULT_EXAMPLE_SOFTWARE_VERSION
string "Software Version"
default "1.0.0"
help
The software version to report to Memfault.

# Override the MCUBOOT image version to exactly match the version reported
# to Memfault
config MCUBOOT_IMGTOOL_SIGN_VERSION
default MEMFAULT_BUILTIN_DEVICE_INFO_SOFTWARE_VERSION
endmenu

source "Kconfig.zephyr"
32 changes: 1 addition & 31 deletions src/main.c
Original file line number Diff line number Diff line change
@@ -1,49 +1,19 @@
//! @file

#include <string.h>
#include <zephyr/drivers/hwinfo.h>
#include <zephyr/kernel.h>
#include <zephyr/logging/log.h>

#include "app_version.h"
#include "memfault/components.h"
#include "memfault/ports/zephyr/http.h"

LOG_MODULE_REGISTER(mflt_app, LOG_LEVEL_DBG);

const char *memfault_zephyr_get_device_id(void) {
uint8_t dev_id[16] = {0};
static char dev_id_str[sizeof(dev_id) * 2 + 1];

// Check if the device id has already been initialized
if (dev_id_str[0]) {
return dev_id_str;
}

// Obtain the device id
ssize_t length = hwinfo_get_device_id(dev_id, sizeof(dev_id));

// Render the obtained serial number in hexadecimal representation
for (size_t i = 0; i < length; i++) {
(void)snprintf(&dev_id_str[i * 2], sizeof(dev_id_str), "%02x", dev_id[i]);
}

return dev_id_str;
}

void memfault_platform_get_device_info(sMemfaultDeviceInfo *info) {
*info = (sMemfaultDeviceInfo){
.device_serial = memfault_zephyr_get_device_id(),
.software_type = "app",
.software_version = APP_VERSION_STRING "+" ZEPHYR_MEMFAULT_EXAMPLE_GIT_SHA1,
.hardware_version = CONFIG_BOARD,
};
}

int main(void) {
LOG_INF("Memfault Demo App! Board %s\n", CONFIG_BOARD);

printk("\n" MEMFAULT_BANNER_COLORIZED);
printk("\nApplication git describe: " STRINGIFY(APP_BUILD_VERSION) "\n");

// 250ms delay seems to make the logs in the *info_dump() commands work
// correctly
Expand Down

0 comments on commit abe7fe3

Please sign in to comment.