fwu: Mark failed bank as invalid during rollback
PATCH 1/1 fwu: Mark failed bank as invalid during rollback
When boot_idx differs from active_idx at boot time, it indicates a rollback scenario where the firmware update failed and the system reverted to the previous working bank. In this case, mark the failed bank (active_idx) as invalid to prevent future boot attempts from that bank.
This change adds a new fwu_invalid_bank() function that sets the bank state to FWU_BANK_INVALID and syncs the metadata. This is only supported in FWU metadata version 2; version 1 provides a no-op stub.
Without this change, a failed bank would remain in a valid state and could potentially be selected for boot again, leading to repeated boot failures.
--- include/fwu.h | 8 ++++++++ lib/fwu_updates/fwu.c | 1 + lib/fwu_updates/fwu_v1.c | 10 ++++++++++ lib/fwu_updates/fwu_v2.c | 19 +++++++++++++++++++ 4 files changed, 38 insertions(+)
include/fwu.h +8 -0
@@ -415,6 +415,14 @@ int fwu_get_mdata_size(uint32_t *mdata_size);*/ int fwu_state_machine_updates (bool trial_state,uint32_t update_index); +/** +* fwu_invalid_bank() - Invalid bank state of a specific bank +* @index: Index of the bank +* +* Only supported in version 2 of FWU metadata. +*/ +void fwu_invalid_bank (uint32_t index); +/** * fwu_init() - FWU specific initialisations *
lib/fwu_updates/fwu.c +1 -0
@@ -766,6 +766,7 @@ static int fwu_boottime_checks(void)if (boot_idx != active_idx) {log_info ("Boot idx %u is not matching active idx %u, changing active_idx\n" , boot_idx, active_idx); +fwu_invalid_bank (active_idx); ret =fwu_set_active_index (boot_idx);if (!ret) boottime_check =1 ;
lib/fwu_updates/fwu_v1.c +10 -0
@@ -136,6 +136,16 @@ int fwu_get_mdata_size(uint32_t *mdata_size)return 0 ; } +/** +* fwu_invalid_bank() - Invalid bank state of a specific bank +* @index: Index of the bank +* +* Not supported. +*/ +void fwu_invalid_bank (uint32_t index) +{ +} +/** * fwu_init() - FWU specific initialisations *
lib/fwu_updates/fwu_v2.c +19 -0
@@ -194,6 +194,25 @@ int fwu_state_machine_updates(bool trial_state, uint32_t update_index)fwu_bank_state_update (0 , update_index); } +/** +* fwu_invalid_bank() - Invalid bank state of a specific bank +* @index: Index of the bank +*/ +void fwu_invalid_bank (uint32_t index) +{ +struct fwu_data *data =fwu_get_data (); +struct fwu_mdata *mdata; +int ret; + + mdata = data->fwu_mdata; + data->bank_state[index] =FWU_BANK_INVALID ; + mdata->bank_state[index] =FWU_BANK_INVALID ; + + ret =fwu_sync_mdata (mdata,BOTH_PARTS ); +if (ret) +log_err ("Unable to invalid bank %u\n" , index); +} +/** * fwu_get_mdata_size() - Get the FWU metadata size * @mdata_size: Size of the metadata structure
Signature · 1 line
2.43.0
Hi Kory,
Quoted 7 lines · Kory Maincent
When
boot_idxdiffers fromactive_idxat boot time, it indicates a rollback scenario where the firmware update failed and the system reverted to the previous working bank. In this case, mark the failed bank (active_idx) as invalid to prevent future boot attempts from that bank.
Quoted 7 lines
This change adds a new
fwu_invalid_bank()function that sets the bank state toFWU_BANK_INVALIDand syncs the metadata. This is only supported in FWU metadata version 2; version 1 provides a no-op stub.Without this change, a failed bank would remain in a valid state and could potentially be selected for boot again, leading to repeated boot failures.
How? Doesn't the code already switch the metadata to point to the 'boot_idx' bank as active?
What could happen here I guess, is the selected active bank to go bad somehow and the firmware would try the secondary bank, which contains an invalid firmware. But in that case the board will fail to boot regardless. Is there a corner case I am missing?
Thanks
/Ilias
Quoted 94 lines
Signed-off-by Kory Maincent <[email protected]>--- include/fwu.h | 8 ++++++++ lib/fwu_updates/fwu.c | 1 + lib/fwu_updates/fwu_v1.c | 10 ++++++++++ lib/fwu_updates/fwu_v2.c | 19 +++++++++++++++++++ 4 files changed, 38 insertions(+)include/fwu.h +8
-0@@ -415,6 +415,14 @@ int fwu_get_mdata_size(uint32_t *mdata_size);*/ int fwu_state_machine_updates (bool trial_state,uint32_t update_index); +/** +* fwu_invalid_bank() - Invalid bank state of a specific bank +* @index: Index of the bank +* +* Only supported in version 2 of FWU metadata. +*/ +void fwu_invalid_bank (uint32_t index); +/** * fwu_init() - FWU specific initialisations * lib/fwu_updates/fwu.c +1
-0@@ -766,6 +766,7 @@ static int fwu_boottime_checks(void)if (boot_idx != active_idx) {log_info ("Boot idx %u is not matching active idx %u, changing active_idx\n" , boot_idx, active_idx); +fwu_invalid_bank (active_idx); ret =fwu_set_active_index (boot_idx);if (!ret) boottime_check =1 ;lib/fwu_updates/fwu_v1.c +10
-0@@ -136,6 +136,16 @@ int fwu_get_mdata_size(uint32_t *mdata_size)return 0 ; } +/** +* fwu_invalid_bank() - Invalid bank state of a specific bank +* @index: Index of the bank +* +* Not supported. +*/ +void fwu_invalid_bank (uint32_t index) +{ +} +/** * fwu_init() - FWU specific initialisations * lib/fwu_updates/fwu_v2.c +19
-1@@ -194,6 +194,25 @@ int fwu_state_machine_updates(bool trial_state, uint32_t update_index)fwu_bank_state_update (0 , update_index); } +/** +* fwu_invalid_bank() - Invalid bank state of a specific bank +* @index: Index of the bank +*/ +void fwu_invalid_bank (uint32_t index) +{ +struct fwu_data *data =fwu_get_data (); +struct fwu_mdata *mdata; +int ret; + + mdata = data->fwu_mdata; + data->bank_state[index] =FWU_BANK_INVALID ; + mdata->bank_state[index] =FWU_BANK_INVALID ; + + ret =fwu_sync_mdata (mdata,BOTH_PARTS ); +if (ret) +log_err ("Unable to invalid bank %u\n" , index); +} +/** * fwu_get_mdata_size() - Get the FWU metadata size * @mdata_size: Size of the metadata structure -- 2.43.0
Quoted 18 lines · On Wed, 14 Jan 2026 15:54:07 +0200 Ilias Apalodimas…
Hi Kory,
Quoted 7 lines · Kory Maincent
When
boot_idxdiffers fromactive_idxat boot time, it indicates a rollback scenario where the firmware update failed and the system reverted to the previous working bank. In this case, mark the failed bank (active_idx) as invalid to prevent future boot attempts from that bank.Quoted 7 lines
This change adds a new
fwu_invalid_bank()function that sets the bank state toFWU_BANK_INVALIDand syncs the metadata. This is only supported in FWU metadata version 2; version 1 provides a no-op stub.Without this change, a failed bank would remain in a valid state and could potentially be selected for boot again, leading to repeated boot failures.
Quoted 6 lines
How? Doesn't the code already switch the metadata to point to the '
boot_idx' bank as active?
What could happen here I guess, is the selected active bank to go bad somehow and the firmware would try the secondary bank, which contains an invalid firmware. But in that case the board will fail to boot regardless. Is there a corner case I am missing?
I think I have faced a corner case, but I can't recall what it was. :/ Anyway we should change the bank state to invalid if we don't manage to boot one bank right. We should provide to the user the information that one bank is in an invalid state if that is the case. What do you think?
Regards,
Signature · 3 lines
Köry Maincent, Bootlin Embedded Linux and kernel engineering https://bootlin.com
Hi Kory,
Quoted 22 lines · Kory Maincent
Quoted 18 lines · On Wed, 14 Jan 2026 15:54:07 +0200 Ilias Apalodimas…
Hi Kory,
Quoted 14 lines · Kory Maincent
When
boot_idxdiffers fromactive_idxat boot time, it indicates a rollback scenario where the firmware update failed and the system reverted to the previous working bank. In this case, mark the failed bank (active_idx) as invalid to prevent future boot attempts from that bank.This change adds a new
fwu_invalid_bank()function that sets the bank state toFWU_BANK_INVALIDand syncs the metadata. This is only supported in FWU metadata version 2; version 1 provides a no-op stub.Without this change, a failed bank would remain in a valid state and could potentially be selected for boot again, leading to repeated boot failures.
Quoted 8 lines
Quoted 6 lines
How? Doesn't the code already switch the metadata to point to the '
boot_idx' bank as active?
What could happen here I guess, is the selected active bank to go bad somehow and the firmware would try the secondary bank, which contains an invalid firmware. But in that case the board will fail to boot regardless. Is there a corner case I am missing?I think I have faced a corner case, but I can't recall what it was. :/
I think this patch has value if you have 3 banks. In that case, you won't have to try and boot the invalid one, before booting a correct one.
Quoted 3 lines
Anyway we should change the bank state to invalid if we don't manage to boot one bank right. We should provide to the user the information that one bank is in an invalid state if that is the case. What do you think?
Yes. The invalid state is already described in the spec so I think this is fine. However, instead of adding a new function to invalidate the state, can't we tweak fwu_bank_state_update() instead?
Instead of a boolean for trial state, pass an the actual state and update it while keeping the same checks.
Regards
/Ilias
Quoted 6 lines
Regards,
--
Köry Maincent, Bootlin
Embedded Linux and kernel engineering
https://bootlin.com
Quoted 33 lines · On Thu, 15 Jan 2026 11:36:29 +0200 Ilias Apalodimas…
Hi Kory,
Quoted 30 lines · Kory Maincent
Quoted 25 lines · On Wed, 14 Jan 2026 15:54:07 +0200 Ilias Apalodimas…
Hi Kory,
Quoted 7 lines · Kory Maincent
When
boot_idxdiffers fromactive_idxat boot time, it indicates a rollback scenario where the firmware update failed and the system reverted to the previous working bank. In this case, mark the failed bank (active_idx) as invalid to prevent future boot attempts from that bank.Quoted 7 lines
This change adds a new
fwu_invalid_bank()function that sets the bank state toFWU_BANK_INVALIDand syncs the metadata. This is only supported in FWU metadata version 2; version 1 provides a no-op stub.Without this change, a failed bank would remain in a valid state and could potentially be selected for boot again, leading to repeated boot failures.
How? Doesn't the code already switch the metadata to point to the '
boot_idx' bank as active?
What could happen here I guess, is the selected active bank to go bad somehow and the firmware would try the secondary bank, which contains an invalid firmware. But in that case the board will fail to boot regardless. Is there a corner case I am missing?
Quoted 5 lines
Quoted 1 line
I think I have faced a corner case, but I can't recall what it was. :/
I think this patch has value if you have 3 banks. In that case, you won't have to try and boot the invalid one, before booting a correct one.
Good point.
Quoted 9 lines
Quoted 3 lines
Anyway we should change the bank state to invalid if we don't manage to boot one bank right. We should provide to the user the information that one bank is in an invalid state if that is the case. What do you think?
Yes. The invalid state is already described in the spec so I think this is fine. However, instead of adding a new function to invalidate the state, can't we tweak
fwu_bank_state_update()instead?
Instead of a boolean for trial state, pass an the actual state and update it while keeping the same checks.
Indeed, we could do that. I will prepare a V2 accordingly.
Regards,
Signature · 3 lines
Köry Maincent, Bootlin Embedded Linux and kernel engineering https://bootlin.com