diff --git a/lib/bin/sb_fota/CMakeLists.txt b/lib/bin/sb_fota/CMakeLists.txt index 3a9e8dc..45d687c 100644 --- a/lib/bin/sb_fota/CMakeLists.txt +++ b/lib/bin/sb_fota/CMakeLists.txt @@ -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) diff --git a/lib/bin/sb_fota/Kconfig b/lib/bin/sb_fota/Kconfig index 10eaef3..f15ce12 100644 --- a/lib/bin/sb_fota/Kconfig +++ b/lib/bin/sb_fota/Kconfig @@ -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 diff --git a/lib/bin/sb_fota/include/sb_fota.h b/lib/bin/sb_fota/include/sb_fota.h index a6ff901..54f46bf 100644 --- a/lib/bin/sb_fota/include/sb_fota.h +++ b/lib/bin/sb_fota/include/sb_fota.h @@ -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, }; /** @@ -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. diff --git a/lib/bin/sb_fota/include/sb_fota_os.h b/lib/bin/sb_fota/include/sb_fota_os.h index 5c0f796..b2f9d98 100644 --- a/lib/bin/sb_fota/include/sb_fota_os.h +++ b/lib/bin/sb_fota/include/sb_fota_os.h @@ -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. */ @@ -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" diff --git a/lib/bin/sb_fota/lib/cortex-m33/hard-float/libsb_fota.a b/lib/bin/sb_fota/lib/cortex-m33/hard-float/libsb_fota.a index b79b63a..eb98730 100644 Binary files a/lib/bin/sb_fota/lib/cortex-m33/hard-float/libsb_fota.a and b/lib/bin/sb_fota/lib/cortex-m33/hard-float/libsb_fota.a differ diff --git a/lib/bin/sb_fota/lib/cortex-m33/hard-float/libsb_fota_log.a b/lib/bin/sb_fota/lib/cortex-m33/hard-float/libsb_fota_log.a new file mode 100644 index 0000000..8fefe86 Binary files /dev/null and b/lib/bin/sb_fota/lib/cortex-m33/hard-float/libsb_fota_log.a differ diff --git a/lib/bin/sb_fota/lib/cortex-m33/softfp-float/libsb_fota.a b/lib/bin/sb_fota/lib/cortex-m33/softfp-float/libsb_fota.a index 6ae4ab8..166b178 100644 Binary files a/lib/bin/sb_fota/lib/cortex-m33/softfp-float/libsb_fota.a and b/lib/bin/sb_fota/lib/cortex-m33/softfp-float/libsb_fota.a differ diff --git a/lib/bin/sb_fota/lib/cortex-m33/softfp-float/libsb_fota_log.a b/lib/bin/sb_fota/lib/cortex-m33/softfp-float/libsb_fota_log.a new file mode 100644 index 0000000..5c4b2b4 Binary files /dev/null and b/lib/bin/sb_fota/lib/cortex-m33/softfp-float/libsb_fota_log.a differ diff --git a/lib/bin/sb_fota/os/sb_fota_os.c b/lib/bin/sb_fota/os/sb_fota_os.c index c43a772..ae7adbf 100644 --- a/lib/bin/sb_fota/os/sb_fota_os.c +++ b/lib/bin/sb_fota/os/sb_fota_os.c @@ -11,7 +11,6 @@ #include #include #include -#include #include #include #include @@ -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(); @@ -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 */ @@ -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); } } @@ -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"); } } } diff --git a/lib/bin/sb_fota/os/sb_fota_settings.c b/lib/bin/sb_fota/os/sb_fota_settings.c index 35bc80d..e8c106a 100644 --- a/lib/bin/sb_fota/os/sb_fota_settings.c +++ b/lib/bin/sb_fota/os/sb_fota_settings.c @@ -12,9 +12,12 @@ #include #include #include +#include #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; @@ -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); } } }