[rtl872x][bootloader] Fix bootloop if system module header corrupted #2739
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
A gen4 device was stuck in a bootloop. Examination showed that the system part binary was partially erased, starting from the start of the binary onwards. Gen4 bootloader will validate the system-part1 module CRC and detect a corrupted system part binary. If the system part is invalid, the bootloader should remain in DFU mode. This was not happening
Solution
Part of the boot process if the system part is not valid is to check if the factory manufacturing app is in place and needs to be replaced with our system binary.
This check is done in
FLASH_AddMfgSystemModuleSlot()
hereret
will almost always be0
sinceFLASH_ModuleInfo()
should always be able to read flash successfully (this says nothing about the validity of the contents, just that it was able to read flash).info.module_function
will NOT be equal to system part, since this is likely to be overwritten flash data.module_info_matches_platform(&info)
also will likely be false, since this is looking at overwritten data.However,
ret
will still be returned and we have a false positive.The solution is to set
ret
to an error if the system part image is not found in flashSteps to Test
Check out this branch, build + flash this bootloader, flash a corrupted system part1 binary
--> The device should remain in DFU mode.
Example App
N/A
References
Discussion/Discovery
Completeness