OTA

Overview

Provides system upgrades.

Since:

1.0

Version:

1.0

Summary

Files

File Name

Description

hota_updater.h

Defines the functions for system upgrades.

Functions

Function Name

Description

HotaSetPackageType (unsigned int flag)

int 

Sets the switch for using the default upgrade package format.

HotaGetUpdateIndex (unsigned int index)

int 

Obtains the index of the A/B partition to be upgraded.

HotaInit (ErrorCallBackFunc errorCallback, StatusCallBackFunc statusCallback)

int 

Initializes the OTA module.

HotaWrite (unsigned char buffer, unsigned int offset, unsigned int buffSize)

int 

Writes specified data into flash memory.

HotaRead (unsigned int offset, unsigned int bufLen, unsigned char *buf)

int 

Reads the data that has been written into flash memory.

HotaCancel (void)

int 

Cancels an upgrade.

HotaSetBootSettings (void)

int 

Sets the system state to be upgrading after data has been written into flash memory by HotaWrite.

HotaRestart (void)

int 

Restarts the system after an upgrade.

Details

Function Documentation

HotaCancel()

  1. intHotaCancel(void)

Description:

Cancels an upgrade.

If an upgrade fails or is interrupted, you can use this function to cancel it.

Returns:

Returns 0 if the operation is successful; returns -1 otherwise.

HotaGetUpdateIndex()

  1. intHotaGetUpdateIndex(unsignedint* index)

Description:

Obtains the index of the A/B partition to be upgraded.

In the A/B upgrade scenario, you can use this function to determine whether partition A or B will be upgraded.

Parameters:

Name

Description

indexIndicates the index of a partition. The value 1 means partition A, and 2 means partition B.

Returns:

Returns 0 if the operation is successful; returns -1 otherwise.

HotaInit()

  1. intHotaInit(ErrorCallBackFunc errorCallback,StatusCallBackFunc statusCallback )

Description:

Initializes the OTA module.

Parameters:

Name

Description

errorCallbackIndicates the callback invoked when an error occurs during the upgrade. This parameter can be null.
statusCallbackIndicates the callback invoked when the upgrade status changes. This parameter can be null.

Returns:

Returns 0 if the operation is successful; returns -1 otherwise.

HotaRead()

  1. intHotaRead(unsignedint offset,unsignedint bufLen,unsignedchar* buf )

Description:

Reads the data that has been written into flash memory.

This function is required for verifying data correctness when the default upgrade package format is not used. It is not required when the default upgrade package format is used.

Parameters:

Name

Description

offsetIndicates the offset from where to start reading data.
bufLenIndicates the length of the data to be read.
bufIndicates the buffer to store the data that has been read.

Returns:

Returns 0 if the operation is successful; returns -1 otherwise.

HotaRestart()

  1. intHotaRestart(void)

Description:

Restarts the system after an upgrade.

You need to call this function after you have called the HotaSetBootSettings function.

Returns:

Returns 0 if the operation is successful; returns -1 otherwise.

HotaSetBootSettings()

  1. intHotaSetBootSettings(void)

Description:

Sets the system state to be upgrading after data has been written into flash memory by HotaWrite.

After this operation is successful, you need to call the HotaRestart function to complete the upgrade.

Returns:

Returns 0 if the operation is successful; returns -1 otherwise.

HotaSetPackageType()

  1. intHotaSetPackageType(unsignedint flag)

Description:

Sets the switch for using the default upgrade package format.

You can call this function to choose the default upgrade package format when developing the system upgrade capability. If the default upgrade package format is used, the system ensures the security and integrity of the upgrade package. If it is not used, you need to ensure the security and integrity of the upgrade package you have chosen. To be specific, you need to call the HotaRead function to read the data that has been written into flash memory, and then verify the data.

Parameters:

Name

Description

flagSpecifies whether to use the default system upgrade package format. The value 1 (default value) means to use it, and 0 means not to use it.

Returns:

Returns 0 if the operation is successful; returns -1 otherwise.

HotaWrite()

  1. intHotaWrite(unsignedchar* buffer,unsignedint offset,unsignedint buffSize )

Description:

Writes specified data into flash memory.

Parameters:

Name

Description

bufferIndicates the data to be written into flash memory.
offsetIndicates the offset from where to start writing data.
buffSizeIndicates the size of the data to be written.

Returns:

Returns 0 if the operation is successful; returns -1 otherwise.