The use of the ESP8266 in the world of IoT

User avatar
By eriksl
#37245 Thanks for your answers. I will let it sink the next few days. It will have some implications anyway, so it's not something I will be doing in one day anyway ;)

You are mentioning iram where you mentioned stack space earlier. Are they equal by coincidence or did you mix them up ;)

How does it work then, is the boot loader in flash and remains there, no iram usage?
User avatar
By rab
#37247 Yes, sorry. But the boot loader itself doesn't add anything to the original rom, so no effect on iram usage. Adding the rBoot api to your rom will add a little code but iirc that all stays in irom. The only thing that will add to iram is the big flash override of an existing sdk function (but the original function will not then be included) so it probably only adds a couple of bytes at most.
User avatar
By eriksl
#37492 [edit: please read all of my text / all posts, before replying, some things tend to clearer to myself when I write them down ;))]

I am now at step #1, the very basics.

Currently (for me) with no boot loader the process is like this:

- compile sources
- link to iram = 0x40100000, irom = 0x40210000
- use esptool to convert elf files to two firmware files iram, irom
- create composite firmware file from iram, pad to 64k, then append irom
- the composite firmware can be flashed to "0x0".

As said, I want to make a similar image of max 1 Mbyte (currently only 240 kbyte, so it could fit into a 4M flash chip, in theory), using BIGFLASH.

As far as I understand this would be the steps required:

- compile boot loader, don't link
- compile sources, link
- link to iram = 0x40100000, irom = 0x40210000 + sizeof(boot loader) % 4kbyte + sizeof(config sector) % 4kbyte
- use esptool to convert elf files to two firmware files iram, irom
- create composite firmware file from iram, pad to 64k, then append boot loader+pad, config sector+pad, irom
- the composite firmware can be flashed to "0x0".

Is my assumption correct?
Last edited by eriksl on Wed Dec 30, 2015 1:43 pm, edited 2 times in total.
User avatar
By eriksl
#37493 When browsing through your examples, I spotted a "weird" address for irom0_0_seg. This probably means I've missed something somewhere ;)

For my "normal" (non-bootloader) images, I have the irom0_0_seg start at 0x40210000. The rationale is that 0x40200000 would be virtually subtracted when flashing over the UART. The layout of the image would then be, if I understand correctly,

1: header of unknown size
2: contents of the iram segment, consisting of 32 kbytes
3: 32 kbyte of padding over an area apparently designated as cache
4: the contents of the irom section

I was assuming that means you can't use the first 64 kbytes (0x10000) for irom and you need to pad over them in this way. This seems to work ;)

But your starting the irom segment at 0x40202010, which is only 8kb+10b above "zero". Does this mean:

- we could start the irom segment actually at 0x4020000 (without boot loader) and the code would neatly end up at the first flash address instead of iram?
- the 8kb+10 mentioned above is the size of the boot loader we need to skip over

I was under the impression that the 64k of the "flash image" would always end up at 0x40100000 and the rest would end up at 0x40200000, which is nonsense of course, because you cannot flash to iram, it is copied there by the boot loader on startup.

So what is really happening? The boot loader just copies the first 32k from the SPI to iram and the first address above that (which would be 0x40208000 then) could be used for the first symbol in the irom segment, right? Which would mean I am now "wasting" 32kb by padding up to 0x10000 (which isn't a big deal anyway).

But still then, I don't understand the irom segment address of 0x40202010 you're using, I would expect it to be at 0x40208000 or higher. Are you using only 8208 bytes of iram? (after some thinking) I remember having read somewhere that you reversed the layout of the image. Irom0 first, then at the final 32k the iram segment right? So the 8208 bytes at the start are really the boot loader + config and not iram, right?

You see, I'd like to be prepared before starting on something ;)

Thanks for your help!