Note

This is the documentation for the latest development branch and may refer to features that are not available in released versions. If you are looking for the documentation for a specific release, use the drop-down menu on the left and select the desired version.

K230 OTA API Reference#

Overview#

K230 provides an independent OTA HAL interface for streaming the kdimg image to the OTA device node.

  • User mode HAL header file: src/rtsmart/libs/rtsmart_hal/components/k230_ota/k230_ota.h

  • User mode HAL implementation: src/rtsmart/libs/rtsmart_hal/components/k230_ota/k230_ota.c

  • Reference example: src/rtsmart/examples/peripheral/ota/test_ota.c

Main interface#

k230_ota_create#

k230_ota_t* k230_ota_create(void);

Create an OTA session and open the OTA device.

  • Return value: A non-empty handle is returned on success; NULL is returned on failure.

k230_ota_update#

int k230_ota_update(k230_ota_t* ctx, const void* buf, size_t size);

Write a piece of image data to the OTA device, suitable for cyclic block calling.

  • ctx: Session handle returned by k230_ota_create()

  • buf: Data buffer to be written

  • size: Number of bytes written

  • Return value: 0 is returned on success; negative value is returned on failure

k230_ota_destroy#

void k230_ota_destroy(k230_ota_t* ctx);

Destroy the OTA session, release resources and shut down the device.

k230_ota_write_file#

int k230_ota_write_file(const char* image_path, size_t chunk_size);

Convenient interface: Directly write the image file into OTA devices in chunk_size chunks.

  • image_path: Mirror path

  • chunk_size: Size per write (bytes)

  • Return value: 0 is returned on success; negative value is returned on failure

Minimal example#

#include "k230_ota.h"
#include <fcntl.h>
#include <unistd.h>

int ota_from_file(const char *path)
{
    int fd = -1;
    int ret = -1;
    char buf[64 * 1024];
    ssize_t rd;
    k230_ota_t *ctx = NULL;

    fd = open(path, O_RDONLY, 0);
    if (fd < 0)
        return -1;

    ctx = k230_ota_create();
    if (!ctx)
        goto out;

    while ((rd = read(fd, buf, sizeof(buf))) > 0) {
        if (k230_ota_update(ctx, buf, (size_t)rd) < 0)
            goto out;
    }

    ret = (rd < 0) ? -1 : 0;

out:
    if (ctx)
        k230_ota_destroy(ctx);
    if (fd >= 0)
        close(fd);
    return ret;
}

Things to note#

  1. Avoid power outages or forced restarts during the OTA process.

  2. It is recommended to complete image verification and version check before upgrading.

  3. Network download capability can be implemented in combination with NetMgmt API documentation.

Comments list
Comments
Log in