Custom bootloader

MateusGL
Posts: 17
Joined: Sun Feb 23, 2020 5:18 am

Custom bootloader

Postby MateusGL » Mon May 02, 2022 1:43 pm

Hi,

I'm designing a custom bootloader using hooks. In the documentation (https://docs.espressif.com/projects/esp ... bootloader) it is said:

"In the bootloader space, you cannot use the drivers and functions from other components. If necessary, then the required functionality should be placed in the project’s bootloader_components directory (note that this will increase its size)."

I'm a little confused about that.

Copying a component would probably require to copy a few others too, because of requirements. Isn't sufficient to just adding the components names on the CMakeLists.txt file in the hooks folder? I tested it and it worked for some components, but doesn't work for others. And even when it works, I can't import some files (like adding esp_system component and trying to import "esp_private/system_internal.h").

It would be great to have a more detailed documentation about doing custom bootloaders using hooks. I'm struggling trying to discover which components are supported in the bootloader space by just adding in the CMakeLists.txt and which are not, and why I can't import some files even when the respective component is in the CMakeLists.txt file.

Thank you,

Mateus

WiFive
Posts: 3529
Joined: Tue Dec 01, 2015 7:35 am

Re: Custom bootloader

Postby WiFive » Mon May 02, 2022 5:46 pm

1. the bootloader has to run completely from iram and 2. many components depend on freertos features. If you can use rom functions to do what you want, it would be easier.

MateusGL
Posts: 17
Joined: Sun Feb 23, 2020 5:18 am

Re: Custom bootloader

Postby MateusGL » Mon May 02, 2022 7:08 pm

Hi WiFive, thank you for your answer!

I'm using hal component to control uart and gpios and bootloader_support component to write and read from flash.

My problem now is that I need to do a software reset from my bootloader hook. I was trying to add esp_system as a requirement in the CMakeLists of the hook and use the esp_restart() function defined in "esp_system.h", but it doesn't work. When I try to include "esp_system.h", the compiler shows "fatal error: esp_system.h: No such file or directory".

Then I realized that esp_restart() calls a FreeRTOS function and, to avoid that, I tried to call esp_restart_noos_dig() and esp_restart_noos() directly (by the way, what is the difference between these functions and when I should call one instead of the other?). I'm including "esp_private/system_internal.h" to use these functions but, again, I'm receiving an error of "No such file or directory".

So:

1) Why adding hal and bootloader_support in the requirements list in the CMakeLists of the hook works fine, but adding esp_system doesn't?

2) How can I do a software reset inside the bootloader hook?

3) Why bootloader should run completely from IRAM? Every function should be declared with IRAM_ATTR flag inside my hook? I'm not doing that and apparently it is working.


EDIT:

I've found the answer to my second question: just call bootloader_reset() (defined in bootloader_utility.h in bootloader_support component)

WiFive
Posts: 3529
Joined: Tue Dec 01, 2015 7:35 am

Re: Custom bootloader

Postby WiFive » Thu May 05, 2022 2:11 pm

You don't need IRAM_ATTR because the bootloader has its own linker script which places everything in iram but it's good to be aware of it.

MateusGL
Posts: 17
Joined: Sun Feb 23, 2020 5:18 am

Re: Custom bootloader

Postby MateusGL » Mon May 09, 2022 11:37 am

Thank you WiFive!

I've found the answer to my question 1: some components verify the flag BOOTLOADER_BUILD inside their CMakeLists file, so they modify their behaviour when it is a bootloader build.

Who is online

Users browsing this forum: Bing [Bot] and 354 guests