Skip to content

Commit

Permalink
Merge pull request #57 from dhalbert/certificates-submodule
Browse files Browse the repository at this point in the history
get roots.pem from adafruit/certificates repo
  • Loading branch information
hathach committed Dec 19, 2023
2 parents 42f4766 + fc3c7f7 commit b1145b4
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 1,084 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ jobs:
- name: Checkout
uses: actions/checkout@v3

- name: Checkout submodules
run: git submodule update --init --depth 1 certificates

- name: Build
run: docker run --rm -v $PWD:/project -w /project espressif/idf:v3.3.1 make firmware

Expand Down
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
40 changes: 26 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,50 @@ 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:
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)
1,068 changes: 0 additions & 1,068 deletions data/roots.pem

This file was deleted.

2 changes: 1 addition & 1 deletion main/CommandHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

#include "Arduino.h"

const char FIRMWARE_VERSION[6] = "1.7.6";
const char FIRMWARE_VERSION[6] = "1.7.7";

// Optional, user-defined X.509 certificate
char CERT_BUF[1300];
Expand Down

0 comments on commit b1145b4

Please sign in to comment.