├── examples ├── OTA_GitHub_Server │ ├── arduino_secrets.h │ ├── OTA_GitHub_Server.ino │ └── root_ca.h ├── OTA_Arduino_Server │ ├── arduino_secrets.h │ ├── OTA_Arduino_Server.ino │ └── root_ca.h ├── LOLIN_32_Blink │ ├── LOLIN_32_Blink.ino.ota │ └── LOLIN_32_Blink.ino └── NANO_ESP32_Blink │ ├── NANO_ESP32_Blink.ino.ota │ └── NANO_ESP32_Blink.ino ├── .codespellrc ├── library.properties ├── .github ├── dependabot.yml └── workflows │ ├── arduino-lint.yml │ ├── spell-check.yml │ ├── report-size-deltas.yml │ ├── compile-examples.yml │ └── sync-labels.yml ├── keywords.txt ├── src ├── decompress │ ├── utility.h │ ├── lzss.h │ ├── utility.cpp │ └── lzss.cpp ├── tls │ └── amazon_root_ca.h ├── Arduino_ESP32_OTA.h └── Arduino_ESP32_OTA.cpp ├── README.md └── LICENSE /examples/OTA_GitHub_Server/arduino_secrets.h: -------------------------------------------------------------------------------- 1 | #define SECRET_SSID "" 2 | #define SECRET_PASS "" 3 | -------------------------------------------------------------------------------- /examples/OTA_Arduino_Server/arduino_secrets.h: -------------------------------------------------------------------------------- 1 | #define SECRET_SSID "" 2 | #define SECRET_PASS "" 3 | -------------------------------------------------------------------------------- /examples/LOLIN_32_Blink/LOLIN_32_Blink.ino.ota: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arduino-libraries/Arduino_ESP32_OTA/HEAD/examples/LOLIN_32_Blink/LOLIN_32_Blink.ino.ota -------------------------------------------------------------------------------- /examples/NANO_ESP32_Blink/NANO_ESP32_Blink.ino.ota: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arduino-libraries/Arduino_ESP32_OTA/HEAD/examples/NANO_ESP32_Blink/NANO_ESP32_Blink.ino.ota -------------------------------------------------------------------------------- /.codespellrc: -------------------------------------------------------------------------------- 1 | [codespell] 2 | # In the event of a false positive, add the problematic word, in all lowercase, to a comma-separated list here: 3 | ignore-words-list = , 4 | check-filenames = 5 | check-hidden = 6 | skip = ./.git 7 | -------------------------------------------------------------------------------- /library.properties: -------------------------------------------------------------------------------- 1 | name=Arduino_ESP32_OTA 2 | version=0.3.1 3 | author=Arduino 4 | maintainer=Arduino 5 | sentence=Firmware update for ESP32. 6 | paragraph=This library allows performing a firmware update on ESP32. 7 | category=Communication 8 | url=https://github.com/arduino-libraries/Arduino_ESP32_OTA 9 | architectures=esp32 10 | includes=Arduino_ESP32_OTA.h 11 | depends=ArduinoHttpClient,Arduino_DebugUtils 12 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | # See: https://docs.github.com/en/code-security/supply-chain-security/configuration-options-for-dependency-updates#about-the-dependabotyml-file 2 | version: 2 3 | 4 | updates: 5 | # Configure check for outdated GitHub Actions actions in workflows. 6 | # Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/dependabot/README.md 7 | # See: https://docs.github.com/en/code-security/supply-chain-security/keeping-your-actions-up-to-date-with-dependabot 8 | - package-ecosystem: github-actions 9 | directory: / # Check the repository's workflows under /.github/workflows/ 10 | schedule: 11 | interval: daily 12 | labels: 13 | - "topic: infrastructure" 14 | -------------------------------------------------------------------------------- /examples/LOLIN_32_Blink/LOLIN_32_Blink.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * Blink for LOLIN32 ESP32 board 3 | * 4 | * This sketch can be used to generate an example binary that can be uploaded to ESP32 via OTA. 5 | * It needs to be used together with OTA.ino 6 | * 7 | * Steps to test OTA on ESP32: 8 | * 1) Upload this sketch or any other sketch (this one will blink LOLIN32 blue LED). 9 | * 2) In the IDE select: Sketch -> Export compiled Binary 10 | * 3) Upload the exported binary to a server 11 | * 4) Open the related OTA.ino sketch and eventually update the OTA_FILE_LOCATION 12 | * 5) Upload the sketch OTA.ino to perform OTA 13 | */ 14 | 15 | void setup() { 16 | // initialize digital pin 5 as an output. 17 | pinMode(5, OUTPUT); 18 | } 19 | 20 | void loop() { 21 | digitalWrite(5, HIGH); 22 | delay(1000); 23 | digitalWrite(5, LOW); 24 | delay(1000); 25 | } -------------------------------------------------------------------------------- /.github/workflows/arduino-lint.yml: -------------------------------------------------------------------------------- 1 | name: Arduino Lint 2 | on: 3 | push: 4 | pull_request: 5 | # Scheduled trigger checks for breakage caused by new rules added to Arduino Lint 6 | schedule: 7 | # run every Saturday at 3 AM UTC 8 | - cron: "0 3 * * 6" 9 | # See: https://docs.github.com/en/free-pro-team@latest/actions/reference/events-that-trigger-workflows#workflow_dispatch 10 | workflow_dispatch: 11 | # See: https://docs.github.com/en/free-pro-team@latest/actions/reference/events-that-trigger-workflows#repository_dispatch 12 | repository_dispatch: 13 | 14 | jobs: 15 | lint: 16 | runs-on: ubuntu-latest 17 | 18 | steps: 19 | - name: Checkout 20 | uses: actions/checkout@v6 21 | 22 | - name: Arduino Lint 23 | uses: arduino/arduino-lint-action@v2 24 | with: 25 | official: true 26 | library-manager: update 27 | -------------------------------------------------------------------------------- /.github/workflows/spell-check.yml: -------------------------------------------------------------------------------- 1 | name: Spell Check 2 | 3 | on: 4 | pull_request: 5 | push: 6 | schedule: 7 | # Run every Saturday at 3 AM UTC to catch new misspelling detections resulting from dictionary updates. 8 | - cron: "0 3 * * 6" 9 | # See: https://docs.github.com/en/free-pro-team@latest/actions/reference/events-that-trigger-workflows#workflow_dispatch 10 | workflow_dispatch: 11 | # See: https://docs.github.com/en/free-pro-team@latest/actions/reference/events-that-trigger-workflows#repository_dispatch 12 | repository_dispatch: 13 | 14 | jobs: 15 | spellcheck: 16 | runs-on: ubuntu-latest 17 | 18 | steps: 19 | - name: Checkout repository 20 | uses: actions/checkout@v6 21 | 22 | # See: https://github.com/codespell-project/actions-codespell/blob/master/README.md 23 | - name: Spell check 24 | uses: codespell-project/actions-codespell@v2 25 | -------------------------------------------------------------------------------- /.github/workflows/report-size-deltas.yml: -------------------------------------------------------------------------------- 1 | name: Report Size Deltas 2 | 3 | on: 4 | push: 5 | paths: 6 | - ".github/workflows/report-size-deltas.ya?ml" 7 | schedule: 8 | - cron: '*/5 * * * *' 9 | # See: https://docs.github.com/en/free-pro-team@latest/actions/reference/events-that-trigger-workflows#workflow_dispatch 10 | workflow_dispatch: 11 | # See: https://docs.github.com/en/free-pro-team@latest/actions/reference/events-that-trigger-workflows#repository_dispatch 12 | repository_dispatch: 13 | 14 | jobs: 15 | report: 16 | runs-on: ubuntu-latest 17 | 18 | steps: 19 | # See: https://github.com/arduino/actions/blob/master/libraries/report-size-deltas/README.md 20 | - name: Comment size deltas reports to PRs 21 | uses: arduino/report-size-deltas@v1 22 | with: 23 | # Regex matching the names of the workflow artifacts created by the "Compile Examples" workflow 24 | sketches-reports-source: ^sketches-report-.+ 25 | -------------------------------------------------------------------------------- /keywords.txt: -------------------------------------------------------------------------------- 1 | ####################################### 2 | # Syntax Coloring Map For Arduino_ESP32_OTA 3 | ####################################### 4 | 5 | ####################################### 6 | # Class (KEYWORD1) 7 | ####################################### 8 | 9 | Arduino_ESP32_OTA KEYWORD1 10 | Error KEYWORD1 11 | 12 | ####################################### 13 | # Methods and Functions (KEYWORD2) 14 | ####################################### 15 | 16 | begin KEYWORD2 17 | update KEYWORD2 18 | reset KEYWORD2 19 | download KEYWORD2 20 | 21 | ####################################### 22 | # Constants (LITERAL1) 23 | ####################################### 24 | 25 | None LITERAL1 26 | NoOtaStorage LITERAL1 27 | OtaStorageInit LITERAL1 28 | OtaStorageEnd LITERAL1 29 | UrlParseError LITERAL1 30 | ServerConnectError LITERAL1 31 | HttpHeaderError LITERAL1 32 | ParseHttpHeader LITERAL1 33 | OtaHeaderLength LITERAL1 34 | OtaHeaderCrc LITERAL1 35 | OtaHeaterMagicNumber LITERAL1 36 | OtaDownload LITERAL1 37 | -------------------------------------------------------------------------------- /src/decompress/utility.h: -------------------------------------------------------------------------------- 1 | #ifndef ESP32_OTA_UTILITY_H_ 2 | #define ESP32_OTA_UTILITY_H_ 3 | 4 | #include 5 | #include 6 | 7 | /************************************************************************************** 8 | INCLUDE 9 | **************************************************************************************/ 10 | 11 | union HeaderVersion 12 | { 13 | struct __attribute__((packed)) 14 | { 15 | uint32_t header_version : 6; 16 | uint32_t compression : 1; 17 | uint32_t signature : 1; 18 | uint32_t spare : 4; 19 | uint32_t payload_target : 4; 20 | uint32_t payload_major : 8; 21 | uint32_t payload_minor : 8; 22 | uint32_t payload_patch : 8; 23 | uint32_t payload_build_num : 24; 24 | } field; 25 | uint8_t buf[sizeof(field)]; 26 | static_assert(sizeof(buf) == 8, "Error: sizeof(HEADER.VERSION) != 8"); 27 | }; 28 | 29 | union OtaHeader 30 | { 31 | struct __attribute__((packed)) 32 | { 33 | uint32_t len; 34 | uint32_t crc32; 35 | uint32_t magic_number; 36 | HeaderVersion hdr_version; 37 | } header; 38 | uint8_t buf[sizeof(header)]; 39 | static_assert(sizeof(buf) == 20, "Error: sizeof(HEADER) != 20"); 40 | }; 41 | 42 | uint32_t crc_update(uint32_t crc, const void * data, size_t data_len); 43 | 44 | #endif /* ESP32_OTA_UTILITY_H_ */ 45 | -------------------------------------------------------------------------------- /examples/NANO_ESP32_Blink/NANO_ESP32_Blink.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * Blink for Arduino NANO ESP32 board 3 | * 4 | * This sketch can be used to generate an example binary that can be uploaded to ESP32 via OTA. 5 | * It needs to be used together with OTA.ino 6 | * 7 | * Steps to test OTA: 8 | * 1) Upload this sketch or any other sketch (this one this one lights up the RGB LED with different colours). 9 | * 2) In the IDE select: Sketch -> Export compiled Binary 10 | * 3) Upload the exported binary to a server 11 | * 4) Open the related OTA.ino sketch and eventually update the OTA_FILE_LOCATION 12 | * 5) Upload the sketch OTA.ino to perform OTA 13 | */ 14 | 15 | void setLed(int blue, int gree, int red) { 16 | if (blue == 1) { 17 | digitalWrite(LED_BLUE, LOW); 18 | } 19 | else { 20 | digitalWrite(LED_BLUE, HIGH); 21 | } 22 | 23 | if (gree == 1) { 24 | digitalWrite(LED_GREEN, LOW); 25 | } 26 | else { 27 | digitalWrite(LED_GREEN, HIGH); 28 | } 29 | 30 | if (red == 1) { 31 | digitalWrite(LED_RED, LOW); 32 | } 33 | else { 34 | digitalWrite(LED_RED, HIGH); 35 | } 36 | } 37 | 38 | 39 | void setup() 40 | { 41 | pinMode(LED_BLUE, OUTPUT); 42 | pinMode(LED_GREEN, OUTPUT); 43 | pinMode(LED_RED, OUTPUT); 44 | } 45 | 46 | void loop() 47 | { // Blue LED on 48 | setLed(1, 0, 0); 49 | delay(1000); 50 | // Green LED on 51 | setLed(0, 1, 0); 52 | delay(1000); 53 | // Red LED on 54 | setLed(0, 0, 1); 55 | delay(1000); 56 | } 57 | -------------------------------------------------------------------------------- /.github/workflows/compile-examples.yml: -------------------------------------------------------------------------------- 1 | name: Compile Examples 2 | 3 | on: 4 | pull_request: 5 | paths: 6 | - ".github/workflows/compile-examples.yml" 7 | - "library.properties" 8 | - "examples/**" 9 | - "src/**" 10 | push: 11 | paths: 12 | - ".github/workflows/compile-examples.yml" 13 | - "library.properties" 14 | - "examples/**" 15 | - "src/**" 16 | # Scheduled trigger checks for breakage caused by changes to external resources (libraries, platforms) 17 | schedule: 18 | # run every Saturday at 3 AM UTC 19 | - cron: "0 3 * * 6" 20 | # See: https://docs.github.com/en/free-pro-team@latest/actions/reference/events-that-trigger-workflows#workflow_dispatch 21 | workflow_dispatch: 22 | # See: https://docs.github.com/en/free-pro-team@latest/actions/reference/events-that-trigger-workflows#repository_dispatch 23 | repository_dispatch: 24 | 25 | jobs: 26 | build: 27 | name: ${{ matrix.board.fqbn }} 28 | runs-on: ubuntu-latest 29 | 30 | env: 31 | SKETCHES_REPORTS_PATH: sketches-reports 32 | 33 | strategy: 34 | fail-fast: false 35 | 36 | matrix: 37 | board: 38 | - fqbn: "esp32:esp32:esp32" 39 | type: esp32 40 | artifact-name-suffix: esp32-esp32-esp32 41 | - fqbn: "arduino:esp32:nano_nora" 42 | type: arduino_esp32 43 | artifact-name-suffix: arduino-esp32-arduino_esp32 44 | 45 | include: 46 | - board: 47 | type: esp32 48 | platforms: | 49 | - name: esp32:esp32 50 | source-url: https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json 51 | libraries: | 52 | - name: Arduino_DebugUtils 53 | - name: ArduinoHttpClient 54 | sketch-paths: | 55 | - examples/OTA_Arduino_Server 56 | - examples/OTA_GitHub_Server 57 | - examples/LOLIN_32_Blink 58 | - board: 59 | type: arduino_esp32 60 | platforms: | 61 | - name: arduino:esp32 62 | libraries: | 63 | - name: Arduino_DebugUtils 64 | - name: ArduinoHttpClient 65 | sketch-paths: | 66 | - examples/OTA_Arduino_Server 67 | - examples/OTA_GitHub_Server 68 | - examples/NANO_ESP32_Blink 69 | 70 | steps: 71 | - name: Checkout 72 | uses: actions/checkout@v6 73 | 74 | - name: Install ESP32 platform dependencies 75 | if: matrix.board.type == 'esp32' 76 | run: pip3 install pyserial 77 | 78 | - name: Compile examples 79 | uses: arduino/compile-sketches@v1 80 | with: 81 | github-token: ${{ secrets.GITHUB_TOKEN }} 82 | platforms: ${{ matrix.platforms }} 83 | fqbn: ${{ matrix.board.fqbn }} 84 | libraries: | 85 | # Install the library from the local path. 86 | - source-path: ./ 87 | ${{ matrix.libraries }} 88 | sketch-paths: | 89 | ${{ matrix.sketch-paths }} 90 | enable-deltas-report: true 91 | sketches-report-path: ${{ env.SKETCHES_REPORTS_PATH }} 92 | 93 | - name: Save memory usage change report as artifact 94 | uses: actions/upload-artifact@v6 95 | with: 96 | name: sketches-report-${{ matrix.board.artifact-name-suffix }} 97 | if-no-files-found: error 98 | path: ${{ env.SKETCHES_REPORTS_PATH }} 99 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | `Arduino_ESP32_OTA` 2 | ==================== 3 | 4 | *Note: This library is currently in [beta](#running-tests).* 5 | 6 | [![Compile Examples](https://github.com/arduino-libraries/Arduino_ESP32_OTA/workflows/Compile%20Examples/badge.svg)](https://github.com/arduino-libraries/Arduino_ESP32_OTA/actions?workflow=Compile+Examples) 7 | [![Arduino Lint](https://github.com/arduino-libraries/Arduino_ESP32_OTA/workflows/Arduino%20Lint/badge.svg)](https://github.com/arduino-libraries/Arduino_ESP32_OTA/actions?workflow=Arduino+Lint) 8 | [![Spell Check](https://github.com/arduino-libraries/Arduino_ESP32_OTA/workflows/Spell%20Check/badge.svg)](https://github.com/arduino-libraries/Arduino_ESP32_OTA/actions?workflow=Spell+Check) 9 | 10 | This library allows OTA (Over-The-Air) firmware updates for ESP32 boards. OTA binaries are downloaded via WiFi and stored in the OTA flash partition. After integrity checks the reference to the new firmware is configured in the bootloader; finally board resets to boot new firmware. 11 | 12 | The library is based on the [Update](https://github.com/espressif/arduino-esp32/tree/master/libraries/Update) library of the [arduino-esp32](https://github.com/espressif/arduino-esp32) core. 13 | 14 | ## :mag: How? 15 | 16 | * Create a minimal [example](examples/OTA/OTA.ino) 17 | * Create a [compressed](https://github.com/arduino-libraries/ArduinoIoTCloud/blob/master/extras/tools/lzss.py) [ota](https://github.com/arduino-libraries/ArduinoIoTCloud/blob/master/extras/tools/bin2ota.py) file 18 | 19 | ## :key: Requirements 20 | 21 | * Flash size >= 4MB 22 | * OTA_1 partition available within selected partition scheme 23 | 24 | | Partition scheme | OTA support | 25 | | --- | --- | 26 | | `app3M_fat9M_16MB` | :heavy_check_mark: | 27 | | `default_16MB` | :heavy_check_mark: | 28 | | `large_spiffs_16MB` | :heavy_check_mark: | 29 | | `ffat` | :heavy_check_mark: | 30 | | `default_8MB` | :heavy_check_mark: | 31 | | `max_app_8MB` | :x: | 32 | | `min_spiffs` | :heavy_check_mark: | 33 | | `default` / `default_ffat` | :heavy_check_mark: | 34 | | `huge_app` | :x: | 35 | | `no_ota` | :x: | 36 | | `noota_3g` / `noota_3gffat` / `noota_ffat` | :x: | 37 | | `rainmaker` | :heavy_check_mark: | 38 | | `minimal` | :x: | 39 | | `bare_minimum_2MB` | :x: | 40 | 41 | 42 | ## :running: Tests 43 | 44 | * The library has been tested on the following boards: 45 | 46 | | Module | Board | 47 | | --- | --- | 48 | | `ESP32-WROOM` | [ESP32-DevKitC V4](https://docs.espressif.com/projects/esp-idf/en/latest/esp32/hw-reference/esp32/get-started-devkitc.html#) | 49 | | `ESP32-WROVER` | [Freenove_ESP32_WROVER](https://github.com/Freenove/Freenove_ESP32_WROVER_Board) | 50 | | | DOIT ESP32 DEVKIT V1 | 51 | | | Wemos Lolin D32 | 52 | | | NodeMCU-32S | 53 | | `ESP32-­S3-­WROOM`| [ESP32-S3-DevKitC-1 v1.1](https://docs.espressif.com/projects/esp-idf/en/latest/esp32s3/hw-reference/esp32s3/user-guide-devkitc-1.html) | 54 | | `ESP32-­S2-­SOLO` | [ESP32-S2-DevKitC-1](https://docs.espressif.com/projects/esp-idf/en/latest/esp32s2/hw-reference/esp32s2/user-guide-s2-devkitc-1.html) | 55 | | | NodeMCU-32-S2 | 56 | | `ESP32-C3` | [LILYGO mini D1 PLUS](https://github.com/Xinyuan-LilyGO/LilyGo-T-OI-PLUS)| 57 | 58 | ## :page_with_curl: License 59 | 60 | Arduino_ESP32_OTA is licensed under the GNU General Public License v3.0 license. 61 | 62 | You can be released from the requirements of the above license by purchasing a commercial license. Buying such a license is mandatory if you want to modify or otherwise use the software for commercial activities involving the Arduino software without disclosing the source code of your own applications. To purchase a commercial license, send an email to license@arduino.cc 63 | -------------------------------------------------------------------------------- /examples/OTA_Arduino_Server/OTA_Arduino_Server.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * This example demonstrates how to use to update the firmware using Arduino_ESP_OTA library 3 | * 4 | * Steps: 5 | * 1) Create a sketch for your ESP board and verify 6 | * that it both compiles and works. 7 | * 2) In the IDE select: Sketch -> Export compiled Binary. 8 | * 3) Create an OTA update file utilising the tools 'lzss.py' and 'bin2ota.py' stored in 9 | * https://github.com/arduino-libraries/ArduinoIoTCloud/tree/master/extras/tools . 10 | * A) ./lzss.py --encode SKETCH.bin SKETCH.lzss 11 | * B) ./bin2ota.py ESP SKETCH.lzss SKETCH.ota 12 | * 4) Upload the OTA file to a network reachable location, e.g. LOLIN_32_Blink.ino.ota 13 | * has been uploaded to: http://downloads.arduino.cc/ota/LOLIN_32_Blink.ino.ota 14 | * 5) Verify if a custom ca_cert is needed by default Amazon root CA are used 15 | * https://www.amazontrust.com/repository/ 16 | * 6) Perform an OTA update via steps outlined below. 17 | */ 18 | 19 | /****************************************************************************** 20 | * INCLUDE 21 | ******************************************************************************/ 22 | 23 | #include 24 | 25 | #include 26 | 27 | #include "arduino_secrets.h" 28 | 29 | #include "root_ca.h" 30 | 31 | /****************************************************************************** 32 | * CONSTANT 33 | ******************************************************************************/ 34 | 35 | /* Please enter your sensitive data in the Secret tab/arduino_secrets.h */ 36 | static char const SSID[] = SECRET_SSID; /* your network SSID (name) */ 37 | static char const PASS[] = SECRET_PASS; /* your network password (use for WPA, or use as key for WEP) */ 38 | 39 | 40 | #if defined(ARDUINO_NANO_ESP32) 41 | static char const OTA_FILE_LOCATION[] = "https://downloads.arduino.cc/ota/NANO_ESP32_Blink.ino.ota"; 42 | #else 43 | static char const OTA_FILE_LOCATION[] = "https://downloads.arduino.cc/ota/LOLIN_32_Blink.ino.ota"; 44 | #endif 45 | 46 | /****************************************************************************** 47 | * SETUP/LOOP 48 | ******************************************************************************/ 49 | 50 | void setup() 51 | { 52 | Serial.begin(9600); 53 | while (!Serial) {} 54 | 55 | while (WiFi.status() != WL_CONNECTED) 56 | { 57 | Serial.print ("Attempting to connect to '"); 58 | Serial.print (SSID); 59 | Serial.println("'"); 60 | WiFi.begin(SSID, PASS); 61 | delay(2000); 62 | } 63 | Serial.print ("You're connected to '"); 64 | Serial.print (WiFi.SSID()); 65 | Serial.println("'"); 66 | 67 | Arduino_ESP32_OTA ota; 68 | Arduino_ESP32_OTA::Error ota_err = Arduino_ESP32_OTA::Error::None; 69 | 70 | /* Configure custom Root CA */ 71 | ota.setCACert(root_ca); 72 | 73 | Serial.println("Initializing OTA storage"); 74 | if ((ota_err = ota.begin()) != Arduino_ESP32_OTA::Error::None) 75 | { 76 | Serial.print ("Arduino_ESP_OTA::begin() failed with error code "); 77 | Serial.println((int)ota_err); 78 | return; 79 | } 80 | 81 | 82 | Serial.println("Starting download to flash ..."); 83 | int const ota_download = ota.download(OTA_FILE_LOCATION); 84 | if (ota_download <= 0) 85 | { 86 | Serial.print ("Arduino_ESP_OTA::download failed with error code "); 87 | Serial.println(ota_download); 88 | return; 89 | } 90 | Serial.print (ota_download); 91 | Serial.println(" bytes stored."); 92 | 93 | 94 | Serial.println("Verify update integrity and apply ..."); 95 | if ((ota_err = ota.update()) != Arduino_ESP32_OTA::Error::None) 96 | { 97 | Serial.print ("ota.update() failed with error code "); 98 | Serial.println((int)ota_err); 99 | return; 100 | } 101 | 102 | Serial.println("Performing a reset after which the bootloader will start the new firmware."); 103 | #if defined(ARDUINO_NANO_ESP32) 104 | Serial.println("Hint: Arduino NANO ESP32 will blink Red Green and Blue."); 105 | #else 106 | Serial.println("Hint: LOLIN32 will blink Blue."); 107 | #endif 108 | delay(1000); /* Make sure the serial message gets out before the reset. */ 109 | ota.reset(); 110 | } 111 | 112 | void loop() 113 | { 114 | 115 | } 116 | -------------------------------------------------------------------------------- /src/decompress/lzss.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of the ArduinoIoTCloud library. 3 | 4 | Copyright (c) 2024 Arduino SA 5 | 6 | This Source Code Form is subject to the terms of the Mozilla Public 7 | License, v. 2.0. If a copy of the MPL was not distributed with this 8 | file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | 11 | #pragma once 12 | 13 | /************************************************************************************** 14 | INCLUDE 15 | **************************************************************************************/ 16 | #include 17 | #include 18 | #include 19 | 20 | /************************************************************************************** 21 | FUNCTION DEFINITION 22 | **************************************************************************************/ 23 | 24 | /************************************************************************************** 25 | LZSS DECODER CLASS 26 | **************************************************************************************/ 27 | 28 | 29 | class LZSSDecoder { 30 | public: 31 | 32 | /** 33 | * Build an LZSS decoder by providing a callback for storing the decoded bytes 34 | * @param putc_cbk: a callback that takes a char and stores it e.g. a callback to fwrite 35 | */ 36 | LZSSDecoder(std::function putc_cbk); 37 | 38 | /** 39 | * Build an LZSS decoder providing a callback for getting a char and putting a char 40 | * in this way you need to call decompress with no parameters 41 | * @param putc_cbk: a callback that takes a char and stores it e.g. a callback to fwrite 42 | * @param getc_cbk: a callback that returns the next char to consume 43 | * -1 means EOF, -2 means buffer is temporairly finished 44 | */ 45 | LZSSDecoder(std::function getc_cbk, std::function putc_cbk); 46 | 47 | /** 48 | * this enum describes the result of the computation of a single FSM computation 49 | * DONE: the decompression is completed 50 | * IN_PROGRESS: the decompression cycle completed successfully, ready to compute next 51 | * NOT_COMPLETED: the current cycle didn't complete because the available data is not enough 52 | */ 53 | enum status: uint8_t { 54 | DONE, 55 | IN_PROGRESS, 56 | NOT_COMPLETED 57 | }; 58 | 59 | /** 60 | * decode the provided buffer until buffer ends, then pause the process 61 | * @return DONE if the decompression is completed, NOT_COMPLETED if not 62 | */ 63 | status decompress(uint8_t* const buffer=nullptr, uint32_t size=0); 64 | 65 | static const int LZSS_EOF = -1; 66 | static const int LZSS_BUFFER_EMPTY = -2; 67 | private: 68 | // TODO provide a way for the user to set these parameters 69 | static const int EI = 11; /* typically 10..13 */ 70 | static const int EJ = 4; /* typically 4..5 */ 71 | static const int N = (1 << EI); /* buffer size */ 72 | static const int F = ((1 << EJ) + 1); /* lookahead buffer size */ 73 | 74 | // algorithm specific buffer used to store text that could be later referenced and copied 75 | uint8_t buffer[N * 2]; 76 | 77 | // this function gets 1 single char from the input buffer 78 | int getc(); 79 | uint8_t* in_buffer = nullptr; 80 | uint32_t available = 0; 81 | 82 | status handle_state(); 83 | 84 | // get 1 bit from the available input buffer 85 | int getbit(uint8_t n); 86 | // the following 2 are variables used by getbits 87 | uint32_t buf, buf_size=0; 88 | 89 | enum FSM_STATES: uint8_t { 90 | FSM_0 = 0, 91 | FSM_1 = 1, 92 | FSM_2 = 2, 93 | FSM_3 = 3, 94 | FSM_EOF 95 | } state; 96 | 97 | // these variable are used in a decode session and specific to the old C implementation 98 | // there is no documentation about their meaning 99 | int i, r; 100 | 101 | std::function put_char_cbk; 102 | std::function get_char_cbk; 103 | 104 | inline void putc(const uint8_t c) { if(put_char_cbk) { put_char_cbk(c); } } 105 | 106 | // get the number of bits the FSM will require given its state 107 | uint8_t bits_required(FSM_STATES s); 108 | }; 109 | -------------------------------------------------------------------------------- /examples/OTA_GitHub_Server/OTA_GitHub_Server.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * This example demonstrates how to use to update the firmware using Arduino_ESP_OTA library 3 | * 4 | * Steps: 5 | * 1) Create a sketch for your ESP board and verify 6 | * that it both compiles and works. 7 | * 2) In the IDE select: Sketch -> Export compiled Binary. 8 | * 3) Create an OTA update file utilising the tools 'lzss.py' and 'bin2ota.py' stored in 9 | * https://github.com/arduino-libraries/ArduinoIoTCloud/tree/master/extras/tools . 10 | * A) ./lzss.py --encode SKETCH.bin SKETCH.lzss 11 | * B) ./bin2ota.py ESP SKETCH.lzss SKETCH.ota 12 | * 4) Upload the OTA file to a network reachable location, e.g. LOLIN_32_Blink.ino.ota 13 | * has been uploaded to: http://downloads.arduino.cc/ota/LOLIN_32_Blink.ino.ota 14 | * 5) Verify if a custom ca_cert is needed by default DigiCert root CA are used 15 | * https://www.digicert.com/kb/digicert-root-certificates.htm 16 | * 6) Perform an OTA update via steps outlined below. 17 | */ 18 | 19 | /****************************************************************************** 20 | * INCLUDE 21 | ******************************************************************************/ 22 | 23 | #include 24 | 25 | #include 26 | 27 | #include "arduino_secrets.h" 28 | 29 | #include "root_ca.h" 30 | 31 | /****************************************************************************** 32 | * CONSTANT 33 | ******************************************************************************/ 34 | 35 | /* Please enter your sensitive data in the Secret tab/arduino_secrets.h */ 36 | static char const SSID[] = SECRET_SSID; /* your network SSID (name) */ 37 | static char const PASS[] = SECRET_PASS; /* your network password (use for WPA, or use as key for WEP) */ 38 | 39 | 40 | #if defined(ARDUINO_NANO_ESP32) 41 | static char const OTA_FILE_LOCATION[] = "https://raw.githubusercontent.com/arduino-libraries/Arduino_ESP32_OTA/main/examples/NANO_ESP32_Blink/NANO_ESP32_Blink.ino.ota"; 42 | #else 43 | static char const OTA_FILE_LOCATION[] = "https://raw.githubusercontent.com/arduino-libraries/Arduino_ESP32_OTA/main/examples/LOLIN_32_Blink/LOLIN_32_Blink.ino.ota"; 44 | #endif 45 | 46 | /****************************************************************************** 47 | * SETUP/LOOP 48 | ******************************************************************************/ 49 | 50 | void setup() 51 | { 52 | Serial.begin(9600); 53 | while (!Serial) {} 54 | 55 | while (WiFi.status() != WL_CONNECTED) 56 | { 57 | Serial.print ("Attempting to connect to '"); 58 | Serial.print (SSID); 59 | Serial.println("'"); 60 | WiFi.begin(SSID, PASS); 61 | delay(2000); 62 | } 63 | Serial.print ("You're connected to '"); 64 | Serial.print (WiFi.SSID()); 65 | Serial.println("'"); 66 | 67 | Arduino_ESP32_OTA ota; 68 | Arduino_ESP32_OTA::Error ota_err = Arduino_ESP32_OTA::Error::None; 69 | 70 | /* Configure custom Root CA */ 71 | ota.setCACert(root_ca); 72 | 73 | Serial.println("Initializing OTA storage"); 74 | if ((ota_err = ota.begin()) != Arduino_ESP32_OTA::Error::None) 75 | { 76 | Serial.print ("Arduino_ESP_OTA::begin() failed with error code "); 77 | Serial.println((int)ota_err); 78 | return; 79 | } 80 | 81 | 82 | Serial.println("Starting download to flash ..."); 83 | int const ota_download = ota.download(OTA_FILE_LOCATION); 84 | if (ota_download <= 0) 85 | { 86 | Serial.print ("Arduino_ESP_OTA::download failed with error code "); 87 | Serial.println(ota_download); 88 | return; 89 | } 90 | Serial.print (ota_download); 91 | Serial.println(" bytes stored."); 92 | 93 | 94 | Serial.println("Verify update integrity and apply ..."); 95 | if ((ota_err = ota.update()) != Arduino_ESP32_OTA::Error::None) 96 | { 97 | Serial.print ("ota.update() failed with error code "); 98 | Serial.println((int)ota_err); 99 | return; 100 | } 101 | 102 | Serial.println("Performing a reset after which the bootloader will start the new firmware."); 103 | #if defined(ARDUINO_NANO_ESP32) 104 | Serial.println("Hint: Arduino NANO ESP32 will blink Red Green and Blue."); 105 | #else 106 | Serial.println("Hint: LOLIN32 will blink Blue."); 107 | #endif 108 | delay(1000); /* Make sure the serial message gets out before the reset. */ 109 | ota.reset(); 110 | } 111 | 112 | void loop() 113 | { 114 | 115 | } 116 | -------------------------------------------------------------------------------- /src/decompress/utility.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2017 Arduino LLC. All right reserved. 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | See the GNU Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public 15 | License along with this library; if not, write to the Free Software 16 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 17 | */ 18 | 19 | /************************************************************************************** 20 | INCLUDE 21 | **************************************************************************************/ 22 | 23 | #include "utility.h" 24 | 25 | /************************************************************************************** 26 | CONST 27 | **************************************************************************************/ 28 | 29 | static const uint32_t crc_table[256] = 30 | { 31 | 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3, 32 | 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, 33 | 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 34 | 0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9, 0xfa0f3d63, 0x8d080df5, 35 | 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, 36 | 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 37 | 0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599, 0xb8bda50f, 38 | 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 39 | 0x76dc4190, 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433, 40 | 0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01, 41 | 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 42 | 0x65b0d9c6, 0x12b7e950, 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65, 43 | 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 44 | 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, 45 | 0x5005713c, 0x270241aa, 0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f, 46 | 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 47 | 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, 48 | 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 49 | 0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb, 0x196c3671, 0x6e6b06e7, 50 | 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, 51 | 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 52 | 0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef, 0x4669be79, 53 | 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 54 | 0xc5ba3bbe, 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d, 55 | 0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713, 56 | 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 57 | 0x86d3d2d4, 0xf1d4e242, 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777, 58 | 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 59 | 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, 60 | 0xaed16a4a, 0xd9d65adc, 0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9, 61 | 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693, 0x54de5729, 0x23d967bf, 62 | 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d 63 | }; 64 | 65 | /************************************************************************************** 66 | FUNCTIONS 67 | **************************************************************************************/ 68 | 69 | uint32_t crc_update(uint32_t crc, const void * data, size_t data_len) 70 | { 71 | const unsigned char *d = (const unsigned char *)data; 72 | unsigned int tbl_idx; 73 | 74 | while (data_len--) { 75 | tbl_idx = (crc ^ *d) & 0xff; 76 | crc = (crc_table[tbl_idx] ^ (crc >> 8)) & 0xffffffff; 77 | d++; 78 | } 79 | 80 | return crc & 0xffffffff; 81 | } 82 | -------------------------------------------------------------------------------- /examples/OTA_GitHub_Server/root_ca.h: -------------------------------------------------------------------------------- 1 | const char* root_ca = \ 2 | /*DigiCert TLS Hybrid ECC SHA384 2020 CA1*/ 3 | "-----BEGIN CERTIFICATE-----\n" \ 4 | "MIIEFzCCAv+gAwIBAgIQB/LzXIeod6967+lHmTUlvTANBgkqhkiG9w0BAQwFADBh\n" \ 5 | "MQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3\n" \ 6 | "d3cuZGlnaWNlcnQuY29tMSAwHgYDVQQDExdEaWdpQ2VydCBHbG9iYWwgUm9vdCBD\n" \ 7 | "QTAeFw0yMTA0MTQwMDAwMDBaFw0zMTA0MTMyMzU5NTlaMFYxCzAJBgNVBAYTAlVT\n" \ 8 | "MRUwEwYDVQQKEwxEaWdpQ2VydCBJbmMxMDAuBgNVBAMTJ0RpZ2lDZXJ0IFRMUyBI\n" \ 9 | "eWJyaWQgRUNDIFNIQTM4NCAyMDIwIENBMTB2MBAGByqGSM49AgEGBSuBBAAiA2IA\n" \ 10 | "BMEbxppbmNmkKaDp1AS12+umsmxVwP/tmMZJLwYnUcu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ncg+d0ohP/rEh\n" \ 25 | "xRqhqjn1VtvChMQ1H3Dau0bwhr9kAMQ+959GG50jBbl9s08PqUU643QwmA==\n" \ 26 | "-----END CERTIFICATE-----\n" \ 27 | /*DigiCert Global Root G2*/ 28 | "-----BEGIN CERTIFICATE-----\n" \ 29 | "MIIDjjCCAnagAwIBAgIQAzrx5qcRqaC7KGSxHQn65TANBgkqhkiG9w0BAQsFADBh\n" \ 30 | "MQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3\n" \ 31 | "d3cuZGlnaWNlcnQuY29tMSAwHgYDVQQDExdEaWdpQ2VydCBHbG9iYWwgUm9vdCBH\n" \ 32 | "MjAeFw0xMzA4MDExMjAwMDBaFw0zODAxMTUxMjAwMDBaMGExCzAJBgNVBAYTAlVT\n" \ 33 | "MRUwEwYDVQQKEwxEaWdpQ2VydCBJbmMxGTAXBgNVBAsTEHd3dy5kaWdpY2VydC5j\n" \ 34 | "b20xIDAeBgNVBAMTF0RpZ2lDZXJ0IEdsb2JhbCBSb290IEcyMIIBIjANBgkqhkiG\n" \ 35 | "9w0BAQEFAAOCAQ8AMIIBCgKCAQEAuzfNNNx7a8myaJCtSnX/RrohCgiN9RlUyfuI\n" \ 36 | "2/Ou8jqJkTx65qsGGmvPrC3oXgkkRLpimn7Wo6h+4FR1IAWsULecYxpsMNzaHxmx\n" \ 37 | "1x7e/dfgy5SDN67sH0NO3Xss0r0upS/kqbitOtSZpLYl6ZtrAGCSYP9PIUkY92eQ\n" \ 38 | "q2EGnI/yuum06ZIya7XzV+hdG82MHauVBJVJ8zUtluNJbd134/tJS7SsVQepj5Wz\n" \ 39 | "tCO7TG1F8PapspUwtP1MVYwnSlcUfIKdzXOS0xZKBgyMUNGPHgm+F6HmIcr9g+UQ\n" \ 40 | "vIOlCsRnKPZzFBQ9RnbDhxSJITRNrw9FDKZJobq7nMWxM4MphQIDAQABo0IwQDAP\n" \ 41 | "BgNVHRMBAf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s5eC91uWg0Kr+HWhMvAjvqFcO3aXbMM9yt1QP6FCvrzMXi3cEsaiVi6gL3z\n" \ 73 | "ax3pfs8LulicWdSQ0/1s/dCYbbdxglvPbQtaCdB73sRD2Cqk3p5BJl+7j5nL3a7h\n" \ 74 | "qG+fh/50tx8bIKuxT8b1Z11dmzzp/2n3YWzW2fP9NsarA4h20ksudYbj/NhVfSbC\n" \ 75 | "EXffPgK2fPOre3qGNm+499iTcc+G33Mw+nur7SpZyEKEOxEXGlLzyQ4UfaJbcme6\n" \ 76 | "ce1XR2bFuAJKZTRei9AqPCCcUZlM51Ke92sRKw2Sfh3oius2FkOH6ipjv3U/697E\n" \ 77 | "A7sKPPcw7+uvTPyLNhBzPvOk\n" \ 78 | "-----END CERTIFICATE-----\n"; 79 | -------------------------------------------------------------------------------- /.github/workflows/sync-labels.yml: -------------------------------------------------------------------------------- 1 | # Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/sync-labels.md 2 | name: Sync Labels 3 | 4 | # See: https://docs.github.com/en/actions/reference/events-that-trigger-workflows 5 | on: 6 | push: 7 | paths: 8 | - ".github/workflows/sync-labels.ya?ml" 9 | - ".github/label-configuration-files/*.ya?ml" 10 | pull_request: 11 | paths: 12 | - ".github/workflows/sync-labels.ya?ml" 13 | - ".github/label-configuration-files/*.ya?ml" 14 | schedule: 15 | # Run daily at 8 AM UTC to sync with changes to shared label configurations. 16 | - cron: "0 8 * * *" 17 | workflow_dispatch: 18 | repository_dispatch: 19 | 20 | env: 21 | CONFIGURATIONS_FOLDER: .github/label-configuration-files 22 | CONFIGURATIONS_ARTIFACT: label-configuration-files 23 | 24 | jobs: 25 | check: 26 | runs-on: ubuntu-latest 27 | 28 | steps: 29 | - name: Checkout repository 30 | uses: actions/checkout@v6 31 | 32 | - name: Download JSON schema for labels configuration file 33 | id: download-schema 34 | uses: carlosperate/download-file-action@v2 35 | with: 36 | file-url: https://raw.githubusercontent.com/arduino/tooling-project-assets/main/workflow-templates/assets/sync-labels/arduino-tooling-gh-label-configuration-schema.json 37 | location: ${{ runner.temp }}/label-configuration-schema 38 | 39 | - name: Install JSON schema validator 40 | run: | 41 | sudo npm install \ 42 | --global \ 43 | ajv-cli \ 44 | ajv-formats 45 | 46 | - name: Validate local labels configuration 47 | run: | 48 | # See: https://github.com/ajv-validator/ajv-cli#readme 49 | ajv validate \ 50 | --all-errors \ 51 | -c ajv-formats \ 52 | -s "${{ steps.download-schema.outputs.file-path }}" \ 53 | -d "${{ env.CONFIGURATIONS_FOLDER }}/*.{yml,yaml}" 54 | 55 | download: 56 | needs: check 57 | runs-on: ubuntu-latest 58 | 59 | strategy: 60 | matrix: 61 | filename: 62 | # Filenames of the shared configurations to apply to the repository in addition to the local configuration. 63 | # https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/sync-labels 64 | - universal.yml 65 | 66 | steps: 67 | - name: Download 68 | uses: carlosperate/download-file-action@v2 69 | with: 70 | file-url: https://raw.githubusercontent.com/arduino/tooling-project-assets/main/workflow-templates/assets/sync-labels/${{ matrix.filename }} 71 | 72 | - name: Pass configuration files to next job via workflow artifact 73 | uses: actions/upload-artifact@v6 74 | with: 75 | path: | 76 | *.yaml 77 | *.yml 78 | if-no-files-found: error 79 | name: ${{ env.CONFIGURATIONS_ARTIFACT }} 80 | 81 | sync: 82 | needs: download 83 | runs-on: ubuntu-latest 84 | 85 | steps: 86 | - name: Set environment variables 87 | run: | 88 | # See: https://docs.github.com/en/actions/reference/workflow-commands-for-github-actions#setting-an-environment-variable 89 | echo "MERGED_CONFIGURATION_PATH=${{ runner.temp }}/labels.yml" >> "$GITHUB_ENV" 90 | 91 | - name: Determine whether to dry run 92 | id: dry-run 93 | if: > 94 | github.event_name == 'pull_request' || 95 | ( 96 | ( 97 | github.event_name == 'push' || 98 | github.event_name == 'workflow_dispatch' 99 | ) && 100 | github.ref != format('refs/heads/{0}', github.event.repository.default_branch) 101 | ) 102 | run: | 103 | # Use of this flag in the github-label-sync command will cause it to only check the validity of the 104 | # configuration. 105 | echo "flag=--dry-run" >> $GITHUB_OUTPUT 106 | 107 | - name: Checkout repository 108 | uses: actions/checkout@v6 109 | 110 | - name: Download configuration files artifact 111 | uses: actions/download-artifact@v7 112 | with: 113 | name: ${{ env.CONFIGURATIONS_ARTIFACT }} 114 | path: ${{ env.CONFIGURATIONS_FOLDER }} 115 | 116 | - name: Remove unneeded artifact 117 | uses: geekyeggo/delete-artifact@v5 118 | with: 119 | name: ${{ env.CONFIGURATIONS_ARTIFACT }} 120 | 121 | - name: Merge label configuration files 122 | run: | 123 | # Merge all configuration files 124 | shopt -s extglob 125 | cat "${{ env.CONFIGURATIONS_FOLDER }}"/*.@(yml|yaml) > "${{ env.MERGED_CONFIGURATION_PATH }}" 126 | 127 | - name: Install github-label-sync 128 | run: sudo npm install --global github-label-sync 129 | 130 | - name: Sync labels 131 | env: 132 | GITHUB_ACCESS_TOKEN: ${{ secrets.GITHUB_TOKEN }} 133 | run: | 134 | # See: https://github.com/Financial-Times/github-label-sync 135 | github-label-sync \ 136 | --labels "${{ env.MERGED_CONFIGURATION_PATH }}" \ 137 | ${{ steps.dry-run.outputs.flag }} \ 138 | ${{ github.repository }} 139 | -------------------------------------------------------------------------------- /src/tls/amazon_root_ca.h: -------------------------------------------------------------------------------- 1 | /* Certificates from https://www.amazontrust.com/repository/ */ 2 | 3 | #ifndef ESP32_OTA_AMAZON_ROOT_CA_H_ 4 | #define ESP32_OTA_AMAZON_ROOT_CA_H_ 5 | 6 | const char* amazon_root_ca = \ 7 | /* Amazon Root CA 1 */ 8 | "-----BEGIN CERTIFICATE-----\n" \ 9 | "MIIDQTCCAimgAwIBAgITBmyfz5m/jAo54vB4ikPmljZbyjANBgkqhkiG9w0BAQsFADA5MQswCQYD\n" \ 10 | "VQQGEwJVUzEPMA0GA1UEChMGQW1hem9uMRkwFwYDVQQDExBBbWF6b24gUm9vdCBDQSAxMB4XDTE1\n" \ 11 | "MDUyNjAwMDAwMFoXDTM4MDExNzAwMDAwMFow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A 3 */ 53 | "-----BEGIN CERTIFICATE-----\n" \ 54 | "MIIBtjCCAVugAwIBAgITBmyf1XSXNmY/Owua2eiedgPySjAKBggqhkjOPQQDAjA5MQswCQYDVQQG\n" \ 55 | "EwJVUzEPMA0GA1UEChMGQW1hem9uMRkwFwYDVQQDExBBbWF6b24gUm9vdCBDQSAzMB4XDTE1MDUy\n" \ 56 | "NjAwMDAwMFoXDTQwMDUyNjAwMDAwMFowOTELMAkGA1UEBhMCVVMxDzANBgNVBAoTBkFtYXpvbjEZ\n" \ 57 | "MBcGA1UEAxMQQW1hem9uIFJvb3QgQ0EgMzBZMBMGByqGSM49AgEGCCqGSM49AwEHA0IABCmXp8ZB\n" \ 58 | "f8ANm+gBG1bG8lKlui2yEujSLtf6ycXYqm0fc4E7O5hrOXwzpcVOho6AF2hiRVd9RFgdszflZwjr\n" \ 59 | "Zt6jQjBAMA8GA1UdEwEB/wQFMAMBAf8wDgYDVR0PAQH/BAQDAgGGMB0GA1UdDgQWBBSrttvXBp43\n" \ 60 | "rDCGB5Fwx5zEGbF4wDAKBggqhkjOPQQDAgNJADBGAiEA4IWSoxe3jfkrBqWTrBqYaGFy+uGh0Psc\n" \ 61 | "eGCmQ5nFuMQCIQCcAu/xlJyzlvnrxir4tiz+OpAUFteMYyRIHN8wfdVoOw==\n" \ 62 | "-----END CERTIFICATE-----\n" \ 63 | /* Amazon Root CA 4 */ 64 | "-----BEGIN CERTIFICATE-----\n" \ 65 | "MIIB8jCCAXigAwIBAgITBmyf18G7EEwpQ+Vxe3ssyBrBDjAKBggqhkjOPQQDAzA5MQswCQYDVQQG\n" \ 66 | "EwJVUzEPMA0GA1UEChMGQW1hem9uMRkwFwYDVQQDExBBbWF6b24gUm9vdCBDQSA0MB4XDTE1MDUy\n" \ 67 | "NjAwMDAwMFoXDTQwMDUyNjAwMDAwMFowOTELMAkGA1UEBhMCVVMxDzANBgNVBAoTBkFtYXpvbjEZ\n" \ 68 | "MBcGA1UEAxMQQW1hem9uIFJvb3QgQ0EgNDB2MBAGByqGSM49AgEGBSuBBAAiA2IABNKrijdPo1MN\n" \ 69 | "/sGKe0uoe0ZLY7Bi9i0b2whxIdIA6GO9mif78DluXeo9pcmBqqNbIJhFXRbb/egQbeOc4OO9X4Ri\n" \ 70 | "83BkM6DLJC9wuoihKqB1+IGuYgbEgds5bimwHvouXKNCMEAwDwYDVR0TAQH/BAUwAwEB/zAOBgNV\n" \ 71 | "HQ8BAf8EBAMCAYYwHQYDVR0OBBYEFNPsxzplbszh2naaVvuc84ZtV+WBMAoGCCqGSM49BAMDA2gA\n" \ 72 | "MGUCMDqLIfG9fhGt0O9Yli/W651+kI0rz2ZVwyzjKKlwCkcO8DdZEv8tmZQoTipPNU0zWgIxAOp1\n" \ 73 | "AE47xDqUEpHJWEadIRNyp4iciuRMStuW1KyLa2tJElMzrdfkviT8tQp21KW8EA==\n" \ 74 | "-----END CERTIFICATE-----\n"; 75 | 76 | #endif /* ESP32_OTA_AMAZON_ROOT_CA_H_ */ 77 | -------------------------------------------------------------------------------- /src/decompress/lzss.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of the ArduinoIoTCloud library. 3 | 4 | Copyright (c) 2024 Arduino SA 5 | 6 | This Source Code Form is subject to the terms of the Mozilla Public 7 | License, v. 2.0. If a copy of the MPL was not distributed with this 8 | file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | 10 | This implementation took inspiration from https://okumuralab.org/~okumura/compression/lzss.c source code 11 | */ 12 | 13 | /************************************************************************************** 14 | INCLUDE 15 | **************************************************************************************/ 16 | #include "lzss.h" 17 | 18 | #include 19 | 20 | /************************************************************************************** 21 | LZSS DECODER CLASS IMPLEMENTATION 22 | **************************************************************************************/ 23 | 24 | // get the number of bits the algorithm will try to get given the state 25 | uint8_t LZSSDecoder::bits_required(LZSSDecoder::FSM_STATES s) { 26 | switch(s) { 27 | case FSM_0: 28 | return 1; 29 | case FSM_1: 30 | return 8; 31 | case FSM_2: 32 | return EI; 33 | case FSM_3: 34 | return EJ; 35 | default: 36 | return 0; 37 | } 38 | } 39 | 40 | LZSSDecoder::LZSSDecoder(std::function getc_cbk, std::function putc_cbk) 41 | : available(0), state(FSM_0), put_char_cbk(putc_cbk), get_char_cbk(getc_cbk) { 42 | for (int i = 0; i < N - F; i++) buffer[i] = ' '; 43 | r = N - F; 44 | } 45 | 46 | 47 | LZSSDecoder::LZSSDecoder(std::function putc_cbk) 48 | : available(0), state(FSM_0), put_char_cbk(putc_cbk), get_char_cbk(nullptr) { 49 | for (int i = 0; i < N - F; i++) buffer[i] = ' '; 50 | r = N - F; 51 | } 52 | 53 | LZSSDecoder::status LZSSDecoder::handle_state() { 54 | LZSSDecoder::status res = IN_PROGRESS; 55 | 56 | int c = getbit(bits_required(this->state)); 57 | 58 | if(c == LZSS_BUFFER_EMPTY) { 59 | res = NOT_COMPLETED; 60 | } else if (c == LZSS_EOF) { 61 | res = DONE; 62 | this->state = FSM_EOF; 63 | } else { 64 | switch(this->state) { 65 | case FSM_0: 66 | if(c) { 67 | this->state = FSM_1; 68 | } else { 69 | this->state = FSM_2; 70 | } 71 | break; 72 | case FSM_1: 73 | putc(c); 74 | buffer[r++] = c; 75 | r &= (N - 1); // equivalent to r = r % N when N is a power of 2 76 | 77 | this->state = FSM_0; 78 | break; 79 | case FSM_2: 80 | this->i = c; 81 | this->state = FSM_3; 82 | break; 83 | case FSM_3: { 84 | int j = c; 85 | 86 | // This is where the actual decompression takes place: we look into the local buffer for reuse 87 | // of byte chunks. This can be improved by means of memcpy and by changing the putc function 88 | // into a put_buf function in order to avoid buffering on the other end. 89 | // TODO improve this section of code 90 | for (int k = 0; k <= j + 1; k++) { 91 | c = buffer[(this->i + k) & (N - 1)]; // equivalent to buffer[(i+k) % N] when N is a power of 2 92 | putc(c); 93 | buffer[r++] = c; 94 | r &= (N - 1); // equivalent to r = r % N 95 | } 96 | this->state = FSM_0; 97 | 98 | break; 99 | } 100 | case FSM_EOF: 101 | break; 102 | } 103 | } 104 | 105 | return res; 106 | } 107 | 108 | LZSSDecoder::status LZSSDecoder::decompress(uint8_t* const buffer, uint32_t size) { 109 | if(!get_char_cbk) { 110 | this->in_buffer = buffer; 111 | this->available += size; 112 | } 113 | 114 | status res = IN_PROGRESS; 115 | 116 | while((res = handle_state()) == IN_PROGRESS); 117 | 118 | this->in_buffer = nullptr; 119 | 120 | return res; 121 | } 122 | 123 | int LZSSDecoder::getbit(uint8_t n) { // get n bits from buffer 124 | int x=0, c; 125 | 126 | // if the local bit buffer doesn't have enough bit get them 127 | while(buf_size < n) { 128 | switch(c=getc()) { 129 | case LZSS_EOF: 130 | case LZSS_BUFFER_EMPTY: 131 | return c; 132 | } 133 | buf <<= 8; 134 | 135 | buf |= (uint8_t)c; 136 | buf_size += sizeof(uint8_t)*8; 137 | } 138 | 139 | // the result is the content of the buffer starting from msb to n successive bits 140 | x = buf >> (buf_size-n); 141 | 142 | // remove from the buffer the read bits with a mask 143 | buf &= (1<<(buf_size-n))-1; 144 | 145 | buf_size-=n; 146 | 147 | return x; 148 | } 149 | 150 | int LZSSDecoder::getc() { 151 | int c; 152 | 153 | if(get_char_cbk) { 154 | c = get_char_cbk(); 155 | } else if(in_buffer == nullptr || available == 0) { 156 | c = LZSS_BUFFER_EMPTY; 157 | } else { 158 | c = *in_buffer; 159 | in_buffer++; 160 | available--; 161 | } 162 | return c; 163 | } 164 | -------------------------------------------------------------------------------- /examples/OTA_Arduino_Server/root_ca.h: -------------------------------------------------------------------------------- 1 | const char* root_ca = \ 2 | /* Google Trust Services LLC */ 3 | "-----BEGIN CERTIFICATE-----\n" \ 4 | "MIIFjDCCA3SgAwIBAgINAgO8UKMnU/CRgCLt8TANBgkqhkiG9w0BAQsFADBHMQsw\n" \ 5 | "CQYDVQQGEwJVUzEiMCAGA1UEChMZR29vZ2xlIFRydXN0IFNlcnZpY2VzIExMQzEU\n" \ 6 | "MBIGA1UEAxMLR1RTIFJvb3QgUjEwHhcNMjAwODEzMDAwMDQyWhcNMjcwOTMwM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AYKKwYBBAHWeQIFAzAqMCgGCCsGAQUFBwIBFhxodHRwczovL3Br\n" \ 22 | "aS5nb29nL3JlcG9zaXRvcnkvMAgGBmeBDAECATANBgkqhkiG9w0BAQsFAAOCAgEA\n" \ 23 | "bGMn7iPf5VJoTYFmkYXffWXlWzcxCCayB12avrHKAbmtv5139lEd15jFC0mhe6HX\n" \ 24 | "02jlRA+LujbdQoJ30o3d9T/768gHmJPuWtC1Pd5LHC2MTex+jHv+TkD98LSzWQIQ\n" \ 25 | "UVzjwCv9twZIUX4JXj8P3Kf+l+d5xQ5EiXjFaVkpoJo6SDYpppSTVS24R7XplrWf\n" \ 26 | "B82mqz4yisCGg8XBQcifLzWODcAHeuGsyWW1y4qn3XHYYWU5hKwyPvd6NvFWn1ep\n" \ 27 | "QW1akKfbOup1gAxjC2l0bwdMFfM3KKUZpG719iDNY7J+xCsJdYna0Twuck82GqGe\n" \ 28 | "RNDNm6YjCD+XoaeeWqX3CZStXXZdKFbRGmZRUQd73j2wyO8weiQtvrizhvZL9/C1\n" \ 29 | "T//Oxvn2PyonCA8JPiNax+NCLXo25D2YlmA5mOrR22Mq63gJsU4hs463zj6S8ZVc\n" \ 30 | "pDnQwCvIUxX10i+CzQZ0Z5mQdzcKly3FHB700FvpFePqAgnIE9cTcGW/+4ibWiW+\n" \ 31 | "dwnhp2pOEXW5Hk3xABtqZnmOw27YbaIiom0F+yzy8VDloNHYnzV9/HCrWSoC8b6w\n" \ 32 | "0/H4zRK5aiWQW+OFIOb12stAHBk0IANhd7p/SA9JCynr52Fkx2PRR+sc4e6URu85\n" \ 33 | "c8zuTyuN3PtYp7NlIJmVuftVb9eWbpQ99HqSjmMd320=\n" \ 34 | "-----END CERTIFICATE-----\n" \ 35 | /* GTS Root R4 */ 36 | "-----BEGIN CERTIFICATE-----\n" \ 37 | "MIICCTCCAY6gAwIBAgINAgPlwGjvYxqccpBQUjAKBggqhkjOPQQDAzBHMQswCQYD\n" \ 38 | "VQQGEwJVUzEiMCA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XyolQL30EzTSo//z9SzBgBggrBgEFBQcBAQRUMFIw\n" \ 70 | "JQYIKwYBBQUHMAGGGWh0dHA6Ly9vY3NwLnBraS5nb29nL2dzcjEwKQYIKwYBBQUH\n" \ 71 | "MAKGHWh0dHA6Ly9wa2kuZ29vZy9nc3IxL2dzcjEuY3J0MDIGA1UdHwQrMCkwJ6Al\n" \ 72 | "oCOGIWh0dHA6Ly9jcmwucGtpLmdvb2cvZ3NyMS9nc3IxLmNybDA7BgNVHSAENDAy\n" \ 73 | "MAgGBmeBDAECATAIBgZngQwBAgIwDQYLKwYBBAHWeQIFAwIwDQYLKwYBBAHWeQIF\n" \ 74 | "AwMwDQYJKoZIhvcNAQELBQADggEBADSkHrEoo9C0dhemMXoh6dFSPsjbdBZBiLg9\n" \ 75 | "NR3t5P+T4Vxfq7vqfM/b5A3Ri1fyJm9bvhdGaJQ3b2t6yMAYN/olUazsaL+yyEn9\n" \ 76 | "WprKASOshIArAoyZl+tJaox118fessmXn1hIVw41oeQa1v1vg4Fv74zPl6/AhSrw\n" \ 77 | "9U5pCZEt4Wi4wStz6dTZ/CLANx8LZh1J7QJVj2fhMtfTJr9w4z30Z209fOU0iOMy\n" \ 78 | "+qduBmpvvYuR7hZL6Dupszfnw0Skfths18dG9ZKb59UhvmaSGZRVbNQpsg3BZlvi\n" \ 79 | "d0lIKO2d1xozclOzgjXPYovJJIultzkMu34qQb9Sz/yilrbCgj8=\n" \ 80 | "-----END CERTIFICATE-----\n"; 81 | -------------------------------------------------------------------------------- /src/Arduino_ESP32_OTA.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of Arduino_ESP32_OTA. 3 | 4 | Copyright 2020 ARDUINO SA (http://www.arduino.cc/) 5 | 6 | This software is released under the GNU General Public License version 3, 7 | which covers the main part of arduino-cli. 8 | The terms of this license can be found at: 9 | https://www.gnu.org/licenses/gpl-3.0.en.html 10 | 11 | You can be released from the requirements of the above licenses by purchasing 12 | a commercial license. Buying such a license is mandatory if you want to modify or 13 | otherwise use the software for commercial activities involving the Arduino 14 | software without disclosing the source code of your own applications. To purchase 15 | a commercial license, send an email to license@arduino.cc. 16 | */ 17 | 18 | #ifndef ARDUINO_ESP32_OTA_H_ 19 | #define ARDUINO_ESP32_OTA_H_ 20 | 21 | /****************************************************************************** 22 | * INCLUDE 23 | ******************************************************************************/ 24 | 25 | #include 26 | #include 27 | #include 28 | #include "decompress/utility.h" 29 | #include "decompress/lzss.h" 30 | #include 31 | #include 32 | #include 33 | 34 | /****************************************************************************** 35 | DEFINES 36 | ******************************************************************************/ 37 | #if defined (ARDUINO_NANO_ESP32) 38 | #define ARDUINO_ESP32_OTA_MAGIC 0x23410070 39 | #else 40 | #define ARDUINO_ESP32_OTA_MAGIC 0x45535033 41 | #endif 42 | /****************************************************************************** 43 | CONSTANTS 44 | ******************************************************************************/ 45 | 46 | static uint32_t const ARDUINO_ESP32_OTA_HTTP_HEADER_RECEIVE_TIMEOUT_ms = 10000; 47 | static uint32_t const ARDUINO_ESP32_OTA_BINARY_HEADER_RECEIVE_TIMEOUT_ms = 10000; 48 | static uint32_t const ARDUINO_ESP32_OTA_BINARY_BYTE_RECEIVE_TIMEOUT_ms = 2000; 49 | 50 | /****************************************************************************** 51 | * CLASS DECLARATION 52 | ******************************************************************************/ 53 | 54 | class Arduino_ESP32_OTA 55 | { 56 | 57 | public: 58 | 59 | enum class Error : int 60 | { 61 | None = 0, 62 | NoOtaStorage = -2, 63 | OtaStorageInit = -3, 64 | OtaStorageEnd = -4, 65 | UrlParseError = -5, 66 | ServerConnectError = -6, 67 | HttpHeaderError = -7, 68 | ParseHttpHeader = -8, 69 | OtaHeaderLength = -9, 70 | OtaHeaderCrc = -10, 71 | OtaHeaderMagicNumber = -11, 72 | OtaDownload = -12, 73 | OtaHeaderTimeout = -13, 74 | HttpResponse = -14 75 | }; 76 | 77 | enum OTADownloadState: uint8_t { 78 | OtaDownloadHeader, 79 | OtaDownloadFile, 80 | OtaDownloadCompleted, 81 | OtaDownloadMagicNumberMismatch, 82 | OtaDownloadError 83 | }; 84 | 85 | Arduino_ESP32_OTA(); 86 | virtual ~Arduino_ESP32_OTA(); 87 | 88 | Arduino_ESP32_OTA::Error begin(uint32_t magic = ARDUINO_ESP32_OTA_MAGIC); 89 | void setMagic(uint32_t magic); 90 | void setCACert(const char *rootCA); 91 | void setCACertBundle(const uint8_t * bundle) __attribute__((deprecated)); 92 | void setCACertBundle (const uint8_t * bundle, size_t size); 93 | 94 | // blocking version for the download 95 | // returns the size of the downloaded binary 96 | int download(const char * ota_url); 97 | 98 | // start a download in a non blocking fashion 99 | // call downloadPoll, until it returns OtaDownloadCompleted 100 | // returns the value in content-length http header 101 | int startDownload(const char * ota_url); 102 | 103 | // This function is used to make the download progress. 104 | // it returns 0, if the download is in progress 105 | // it returns 1, if the download is completed 106 | // it returns <0 if an error occurred, following Error enum values 107 | virtual int downloadPoll(); 108 | 109 | // this function is used to get the progress of the download 110 | // it returns a positive value when the download is progressing correctly 111 | // it returns a negative value on error following Error enum values 112 | int downloadProgress(); 113 | 114 | // this function is used to get the size of the download 115 | // 0 if no download is in progress 116 | size_t downloadSize(); 117 | 118 | virtual void write_byte_to_flash(uint8_t data); 119 | Arduino_ESP32_OTA::Error verify(); 120 | Arduino_ESP32_OTA::Error update(); 121 | void reset(); 122 | static bool isCapable(); 123 | 124 | protected: 125 | struct Context { 126 | Context( 127 | const char* url, 128 | std::function putc); 129 | 130 | ~Context(); 131 | 132 | char* url; 133 | ParsedUrl parsed_url; 134 | OtaHeader header; 135 | OTADownloadState downloadState; 136 | uint32_t calculatedCrc32; 137 | uint32_t headerCopiedBytes; 138 | uint32_t downloadedSize; 139 | uint32_t writtenBytes; 140 | 141 | // If an error occurred during download it is reported in this field 142 | Error error; 143 | 144 | // LZSS decoder 145 | LZSSDecoder decoder; 146 | 147 | const size_t buf_len = 64; 148 | uint8_t buffer[64]; 149 | } *_context; 150 | 151 | private: 152 | Client * _client; 153 | HttpClient* _http_client; 154 | const char * _ca_cert; 155 | const uint8_t * _ca_cert_bundle; 156 | size_t _ca_cert_bundle_size; 157 | uint32_t _magic; 158 | 159 | void clean(); 160 | }; 161 | 162 | #endif /* ARDUINO_ESP32_OTA_H_ */ 163 | -------------------------------------------------------------------------------- /src/Arduino_ESP32_OTA.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of Arduino_ESP32_OTA. 3 | 4 | Copyright 2022 ARDUINO SA (http://www.arduino.cc/) 5 | 6 | This software is released under the GNU General Public License version 3, 7 | which covers the main part of arduino-cli. 8 | The terms of this license can be found at: 9 | https://www.gnu.org/licenses/gpl-3.0.en.html 10 | 11 | You can be released from the requirements of the above licenses by purchasing 12 | a commercial license. Buying such a license is mandatory if you want to modify or 13 | otherwise use the software for commercial activities involving the Arduino 14 | software without disclosing the source code of your own applications. To purchase 15 | a commercial license, send an email to license@arduino.cc. 16 | */ 17 | 18 | /****************************************************************************** 19 | INCLUDE 20 | ******************************************************************************/ 21 | 22 | #include 23 | #include "Arduino_ESP32_OTA.h" 24 | #include "tls/amazon_root_ca.h" 25 | #include "esp_ota_ops.h" 26 | 27 | /****************************************************************************** 28 | CTOR/DTOR 29 | ******************************************************************************/ 30 | 31 | Arduino_ESP32_OTA::Arduino_ESP32_OTA() 32 | : _context(nullptr) 33 | , _client(nullptr) 34 | , _http_client(nullptr) 35 | ,_ca_cert{amazon_root_ca} 36 | ,_ca_cert_bundle{nullptr} 37 | ,_ca_cert_bundle_size(0) 38 | ,_magic(0) 39 | { 40 | 41 | } 42 | 43 | Arduino_ESP32_OTA::~Arduino_ESP32_OTA(){ 44 | clean(); 45 | } 46 | 47 | /****************************************************************************** 48 | PUBLIC MEMBER FUNCTIONS 49 | ******************************************************************************/ 50 | 51 | Arduino_ESP32_OTA::Error Arduino_ESP32_OTA::begin(uint32_t magic) 52 | { 53 | /* ... configure board Magic number */ 54 | setMagic(magic); 55 | 56 | if(!isCapable()) { 57 | DEBUG_ERROR("%s: board is not capable to perform OTA", __FUNCTION__); 58 | return Error::NoOtaStorage; 59 | } 60 | 61 | if(Update.isRunning()) { 62 | Update.abort(); 63 | DEBUG_DEBUG("%s: Aborting running update", __FUNCTION__); 64 | } 65 | 66 | if(!Update.begin(UPDATE_SIZE_UNKNOWN)) { 67 | DEBUG_ERROR("%s: failed to initialize flash update", __FUNCTION__); 68 | return Error::OtaStorageInit; 69 | } 70 | return Error::None; 71 | } 72 | 73 | void Arduino_ESP32_OTA::setCACert (const char *rootCA) 74 | { 75 | if(rootCA != nullptr) { 76 | _ca_cert = rootCA; 77 | } 78 | } 79 | 80 | void Arduino_ESP32_OTA::setCACertBundle (const uint8_t * bundle) 81 | { 82 | if(bundle != nullptr) { 83 | _ca_cert_bundle = bundle; 84 | } 85 | } 86 | 87 | void Arduino_ESP32_OTA::setCACertBundle (const uint8_t * bundle, size_t size) 88 | { 89 | if(bundle != nullptr && size != 0) { 90 | _ca_cert_bundle = bundle; 91 | _ca_cert_bundle_size = size; 92 | } 93 | } 94 | 95 | void Arduino_ESP32_OTA::setMagic(uint32_t magic) 96 | { 97 | _magic = magic; 98 | } 99 | 100 | void Arduino_ESP32_OTA::write_byte_to_flash(uint8_t data) 101 | { 102 | Update.write(&data, 1); 103 | } 104 | 105 | int Arduino_ESP32_OTA::startDownload(const char * ota_url) 106 | { 107 | assert(_context == nullptr); 108 | assert(_client == nullptr); 109 | assert(_http_client == nullptr); 110 | 111 | Error err = Error::None; 112 | int statusCode; 113 | int res; 114 | 115 | _context = new Context(ota_url, [this](uint8_t data){ 116 | _context->writtenBytes++; 117 | write_byte_to_flash(data); 118 | }); 119 | 120 | if(strcmp(_context->parsed_url.schema(), "http") == 0) { 121 | _client = new WiFiClient(); 122 | } else if(strcmp(_context->parsed_url.schema(), "https") == 0) { 123 | _client = new WiFiClientSecure(); 124 | if (_ca_cert != nullptr) { 125 | static_cast(_client)->setCACert(_ca_cert); 126 | } 127 | #if (ESP_ARDUINO_VERSION < ESP_ARDUINO_VERSION_VAL(3, 0, 4)) 128 | else if (_ca_cert_bundle != nullptr) { 129 | static_cast(_client)->setCACertBundle(_ca_cert_bundle); 130 | } 131 | #else 132 | else if (_ca_cert_bundle != nullptr && _ca_cert_bundle_size != 0) { 133 | static_cast(_client)->setCACertBundle(_ca_cert_bundle, _ca_cert_bundle_size); 134 | } 135 | #endif 136 | else { 137 | DEBUG_VERBOSE("%s: CA not configured for download client"); 138 | } 139 | } else { 140 | err = Error::UrlParseError; 141 | goto exit; 142 | } 143 | 144 | _http_client = new HttpClient(*_client, _context->parsed_url.host(), _context->parsed_url.port()); 145 | 146 | res= _http_client->get(_context->parsed_url.path()); 147 | 148 | if(res == HTTP_ERROR_CONNECTION_FAILED) { 149 | DEBUG_VERBOSE("OTA ERROR: http client error connecting to server \"%s:%d\"", 150 | _context->parsed_url.host(), _context->parsed_url.port()); 151 | err = Error::ServerConnectError; 152 | goto exit; 153 | } else if(res == HTTP_ERROR_TIMED_OUT) { 154 | DEBUG_VERBOSE("OTA ERROR: http client timeout \"%s\"", _context->url); 155 | err = Error::OtaHeaderTimeout; 156 | goto exit; 157 | } else if(res != HTTP_SUCCESS) { 158 | DEBUG_VERBOSE("OTA ERROR: http client returned %d on get \"%s\"", res, _context->url); 159 | err = Error::OtaDownload; 160 | goto exit; 161 | } 162 | 163 | statusCode = _http_client->responseStatusCode(); 164 | 165 | if(statusCode != 200) { 166 | DEBUG_VERBOSE("OTA ERROR: get response on \"%s\" returned status %d", _context->url, statusCode); 167 | err = Error::HttpResponse; 168 | goto exit; 169 | } 170 | 171 | // The following call is required to save the header value , keep it 172 | if(_http_client->contentLength() == HttpClient::kNoContentLengthHeader) { 173 | DEBUG_VERBOSE("OTA ERROR: the response header doesn't contain \"ContentLength\" field"); 174 | err = Error::HttpHeaderError; 175 | goto exit; 176 | } 177 | 178 | exit: 179 | if(err != Error::None) { 180 | clean(); 181 | return static_cast(err); 182 | } else { 183 | return _http_client->contentLength(); 184 | } 185 | } 186 | 187 | int Arduino_ESP32_OTA::downloadPoll() 188 | { 189 | int http_res = static_cast(Error::None);; 190 | int res = 0; 191 | 192 | if(_http_client->available() == 0) { 193 | goto exit; 194 | } 195 | 196 | http_res = _http_client->read(_context->buffer, _context->buf_len); 197 | 198 | if(http_res < 0) { 199 | DEBUG_VERBOSE("OTA ERROR: Download read error %d", http_res); 200 | res = static_cast(Error::OtaDownload); 201 | goto exit; 202 | } 203 | 204 | for(uint8_t* cursor=(uint8_t*)_context->buffer; cursor<_context->buffer+http_res; ) { 205 | switch(_context->downloadState) { 206 | case OtaDownloadHeader: { 207 | uint32_t copied = http_res < sizeof(_context->header.buf) ? http_res : sizeof(_context->header.buf); 208 | memcpy(_context->header.buf+_context->headerCopiedBytes, _context->buffer, copied); 209 | cursor += copied; 210 | _context->headerCopiedBytes += copied; 211 | 212 | // when finished go to next state 213 | if(sizeof(_context->header.buf) == _context->headerCopiedBytes) { 214 | _context->downloadState = OtaDownloadFile; 215 | 216 | _context->calculatedCrc32 = crc_update( 217 | _context->calculatedCrc32, 218 | &(_context->header.header.magic_number), 219 | sizeof(_context->header) - offsetof(OtaHeader, header.magic_number) 220 | ); 221 | 222 | if(_context->header.header.magic_number != _magic) { 223 | _context->downloadState = OtaDownloadMagicNumberMismatch; 224 | res = static_cast(Error::OtaHeaderMagicNumber); 225 | 226 | goto exit; 227 | } 228 | } 229 | 230 | break; 231 | } 232 | case OtaDownloadFile: 233 | _context->decoder.decompress(cursor, http_res - (cursor-_context->buffer)); // TODO verify return value 234 | 235 | _context->calculatedCrc32 = crc_update( 236 | _context->calculatedCrc32, 237 | cursor, 238 | http_res - (cursor-_context->buffer) 239 | ); 240 | 241 | cursor += http_res - (cursor-_context->buffer); 242 | _context->downloadedSize += (cursor-_context->buffer); 243 | 244 | // TODO there should be no more bytes available when the download is completed 245 | if(_context->downloadedSize == _http_client->contentLength()) { 246 | _context->downloadState = OtaDownloadCompleted; 247 | res = 1; 248 | } 249 | 250 | if(_context->downloadedSize > _http_client->contentLength()) { 251 | _context->downloadState = OtaDownloadError; 252 | res = static_cast(Error::OtaDownload); 253 | } 254 | // TODO fail if we exceed a timeout? and available is 0 (client is broken) 255 | break; 256 | case OtaDownloadCompleted: 257 | res = 1; 258 | goto exit; 259 | default: 260 | _context->downloadState = OtaDownloadError; 261 | res = static_cast(Error::OtaDownload); 262 | goto exit; 263 | } 264 | } 265 | 266 | exit: 267 | if(_context->downloadState == OtaDownloadError || 268 | _context->downloadState == OtaDownloadMagicNumberMismatch) { 269 | clean(); // need to clean everything because the download failed 270 | } else if(_context->downloadState == OtaDownloadCompleted) { 271 | // only need to delete clients and not the context, since it will be needed 272 | if(_client != nullptr) { 273 | delete _client; 274 | _client = nullptr; 275 | } 276 | 277 | if(_http_client != nullptr) { 278 | delete _http_client; 279 | _http_client = nullptr; 280 | } 281 | } 282 | 283 | return res; 284 | } 285 | 286 | int Arduino_ESP32_OTA::downloadProgress() 287 | { 288 | if(_context->error != Error::None) { 289 | return static_cast(_context->error); 290 | } else { 291 | return _context->downloadedSize; 292 | } 293 | } 294 | 295 | size_t Arduino_ESP32_OTA::downloadSize() 296 | { 297 | return _http_client!=nullptr ? _http_client->contentLength() : 0; 298 | } 299 | 300 | int Arduino_ESP32_OTA::download(const char * ota_url) 301 | { 302 | int err = startDownload(ota_url); 303 | 304 | if(err < 0) { 305 | return err; 306 | } 307 | 308 | int res = 0; 309 | while((res = downloadPoll()) <= 0); 310 | 311 | return res == 1? _context->writtenBytes : res; 312 | } 313 | 314 | void Arduino_ESP32_OTA::clean() 315 | { 316 | if(_client != nullptr) { 317 | delete _client; 318 | _client = nullptr; 319 | } 320 | 321 | if(_http_client != nullptr) { 322 | delete _http_client; 323 | _http_client = nullptr; 324 | } 325 | 326 | if(_context != nullptr) { 327 | delete _context; 328 | _context = nullptr; 329 | } 330 | } 331 | 332 | Arduino_ESP32_OTA::Error Arduino_ESP32_OTA::verify() 333 | { 334 | assert(_context != nullptr); 335 | 336 | /* ... then finalize ... */ 337 | _context->calculatedCrc32 ^= 0xFFFFFFFF; 338 | 339 | /* Verify the crc */ 340 | if(_context->header.header.crc32 != _context->calculatedCrc32) { 341 | DEBUG_ERROR("%s: CRC32 mismatch", __FUNCTION__); 342 | return Error::OtaHeaderCrc; 343 | } 344 | 345 | clean(); 346 | 347 | return Error::None; 348 | } 349 | 350 | Arduino_ESP32_OTA::Error Arduino_ESP32_OTA::update() 351 | { 352 | Arduino_ESP32_OTA::Error res = Error::None; 353 | if(_context != nullptr && (res = verify()) != Error::None) { 354 | return res; 355 | } 356 | 357 | if (!Update.end(true)) { 358 | DEBUG_ERROR("%s: Failure to apply OTA update", __FUNCTION__); 359 | return Error::OtaStorageEnd; 360 | } 361 | 362 | return res; 363 | } 364 | 365 | void Arduino_ESP32_OTA::reset() 366 | { 367 | ESP.restart(); 368 | } 369 | 370 | bool Arduino_ESP32_OTA::isCapable() 371 | { 372 | const esp_partition_t * ota_0 = esp_partition_find_first(ESP_PARTITION_TYPE_APP, ESP_PARTITION_SUBTYPE_APP_OTA_0, NULL); 373 | const esp_partition_t * ota_1 = esp_partition_find_first(ESP_PARTITION_TYPE_APP, ESP_PARTITION_SUBTYPE_APP_OTA_1, NULL); 374 | return ((ota_0 != nullptr) && (ota_1 != nullptr)); 375 | } 376 | 377 | /****************************************************************************** 378 | PROTECTED MEMBER FUNCTIONS 379 | ******************************************************************************/ 380 | 381 | Arduino_ESP32_OTA::Context::Context( 382 | const char* url, std::function putc) 383 | : url((char*)malloc(strlen(url)+1)) 384 | , parsed_url(url) 385 | , downloadState(OtaDownloadHeader) 386 | , calculatedCrc32(0xFFFFFFFF) 387 | , headerCopiedBytes(0) 388 | , downloadedSize(0) 389 | , writtenBytes(0) 390 | , error(Error::None) 391 | , decoder(putc) { 392 | strcpy(this->url, url); 393 | } 394 | 395 | Arduino_ESP32_OTA::Context::~Context(){ 396 | free(url); 397 | url = nullptr; 398 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | --------------------------------------------------------------------------------