Flash Firmware

Last Updated on : 2024-08-05 05:48:17download

This topic describes how to flash firmware to the THP23-X-D development board.

Flash via OTA

There are two approaches to flashing firmware via OTA: platform OTA and local OTA.

Platform OTA

How it works:

  1. Upload the firmware to the Tuya Developer Platform. See Manage Firmware for details.
  2. Configure the firmware version. See Update Firmware for details.
  3. Trigger the update using the mobile app.

Local OTA

How it works:

  1. Install a TFTP server on your computer and place the firmware in its directory.

  2. Log in to the THP23-X-D development board’s terminal using SSH or a serial port.

  3. Run the firmware download and update command in the terminal.

    The firmware download and update command:

    root@SmartGateway:~# cd /tmp && \
    tftp <TFTP server IP address> -g -l <Firmware file name> && \
    unpack -f <Firmware file name>
    

    Example:

    root@SmartGateway:~# cd /tmp && \
    tftp 192.168.1.128 -g -l tuyaos_gw_ssd202d_fw_UG_1.0.0.bin && \
    unpack -f tuyaos_gw_ssd202d_fw_UG_1.0.0.bin
    

Flash full firmware

Write the firmware to the entire flash memory in U-Boot mode. Before flashing, it is recommended to back up the device’s factory settings and restore them after flashing is completed.

Back up data

Log in to the THP23-X-D development board’s terminal. Run the command nvram show to print the factory information and save the output to a text file on your computer. Be sure to back up the UUID and Authkey, while the other fields are optional.

  • UUID: Authorization information, the unique ID of a device.
  • Authkey: Authorization information, the device key assigned to a device by the platform.
  • slave_mac1: The MAC address of the Wi-Fi interface.
  • master_mac: The MAC address of the wired interface.
  • bsn: The production serial number.

Flash firmware

  1. Connect to the THP23-X-D development board via serial port and run the command nvram set persist.uboot.enter on && nvram commit to access U-Boot mode.

  2. Power off the device and restart it. Press and hold the Enter key during restart to enter U-Boot mode. The login password is tygw@SSD20x.

  3. Set the U-Boot environment variables. Configure the board’s IP address (ipaddr) and the computer’s TFTP server IP address (serverip).

  4. Extract the archive tuyaos_gw_ssd202d_fw_PROD_*.tar.gz and place ssd20x_256m_all.img.0 and ssd20x_256m_all.img.1 in the TFTP server directory.

  5. Connect the board to the computer with an Ethernet cable and then run the firmware download and flashing command.

  6. Power off and restart the board.

    Example of the flashing command:

    SigmaStar # setenv serverip 192.168.1.128
    SigmaStar # setenv ipaddr 192.168.1.2
    SigmaStar # nand erase.chip
    SigmaStar # tftp 0x21000000 ssd20x_256m_all.img.0
    SigmaStar # nand write 0x21000000 0x0 ${filesize}
    SigmaStar # tftp 0x21000000 ssd20x_256m_all.img.1
    SigmaStar # nand write 0x21000000 0x2d00000 ${filesize}
    

Restore data

After flashing is completed, log in to the THP23-X-D terminal, write the factory information to the board, and restart it. The username and password are root and tygw@SSD20x, respectively.

Example of data recovery:

root@SmartGateway:~# nvram set UUID uuid7faa8a3438d4d2a9
root@SmartGateway:~# nvram set AUTHKEY VpI2WeDQS7KjTRcLBgKNdNScTkr8LCcq
root@SmartGateway:~# nvram set slave_mac1 4ca919e68a60
root@SmartGateway:~# nvram set master_mac 4ca919e68a1c
root@SmartGateway:~# nvram set bsn MCFE21MTS00001
root@SmartGateway:~# nvram commit
root@SmartGateway:~# reboot

Flashing for debugging

For efficiency, you can replace the executable directly during debugging. The steps are as follows:

  1. Place the archive gateway.tar.gz in the TFTP server’s directory.

  2. Log in to the THP23-X-D development board’s terminal using SSH or a serial port.

  3. In the development board terminal, you can start or stop an application and download and unzip an archive.

    Example:

    root@SmartGateway:~# cd /tmp && tftp 192.168.1.128 -gr gateway.tar.gz
    root@SmartGateway:~# /tmp/tuya/tuya_user1/app_stop.sh
    root@SmartGateway:~# cd /tmp && echo "tuya_start_dir=/tmp/tuya/tuya_user1" > /tmp/tuya/start.conf;tar -xf gateway.tar.gz -C /tmp/tuya
    root@SmartGateway:~# /tmp/tuya/tuya_start.sh /tmp/tuya