Skip to content

Commit

Permalink
lib: nrf_modem: update modem init return values
Browse files Browse the repository at this point in the history
Add modem init return values.

Signed-off-by: Eivind Jølsgard <eivind.jolsgard@nordicsemi.no>
  • Loading branch information
eivindj-nordic authored and lemrey committed Sep 19, 2023
1 parent 88ac79a commit 76be615
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 24 deletions.
20 changes: 9 additions & 11 deletions applications/asset_tracker_v2/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -183,19 +183,19 @@ static void on_modem_lib_dfu(int dfu_res, void *ctx)
/* Fallthrough */
case NRF_MODEM_DFU_RESULT_UUID_ERROR:
case NRF_MODEM_DFU_RESULT_AUTH_ERROR:
LOG_ERR("MODEM UPDATE ERROR %d. Running old firmware", dfu_res);
LOG_ERR("MODEM UPDATE ERROR 0x%x. Running old firmware", dfu_res);
break;
case NRF_MODEM_DFU_RESULT_HARDWARE_ERROR:
case NRF_MODEM_DFU_RESULT_INTERNAL_ERROR:
LOG_ERR("MODEM UPDATE FATAL ERROR %d. Modem failure", dfu_res);
LOG_ERR("MODEM UPDATE FATAL ERROR 0x%x. Modem failure", dfu_res);
break;
case NRF_MODEM_DFU_RESULT_VOLTAGE_LOW:
LOG_ERR("MODEM UPDATE CANCELLED %d.", dfu_res);
LOG_ERR("MODEM UPDATE CANCELLED 0x%x.", dfu_res);
LOG_ERR("Please reboot once you have sufficient power for the DFU");
break;
default:
/* Unknown DFU result code */
LOG_ERR("nRF modem DFU failed, error: %d", dfu_res);
LOG_ERR("nRF modem DFU failed, error: 0x%x", dfu_res);
break;
}
}
Expand All @@ -207,18 +207,16 @@ NRF_MODEM_LIB_ON_DFU_RES(main_dfu_hook, on_modem_lib_dfu, NULL);
*/
static void modem_init(void)
{
int ret = nrf_modem_lib_init();
int ret;

/* Handle return values */
switch (ret) {
case 0:
ret = nrf_modem_lib_init();
if (ret == 0) {
LOG_DBG("nRF Modem Library initialized successfully");
return;
default:
LOG_ERR("nRF modem lib initialization failed, error: %d", ret);
break;
}

LOG_ERR("nRF modem lib initialization failed, error: %d", ret);

#if defined(CONFIG_NRF_CLOUD_FOTA)
/* Ignore return value, rebooting below */
(void)nrf_cloud_fota_pending_job_validate(NULL);
Expand Down
8 changes: 4 additions & 4 deletions applications/serial_lte_modem/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -257,26 +257,26 @@ static void nrf_modem_on_dfu_res(int dfu_res, void *ctx)
break;
case NRF_MODEM_DFU_RESULT_UUID_ERROR:
case NRF_MODEM_DFU_RESULT_AUTH_ERROR:
LOG_ERR("MODEM UPDATE ERROR %d. Running old firmware", dfu_res);
LOG_ERR("MODEM UPDATE ERROR 0x%x. Running old firmware", dfu_res);
fota_status = FOTA_STATUS_ERROR;
fota_info = dfu_res;
break;
case NRF_MODEM_DFU_RESULT_HARDWARE_ERROR:
case NRF_MODEM_DFU_RESULT_INTERNAL_ERROR:
LOG_ERR("MODEM UPDATE FATAL ERROR %d", dfu_res);
LOG_ERR("MODEM UPDATE FATAL ERROR 0x%x", dfu_res);
LOG_ERR("Please program full modem firmware with the bootloader or external tools");
fota_status = FOTA_STATUS_ERROR;
fota_info = dfu_res;
break;
case NRF_MODEM_DFU_RESULT_VOLTAGE_LOW:
LOG_ERR("MODEM UPDATE CANCELLED %d.", dfu_res);
LOG_ERR("MODEM UPDATE CANCELLED 0x%x.", dfu_res);
LOG_ERR("Please reboot once you have sufficient power for the DFU");
fota_stage = FOTA_STAGE_ACTIVATE;
fota_status = FOTA_STATUS_ERROR;
fota_info = dfu_res;
break;
default:
LOG_ERR("Unknown DFU result: %d", dfu_res);
LOG_ERR("Unknown DFU result: 0x%x", dfu_res);
fota_status = FOTA_STATUS_ERROR;
fota_info = dfu_res;
}
Expand Down
27 changes: 25 additions & 2 deletions include/modem/nrf_modem_lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,20 @@ extern "C" {
* Use @ref nrf_modem_lib_init() to initialize in normal mode and
* @ref nrf_modem_lib_bootloader_init() to initialize the Modem library in bootloader mode.
*
* @return int Zero on success, non-zero otherwise.
* @retval Zero on success.
*
* @retval -NRF_EPERM The Modem library is already initialized.
* @retval -NRF_EFAULT @c init_params is @c NULL.
* @retval -NRF_ENOLCK Not enough semaphores.
* @retval -NRF_ENOMEM Not enough shared memory.
* @retval -NRF_EINVAL Control region size is incorrect or missing handlers in @c init_params.
* @retval -NRF_ENOTSUPP RPC version mismatch.
* @retval -NRF_ETIMEDOUT Operation timed out.
* @retval -NRF_ACCESS Modem firmware authentication failure.
* @retval -NRF_EAGAIN Modem device firmware upgrade failure.
* DFU is scheduled at next initialization.
* @retval -NRF_EIO Modem device firmware upgrade failure.
* Reprogramming the modem firmware is necessary to recover.
*/
int nrf_modem_lib_init(void);

Expand All @@ -53,7 +66,17 @@ int nrf_modem_lib_init(void);
* Use @ref nrf_modem_lib_init() to initialize in normal mode and
* @ref nrf_modem_lib_bootloader_init() to initialize the Modem library in bootloader mode.
*
* @return int Zero on success, non-zero otherwise.
* @retval Zero on success.
*
* @retval -NRF_EPERM The Modem library is already initialized.
* @retval -NRF_EFAULT @c init_params is @c NULL.
* @retval -NRF_ENOLCK Not enough semaphores.
* @retval -NRF_ENOMEM Not enough shared memory.
* @retval -NRF_EINVAL Missing handler in @c init_params.
* @retval -NRF_EACCES Bad root digest.
* @retval -NRF_ETIMEDOUT Operation timed out.
* @retval -NRF_EIO Bootloader fault.
* @retval -NRF_ENOSYS Operation not available.
*/
int nrf_modem_lib_bootloader_init(void);

Expand Down
2 changes: 1 addition & 1 deletion lib/nrf_modem_lib/nrf_modem_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ static void log_fw_version_uuid(void)

static void nrf_modem_lib_dfu_handler(uint32_t dfu_res)
{
LOG_DBG("Modem library dfu res %d", dfu_res);
LOG_DBG("Modem library update result %d", dfu_res);
STRUCT_SECTION_FOREACH(nrf_modem_lib_dfu_cb, e) {
LOG_DBG("Modem dfu callback: %p", e->callback);
e->callback(dfu_res, e->context);
Expand Down
2 changes: 1 addition & 1 deletion samples/cellular/azure_fota/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ static void on_modem_lib_dfu(int32_t dfu_res, void *ctx)
{
switch (dfu_res) {
case NRF_MODEM_DFU_RESULT_OK:
LOG_DBG("nRF Modem firmware updated");
LOG_DBG("Modem firmware updated");
break;
case NRF_MODEM_DFU_RESULT_UUID_ERROR:
case NRF_MODEM_DFU_RESULT_AUTH_ERROR:
Expand Down
2 changes: 1 addition & 1 deletion samples/cellular/http_update/modem_delta_update/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ static void on_modem_lib_dfu(int32_t dfu_res, void *ctx)
{
switch (err) {
case NRF_MODEM_DFU_RESULT_OK:
LOG_DBG("nRF Modem firmware updated");
LOG_DBG("Modem firmware updated");
break;
case NRF_MODEM_DFU_RESULT_UUID_ERROR:
case NRF_MODEM_DFU_RESULT_AUTH_ERROR:
Expand Down
2 changes: 1 addition & 1 deletion samples/cellular/modem_shell/src/fota/fota.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ static void on_modem_lib_dfu(uint32_t dfu_res, void *ctx)
{
switch (dfu_res) {
case NRF_MODEM_DFU_RESULT_OK:
LOG_DBG("nRF Modem firmware updated");
LOG_DBG("Modem firmware updated");
mosh_error("FOTA: Modem firmware update successful!");
break;
case NRF_MODEM_DFU_RESULT_UUID_ERROR:
Expand Down
2 changes: 1 addition & 1 deletion subsys/net/lib/lwm2m_client_utils/lwm2m/lwm2m_firmware.c
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ static void on_modem_lib_dfu(int32_t dfu_res, void *ctx)
dfu_result = RESULT_SUCCESS;
break;
default:
LOG_INF("MODEM UPDATE fail %d", ret);
LOG_INF("MODEM UPDATE fail 0x%x", ret);
dfu_result = RESULT_UPDATE_FAILED;
break;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/subsys/net/lib/lwm2m_fota_utils/src/firmware.c
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,7 @@ ZTEST(lwm2m_client_utils_firmware, test_firmware_update)
printf("State %d\r\n", state);
zassert_equal(state, STATE_DOWNLOADED, "wrong result value");

lwm2m_firmware_emulate_modem_lib_init(-NRF_EAGAIN);
lwm2m_firmware_emulate_modem_lib_init(-NRF_EIO);
do_firmware_update(modem_instance);
result = get_modem_result();
state = get_app_state();
Expand Down
2 changes: 1 addition & 1 deletion west.yml
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ manifest:
repo-path: sdk-nrfxlib
path: nrfxlib
remote: lemrey
revision: pull/25/head
revision: a14c7b3f142f1c3c358a5d381007e7e438ff0386
- name: trusted-firmware-m
repo-path: sdk-trusted-firmware-m
path: modules/tee/tf-m/trusted-firmware-m
Expand Down

0 comments on commit 76be615

Please sign in to comment.