ESP32: How to select and flash a bin file from an SD card using a button?

I have an ESP32 and I have connected an SD card module to it. I have several Arduino bin files on my SD card, like firmware1.bin, firmware2.bin, etc.

What I want to do is, by pressing a button, flash a specific bin file from the SD card onto the ESP32. For example, if I press Button 1, I want the firmware1.bin file from the SD card to be flashed onto the ESP32. Similarly, if I press Button 2, I want the firmware2.bin file to be flashed.

I want to set this up so that when one firmware is flashed, the current firmware on the ESP32 is erased and the new firmware replaces it.

What I need to know:

  • How do I write the Arduino code required to select a specific bin file from the SD card based on a button press and flash it onto the ESP32?

  • Is using flash partitions mandatory for this? Or is there another way to do it?

  • Can you provide a code example showing how to recognize the name of a specific bin file through the SD card module I'm using and flash it?

I need your help to get this working correctly. Thank you!

Hardware being used:

  • ESP32 module (The specific name of the module you are using)

  • SD Card module (The specific name of the module you are using)

  • Button (How many buttons are you using?)

Posting your question in this way will make it easy for anyone to understand exactly what you need to achieve.

Couple points, you have posted in the Nano ESP32 category, but you are using an Espressif ESP32. It appears you want somebody to do all the work, that is not what we are here for. Spend a few weeks doing research and attempt to code and wire yourself. When you absolutely can't make any progress, post all your code in code tags, any error logs also in code tags, a picture of your hand drawn wiring diagram.

I don't know how to do this either. However from the little I know:

  1. Write a bootloader for your the ESP32. That bootloader would have to be able to read the SD card (on power up) and if there is a .bin file, load it into the ESP32, else pass the vector to whatever code is in the ESP32.

  2. Use another ESP32 Or similar. to load the code.

Not sure where you would put your button, Perhaps some combination of I/O pins for the boot loader to read.