Skip to content

Commit f40a801

Browse files
committed
Add compile_with_docker.bat
1 parent 71b9170 commit f40a801

File tree

4 files changed

+59
-10
lines changed

4 files changed

+59
-10
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_firmware --no-cache-filter deployment .
2+
docker create --name=rtk_container rtk_firmware:latest
3+
docker cp rtk_container:/RTK_Surveyor.ino.bin .
4+
docker cp rtk_container:/RTK_Surveyor.ino.elf .
5+
docker cp rtk_container:/RTK_Surveyor.ino.bootloader.bin .
6+
docker container rm rtk_container

docs/firmware_update.md

Lines changed: 53 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ In the rare event that a unit is not staying on long enough for new firmware to
114114

115115
## Updating Firmware From WiFi
116116

117-
![Advanced system settings](img/WiFi Config/SparkFun%20RTK%20System%20Config%20Upload%20BIN.png)
117+
![Advanced system settings](img/WiFi%20Config/SparkFun%20RTK%20System%20Config%20Upload%20BIN.png)
118118

119119
**Note:** Firmware versions 1.1 to 1.9 have an issue that severely limits firmware upload over WiFi and is not recommended; use the [GUI](firmware_update.md#updating-firmware-using-the-uploader-gui) method instead. Firmware versions v1.10 and beyond support direct firmware updates via WiFi.
120120

@@ -158,7 +158,9 @@ Get [esptool.py](https://github.com/espressif/esptool). Connect a USB A to C cab
158158

159159
If the COM port is not showing be sure the unit is turned **On**. If an unknown device is appearing, you’ll need to [install drivers for the CH340](https://learn.sparkfun.com/tutorials/how-to-install-ch340-drivers/all). Once you know the COM port, run the following command:
160160

161+
```
161162
py esptool.py --chip esp32 --port /dev/ttyUSB0 --baud 921600 --before default_reset --after hard_reset write_flash -z --flash_mode dio --flash_freq 80m --flash_size detect 0x1000 ./bin/RTK_Surveyor.ino.bootloader.bin 0x8000 ./bin/RTK_Surveyor_Partitions_16MB.bin 0xe000 ./bin/boot_app0.bin 0x10000 ./RTK_Surveyor_Firmware_vxx.bin
163+
```
162164

163165
Where */dev/ttyUSB0* is replaced with the port that the RTK product enumerated at and *RTK_Surveyor_Firmware_vxx.bin* is the firmware you would like to load.
164166

@@ -288,12 +290,14 @@ You are welcome to clone or fork this repo and do the exact same thing yourself.
288290

289291
If you run the [compilation workflow](https://github.com/sparkfun/SparkFun_RTK_Firmware/blob/main/.github/workflows/compile-rtk-firmware.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_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.
290292

291-
You can then use the [SparkFun RTK Firmware Uploader](https://github.com/sparkfun/SparkFun_RTK_Firmware_Uploader) to upload the binary onto the ESP32.
293+
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.
292294

293295
## Using Docker
294296

295297
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 Server.h... It is much easier to sandbox the firmware compilation using an environment like [Docker](https://www.docker.com/).
296298

299+
Docker is open-source. It is our new favourite thing!
300+
297301
Here is a step-by-step guide for how to install Docker and compile the firmware from scratch:
298302

299303
### Clone, fork or download the RTK Firmware repo
@@ -330,20 +334,20 @@ For the real Wild West experience, you can also download a copy of the `release_
330334

331335
### Install Docker Desktop
332336

333-
* Head to [Docker](https://www.docker.com/) and create an account. A free "Personal" account will cover occasional compilations of the firmware
337+
* **(Optional)** Head to [Docker](https://www.docker.com/) and create an account. A free "Personal" account will cover occasional compilations of the firmware
334338
* 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.
335-
* Run the Desktop and sign in
339+
* Run the Desktop. If you don't sign in, it will run in Personal mode - which will cover occasional compilations of the firmware
336340
* 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:
337341
* Open a command prompt
338342
* Type `wsl --update` to update WSL. At the time of writing, this installs Windows Subsystem for Linux 2.6.1
339343
* Restart the Docker Desktop
340-
* If you are using Docker for the first time, the "What is a container?" and "How do I run a container?" demos are useful
344+
* 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_
341345
* On Windows, you may want to give Docker Desktop permission to access to your Network, so it can access (e.g.) HTML ports
342346
* You can Stop the container and Delete it when you are done
343347
* You may want to prevent Docker from running when your machine starts up
344348
* Uncheck "Start Docker Desktop when you sign in to your computer" in the Desktop settings
345349

346-
### Running the Dockerfile to create an Image
350+
### Using Docker to create the firmware binary
347351

348352
* **Make sure you have Docker Desktop running.** You don't need to be logged in, but it needs to be running.
349353
* Open a Command Prompt and `cd` into the SparkFun_RTK_Firmware folder
@@ -365,19 +369,35 @@ For the real Wild West experience, you can also download a copy of the `release_
365369

366370
```
367371
app3M_fat9M_16MB.csv
372+
compile_with_docker.bat
368373
Dockerfile
369374
readme.md
370375
RTKFirmware.csv
371376
RTK_Surveyor
372377
```
373378

374-
* The file we will be using is the `Dockerfile`.
375-
* Type:
379+
* The file that does most of the work is the `Dockerfile`
380+
381+
* But, if you're short on time, run `compile_with_docker.bat`. It does everything for you:
382+
383+
![Output of the compile batch file](./img/CompileSource/compile_me_batch_file.png)
384+
385+
* Hey presto! You have your newly compiled firmware binary!
386+
387+
### Running the Dockerfile manually
388+
389+
If you want to see and understand what's going on under the hood with the Dockerfile, Image and Container:
390+
391+
Here is how to perform each step manually:
392+
393+
* To begin, run the Dockerfile. Type:
376394

377395
```
378396
docker build -t rtk_firmware .
379397
```
380398

399+
You should see:
400+
381401
![Dockerfile starting](./img/CompileSource/Dockerfile_starting.png)
382402

383403
![Dockerfile complete](./img/CompileSource/Dockerfile_complete.png)
@@ -396,15 +416,15 @@ docker build -t rtk_firmware --progress=plain --no-cache .
396416

397417
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.
398418

399-
* When you make changes to the source code and want to recompile, use:
419+
* **When you make changes to the source code and want to recompile, use:**
400420

401421
```
402422
docker build -t rtk_firmware --no-cache-filter deployment .
403423
```
404424

405425
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.
406426

407-
### Access the firmware by running the Image
427+
#### Access the firmware binary by running the Image
408428

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

@@ -436,12 +456,35 @@ If you need the `.elf` file so you can debug code crashes with me-no-dev's [ESP
436456
docker cp rtk_container:/RTK_Surveyor.ino.elf .
437457
```
438458

459+
If you need the `.bootloader.bin` file so you can upload it with esptool:
460+
461+
```
462+
docker cp rtk_container:/RTK_Surveyor.ino.bootloader.bin .
463+
```
464+
439465
If you want the files to appear in a more convenient directory, replace the single `.` with a folder path.
440466

441467
Delete the `rtk_container` 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:
442468

443469
```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.```
444470

471+
* **Remember:** when you make changes to the source code and want to recompile, use:
472+
473+
```
474+
docker build -t rtk_firmware --no-cache-filter deployment .
475+
```
476+
477+
* **Shortcut:** the `compile_with_docker.bat` batch file does everything for you:
478+
479+
```
480+
docker build -t rtk_firmware --no-cache-filter deployment .
481+
docker create --name=rtk_container rtk_firmware:latest
482+
docker cp rtk_container:/RTK_Surveyor.ino.bin .
483+
docker cp rtk_container:/RTK_Surveyor.ino.elf .
484+
docker cp rtk_container:/RTK_Surveyor.ino.bootloader.bin .
485+
docker container rm rtk_container
486+
```
487+
445488
### Compiling on Windows (Deprecated)
446489

447490
The SparkFun RTK Firmware is compiled using Arduino (currently v1.8.15). To compile:
73.5 KB
Loading

docs/img/RTK_Uploader_Windows.png

-121 Bytes
Loading

0 commit comments

Comments
 (0)