How to compile firmware?

All ESP8266 boards running MicroPython.
Official boards are the Adafruit Huzzah and Feather boards.
Target audience: MicroPython users with an ESP8266 board.
newb
Posts: 43
Joined: Wed Jan 10, 2018 8:19 pm
Location: Bulgaria

How to compile firmware?

Post by newb » Mon Sep 27, 2021 6:30 pm

Hello,

is there an up-to-date tutorial on how to compile Micropython esp8266 firmware? My goal is to byte freeze my code into the firmware.

I was looking at pfalcon's: https://github.com/pfalcon/esp-open-sdk but it's not supported anymore and a lot of library dependancies are broken, so I can't really use it. I tried compiling it on Debian Buster and even applied various fixes from the "Issues" section of the GitHub repo, but it doesn't compile because of the mentioned dependancy issues.

I saw somewhere that it's recommended to use Docker container with prebuilt esp-sdk for this, but that's another learning curve which I prefer to avoid, if I can. If using a container is the only working option, I would appreciate if someone points me out a resource which explains how to do the firmware compiling. Thank you.

bitninja
Posts: 165
Joined: Thu Sep 15, 2016 4:09 pm
Location: Spring, Texas

Re: How to compile firmware?

Post by bitninja » Wed Sep 29, 2021 12:43 am

Hello,
I can certainly understand any frustration you may have at attempting this, but I am glad to see you giving it some effort. Compiling the firmware (and allowing frozen modules and other modifications) is a very important skillset in the MicroPython world... that unfortunately has not been given the attention it should.

Anyway, I have been doing it a while, so I never moved to the Docker method... instead preferring to do the steps per the instructions. Here are some tips that may help with the first part of setting up the OPEN-ESP-SDK toolchain.

PART I - OPEN_ESP_SDK

- Use a VM (I use VirtualBox) to setup a build machine using the Linux version that the instructions mention (Ubuntu 14.04). Using anything else will just cause more issues with updated libs and such. I am not saying it can't be done with another distro... just that it may be harder.

- Even with a VM, you will run into some updated libs that will break the build of the esp-open-sdk. Check the GITHUB page issues pages for the https://github.com/pfalcon/esp-open-sdk project. You may have to tweak a config file or two to use an updated library version.

- When you can get the open-esp-sdk toolkit to build, from then on you just need to execute the EXPORT path statement to use it

PART II - BUILD MICROPYTHON

- Follow the instructions on the github page... they are fairly accurate

- Save your VM. You will want to try different firmware builds.

Here is a video I did a while ago, following this basic process. https://youtu.be/jG7WBY_vmpE

I'll be here if you have any questions...

bitninja
Posts: 165
Joined: Thu Sep 15, 2016 4:09 pm
Location: Spring, Texas

Re: How to compile firmware?

Post by bitninja » Mon Oct 11, 2021 1:20 pm

Just so you know, I just went through the documented steps and ran into only two dependency issues breaking the building of the esp_open_sdk toolkit.

I can document all my steps, here if you still need it.

Otherwise, I think I will format some documentation on the process and post somewhere.

newb
Posts: 43
Joined: Wed Jan 10, 2018 8:19 pm
Location: Bulgaria

Re: How to compile firmware?

Post by newb » Thu Oct 14, 2021 8:44 pm

Yes! Please document it. There hasn't been up to date tutorial on this topic for years.

JennaSys
Posts: 33
Joined: Tue Jul 15, 2014 8:29 am
Location: Southern California, US
Contact:

Re: How to compile firmware?

Post by JennaSys » Fri Oct 15, 2021 6:24 pm

I attempted trying to get the build toolchain set up on my Linux box a few months ago and after a few hours of troubleshooting errors I just gave up on it. I switched to the Docker route and it just worked out of the box. That said, I was already using Docker for other projects so installing it wasn't an extra step for me. I also have concerns with that approach since I'm not sure it that container build is being maintained.
John Sheehan

User avatar
hcet14
Posts: 34
Joined: Sat Dec 19, 2020 12:59 am

Re: How to compile firmware?

Post by hcet14 » Fri Oct 15, 2021 7:50 pm

bitninja wrote:
Mon Oct 11, 2021 1:20 pm
Otherwise, I think I will format some documentation on the process and post somewhere.
Please :P
hcet14
I'm a beginner with this stuff and no programmer at all.

bitninja
Posts: 165
Joined: Thu Sep 15, 2016 4:09 pm
Location: Spring, Texas

Re: How to compile firmware?

Post by bitninja » Fri Oct 15, 2021 11:45 pm

Here is a doc describing the two problems I ran into in building the ESP_OPEN_SDK...

Once that is done, the tools should build and you can move on to building MicroPython...

Basically...

- one of the source websites is unavailable (to me) (http://isl.gforge.inria.fr/)

- and the version of expat needs to be updated from 2.1.0 to 4.2.1

Then the esp_open_sdk should build like it should.

I am working on a complete document as well.
Attachments
Shortcut20211015.zip
(66.29 KiB) Downloaded 4009 times

bitninja
Posts: 165
Joined: Thu Sep 15, 2016 4:09 pm
Location: Spring, Texas

Re: How to compile firmware?

Post by bitninja » Sun Nov 21, 2021 7:07 am

For anyone interested...

https://wezensky.no-ip.org/fwm/doku.php ... onfirmware

I will be refining the content over the next few days.

jomas
Posts: 59
Joined: Mon Dec 25, 2017 1:48 pm
Location: Netherlands

Re: How to compile firmware?

Post by jomas » Sun Nov 21, 2021 10:51 am

Nice work @bitninja

To patch esp-open-sdk you can also apply a patchfile, which is more common.

save the following code to a file named esp-open-sdk.patch

Code: Select all

diff -Naur esp-open-sdk/crosstool-NG/config/companion_libs/expat.in esp-open-sdk.patched/crosstool-NG/config/companion_libs/expat.in
--- esp-open-sdk/crosstool-NG/config/companion_libs/expat.in	2021-11-15 15:16:18.901090300 +0100
+++ esp-open-sdk.patched/crosstool-NG/config/companion_libs/expat.in	2021-11-15 15:19:24.088491000 +0100
@@ -6,9 +6,9 @@
 # Don't remove next line
 # CT_INSERT_VERSION_BELOW
 
-config EXPAT_V_2_1_0
+config EXPAT_V_2_4_1
     bool
-    prompt "2.1.0"
+    prompt "2.4.1"
 
 endchoice
 
@@ -16,4 +16,4 @@
     string
 # Don't remove next line
 # CT_INSERT_VERSION_STRING_BELOW
-    default "2.1.0" if EXPAT_V_2_1_0
+    default "2.4.1" if EXPAT_V_2_4_1
diff -Naur esp-open-sdk/crosstool-NG/scripts/build/companion_libs/121-isl.sh esp-open-sdk.patched/crosstool-NG/scripts/build/companion_libs/121-isl.sh
--- esp-open-sdk/crosstool-NG/scripts/build/companion_libs/121-isl.sh	2021-11-15 15:16:19.930132500 +0100
+++ esp-open-sdk.patched/crosstool-NG/scripts/build/companion_libs/121-isl.sh	2021-11-15 15:22:40.477652500 +0100
@@ -14,7 +14,7 @@
 # Download ISL
 do_isl_get() {
     CT_GetFile "isl-${CT_ISL_VERSION}" \
-        http://isl.gforge.inria.fr
+        https://gcc.gnu.org/pub/gcc/infrastructure
 }
 
 # Extract ISL

Then clone the esp-open-sdk repository and execute:

Code: Select all

patch -p1 -l -ruN -d esp-open-sdk < esp-open-sdk.patch
B.t.w. I also found a way to compile micropython (and freeze your own modules) without installing any software on your computer.
Just a browser is enough to compile your own image in a few minutes.

If there is interest in this method just let me know. (Or bitnija can add this as an alternative to his site).

bitninja
Posts: 165
Joined: Thu Sep 15, 2016 4:09 pm
Location: Spring, Texas

Re: How to compile firmware?

Post by bitninja » Sun Nov 21, 2021 11:40 am

Thank you jomas!

I am happy to learn about the patch file method... that is really useful. Much easier to apply without making mistakes!

Anyway, I definitely would like to know about this web site. I have been looking for a more simpler type of system for building these BIN files and I had not thought about the online approach.

Post Reply