> 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/flash-uploading-tool.md).

# Flash Uploading Tool

This Python-based tool provides the functionality to flash the bootloader and the firmware of the LinkIt 7697 platform (based on the [MT7697 SoC)](https://labs.mediatek.com/en/chipset/MT7697), including firmwares for both CM4 and the N9 processors. The official GitHub repository is: <https://github.com/MediaTek-Labs/mt76x7-uploader>

* Supports Windows, macOS, and Linux (based on Python 2.7)
* Flashes bootloader, CM4 (application binary), and N9 firmware sections.

### Command Options <a href="#flashuploadingtool-commandoptions" id="flashuploadingtool-commandoptions"></a>

```
-c COM_PORT      COM port, can be COM1, COM2, ..., COMx 
-f BIN_FILE      path of the bin file to be uploaded 
-n DA_FILE       path of the DA file to be used. The default file is da97.bin for mt7697 and da87.bin for mt7687 
-p PLATFORM_NAME platform to be flashed (mt7687 | mt7697). The default platform is mt7697 
-t FLASH_TARGET  target to be flashed (cm4 | ldr | n9). The default target is cm4
```

### Examples <a href="#flashuploadingtool-examples" id="flashuploadingtool-examples"></a>

#### Windows <a href="#flashuploadingtool-windows" id="flashuploadingtool-windows"></a>

Upload firmware *sample.bin* to COM port *24*:

```
upload.exe -c COM24 -f sample.bin
```

#### Linux and macOS <a href="#flashuploadingtool-linuxandmacos" id="flashuploadingtool-linuxandmacos"></a>

Upload firmware *sample.bin* to the serial device */dev/cu.SLAB\_USBtoUART*:

```
python ./upload.py -c /dev/cu.SLAB_USBtoUART -f sample.bin
```

You can also assign customized download agent, specific SoC platform, and different flash uploading partition by using different parameters (-n / -p / -t).

#### Flash a build from LinkIt SDK <a href="#flashuploadingtool-flashabuildfromlinkitsdk" id="flashuploadingtool-flashabuildfromlinkitsdk"></a>

If you build your project using LinkIt SDK 4.x, the output folder should look like this:&#x20;

```
.
├── flash_download.ini
├── your_application.bin
├── mt7697_bootloader.bin
└── WIFI_RAM_CODE_MT76X7_in_flash.bin
```

You can flash the bootloader (`mt7697_bootloader.bin`), N9 firmmware (`WIFI_RAM_CODE_MT76X7_in_flash.bin`) and application binary by copying these files to the uploader tool folder and type the following command:

```
python upload.py -c /dev/cu.SLAB_USBtoUART -t ldr -f mt7697_bootloader.bin
python upload.py -c /dev/cu.SLAB_USBtoUART -t n9 -f WIFI_RAM_CODE_MT76X7_in_flash.bin
python upload.py -c /dev/cu.SLAB_USBtoUART -t cm4 -f your_application.bin
```

#### Flash Access Mode on MT7697 <a href="#flashuploadingtool-flashaccessmodeonmt7697" id="flashuploadingtool-flashaccessmodeonmt7697"></a>

MT7697 have 2 bootstrap modes, a normal mode and a **Flash Recovery Mode**. The mode is determined by the state of **GPIO37** during bootup. The table below is excerpted from MT7697 datasheet:

![](https://3972650740-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FY4gduUSLWOCI23CXUWej%2Fuploads%2FUrqhXQCw3EByUPxR03Ei%2Fflash_mode_table.png?alt=media\&token=7bfb6693-8804-438a-83ac-df8ec60b0ceb)

GPIO37 maps to **P6** on LinkIt 7697 HDK, as shown in the pinout diagram:

![](https://3972650740-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FY4gduUSLWOCI23CXUWej%2Fuploads%2FHpBIQ8H9Lt7CtJDMbwQq%2Flinkit7697_gpio37.png?alt=media\&token=ccbfd5a2-7f0c-48bc-a7c0-528fee79e69a)

#### Switching Flash Mode on LinkIt 7697 <a href="#flashuploadingtool-switchingflashmodeonlinkit7697" id="flashuploadingtool-switchingflashmodeonlinkit7697"></a>

On LinkIt 7697, to improve the usability, the GPIO37 state is controlled by the onboard **CP2102N** USB-to-UART chipset. The GPIO37 pin is connected to the flow contorl pins of CP2102N. This allows the flash uploading tool to reset the board and put the board into Flash Recovery Mode without user intervention.

The truth table of the control logic is:

| DTR | RTS | GPIO37 | SYS\_RST\_N |
| --- | --- | ------ | ----------- |
| 0   | 0   | 0      | 1           |
| 1   | 1   | 0      | 1           |
| 0   | 1   | 0      | 0           |
| 1   | 0   | 1      | 1           |

![](https://3972650740-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FY4gduUSLWOCI23CXUWej%2Fuploads%2FtbMP047SuqYbCAIQCiGA%2Flinkit_7697_flash_mode_switch.png?alt=media\&token=04a5dfcd-c06a-444d-a503-a3ec1c26bb6e)

As a result, if you use a terminal program to access the serial port of LinkIt 7697, be aware of the flow control settings in the terminal program. For example, the **Flow control** field in **PuTTY** (set it to *None*):

![](https://3972650740-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FY4gduUSLWOCI23CXUWej%2Fuploads%2FuqXFFZ2hrGcUGI7FKC1w%2Fserial_port_config.png?alt=media\&token=abd98204-6966-446a-9414-b195742a6fb4)

Or the DTR/RTS settings in the **Lines** tab of **eagleCom**:

![](https://3972650740-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FY4gduUSLWOCI23CXUWej%2Fuploads%2FbPCvHoH6b4WXE5noI7Vt%2Feagle_com_config.png?alt=media\&token=670f970f-f1f1-4b4d-9523-bb7a42b4f80c)

#### Flash Layout <a href="#flashuploadingtool-flashlayout" id="flashuploadingtool-flashlayout"></a>

The flash layout of LinkIt 7697 is shown in the image below.

![](https://3972650740-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FY4gduUSLWOCI23CXUWej%2Fuploads%2FMjX14uGucVkBCawDe3fz%2Fflash_layout.png?alt=media\&token=91c92fc7-9a6f-4baf-a454-329ff9b0a8f7)

There are 3 regions that can be uploaded:

* Bootloader
* N9 firmware (Wi-Fi and Bluetooth subsystem)
* CM4 firmwear (the application binary - this is the most commonly updated part during your development)

The following regions are reserved for LinkIt SDK modules:

* FOTA: reserved for firmware update over-the-air
* NVDM: reserved for a non-volatile data manager that stores persistent data

#### Uploading Flow <a href="#flashuploadingtool-uploadingflow" id="flashuploadingtool-uploadingflow"></a>

Initially state of RAM and Flash looks like this:

![](https://3972650740-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FY4gduUSLWOCI23CXUWej%2Fuploads%2F8JH6uqeuIbF24cl84sgv%2Fupload_flow_1.png?alt=media\&token=5db858d1-3658-4cf7-beab-6904a6368788)

The Python script resets the board and put it into Flash Recovery mode. Under this mode the MT7697 chipset BootROM (BROM) accepts data from UART0 to write a small program to the RAM. We call this small program the **Download** **Agent** (**DA**) program.&#x20;

![](https://3972650740-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FY4gduUSLWOCI23CXUWej%2Fuploads%2F85eGuJW9rh0cMHch3lWU%2Fupload_flow_2.png?alt=media\&token=092fdf1c-c73e-4b3d-a0a0-427ca3b441d7)

This DA program then takes over the CM4 processor to receive data from the Python script through XModem protocol:

![](https://3972650740-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FY4gduUSLWOCI23CXUWej%2Fuploads%2FXEubOCqPad46J23hysft%2Fupload_flow_3.png?alt=media\&token=f3b36a5f-9d48-4b60-9877-0d06c6607ef9)

Finally, the script resets the board again and reboot it into normal execution mode. This completes the flash uploading process.
