2008-12-22 06:04 AM
2011-05-17 12:56 AM
Hi All
I have enet bootloader 99% working. But there is one last problem I cannot resolve. We have a 2M part and I have set it to boot in bank 1. The bootloader checks for a specific piece of data in a specific sector in Bank 0. If found, it does a jump to the bank0 code, otherwise it carries on into its bootloader code. The bootloader allows me to upload a new bin file, which the bootloader flashes into bank0. It then updates the bank 0 security sector with the specific data to say the code is valid and jumps to the start of bank0. This all works great. Now what I need to do is to clear the security sector in bank0 whilst running the main app in bank0, so that when it reboots, the bootloader code will detect an invalid main app and so run the bootloader again. What happens is that the erase just hangs. Here is the code I use for the erase: SCU_AHBPeriphClockConfig(__FMI, ENABLE); SCU_AHBPeriphReset(__FMI, DISABLE); WriteProtectionCmd(IAP_SecSector + FMI_BANK_0, DISABLE); EraseSector(IAP_SecSector + FMI_BANK_0); WaitForLastOperation(FMI_BANK_0); these are using the standard STLib calls. The WriteProtectionCdmd works, but EraseSector just hangs. These are the same calls I use when clearing the sector from Bank1 so I know the code works fine. It seems to do with the fact that I am trying to erase a bank0 sector whilst running in bank0. Any suggestions as to what may be the problem? Zahir2011-05-17 12:56 AM
Hi Zahir,
what you are doing, it's not obvious since you are performing a read while write (RWW) operation from the same bank, which is possible only from two differents banks. So I suggest to you to store the specific piece of data (valid/invalid)instead in a specific sector in Bank1. In this case you will be able to clear the security sector in bank1 while running the main app in bank0. Now when rebooting the bootloader code will detect an invalid main app and so run the bootloader again. is this suitable for you? Kind regards, eris.2011-05-17 12:56 AM
Hi Eris
unfortunately that will not work, as when the bootloader writes a new bin file to bank0, it also writes the security sector in bank0 (since it knows the checksum etc). If I were to implement the security sector in bank1, then if your theory is correct, the bank1 code would fail :( Having said that, the current code is actually failing on erasing the sector - all the main app does is to clear the sector, so it should not be doing RWW ops. I found another thread that mentioned turning off interrupts, so I am about to try that as well. Thx for the info though Zahir2011-05-17 12:56 AM
Hi,
Just an idea : To write in the flash (Bank 0 as 1), the piece of code which do it HAVE TO be executed from RAM, never from Flash (including the other flash bank) Hoping will help you. Regards. damien HOYEN