-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
lib: nrf_modem: init once on dfu apply #105
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -250,17 +250,18 @@ static int handle_at_modemreset(enum at_cmd_type type) | |
++step; | ||
|
||
ret = nrf_modem_lib_init(); | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It could be good to add a small comment saying that |
||
/* nrf_modem_dfu_res() is called in nrf_modem_lib_init with the DFU result. */ | ||
if ((fota_stage != FOTA_STAGE_INIT && | ||
fota_type == DFU_TARGET_IMAGE_TYPE_MODEM_DELTA)) { | ||
slm_fota_post_process(); | ||
} | ||
|
||
if (ret < 0) { | ||
break; | ||
} | ||
++step; | ||
|
||
if (ret > 0 || (fota_stage != FOTA_STAGE_INIT | ||
&& fota_type == DFU_TARGET_IMAGE_TYPE_MODEM_DELTA)) { | ||
slm_finish_modem_fota(ret); | ||
slm_fota_post_process(); | ||
} | ||
|
||
/* Success. */ | ||
rsp_send("\r\n#XMODEMRESET: 0\r\n"); | ||
return 0; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -372,30 +372,3 @@ void slm_fota_post_process(void) | |
slm_settings_fota_save(); | ||
} | ||
} | ||
|
||
void slm_finish_modem_fota(int modem_lib_init_ret) | ||
{ | ||
if (handle_nrf_modem_lib_init_ret(modem_lib_init_ret)) { | ||
char buf[40]; | ||
|
||
LOG_INF("Re-initializing the modem due to" | ||
" ongoing modem firmware update."); | ||
|
||
/* The second init needs to be done regardless of the return value. | ||
* Refer to the below link for more information on the procedure. | ||
* https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrfxlib/nrf_modem/doc/delta_dfu.html#reinitializing-the-modem-to-run-the-new-firmware | ||
*/ | ||
modem_lib_init_ret = nrf_modem_lib_init(); | ||
handle_nrf_modem_lib_init_ret(modem_lib_init_ret); | ||
|
||
nrf_modem_at_cmd(buf, sizeof(buf), "%s", "AT%SHORTSWVER"); | ||
if (strstr(buf, "1.3.4") || strstr(buf, "1.3.5")) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note, this has been removed already by nrfconnect#12086. |
||
/* Those versions suffer from a bug that provokes UICC failure (+CEREG: 90) | ||
* after the update, preventing the modem from registering to the network. | ||
*/ | ||
LOG_INF("Applying the workaround to a modem firmware update issue..."); | ||
nrf_modem_lib_shutdown(); | ||
nrf_modem_lib_init(); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,8 +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, a positive value @em nrf_modem_dfu when executing | ||
* Modem firmware updates, and negative errno on other failures. | ||
* @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); | ||
|
||
|
@@ -54,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); | ||
|
||
|
@@ -67,6 +89,20 @@ int nrf_modem_lib_bootloader_init(void); | |
*/ | ||
int nrf_modem_lib_shutdown(void); | ||
|
||
/** | ||
* @brief Modem library dfu callback struct. | ||
*/ | ||
struct nrf_modem_lib_dfu_cb { | ||
/** | ||
* @brief Callback function. | ||
* @param dfu_res The return value of nrf_modem_init() | ||
* @param ctx User-defined context | ||
*/ | ||
void (*callback)(int dfu_res, void *ctx); | ||
/** User defined context */ | ||
void *context; | ||
}; | ||
|
||
/** | ||
* @brief Modem library initialization callback struct. | ||
*/ | ||
|
@@ -94,6 +130,25 @@ struct nrf_modem_lib_shutdown_cb { | |
void *context; | ||
}; | ||
|
||
/** | ||
* @brief Define a callback for DFU result @ref nrf_modem_lib_init calls. | ||
* | ||
* The callback function @p _callback is invoked after the library has been initialized. | ||
* | ||
* @note The @c NRF_MODEM_LIB_ON_DFU_RES callback can be used to subscribe to the result of a modem | ||
* DFU operation. | ||
* | ||
* @param name Callback name | ||
* @param _callback Callback function name | ||
* @param _context User-defined context for the callback | ||
*/ | ||
#define NRF_MODEM_LIB_ON_DFU_RES(name, _callback, _context) \ | ||
static void _callback(int dfu_res, void *ctx); \ | ||
STRUCT_SECTION_ITERABLE(nrf_modem_lib_dfu_cb, nrf_modem_dfu_hook_##name) = { \ | ||
.callback = _callback, \ | ||
.context = _context, \ | ||
}; | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
/** | ||
* @brief Define a callback for @ref nrf_modem_lib_init calls. | ||
* | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do I understand correctly that
nrf_modem_on_dfu_res()
will get called right beforenrf_modem_lib_init()
returns?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, or rather, right before
nrf_modem_init()
returns tonrf_modem_lib_init()
, so theNRF_MODEM_LIB_ON_INIT
hooks are called after.