fota - Underlying Firmware Upgrade#

Adapted Air780E/Air700E Air780EP/Air780EPV Air601 Air101/Air103 Air105

Note

This page document is automatically generated by this file. If there is any error, please submit issue or help modify pr, thank you!

Tip

This library has its own demo,click this link to view the demo example of fota

Example

-- If you get the upgrade package from http, just look at demo/fota
-- The following is the basic logic of calling this fota library after obtaining the update package from other ways

-- Passthrough
sys.taskInit(function()
    fota.init()
    while 1 do
        local buf = xxx -- Here is the upgrade package fragment obtained from other means
        -- buf It can be zbuff or string
        -- The maximum length of data written each time should not exceed 4k
        local result, isDone, cache = fota.run(buf) 
        if not result then
            log.info("fota", "Something went wrong.")
            break
        end
        if isDone then
            while true do
                local succ,fotaDone  = fota.isDone()
                if not succ then
                    log.info("fota", "Something went wrong.")
                    break
                end
                if fotaDone then
                    log.info("fota", "Completed")
                    break
                end
                sys.wait(100)
            end
            break
        end
        sys.wait(100)
    end
end)

-- Use file one-time pass-in
sys.taskInit(function()
    fota.init()
    fota.file("/xxx") -- Pass in concrete path
end)

fota.init(storge_location, len, param1)#

Initialize the fota process

Parameters

Incoming Value Type

Explanation

int/string

fota the starting position of data storage
if it is int, it is specifically judged by the chip platform
if it is string, it is stored in the file system
if it is nil, the storage position is decided by the bottom layer

int

Maximum space for data storage

userdata

param1,If the data is stored in the spiflash spi_device

Return Value

return value type

explanation

boolean

Returns true on success and true on failure false

Examples

-- Initialize the fota process
local result = fota.init(0, 0x00300000, spi_device)    --Since the 105 flash starts at 0x 01000000, 0 is external spiflash
local result = fota.init()    --ec618 Series/EC718 series use fixed internal addresses, so no parameters are required

fota.wait()#

Wait for the underlying fota process to be ready

Parameters

Incoming Value Type

Explanation

boolean

Whether the process has been completed completely. true indicates that the process has been completed correctly.

Return Value

return value type

explanation

boolean

Ready to return.true

Examples

local isDone = fota.wait()

fota.run(buff, offset, len)#

write fota data

Parameters

Incoming Value Type

Explanation

zbuff/string

fota Data, try to use zbuff

int

Starting offset, valid when zbuff is passed in, default is 0

int

Write length, valid when zbuff is passed in. The default value is zbuff:used()

Return Value

return value type

explanation

boolean

Return false with exception, return without exception true

boolean

Received the last block returned true

int

The amount of data that has not been written must wait if it exceeds 64K.

Examples

local result, isDone, cache = fota.run(buf) -- write fota process

-- Hint: If zbuff is passed in, please empty the data in zbuff after writing successfully.

-- 2024.4.3 Added offset and len parameters, valid only for zbuff
fota.run(buff, 0, 1024)

fota.file(path)#

read fota data from specified file

Parameters

Incoming Value Type

Explanation

string

File Path

Return Value

return value type

explanation

boolean

Return false with exception, return without exception true

boolean

Received the last block returned true

int

The amount of data that has not been written must wait if it exceeds 64K.

Examples

local result, isDone, cache = fota.file("/xxx.bin") -- write fota process
-- This API was added on 2023.03.23

fota.isDone()#

Wait for the underlying fota process to complete

Parameters

None

Return Value

return value type

explanation

boolean

Return false with exception, return without exception true

boolean

Write to last block returns true

Examples

local result, isDone = fota.isDone()

fota.finish(is_ok)#

End the fota process

Parameters

Incoming Value Type

Explanation

boolean

Whether the process has been completed completely. true indicates that the process has been completed correctly.

Return Value

return value type

explanation

boolean

Returns true on success and true on failure false

Examples

-- End the fota process
local result = fota.finish(true)