Files
luban-lite-t3e-pro/packages/artinchip/ota/test_ota.c
刘可亮 8bca5e8332 v1.0.4
2024-04-03 16:40:57 +08:00

78 lines
1.6 KiB
C

/*
* Copyright (c) 2022-2023, ArtInChip Technology Co., Ltd
*
* SPDX-License-Identifier: Apache-2.0
*
* Authors: zrq <ruiqi.zheng@artinchip.com>
*/
#include <stdio.h>
#include <rtthread.h>
#include <rtdevice.h>
#include <ota.h>
#include <env.h>
#include <absystem.h>
#define BUFFER_SIZE 256 //Need to be less than 2048 bytes
char buffer[BUFFER_SIZE];
int test_ota()
{
FILE *file;
int size;
int ret;
//update file ota.cpio is placed in the sdcard
file = fopen("/sdcard/ota.cpio", "rb");
if (file == NULL) {
printf("Failed to open the file.\n");
return -1;
}
//1.Preparing to update environment variables
ret = aic_upgrade_start();
if (ret) {
printf("Aic get os to upgrade");
goto __exit;
}
//2.Buffer allocation required by OTA
ret = ota_init();
if (ret != RT_EOK) {
printf("ota initialization failed.");
goto __exit;
}
//3.Read BUFFER_SIZE each time and update it into flash
while (!feof(file)) {
size = fread(buffer, 1, BUFFER_SIZE, file);
if (size > 0) {
if(ota_shard_download_fun(buffer, size) < 0) {
printf ("ota download failed.");
goto __exit;
}
}
}
//4.Update the environment variables
ret = aic_upgrade_end();
if (ret) {
printf("Aic upgrade end");
}
//5. Reset the device, Start new firmware
extern void rt_hw_cpu_reset(void);
rt_hw_cpu_reset();
__exit:
fclose(file);
ota_deinit();
return 0;
}
MSH_CMD_EXPORT_ALIAS(test_ota, test_ota, Test OTA);