Skip to content

Commit

Permalink
Update to the latest library
Browse files Browse the repository at this point in the history
update to the latest library, including removal of reboot event.

Signed-off-by: Håvard Vermeer <[email protected]>
  • Loading branch information
nordic-hani authored and kacperradoszewski committed Feb 25, 2025
1 parent da1c314 commit 98d80df
Show file tree
Hide file tree
Showing 10 changed files with 74 additions and 55 deletions.
8 changes: 6 additions & 2 deletions lib/bin/sb_fota/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,12 @@ if(NOT EXISTS ${SB_FOTA_LIB_PATH})
"(${SB_FOTA_LIB_PATH} doesn't exist.)")
endif()

set( SB_FOTA_TARGET libsb_fota)
zephyr_library_import(${SB_FOTA_TARGET} ${SB_FOTA_LIB_PATH}/libsb_fota.a)
set(SB_FOTA_TARGET libsb_fota)
if(CONFIG_SB_FOTA_LOG)
zephyr_library_import(${SB_FOTA_TARGET} ${SB_FOTA_LIB_PATH}/libsb_fota_log.a)
else()
zephyr_library_import(${SB_FOTA_TARGET} ${SB_FOTA_LIB_PATH}/libsb_fota.a)
endif()
target_link_libraries(${SB_FOTA_TARGET} INTERFACE modem -lc)

zephyr_include_directories(include)
Expand Down
8 changes: 7 additions & 1 deletion lib/bin/sb_fota/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,15 @@ config SB_FOTA_ID_PREFIX
be used on provisioning. Prefix is only appended on IMEI or UUID. Not appended on
client ID changed on runtime API.

config SB_FOTA_LOG
bool "Link binary with logs"
help
Links the application with the library version capable of emitting logs.
This increases the final size of the application.

module=SB_FOTA
module-dep=LOG
module-str=Modem Firmware Over the Air client
module-str=SoftBank FOTA library
source "${ZEPHYR_BASE}/subsys/logging/Kconfig.template.log_config"

endif # SB_FOTA
5 changes: 0 additions & 5 deletions lib/bin/sb_fota/include/sb_fota.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ enum sb_fota_event {
* device is booted.
*/
SB_FOTA_EVENT_MODEM_SHUTDOWN,
/** Modem FW is now updated, reboot the device to resume network operations. */
SB_FOTA_EVENT_REBOOT_PENDING,
};

/**
Expand All @@ -60,9 +58,6 @@ typedef void (*sb_fota_callback_t)(enum sb_fota_event event);
* If Kconfig value CONFIG_SB_FOTA_AUTOINIT is set, then application is not required to call this
* function, but might still want to use it for registering the callback.
*
* If there is no callback set, then the library automatically reboots the device in case of
* SB_FOTA_EVENT_REBOOT_PENDING event.
*
* @param callback Callback for the application events or NULL for no callback.
*
* @retval 0 If the operation was successful.
Expand Down
23 changes: 7 additions & 16 deletions lib/bin/sb_fota/include/sb_fota_os.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,6 @@ uint32_t sb_fota_os_uptime_get_32(void);
*/
int sb_fota_os_sleep(int ms);

/**
* @brief Reboot system.
*/
void sb_fota_os_sys_reset(void);

/**
* @brief Get a random value.
*/
Expand Down Expand Up @@ -123,19 +118,15 @@ bool sb_fota_os_timer_is_running(struct sb_fota_os_timer *timer);

int64_t sb_fota_os_timegm64(const struct tm *time);

#define FOTA_LOG_LEVEL_NONE 0U
#define FOTA_LOG_LEVEL_ERR 1U
#define FOTA_LOG_LEVEL_WRN 2U
#define FOTA_LOG_LEVEL_INF 3U
#define FOTA_LOG_LEVEL_DBG 4U
enum sb_fota_os_log_level {
SB_FOTA_OS_LOG_LEVEL_NONE,
SB_FOTA_OS_LOG_LEVEL_ERR,
SB_FOTA_OS_LOG_LEVEL_WRN,
SB_FOTA_OS_LOG_LEVEL_INF,
SB_FOTA_OS_LOG_LEVEL_DBG,
};

void sb_fota_os_log(int level, const char *fmt, ...);
const char *sb_fota_os_log_strdup(const char *str);

#define FOTA_LOG_ERR(...) sb_fota_os_log(FOTA_LOG_LEVEL_ERR, __VA_ARGS__);
#define FOTA_LOG_WRN(...) sb_fota_os_log(FOTA_LOG_LEVEL_WRN, __VA_ARGS__);
#define FOTA_LOG_INF(...) sb_fota_os_log(FOTA_LOG_LEVEL_INF, __VA_ARGS__);
#define FOTA_LOG_DBG(...) sb_fota_os_log(FOTA_LOG_LEVEL_DBG, __VA_ARGS__);

#define SB_FOTA_SETTINGS_PREFIX "sb_fota"

Expand Down
Binary file modified lib/bin/sb_fota/lib/cortex-m33/hard-float/libsb_fota.a
Binary file not shown.
Binary file not shown.
Binary file modified lib/bin/sb_fota/lib/cortex-m33/softfp-float/libsb_fota.a
Binary file not shown.
Binary file not shown.
78 changes: 49 additions & 29 deletions lib/bin/sb_fota/os/sb_fota_os.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#include <zephyr/device.h>
#include <zephyr/types.h>
#include <zephyr/random/random.h>
#include <zephyr/sys/reboot.h>
#include <zephyr/sys/timeutil.h>
#include <zephyr/logging/log.h>
#include <zephyr/logging/log_msg.h>
Expand Down Expand Up @@ -56,12 +55,6 @@ int sb_fota_os_sleep(int ms)

/* OS functions */

void sb_fota_os_sys_reset(void)
{
sys_reboot(SYS_REBOOT_COLD);
CODE_UNREACHABLE;
}

uint32_t sb_fota_os_rand_get(void)
{
return sys_rand32_get();
Expand Down Expand Up @@ -215,30 +208,57 @@ int64_t sb_fota_os_timegm64(const struct tm *time)
}

/* Logging */

LOG_MODULE_REGISTER(sb_fota, CONFIG_SB_FOTA_LOG_LEVEL);

void sb_fota_os_log(int level, const char *fmt, ...)
#if defined(CONFIG_LOG)
static uint8_t log_level_translate(uint8_t level)
{
if (!IS_ENABLED(CONFIG_LOG_MODE_MINIMAL)) {
va_list ap;

va_start(ap, fmt);
log_generic(level, fmt, ap);
va_end(ap);
switch (level) {
case SB_FOTA_OS_LOG_LEVEL_ERR:
return LOG_LEVEL_ERR;
case SB_FOTA_OS_LOG_LEVEL_WRN:
return LOG_LEVEL_WRN;
case SB_FOTA_OS_LOG_LEVEL_INF:
return LOG_LEVEL_INF;
case SB_FOTA_OS_LOG_LEVEL_DBG:
return LOG_LEVEL_DBG;
default:
return LOG_LEVEL_NONE;
}
}
#endif

const char *sb_fota_os_log_strdup(const char *str)
{
return str;
}

void sb_fota_os_logdump(const char *str, const void *data, size_t len)
void sb_fota_os_log(int level, const char *fmt, ...)
{
if (IS_ENABLED(CONFIG_LOG)) {
LOG_HEXDUMP_DBG(data, len, str);
#if defined(CONFIG_LOG)
level = log_level_translate(level);
if (level > CONFIG_SB_FOTA_LOG_LEVEL) {
return;
}

va_list ap;
va_start(ap, fmt);

#if CONFIG_LOG_MODE_MINIMAL
/* Fallback to minimal implementation. */
printk("%c: ", z_log_minimal_level_to_char(level));
z_log_minimal_vprintk(fmt, ap);
printk("\n");
#else
void *source;

if (IS_ENABLED(CONFIG_LOG_RUNTIME_FILTERING)) {
source = (void *)__log_current_dynamic_data;
} else {
source = (void *)__log_current_const_data;
}

z_log_msg_runtime_vcreate(Z_LOG_LOCAL_DOMAIN_ID, source, level,
NULL, 0, 0, fmt, ap);
#endif /* CONFIG_LOG_MODE_MINIMAL */

va_end(ap);
#endif /* CONFIG_LOG */
}

/* Settings */
Expand Down Expand Up @@ -304,19 +324,19 @@ void sb_fota_os_store_setting(const char *name, size_t len, const void *ptr)

void sb_fota_os_update_apply(void)
{
FOTA_LOG_INF("Applying modem firmware update...");
FOTA_LOG_DBG("Shutting down modem");
LOG_INF("Applying modem firmware update...");
LOG_DBG("Shutting down modem");

if (fota_download_util_apply_update(DFU_TARGET_IMAGE_TYPE_MODEM_DELTA) == 0) {
FOTA_LOG_DBG("Modem update OK");
LOG_DBG("Modem update OK");
} else {
FOTA_LOG_ERR("Modem update failed");
LOG_ERR("Modem update failed");
}

int err = lte_lc_connect();

if (err) {
FOTA_LOG_ERR("Connecting to network failed, err %d\n", err);
LOG_ERR("Connecting to network failed, err %d", err);
}
}

Expand All @@ -329,7 +349,7 @@ static void sb_fota_on_modem_init(int ret, void *ctx)
if (IS_ENABLED(CONFIG_SB_FOTA_AUTOINIT)) {
err = sb_fota_init(NULL);
if (err) {
FOTA_LOG_ERR("Failed to initialize FOTA client");
LOG_ERR("Failed to initialize FOTA client");
}
}
}
7 changes: 5 additions & 2 deletions lib/bin/sb_fota/os/sb_fota_settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@
#include <modem/modem_jwt.h>
#include <modem/modem_info.h>
#include <zephyr/sys/util_macro.h>
#include <zephyr/logging/log.h>

#define IMEI_LEN 15

LOG_MODULE_REGISTER(sb_fota_settings, CONFIG_SB_FOTA_LOG_LEVEL);

int sb_fota_settings_cloud_sec_tag_get(void)
{
return CONFIG_SB_FOTA_TLS_SECURITY_TAG;
Expand Down Expand Up @@ -71,11 +74,11 @@ const char *sb_fota_settings_client_id_get(void)
int ret;
if (IS_ENABLED(CONFIG_SB_FOTA_ID_UUID)) {
if ((ret = get_uuid())) {
FOTA_LOG_ERR("Failed to read UUID (err %d)", ret);
LOG_ERR("Failed to read UUID (err %d)", ret);
}
} else {
if ((ret = get_imei())) {
FOTA_LOG_ERR("Failed to read IMEI (err %d)", ret);
LOG_ERR("Failed to read IMEI (err %d)", ret);
}
}
}
Expand Down

0 comments on commit 98d80df

Please sign in to comment.