refactor(core): extract the firmware's embedded image updates
What changed, and why it matters
This commit is a straightforward code cleanup: it moves the existing bootloader and nRF firmware update logic into a new helper function without changing what the code actually does. There is no security-relevant change visible in the diff.
No security action needed. Treat as a normal refactoring review.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The change extracts the embedded image update sequence from main_func() into a new static helper update_embedded_images() in core/embed/projects/firmware/src/stm32/main.c. The commit message explicitly states ‘No behavior change: same checks, same order,’ and the diff confirms the logic, conditional compilation guards, and reboot behavior are preserved. The only observable difference in main_func() is that fading is set to true when update_embedded_images() returns true (i.e., when the update screen was shown), which is equivalent to the previous code setting fading = true inside the update block.
Changed components
core/embed/projects/firmware/src/stm32/main.cInspect captured patch +38 / −26
### core/embed/projects/firmware/src/stm32/main.c
@@ -76,22 +76,10 @@ LOG_DECLARE(coreapp_main)
uint32_t ipc_buffer[IPC_COREAPP_BUFFER_SIZE / sizeof(uint32_t)];
#endif
-int main_func(uint32_t cmd, void *arg) {
- if (cmd == 1) {
- systask_postmortem_t *info = (systask_postmortem_t *)arg;
- rsod_gui(info);
- system_exit(0);
- }
-
-#if USE_IPC
- // Registered once for the coreapp's lifetime: re-registering while an
- // extapp is running would reset the queue under it, so this is not
- // something extapp orchestration (e.g. run.py) is allowed to repeat.
- ipc_register(IPC_REMOTE_EXTAPP, ipc_buffer, sizeof(ipc_buffer));
-#endif
-
- bool fading = DISPLAY_JUMP_BEHAVIOR == DISPLAY_RESET_CONTENT;
-
+// Installs the images this firmware carries (bootloader, nRF) when the device
+// has different ones. Returns true if the update screen was shown. Reboots
+// after a bootloader update and does not return.
+static bool update_embedded_images(void) {
bool update_required = false;
#if PRODUCTION || FORCE_BOOTLOADER_UPGRADE
@@ -106,29 +94,53 @@ int main_func(uint32_t cmd, void *arg) {
update_required = update_required || nrf_update_required_;
#endif
- if (update_required) {
- screen_update();
- fading = true;
+ if (!update_required) {
+ return false;
+ }
+
+ screen_update();
#if PRODUCTION || FORCE_BOOTLOADER_UPGRADE
- if (bl_update_required) {
- boot_image_replace(boot_image_get_embdata());
- }
+ if (bl_update_required) {
+ boot_image_replace(boot_image_get_embdata());
+ }
#endif
#ifdef USE_NRF
- if (nrf_update_required_) {
- nrf_update(&nrf_app_start, (size_t)&nrf_app_size);
- }
-#endif
+ if (nrf_update_required_) {
+ nrf_update(&nrf_app_start, (size_t)&nrf_app_size);
}
+#endif
#if PRODUCTION || FORCE_BOOTLOADER_UPGRADE
if (bl_update_required) {
reboot_device();
}
#endif
+ return true;
+}
+
+int main_func(uint32_t cmd, void *arg) {
+ if (cmd == 1) {
+ systask_postmortem_t *info = (systask_postmortem_t *)arg;
+ rsod_gui(info);
+ system_exit(0);
+ }
+
+#if USE_IPC
+ // Registered once for the coreapp's lifetime: re-registering while an
+ // extapp is running would reset the queue under it, so this is not
+ // something extapp orchestration (e.g. run.py) is allowed to repeat.
+ ipc_register(IPC_REMOTE_EXTAPP, ipc_buffer, sizeof(ipc_buffer));
+#endif
+
+ bool fading = DISPLAY_JUMP_BEHAVIOR == DISPLAY_RESET_CONTENT;
+
+ if (update_embedded_images()) {
+ fading = true;
+ }
+
#ifdef USE_NRF
#if PRODUCTION
if (!nrf_authenticate()) {Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.