Skip to content

Commit e85db0e

Browse files
committed
Add compile_with_docker.bat
1 parent 5595ba4 commit e85db0e

File tree

3 files changed

+78
-13
lines changed

3 files changed

+78
-13
lines changed

Firmware/compile_with_docker.bat

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
docker build -t rtk_everywhere_firmware --no-cache-filter deployment .
2+
docker create --name=rtk_everywhere rtk_everywhere_firmware:latest
3+
docker cp rtk_everywhere:/RTK_Everywhere.ino.bin .
4+
docker cp rtk_everywhere:/RTK_Everywhere.ino.elf .
5+
docker cp rtk_everywhere:/RTK_Everywhere.ino.bootloader.bin .
6+
docker container rm rtk_everywhere

docs/firmware_compile.md

Lines changed: 72 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,14 @@ You are welcome to clone or fork this repo and do the exact same thing yourself.
1414

1515
If you run the [compilation workflow](https://github.com/sparkfun/SparkFun_RTK_Everywhere_Firmware/blob/main/.github/workflows/compile-rtk-everywhere.yml), it will compile the firmware and attempt to push the binary to the Binaries repo. This will fail as your account won't have the right permissions. The [non-release-build](https://github.com/sparkfun/SparkFun_RTK_Everywhere_Firmware/blob/main/.github/workflows/non-release-build.yml) is the one for you. The firmware binary will be attached as an Artifact to the workflow run. Navigate to Actions \ Non-Release Build, select the latest run of Non-Release Build, the binary is in the Artifacts.
1616

17-
You can then use the [SparkFun RTK Firmware Uploader](https://github.com/sparkfun/SparkFun_RTK_Firmware_Uploader) to upload the binary onto the ESP32.
17+
You can then use (e.g.) the [SparkFun RTK Firmware Uploader](https://github.com/sparkfun/SparkFun_RTK_Firmware_Uploader) to upload the binary onto the ESP32.
1818

1919
## Using Docker
2020

2121
Installing the correct version of the ESP32 core and of each required Arduino library, is tedious and error-prone. Especially on Windows. We've lost count of the number of times code compilation fails on our local machines, because we had the wrong ESP32 core installed, or forgot to patch libbt or libmbedcrypto... It is much easier to sandbox the firmware compilation using an environment like [Docker](https://www.docker.com/).
2222

23+
Docker is open-source. It is our new favourite thing!
24+
2325
Here is a step-by-step guide for how to install Docker and compile the firmware from scratch:
2426

2527
### Clone, fork or download the RTK Everywhere Firmware repo
@@ -56,20 +58,20 @@ For the real Wild West experience, you can also download a copy of the `release_
5658

5759
### Install Docker Desktop
5860

59-
* Head to [Docker](https://www.docker.com/) and create an account. A free "Personal" account will cover occasional compilations of the firmware
61+
* **(Optional)** Head to [Docker](https://www.docker.com/) and create an account. A free "Personal" account will cover occasional compilations of the firmware
6062
* Download and install [Docker Desktop](https://docs.docker.com/get-started/get-docker/) - there are versions for Mac, Windows and Linux. You may need to restart to complete the installation.
61-
* Run the Desktop and sign in
63+
* Run the Desktop. If you don't sign in, it will run in Personal mode - which will cover occasional compilations of the firmware
6264
* On Windows, you may see an error saying "**WSL needs updating** Your version of Windows Subsystem for Linux (WSL) is too old". If you do:
6365
* Open a command prompt
6466
* Type `wsl --update` to update WSL. At the time of writing, this installs Windows Subsystem for Linux 2.6.1
6567
* Restart the Docker Desktop
66-
* If you are using Docker for the first time, the "What is a container?" and "How do I run a container?" demos are useful
68+
* If you are using Docker for the first time, the "What is a container?" and "How do I run a container?" demos are useful - _but not essential_
6769
* On Windows, you may want to give Docker Desktop permission to access to your Network, so it can access (e.g.) HTML ports
6870
* You can Stop the container and Delete it when you are done
6971
* You may want to prevent Docker from running when your machine starts up
7072
* Uncheck "Start Docker Desktop when you sign in to your computer" in the Desktop settings
7173

72-
### Running the Dockerfile to create an Image
74+
### Using Docker to create the firmware binary
7375

7476
* **Make sure you have Docker Desktop running.** You don't need to be logged in, but it needs to be running.
7577
* Open a Command Prompt and `cd` into the SparkFun_RTK_Everywhere_Firmware folder
@@ -90,14 +92,31 @@ For the real Wild West experience, you can also download a copy of the `release_
9092
* `cd Firmware` and then `dir` again. You should see:
9193

9294
```
95+
compile_with_docker.bat
9396
Dockerfile
9497
readme.md
9598
RTKEverywhere.csv
9699
RTKEverywhere_8MB.csv
100+
RTK_Everywhere
97101
```
98102

99-
* The file we will be using is the `Dockerfile`.
100-
* Type:
103+
* The file that does most of the work is the `Dockerfile`
104+
105+
* But, if you're short on time, run `compile_with_docker.bat`. It does everything for you:
106+
107+
![Output of the compile batch file](./img/CompileSource/compile_me_batch_file.png)
108+
109+
* Hey presto! You have your newly compiled firmware binary!
110+
111+
You can then use (e.g.) the [SparkFun RTK Firmware Uploader](https://github.com/sparkfun/SparkFun_RTK_Firmware_Uploader) to upload the binary onto the ESP32.
112+
113+
### Running the Dockerfile manually
114+
115+
If you want to see and understand what's going on under the hood with the Dockerfile, Image and Container:
116+
117+
Here is how to perform each step manually:
118+
119+
* To begin, run the Dockerfile. Type:
101120

102121
```
103122
docker build -t rtk_everywhere_firmware .
@@ -121,15 +140,15 @@ docker build -t rtk_everywhere_firmware --progress=plain --no-cache .
121140

122141
Building the full Image from scratch is slow, taking several minutes. You should only need to do it once - unless you make any changes to the Dockerfile.
123142

124-
* When you make changes to the source code and want to recompile, use:
143+
* **When you make changes to the source code and want to recompile, use:**
125144

126145
```
127146
docker build -t rtk_everywhere_firmware --no-cache-filter deployment .
128147
```
129148

130149
This uses the cache for the `upstream` stage and avoids recreating the full ubuntu machine. But it ignores the cache for the `deployment` stage, ensuring the code is recompiled.
131150

132-
### Access the firmware by running the Image
151+
### Access the firmware binary by running the Image
133152

134153
In Docker Desktop, in the Images tab, you should now be able to see an Image named `rtk_everywhere_firmware`. We now need to Run that Image to access the firmware binary. Click the triangular Run icon under Actions:
135154

@@ -161,12 +180,39 @@ If you need the `.elf` file so you can debug code crashes with me-no-dev's [ESP
161180
docker cp rtk_everywhere:/RTK_Everywhere.ino.elf .
162181
```
163182

183+
If you need the `.bootloader.bin` file so you can upload it with esptool:
184+
185+
```
186+
docker cp rtk_everywhere:/RTK_Everywhere.ino.bootloader.bin .
187+
```
188+
164189
If you want the files to appear in a more convenient directory, replace the single `.` with a folder path.
165190

166-
Delete the `rtk_everywhere` container afterwards, to save disk space and so you can reuse the same container name next time.
191+
Delete the `rtk_everywhere` container afterwards, to save disk space and so you can reuse the same container name next time. If you forget, you will see an error:
192+
193+
```Conflict. The container name "/rtk_container" is already in use by container. You have to remove (or rename) that container to be able to reuse that name.```
194+
195+
* **Remember:** when you make changes to the source code and want to recompile, use:
196+
197+
```
198+
docker build -t rtk_everywhere_firmware --no-cache-filter deployment .
199+
```
200+
201+
* **Shortcut:** the `compile_with_docker.bat` batch file does everything for you:
202+
203+
```
204+
docker build -t rtk_everywhere_firmware --no-cache-filter deployment .
205+
docker create --name=rtk_everywhere rtk_everywhere_firmware:latest
206+
docker cp rtk_everywhere:/RTK_Everywhere.ino.bin .
207+
docker cp rtk_everywhere:/RTK_Everywhere.ino.elf .
208+
docker cp rtk_everywhere:/RTK_Everywhere.ino.bootloader.bin .
209+
docker container rm rtk_everywhere
210+
```
167211

168212
## Compiling on Windows (Deprecated)
169213

214+
**Note: we recommend using the Docker method. It is far easier and much less error-prone...**
215+
170216
The SparkFun RTK Everywhere Firmware is compiled using Arduino CLI (currently [v1.0.4](https://github.com/arduino/arduino-cli/releases)). To compile:
171217

172218
1. Install [Arduino CLI](https://github.com/arduino/arduino-cli/releases).
@@ -188,13 +234,26 @@ The SparkFun RTK Everywhere Firmware is compiled using Arduino CLI (currently [v
188234

189235
This will increase the program partitions, as well as the SPIFFs partition to utilize the full 16MB of flash (8MB in the case of the Postcard).
190236

191-
6. Compile using the following command
237+
6. Patch the core (libmbedtls, NetworkEvents and libbt) - as shown in the workflow
192238

193-
arduino-cli compile 'Firmware/RTK_Everywhere' --build-property build.partitions=RTKEverywhere --build-property upload.maximum_size=4055040 --fqbn esp32:esp32:esp32:FlashSize=16M,PSRAM=enabled
239+
7. Update the web config `form.h` by running the two python scripts in the `Tools` folder:
194240

195-
8. Once compiled, upload to the device using the following command where `[COM_PORT]` is the COM port on which the RTK device is located (ie `COM42`).
241+
```
242+
python index_html_zipper.py ../RTK_Everywhere/AP-Config/index.html ../RTK_Everywhere/form.h
243+
python main_js_zipper.py ../RTK_Everywhere/AP-Config/src/main.js ../RTK_Everywhere/form.h
244+
```
245+
246+
8. Compile using the following command
196247

248+
```
249+
arduino-cli compile --fqbn "esp32:esp32:esp32":DebugLevel=none,PSRAM=enabled ./Firmware/RTK_Everywhere/RTK_Everywhere.ino --build-property build.partitions=RTKEverywhere --build-property upload.maximum_size=4055040 --build-property "compiler.cpp.extra_flags=-MMD -c" --export-binaries
250+
```
251+
252+
9. Once compiled, upload to the device using the following command where `[COM_PORT]` is the COM port on which the RTK device is located (ie `COM42`).
253+
254+
```
197255
arduino-cli upload -p [COM_PORT] --fqbn esp32:esp32:esp32:UploadSpeed=512000,FlashSize=16M 'Firmware/RTK_Everywhere'
256+
```
198257

199258
If you are seeing the error:
200259

78 KB
Loading

0 commit comments

Comments
 (0)