Skip to content
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

BFB2 flag, vs REMAP flag #2

Open
EitanTal opened this issue Dec 5, 2022 · 3 comments
Open

BFB2 flag, vs REMAP flag #2

EitanTal opened this issue Dec 5, 2022 · 3 comments

Comments

@EitanTal
Copy link

EitanTal commented Dec 5, 2022

The decision on which bank to load the new firmware to, is based off the REMAP flag, which is correct. The remap flag tells you which flash bank you're running from.

However, the decision to set BFB2, is based on the BFB2 flag. Unlike Remap, BFB2 flag does not necessarily mean you're executing from the bank you think you are. What this flag actually means is whether or not the rom bootloader will attempt to boot from bank2. If bank2 contains no valid firmware, then the bootloader will boot from bank1. In this situation, Remap will be zero, but BFB2 will be one.

if (((OBInit.USERConfig) & (OB_BFB2_ENABLE)) == OB_BFB2_ENABLE) {

@barafael
Copy link
Owner

barafael commented Dec 6, 2022

Again, thanks for sharing your insight. Would you mind explaining further what needs to be done here or if you want PR'ing the needed changes?

@EitanTal
Copy link
Author

EitanTal commented Dec 7, 2022

This is my suggestion:

    if (GetActiveBank() == FLASH_BANK_2) {
        // Switch over boot from Bank2 to Bank1, by disabling BFB2 flag
        OBInit.USERConfig = OB_BFB2_DISABLE;
    } else {
        // Switch over boot from Bank1 to Bank2, by enabling BFB2 flag
        OBInit.USERConfig = OB_BFB2_ENABLE;
    }

@EitanTal
Copy link
Author

I'm changing the condition inside the if(). I don't want to blindly toggle BFB2.

From
(((OBInit.USERConfig) & (OB_BFB2_ENABLE)) == OB_BFB2_ENABLE)
to
(GetActiveBank() == FLASH_BANK_2)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants