problem with OTA with different flash [Solved: change command in bootloader]

Started by LukaQ, February 12, 2017, 11:04:25 AM

LukaQ

Hello,
has anyone else use non default flash chip? I used M25P40, which has almost the same commands as winbond one, erase command is different and is 0xC7 instead of 0x60. This was changed, but nothing else, since this flash does not have 4k, 32k and 64k erase. I hope that is not used by bootloader or anything else.
Also
#define SPIFLASH_MACREAD    0x4B
does not exist.
Anyway, with windows OTA I can transfer the image with no errors, since I get this:

Tx: FLX?EOF
Rx: FLX?OK
Rx: FLASH IMG TRANSMISSION SUCCESS


Then the target reads the flash and keeps doing that forever. And it seems that new program does not stick at all, since if I repower the target, it always goes to read flash and nothing else works in that time.

What can I test on my end?

PS: I do have DualOptiboot bootloader, uploaded with Pictkit2 of all things
PS2: in SPI flash write/read example, what is writen in those two bytes if you send serial 012 and read back the flash?
I get
BB.BB.BB.FF.FF.FF.FF.FF.FF......

LukaQ

Start node...Node ID = 123
SPI Flash Init OK!
Got [254:4] > 464C583F
FLX?OK (ACK sent)
Shifting channel to 916000000

radio [56] > 464c583a3330313a65726173696e67207772697474656e2064617461202e2e2e200000000000ad1319152f1348133a138b130d0a006e616e
FLX:301:OK
radio [18] > 464c583a3330323a00696e66006f76660000
FLX:302:OK
FLX?OK
UNShifting channel to 915000000
FLASH IMG TRANSMISSION SUCCESS!
REBOOTING...

why is it shifting to 916MHz, when I have comment that out in programer. Target does not reboot, all it does is reads flash.

So basic example does not work

Felix

You will need to make sure the non-supported flash will behave exactly the same, or you may need to change the library commands etc. Good luck.

LukaQ

#3
I changed one command, full chip erase, which work as expected. Everything else is the same. Erase 4k,32k and 64k don't exist for this flash and one command for Read Unique ID. Don't know what bootloader does, if it uses any of those commands. Nothing important in my mind I would think.

Once WP is done, how long can it take for 328 to read flash for new firmware and reboot and such?
How about timings, could those be the problem?

I can write to flash just fine:
    else if (input >= 48 && input <= 57) //0-9
    {
      Serial.print("\nWriteByte("); Serial.print(input); Serial.print(")");
      flash.writeByte(input-48, input-48);
    }

for 0123456789 input and d for flash dump:
0.1.2.3.4.5.6.7.8.9.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.F.......


And
flash.blockErase64K(0);
works fine, returning all bits to FF.FF....

I don't think flash is the problem, unless you used 4k and/or 32k erase somewhere, what do you think?

LukaQ

And for some unknown reason, I can't burn ext fuse to 0xFD, it is 0x05. How big of a problem is that?

Felix

The bootloader copying the new image is very quick.
Then it uses 32k block erase , that could be your problem.
Then the new program is ready to run.

LukaQ

Quote from: Felix on February 14, 2017, 08:17:04 AM
Then it uses 32k block erase , that could be your problem.
Why does it need to erase 32k at a time? why erase at all or why not at the end, whole chip in one go?
Is there a way to fix that for flash devices, that don't have that set of instructions?

Felix

32k just so happens to be the size of the atmega328p flash memory (well less the bootloader). So that's why. So the erase32k is perfect for that.
Hence I don't support other flash chips and if you want to experiment with chips that are more limited then it will be necessary to change and recompile the bootloader to support that particular chip.
Not sure why you'd really bother, if you just needed a lot more memory (or less?) then sticking with the same family of chips could save you a lot of headache.
FWIW The windbond chips are pretty well known and supported and their instruction set is pretty common.

LukaQ

#8
Quote from: Felix on February 14, 2017, 01:34:40 PM
32k just so happens to be the size of the atmega328p flash memory (well less the bootloader). So that's why. So the erase32k is perfect for that.
Hence I don't support other flash chips and if you want to experiment with chips that are more limited then it will be necessary to change and recompile the bootloader to support that particular chip.
Not sure why you'd really bother, if you just needed a lot more memory (or less?) then sticking with the same family of chips could save you a lot of headache.
Good to know. I don't even know, how bootloader is made, never seen it before. This is out of my league but, what would happen if 32k command in optiboot would be replaced with chip erase command? Would that even work?
Quote from: Felix on February 14, 2017, 01:34:40 PMFWIW The windbond chips are pretty well known and supported and their instruction set is pretty common.
True, but I can't get it easy or that would be first thing to do. Since I can't get it, I have already learn a lot, when it doesn't work first go at it. I will find one chip that has also 32k erase, if nothing else helps.

Felix

chip erase would work, assuming you don't care about anything beyond the first 32k block.

LukaQ

#10
Happy to report, that sector erase instead of 32k erase also works. BUT... you need to change that in bootloader, compile it and upload it instead of Felix's bootloader (it is still his bootloader, just with one changed command)

The change needs to be at line 493
#define SPIFLASH_BLOCKERASE_32K   0x52        // erase one 32K block of flash memory

my flash didn't have this command, do 0x52 was changed to 0xD8, sector erase, which is 512kb (1/8 of whole 4Mb)