cancel
Showing results for 
Search instead for 
Did you mean: 

Writing to same bank

zahir
Associate II
Posted on December 22, 2008 at 15:04

Writing to same bank

4 REPLIES 4
zahir
Associate II
Posted on May 17, 2011 at 09:56

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?

Zahir

kais
Associate II
Posted on May 17, 2011 at 09:56

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.

zahir
Associate II
Posted on May 17, 2011 at 09:56

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

Zahir

dhoyen
Associate II
Posted on May 17, 2011 at 09:56

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