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. int HotaCancel (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. int HotaGetUpdateIndex (unsigned int * 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

index Indicates 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. int HotaInit (ErrorCallBackFunc errorCallback, StatusCallBackFunc statusCallback )

Description:

Initializes the OTA module.

Parameters:

Name

Description

errorCallback Indicates the callback invoked when an error occurs during the upgrade. This parameter can be null.
statusCallback Indicates 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. int HotaRead (unsigned int offset, unsigned int bufLen, unsigned char * 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

offset Indicates the offset from where to start reading data.
bufLen Indicates the length of the data to be read.
buf Indicates the buffer to store the data that has been read.

Returns:

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

HotaRestart()

  1. int HotaRestart (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. int HotaSetBootSettings (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. int HotaSetPackageType (unsigned int 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

flag Specifies 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. int HotaWrite (unsigned char * buffer, unsigned int offset, unsigned int buffSize )

Description:

Writes specified data into flash memory.

Parameters:

Name

Description

buffer Indicates the data to be written into flash memory.
offset Indicates the offset from where to start writing data.
buffSize Indicates the size of the data to be written.

Returns:

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