How can I change Linker Script

I am currently working on a project with ESP8266 and I want to write an OTA bootloader for it. This bootloader should run when the microcontroller is reset and, based on user selection, either enter programming mode to upload a new main application, or run the previously uploaded application.

I have not worked with linker scripts before, so I am looking for a simple example that includes two programs:

Bootloader program: This program should remain constant and perform the following tasks:
Detect whether the user has pressed a button to enter programming mode.
If the button is pressed, go to programming mode.
If the button is not pressed, run the main application that is already stored in flash memory.
Main application: This could be a simple program like an LED blinker program.
I would appreciate any help you can provide on writing this bootloader and how to use linker scripts to achieve this goal.

Additional details:

I am using an ESP8266-12E.
I want to use the platform IO for development.
Questions:

How can I write a bootloader program that runs when the microcontroller is reset?
How can I use linker scripts to select which program (bootloader or main application) should run?
What is a simple example of how to use linker scripts to achieve this goal?
Thanks for your time!

I think you are asking the wrong question about the wrong problem.
Even if you change the linker script, you still have to write a bootloader - which is not trivial.

Why don’t you prefer a very simple solution?

Write a function which is called directly in the setup() function.
This function

  • checks if the button is pressed
  • if the button is pressed, start ArduinoOTA
  • execute a loop with a timeout which calls ArduinoOTA.handle().
  • end the loop when the timeout is reached or the update is completed

because the customer is concerned about the possibility of ESP8266 firmware corruption if an OTA update is interrupted due to user actions or power loss. They lack remote access to the devices, making it crucial to ensure a robust update process.

You cannot brick an esp8266 by an OTA Update.
The firmware is written to a different location in the flash. If an OTA Update is interrupted, the old sketch is loaded.

what’s the spiffs? also shouldn’t the flash memory map be partitioned like this, first bootloader for performing OTA, then with some space the main application? and I think the OTA bootloader should have a fixed flash address, so it would not change, and it’s main prepose is for replacing my old main application, also Please note that my main application code is large, something in the order of 1.5MB before adding some MP3 files to it.so there is no chance of having two main applications

That’s just a simplified flash layout image i could find on the net.
SPIFFS the for the file system - deprecated now. New file system is LittleFS.

For your application, I would suggest switching the ESP32 series.
This is much more suitable for you:

1 Like

Thank you for your guidance and assistance. sivar2311

1 Like

Hi Masm31
Were you able to solve your problem and change the start address of the program in the esp8266?
Because I have the same challenge and I want my program to start from another address of the flash memory.