> For the complete documentation index, see [llms.txt](https://cavedu.gitbook.io/linkit-7697/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://cavedu.gitbook.io/linkit-7697/linkit-7697-development-guide-for-arduino-ide/developer-guide/fota-update.md).

# FOTA Update

**FOTA** stands for Firmware Over the Air, allowing you to update the on-board sketch binary using Wi-Fi.

The **LHTTPUpdate** library allows you to download a **FOTA binary** from a given **HTTP** URL, and apply it to LinkIt 7697.&#x20;

### Example <a href="#fotaupdate-example" id="fotaupdate-example"></a>

* Upgrade your LinkIt 7697 Arduino BSP to **v0.10.5** or later version.
* Select **LinkIt 7697** from **Tools > Board** menu.
* Open **Examples > LHTTPUpdate > LHTTPUpdate**
* Change the **ssid** and **pass** according to your Wi-Fi AP setting:

  ```
  char ssid[] = "yourapssid";      // your WPA2 network SSID (AP name)
  char pass[] = "yourpassword";    // your WPA2 network password
  ```
* Click **Upload** to upload the sketch to LinkIt 7697
* After upload, open the **Serial Monitor**
* You should see the following message:

  ```
  HTTPUpdate example begins.
  Attempting to connect to SSID: yourssid
  Connected to wifi
  Begin downloading new firmware
  Press RST key to reboot to updated firmware version.
  After reboot, it may take a while to update the firmware.
  The USR LED lights up during the update process.
  ```

  This means the example is now downloading the new binary from the URL <http://download.labs.mediatek.com/resource/fota_example.bin>
* Press **RST** button to reboot and replace on-board binary with the downloaded sketch binary(fota\_example.bin)
* It may take sometime for the update process to complete. After complete, the board starts blinking - and the on-board sketch binary is now updated.\
  &#x20;

### How It Works <a href="#fotaupdate-howitworks" id="fotaupdate-howitworks"></a>

The sketch downloads the "**FOTA binary**" from <http://download.labs.mediatek.com/resource/fota_example.bin>, using the following call:

```
fotaUpdater.update(fotaBinaryURL);
```

The **FOTA binary** is a processed sketch binary. It is compressed and checksum to ensure that corruptions can be detected during the update process.

During the **update()** method, the FOTA binary is written in to the **FOTA region** of the on-board flash. The on-board flash layout is shown below:

![](https://3972650740-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FY4gduUSLWOCI23CXUWej%2Fuploads%2Fv9GOyvl7AfFDXWFYGA67%2Fimage2017-10-20%2B12_17_25.png?alt=media\&token=9ca1ca89-16c4-4a39-b145-2fdaf1c4e757)

After finish downloading the **FOTA** **binary**, the **update()** method flags the **FOTA** **region** as ready to update.

After the system reboots, the **bootloader** detects new binaries in the FOTA region, uncompress and verifies it, and write the new binary to the **CM4 firmware** region.

![](https://3972650740-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FY4gduUSLWOCI23CXUWej%2Fuploads%2F7ZhLlABV4p3OEdqCP3Jb%2Fimage2017-10-20%2B12_18_14.png?alt=media\&token=e9896178-09da-44b7-b00b-a394899d8c2a)

And completes the FOTA operation.

### How to Generate FOTA Binary <a href="#fotaupdate-howtogeneratefotabinary" id="fotaupdate-howtogeneratefotabinary"></a>

As we mentioned, the **FOTA binary** is a processed sketch binary. You can follow these steps to generate the FOTA binary:

* Download the **FOTA ROM Package** tool from <https://docs.labs.mediatek.com/resource/mt7687-mt7697/en/downloads#Downloads-Tools>.
* Export your sketch binary by selecting **Sketch > Export Compiled Binary** from the IDE menu.
* Follow the instruction of the **FOTA ROM Package** to process the sketch binary. We show the instructions of the Windows version below.

#### Windows FOTA ROM Package Tool <a href="#fotaupdate-windowsfotarompackagetool" id="fotaupdate-windowsfotarompackagetool"></a>

We denote the FOTA ROM Package root folder as **$FOTA\_ROOT**.

* Copy **$FOTA\_ROOT\\\_ini\template\mt7697\FOTARomPacker.ini** to **\_ini**
* Modify **$FOTA\_ROOT\\**\_ini\FOTARomPacker.ini

  ```
  [General Setting]
  Base_Directory=.\_Load\mt7697

  [CM4 bin]
  File=fota_example.bin
  Start_Address=0x79000
  Partition_Size=0x1ED000
  Is_Compressed=true
  ```

  Modify the **File** attribute.&#x20;

{% hint style="danger" %}
**Do not** change the **Start\_Address**, **Partiion\_Size** and **Is\_Compressed** option. These settings must match the flash layout of LinkIt 7697.
{% endhint %}

* Copy the sketch binary to **$FOTA\_ROOT\\\_Load\mt7697**
* Execute the script **gen\_image.bat**
* The generated FOTA binary is located in the **\_Output** folder

After generating the FOTA binary, you can then host the binary in a HTTP server and use **LHTTPUpdate.update()** to download and apply the FOTA binary.
