Skip to content

Commit

Permalink
get roots.pem from adafruit/certificates repo
Browse files Browse the repository at this point in the history
  • Loading branch information
dhalbert committed Dec 14, 2023
1 parent 42f4766 commit c895779
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 1,084 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "certificates"]
path = certificates
url = https://github.com/adafruit/certificates
4 changes: 4 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
Adafruit's Arduino NINA-W102 firmware 1.7.7 - 2023.09.20

* Change to use adafruit/certificates repo for roots.pem

Adafruit's Arduino NINA-W102 firmware 1.7.5 - 2023.07.21

* Fix for bug in NINA-W102 firmware 1.7.5 not allowing uploads on Windows/Linux
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@ original Arduino firmware repository.
1. Extract it and add it to your `PATH`: `export PATH=$PATH:<path/to/toolchain>/bin`
1. Clone **v3.3.1** of the IDF: `git clone --branch v3.3.1 --recursive https://github.com/espressif/esp-idf.git`
1. Set the `IDF_PATH` environment variable: `export IDF_PATH=<path/to/idf>`
1. `git submodule update --init` to fetch the `certificates` submodule.
1. Run `make firmware` to build the firmware (in the directory of this read me)
1. You may need to set up a python3 `venv` to avoid Python library version issues.
1. You should have a file named `NINA_W102-x.x.x.bin` in the top directory
1. Use appropriate tools (esptool.py, appropriate pass-through firmware etc)
1. Use appropriate tools (`esptool.py`, appropriate pass-through firmware etc)
to load this binary file onto your board.
a. If you do not know how to do this, [we have an excellent guide on the Adafruit Learning System for upgrading your ESP32's firmware](https://learn.adafruit.com/upgrading-esp32-firmware)

Expand Down
1 change: 1 addition & 0 deletions certificates
Submodule certificates added at cbb33c
41 changes: 27 additions & 14 deletions combine.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env python

import sys;
import re
import sys


def extract_firmware_version():
Expand All @@ -16,39 +17,51 @@ def extract_firmware_version():
booloaderData = open("build/bootloader/bootloader.bin", "rb").read()
partitionData = open("build/partitions.bin", "rb").read()
appData = open("build/nina-fw.bin", "rb").read()
certsData = open("data/roots.pem", "rb").read()

# remove everything between certificate markers to save space. There might be comments and other information.
certsData = b""
with open("certificates/data/roots.pem", "rb") as certs_file:
in_cert = False
for line in certs_file:
print(line)
if line.startswith(b"-----BEGIN CERTIFICATE-----"):
in_cert = True
if in_cert:
certsData += line
if line.startswith(b"-----END CERTIFICATE-----"):
in_cert = False

# calculate the output binary size, app offset
outputSize = 0x30000 + len(appData)
if (outputSize % 1024):
outputSize += 1024 - (outputSize % 1024)
if outputSize % 1024:
outputSize += 1024 - (outputSize % 1024)

# allocate and init to 0xff
outputData = bytearray(b'\xff') * outputSize
outputData = bytearray(b"\xff") * outputSize

# copy data: bootloader, partitions, app
for i in range(0, len(booloaderData)):
outputData[0x1000 + i] = booloaderData[i]
outputData[0x1000 + i] = booloaderData[i]

for i in range(0, len(partitionData)):
outputData[0x8000 + i] = partitionData[i]
outputData[0x8000 + i] = partitionData[i]

for i in range(0, len(appData)):
outputData[0x30000 + i] = appData[i]
outputData[0x30000 + i] = appData[i]

for i in range(0, len(certsData)):
outputData[0x10000 + i] = certsData[i]
outputData[0x10000 + i] = certsData[i]

# zero terminate the pem file
outputData[0x10000 + len(certsData)] = 0

version = extract_firmware_version()
outputFilename = f"NINA_W102-{version}.bin"

if (len(sys.argv) > 1):
outputFilename = sys.argv[1]
if len(sys.argv) > 1:
outputFilename = sys.argv[1]

# write out
with open(outputFilename,"w+b") as f:
f.seek(0)
f.write(outputData)
with open(outputFilename, "w+b") as f:
f.seek(0)
f.write(outputData)
Loading

0 comments on commit c895779

Please sign in to comment.