ESP8266 512k flash: compiling using RTOS SDK 1.3

by kacang bawang

Since update from version 1.2 to 1.3 of Espressif’s RTOS SDK, if you try to compile anything targeting a 512kB flash device you get this message:

In this post I will show you how to organize and compile a project to using the RTOS SDK and how to solve the above problem. This post builds on this one, review as necessary.

First, let’s oranize our project. As an example I will use examples/smart_config from the 1.3 RTOS SDK. Just like before (with the regular SDK) we organize our folder structure like this:

Notice that we’ve skipped linking to RTOS_SDK/include and RTOS_SDK/tools as the makefile specifies these paths explicitly.

Now, let’s fix the makefile. Note that we’re talking about the “root” makefile – one which is in root directory of the project. There are additional makefiles inside the src/ directory. We will not change those.

Add the following to the top of the file:

This specifies compilation options related to flash size and specifies locations for the tool chain and the RTOS SDK.

At this point we can try compiling. You should see something like this:

Somehow, starting with version 1.3 of the RTOS SDK the libs from Espressif went up in size, so much so that they don’t fit into the 244kB alloted for irom0. What can we do? We can try compiling with -O2 and -Os flags, but the resulting size is still too big. There still one thing to try.

Take a look at RTOS_SDK/ld/ It says that we can change the location and size of the irom0 area, as long as we take care not to run into to other areas. The flash.bin (our own code) is typically a lot smaller than all the irom0 stuff. In this example, the sizes end up being:

Thus, we will steal a little bit of space from the end of the flash.bin area. Let’s take a look at what that makes our flash layout look like:

To achieve this change in flash layout we need to modify RTOS_SDK/ld/ We need to change *both* the starting offset and the length of the irom0 area. Edit the file like this:

Flash is mapped to 0x40200000 in memory address space. irom0 originally appears at 0x40240000, corresponding to 0x40000 in flash space. But we want it to now begin at 0x30000, so we change the org value to 0x40230000. Don’t forget to also increase length from 0x3C000 to 0x4C000.

Note that this means that we need to flash irom0 to 0x30000 (as opposed to 0x40000 before). Additionally this change will affect all projects, not just this one since we changed the original linker script in the RTOS_SDK directory.

Let’s try compiling. Booya, no errors. Note that the success printout from the makefile includes a hardcoded message of where to flash, so our change will not be reflected.

Lastly, take a look inside the /bin directory and observe that eagle.irom0text.bin is 257kB, which is indeed too large to fit in the original amount of flash that was reserved for it. Good thing the linker caught that.

Hat tip: kolban