From a bootloader how to read in an external Flash SPI ?

Hi,

I would like to read my new firmware, stored in the external Flash via SPI bus, and to burn it in the internal Flash.

Have you got some examples about to access external Flash via SPI bus from a bootloader ?

Thank you very much !

embedded/avr/2boots at master · thseiler/embedded · GitHub is supposed to bootload from an SD card (which is basically a fancy SPI flash memory.) That might be a good starting place.

This is an updated project: GitHub - zevero/avr_boot: Arduino Bootloader to Flash from SD Card

You could also check this fork of Optiboot claiming to have working SPI flash support on Atmega328:

Hello everybody!
I know, this topic has not been posted in for a long time.
But I have today burned the spiflash optiboot (kalanda optiboot) on my ardiono nano.
At least, I did not brick the device. But now I try to find out, what the sketch file on the sd Card should be in place, name and format.
Should it be the only file on the sd card?
Should it be a .hex or .bin file?
Does it have to be named something like "firmware.xxx" or can it just keep the name of the original sketch?

I tried to read all this from the optiboot.c file but could only find, that the device should look for a flash file.

Thank you in advance and best regards

Update: SD Card is working correctly; checked it with the sketch from examples.
I tried differently named files in .bin and .hex format. When pressing the reset button on the nano, the led flashes 3 times but the old sketch present continues to run.

Uploaded the blink examlple via USB and then read it out via ISP and avrdude into raw bin file. Copied this file to SD card and tried to flash it from the card to the nano with no success.
I think the bootloader is looking for something like FLX:: in the first bytes, but could not find anything similar in the downloaded bin file.

Can anybody tell me, how I should build the firmware file for the SD card and how to name it?

But I have today burned the spiflash optiboot (kalanda optiboot) on my ardiono nano.
... But now I try to find out, what the sketch file on the sd Card

the Kalanda bootloader doesn't support an SD card; it'll copy the program from a plain SPI flash chip (which doesnt have any filesystem, so doesn't have file names.)

Hello westfw!
Thank you! Saved me a lot of frustration!
For starter I burned the "zevero/avr_bootloader" to the board - works as intended.
But in the long run, the installation of a SPI flash would be the optimum addition to my home-brew board.
I intend to upgrade the firmware for this board by first uploading it to the flash (e.g. UART, bluetooth, etc.) and have reset by command.

If I understood correctly, the Bootloader looks for some bytes in the flash memory containing "F L X : :".
Do they have to be added to the binary data manually?

To be honest, I never created just binary data without any file structure. Would it be enough just to open the file on a pc and have the bytes read out and send over one by one to the flash

Thank you and best regards

Sorry; I don't know much about how it actually works. I was just curious about the name (which didn't mention SD) and investigated enough to notice "the problem." (actually, I was curious as to how/whether they had really managed to fit SDcard support into something small enough to be a bootloader. SD/FAT support is usually quite a lot of code.)

I would think that there would be some sort of utility for loading the code into the SPI flash as well, but I didn't see any sign of it.

You might check out https://github.com/LowPowerLab/ - it looks like they have a similarly modified optiboot, and their "moteino" core apparently supports wireless download of an image to a flash chip, and subsequent bootload of that image...

Thank you again, westfw!
I will check this out later.
Maybe I should try to contact kalanda in some way, to get the details for the data structure needed.
If I succeed, I will post it here later on.
Meanwhile, I will continue with my project using a SPI sd card-reader an zevero bootloader, as I need a working prototype urgently.
Will probalby be back with toying around with SPI flash in a week (I ordered a couple of breakout boards with W25Q32 flash).
Thank you and all the best