RT-Thread 軟件包-軟件包分類-IoT-OTA Downloader①
OTA Downloader
中文頁 | 英文頁
1、介紹
本軟件包是用于 OTA 升級的固件下載器,該下載器提供多種固件下載方式。開發(fā)者可以根據(jù)自己的需求靈活選擇升級方式,每種升級方式都只需調(diào)用一次函數(shù)或者命令就可實現(xiàn),目前支持的下載方式如下所示:
- HTTP/HTTPS 協(xié)議下載固件
- Ymodem 協(xié)議下載固件
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 協(xié)議下載固件功能 |
Enable Ymodem OTA | 使能 Ymodem 協(xié)議下載固件功能 |
選擇完自己需要的選項后使用 RT-Thread 的包管理器自動更新,或者使用 pkgs --update
命令更新包到 BSP 中。
3、使用 OTA Downloader
在打開 OTA downloader package ,選中相應(yīng)的功能選項后,當進行 BSP 編譯時,它會被加入到 BSP 工程中進行編譯。
燒錄程序到目標開發(fā)板,用戶可在 FinSH 終端找到對應(yīng)的命令。目前軟件包支持的升級方式如下表:
功能 | 函數(shù)調(diào)用 | 執(zhí)行命令 |
---|---|---|
使用 HTTP/HTTPS 協(xié)議固件升級 | void http_ota(uint8_t argc, char **argv) |
http_ota |
使用 Ymodem 協(xié)議固件升級 | void ymodem_ota(uint8_t argc, char **argv) |
ymodem_ota |
3.1 Ymodem 協(xié)議固件升級命令行演示
推薦使用支持 Ymodem 協(xié)議的 Xshell 。在終端輸入 ymodem_ota
命令后,鼠標右鍵然后在菜單欄找到用 YMODEM 發(fā)送選項發(fā)送文件。具體步驟如下圖:
3.2 HTTP/HTTPS 協(xié)議固件升級命令行演示
在終端輸入 http_ota http://xxx/xxx/rtthreadf.rbl
命令,執(zhí)行該命令后將會從鏈接 http://xxx/xxx/rtthreadf.rbl
處下載固件。具體步驟如下圖所示:
4、注意事項
- 確保 FAL 中有 downloader 分區(qū)。
- Ymodem 協(xié)議升級固件時,請使用支持 Ymodem 協(xié)議的工具。
- HTTP/HTTPS 協(xié)議升級固件時,需確保遠端鏈接地址可用。
5、參考資料
《RT-Thread OTA 用戶手冊》: docs/RT-Thread-OTA 用戶手冊.pdf文章來源:http://www.zghlxwxcb.cn/news/detail-816086.html
示例代碼
ymodem_ota.c文章來源地址http://www.zghlxwxcb.cn/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
到了這里,關(guān)于RT-Thread 軟件包-軟件包分類-IoT-OTA Downloader①的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!