RT-Thread 软件包-软件包分类-IoT-OTA Downloader①
OTA Downloader
中文页 | 英文页
1、介绍
本软件包是用于 OTA 升级的固件下载器,该下载器提供多种固件下载方式。开发者可以根据自己的需求灵活选择升级方式,每种升级方式都只需调用一次函数或者命令就可实现,目前支持的下载方式如下所示:
- HTTP/HTTPS 协议下载固件
- Ymodem 协议下载固件
1.1 许可证
OTA Downloader package 遵循 Apache2.0 许可,详见 LICENSE
文件。
1.2 依赖
- RT-Thread 3.0+
- FAL 软件包支持
- Ymodem 下载方式依赖于 Ymodem 组件
- HTTP/HTTPS 下载方式依赖于 webclient 软件包
2、如何打开 OTA Downloader
使用 OTA downloader package 需要在 RT-Thread 的包管理器中选择它,具体路径如下:
RT-Thread online packages
IoT - internet of things --->
[*] The firmware downloader which using on RT-Thread OTA component --->
[*] Enable OTA downloader debug
[*] Enable HTTP/HTTPS OTA
(http://xxx/xxx/rtthread.rbl) HTTP OTA URL
[*] Enable Ymodem OTA
软件包选项的详细说明如下图:
选项 | 说明 |
---|---|
Enable OTA downloader debug | 使能固件下载器 debug 模式 |
Enable HTTP/HTTPS OTA | 使能 HTTP/HTTPS 协议下载固件功能 |
Enable Ymodem OTA | 使能 Ymodem 协议下载固件功能 |
选择完自己需要的选项后使用 RT-Thread 的包管理器自动更新,或者使用 pkgs --update
命令更新包到 BSP 中。
3、使用 OTA Downloader
在打开 OTA downloader package ,选中相应的功能选项后,当进行 BSP 编译时,它会被加入到 BSP 工程中进行编译。
烧录程序到目标开发板,用户可在 FinSH 终端找到对应的命令。目前软件包支持的升级方式如下表:
功能 | 函数调用 | 执行命令 |
---|---|---|
使用 HTTP/HTTPS 协议固件升级 | void http_ota(uint8_t argc, char **argv) |
http_ota |
使用 Ymodem 协议固件升级 | void ymodem_ota(uint8_t argc, char **argv) |
ymodem_ota |
3.1 Ymodem 协议固件升级命令行演示
推荐使用支持 Ymodem 协议的 Xshell 。在终端输入 ymodem_ota
命令后,鼠标右键然后在菜单栏找到用 YMODEM 发送选项发送文件。具体步骤如下图:
3.2 HTTP/HTTPS 协议固件升级命令行演示
在终端输入 http_ota http://xxx/xxx/rtthreadf.rbl
命令,执行该命令后将会从链接 http://xxx/xxx/rtthreadf.rbl
处下载固件。具体步骤如下图所示:
4、注意事项
- 确保 FAL 中有 downloader 分区。
- Ymodem 协议升级固件时,请使用支持 Ymodem 协议的工具。
- HTTP/HTTPS 协议升级固件时,需确保远端链接地址可用。
5、参考资料
《RT-Thread OTA 用户手册》: docs/RT-Thread-OTA 用户手册.pdf文章来源:https://www.toymoban.com/news/detail-816086.html
示例代码
ymodem_ota.c文章来源地址https://www.toymoban.com/news/detail-816086.html
/*
* Copyright (c) 2006-2018, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2018-01-30 armink the first version
* 2018-08-27 Murphy update log
*/
#include <rtthread.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdbool.h>
#include <finsh.h>
#include <fal.h>
#include <ymodem.h>
#define DBG_ENABLE
#define DBG_SECTION_NAME "ymodem"
#ifdef OTA_DOWNLOADER_DEBUG
#define DBG_LEVEL DBG_LOG
#else
#define DBG_LEVEL DBG_INFO
#endif
#define DBG_COLOR
#include <rtdbg.h>
#ifdef PKG_USING_YMODEM_OTA
#define DEFAULT_DOWNLOAD_PART "download"
static size_t update_file_total_size, update_file_cur_size;
static const struct fal_partition * dl_part = RT_NULL;
static uint8_t enable_output_log = 0;
static enum rym_code ymodem_on_begin(struct rym_ctx *ctx, rt_uint8_t *buf, rt_size_t len)
{
char *file_name, *file_size;
/* calculate and store file size */
file_name = (char *)&buf[0];
file_size = (char *)&buf[rt_strlen(file_name) + 1];
update_file_total_size = atol(file_size);
if (enable_output_log) {rt_kprintf("Ymodem file_size:%d\n", update_file_total_size);}
update_file_cur_size = 0;
/* Get download partition information and erase download partition data */
if (update_file_total_size > dl_part->len)
{
if (enable_output_log) {LOG_E("Firmware is too large! File size (%d), '%s' partition size (%d)", update_file_total_size, dl_part->name, dl_part->len);}
return RYM_CODE_CAN;
}
if (enable_output_log) {LOG_I("Start erase. Size (%d)", update_file_total_size);}
/* erase DL section */
if (fal_partition_erase(dl_part, 0, update_file_total_size) < 0)
{
if (enable_output_log) {LOG_E("Firmware download failed! Partition (%s) erase error!", dl_part->name);}
return RYM_CODE_CAN;
}
return RYM_CODE_ACK;
}
static enum rym_code ymodem_on_data(struct rym_ctx *ctx, rt_uint8_t *buf, rt_size_t len)
{
/* write data of application to DL partition */
if (fal_partition_write(dl_part, update_file_cur_size, buf, len) < 0)
{
if (enable_output_log) {LOG_E("Firmware download failed! Partition (%s) write data error!", dl_part->name);}
return RYM_CODE_CAN;
}
update_file_cur_size += len;
return RYM_CODE_ACK;
}
void ymodem_ota(uint8_t argc, char **argv)
{
struct rym_ctx rctx;
const char str_usage[] = "Usage: ymodem_ota -p <partiton name> -t <device name>.\n";
int i;
char* recv_partition = DEFAULT_DOWNLOAD_PART;
rt_device_t dev = rt_console_get_device();
enable_output_log = 0;
for (i=1; i<argc;)
{
/* change default partition to save firmware */
if (!strcmp(argv[i], "-p"))
{
if (argc <= (i+1))
{
rt_kprintf("%s", str_usage);
return;
}
recv_partition = argv[i+1];
i += 2;
}
/* change default device to transfer */
else if (!strcmp(argv[i], "-t"))
{
if (argc <= (i+1))
{
rt_kprintf("%s", str_usage);
return;
}
dev = rt_device_find(argv[i+1]);
if (dev == RT_NULL)
{
rt_kprintf("Device (%s) find error!\n", argv[i+1]);
return;
}
i += 2;
}
/* NOT supply parameter */
else
{
rt_kprintf("%s", str_usage);
return;
}
}
if ((dl_part = fal_partition_find(recv_partition)) == RT_NULL)
{
rt_kprintf("Partition (%s) find error!\n", recv_partition);
return;
}
if (dev != rt_console_get_device()) {enable_output_log = 1;}
rt_kprintf("Save firmware on \"%s\" partition with device \"%s\".\n", recv_partition, dev->parent.name);
rt_kprintf("Warning: Ymodem has started! This operator will not recovery.\n");
rt_kprintf("Please select the ota firmware file and use Ymodem to send.\n");
if (!rym_recv_on_device(&rctx, dev, RT_DEVICE_OFLAG_RDWR | RT_DEVICE_FLAG_INT_RX,
ymodem_on_begin, ymodem_on_data, NULL, RT_TICK_PER_SECOND))
{
rt_kprintf("Download firmware to flash success.\n");
rt_kprintf("System now will restart...\r\n");
/* wait some time for terminal response finish */
rt_thread_delay(rt_tick_from_millisecond(200));
/* Reset the device, Start new firmware */
extern void rt_hw_cpu_reset(void);
rt_hw_cpu_reset();
/* wait some time for terminal response finish */
rt_thread_delay(rt_tick_from_millisecond(200));
}
else
{
/* wait some time for terminal response finish */
rt_thread_delay(RT_TICK_PER_SECOND);
rt_kprintf("Update firmware fail.\n");
}
return;
}
/**
* msh />ymodem_ota
*/
MSH_CMD_EXPORT(ymodem_ota, Use Y-MODEM to download the firmware);
#endif /* PKG_USING_YMODEM_OTA */
维护人:
- 华为奋斗者精神, 邮箱:1992152446@qq.com
到了这里,关于RT-Thread 软件包-软件包分类-IoT-OTA Downloader①的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!