我正在尝试在esp8266上实现FOTA。我正在构建2个映像:user1.bin和user2.bin,使用1.7 bootloader将user2.bin写入esp8266,当我尝试进行OTA更新时,我收到错误。
代码:
#include "user_interface.h"
#include "mem.h"
#include "osapi.h"
#include "espconn.h"
#include "upgrade.h"
#include "user_update.h"
void ICACHE_FLASH_ATTR user_esp_platform_upgrade_rsp(void *arg) {
struct upgrade_server_info *server = arg;
if (server->upgrade_flag == true) {
INFO("user_esp_platform_upgarde_successfully\n");
}
else {
INFO("user_esp_platform_upgrade_failed\n");
}
os_free(server->url);
server->url = NULL;
os_free(server);
server = NULL;
}
void ICACHE_FLASH_ATTR user_esp_platform_upgrade_begin(struct espconn *pespconn, struct upgrade_server_info *server)
{
uint8 user_bin[9] = {0};
INFO("user_bin is set\r\n");
// os_memcpy(devkey, esp_param.devkey, 40);
os_memcpy(server->ip, pespconn->proto.tcp->remote_ip, 4);
INFO("pespconn->proto.tcp->remote_ip\r\n");
if (server->port == NULL) {
INFO("server port is null\r\n");
#ifdef UPGRADE_SSL_ENABLE
server->port = 443;
#else
server->port = 80;
#endif
}
else
{
INFO("server port is NOT null\r\n");
}
server->check_cb = user_esp_platform_upgrade_rsp;
INFO("callback is set\r\n");
server->check_times = 120000;
INFO("checktimes is set\r\n");
if (server->url == NULL) {
server->url = (uint8 *)os_zalloc(512);
}
if (system_upgrade_userbin_check() == UPGRADE_FW_BIN1)
{
os_memcpy(user_bin, "user2.bin", 10);
}
else if (system_upgrade_userbin_check() == UPGRADE_FW_BIN2)
{
os_memcpy(user_bin, "user1.bin", 10);
}
os_sprintf(server->url,"GET /%s"
"HTTP/1.0\r\nHost: %s:%d\r\n",
user_bin, IP2STR(server->ip),
server->port);
INFO("%s\n", server->url);
#ifdef UPGRADE_SSL_ENABLE
if (system_upgrade_start_ssl(server) == false)
{
#else
if (system_upgrade_start(server) == false)
{
#endif
INFO("upgrade is already started\n");
}
}
}
void ICACHE_FLASH_ATTR ota_finished_callback(void *arg)
{
struct upgrade_server_info *update = arg;
if (update->upgrade_flag == true)
{
INFO("[OTA]success; rebooting!\n");
system_upgrade_reboot();
}
else
{
INFO("[OTA]failed!\n");
}
os_free(update->pespconn);
os_free(update->url);
os_free(update);
}
void ICACHE_FLASH_ATTR handleUpgrade(uint8_t serverVersion, const char *server_ip, uint16_t port, const char *path)
{
const char* file;
uint8_t userBin = system_upgrade_userbin_check();
switch (userBin)
{
case UPGRADE_FW_BIN1: file = "user2.bin"; break;
case UPGRADE_FW_BIN2: file = "user1.bin"; break;
default:
INFO("[OTA]Invalid userbin number!\n");
return;
}
uint16_t version=1;
if (serverVersion <= version)
{
INFO("[OTA]No update. Server version:%d, local version %d\n", serverVersion, version);
return;
}
INFO("[OTA]Upgrade available version: %d\n", serverVersion);
struct upgrade_server_info* update = (struct upgrade_server_info *)os_zalloc(sizeof(struct upgrade_server_info));
update->pespconn = (struct espconn *)os_zalloc(sizeof(struct espconn));
os_memcpy(update->ip, server_ip, 4);
update->port = port;
INFO("[OTA]Server "IPSTR":%d. Path: %s%s\n", IP2STR(update->ip), update->port, path, file);
update->check_cb = ota_finished_callback;
update->check_times = 10000;
update->url = (uint8 *)os_zalloc(512);
os_sprintf((char*)update->url,
"GET %s%s HTTP/1.1\r\n"
"Host: "IPSTR":%d\r\n"
"Connection: close\r\n"
"\r\n",
path, file, IP2STR(update->ip), update->port);
if (system_upgrade_start(update) == false)
{
INFO("[OTA]Could not start upgrade\n");
os_free(update->pespconn);
os_free(update->url);
os_free(update);
}
else
{
INFO("[OTA]Upgrading...\n");
}
}
调试数据:
[INFO] BOOTUP...
STATION_IDLE
WIFI connected
scandone
state: 0 -> 2 (b0)
state: 2 -> 3 (0)
state: 3 -> 5 (10)
add 0
aid 2
cnt
connected with Home, channel 7
dhcp client start...
ip:192.168.31.30,mask:255.255.255.0,gw:192.168.31.1
WIFI connected
WIFI got ip
firmware version 2
[OTA]Upgrade available version: 2
[OTA]Server 192.168.31.73:3000. Path: /user2.bin
system_upgrade_start
upgrade_connect 41560
[OTA]Upgrading...
upgrade_connect_cb
pusrdata = HTTP/1.1 200 OK
X-Powered-By: Express
Content-Type: application/octet-stream
Content-Length: 312356
Content-Disposition: attachment; filename=user2.bin
x-MD5: 99771edeb6f0f3e6b1eacccd5ee521fe
Date: Mon, 06 Nov 2017 20:14:39 GMT
Connection: close
sumlength = 312356
sec_block 77
.............................................................................upgrade_get_sum_disconcb 39232
erase sector=129 ok
....
erase sector=205 ok
ALL=77 sectors erase ok!
upgrade_connect_cb
sumlength = 312356
upgrade file download start.
please check the bin file
totallen = 2664
totallen = 4124
upgrade_check
[OTA]failed!
pm open,type:2 0
我可以配置芯片从第二扇区启动以检查user2.bin吗?可能是更新服务器中的问题?也许是代码或makefile中的问题?
答案 0 :(得分:1)
短假设:您的Makefile没有正确命名user1.bin和user2.bin或gen_appbin.py的输出未正确处理。
我有完全相同的问题。碰巧我错误地加载了与当前运行版本相同的userN.bin文件(例如,当前运行的固件是user1.bin,更新程序试图下载相同的user1.bin并闪存)。
以下是损坏的更新程序的输出:
connected with WIFINETWORK, channel 3
dhcp client start...
event 0
ip:192.168.0.103,mask:255.255.255.0,gw:192.168.0.1
event 3
we have IP!
handleUpgrade()
current fw is user1.bin
[OTA]Upgrade available version: 2
[OTA]Server 8.8.8.8:80. Path: /user1.bin
[OTA][URL] GET /user1.bin HTTP/1.1
Host: your.site.com:80
Connection: keep-alive
Cache-Control: no-cache
User-Agent: Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.101 Safari/537.36
Accept: */*
Accept-Encoding: gzip,deflate,sdch
Accept-Language: zh-CN,zh;q=0.8
/**/
system_upgrade_start
upgrade_connect 40840
[OTA]Upgrading...
upgrade_connect_cb
pusrdata = HTTP/1.1 200 OK
Server: nginx/1.10.3 (Ubuntu)
Date: Fri, 19 Jan 2018 18:22:59 GMT
Content-Type: application/octet-stream
Content-Length: 327252
Last-Modified: Fri, 19 Jan 2018 18:22:04 GMT
Connection: close
ETag: "5a62374c-4fe54"
Accept-Ranges: bytes
sumlength = 327252
sec_block 80
................................................................................ upgrade_get_sum_disconcb 38568
erase sector=257 ok
...
erase sector=336 ok
ALL=80 sectors erase ok!
upgrade_connect_cb
sumlength = 327252
upgrade file download start.
please check the bin file
totallen = 2653
totallen = 4113
upgrade_check
[OTA]failed!
pm open,type:2 0
在我更改代码以便使用正确的bin文件后,更新程序成功地通过无线方式刷新固件。
以下是工作更新程序的输出:
connected with WIFINETWORK, channel 3
dhcp client start...
event 0
ip:192.168.0.103,mask:255.255.255.0,gw:192.168.0.1
event 3
we have IP!
handleUpgrade()
current fw is user1.bin
[OTA]Upgrade available version: 2
[OTA]Server 8.8.8.8:80. Path: /user2.bin
[OTA][URL] GET /user2.bin HTTP/1.1
Host: your.site.com:80
Connection: keep-alive
Cache-Control: no-cache
User-Agent: Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.101 Safari/537.36
Accept: */*
Accept-Encoding: gzip,deflate
Accept-Language: en-US,en;q=0.8
/**/
system_upgrade_start
upgrade_connect 40872
[OTA]Upgrading...
upgrade_connect_cb
pusrdata = HTTP/1.1 200 OK
Server: nginx/1.10.3 (Ubuntu)
Date: Sat, 20 Jan 2018 08:28:42 GMT
Content-Type: application/octet-stream
Content-Length: 327188
Last-Modified: Sat, 20 Jan 2018 08:27:57 GMT
Connection: close
ETag: "5a62fd8d-4fe14"
Accept-Ranges: bytes
sumlength = 327188
sec_block 80
................................................................................upgrade_get_sum_disconcb 38736
erase sector=257 ok
...
erase sector=336 ok
ALL=80 sectors erase ok!
upgrade_connect_cb
sumlength = 327188
upgrade file download start.
totallen = 2653
totallen = 4113
totallen = 5573
...
totallen = 325313
totallen = 326773
totallen = 327188
upgrade file download finished.
flash_crc = 1177058584
img_crc = 1177058584
upgrade_check
[OTA]success; rebooting!
reboot to use2
state: 5 -> 0 (0)
rm 0
del if0
usl
event 1
ets Jan 8 2013,rst cause:2, boot mode:(3,6)
load 0x40100000, len 2408, room 16
tail 8
chksum 0xe5
load 0x3ffe8000, len 776, room 0
tail 8
chksum 0x84
load 0x3ffe8310, len 632, room 0
tail 8
chksum 0xd8
csum 0xd8
2nd boot version : 1.6
SPI Speed : 40MHz
SPI Mode : QIO
SPI Flash Size & Map: 32Mbit(1024KB+1024KB)
jump to run user2 @ 101000
这是我的代码:
// credits to Martin Harizanov, IoT_Demo
#include "fota.h"
#include "ets_sys.h"
#include "upgrade.h" //for struct update
#include "ip_addr.h" //for ip_addr_t and etc.
#include "espconn.h" //for struct espconn
#include "mem.h" //os_free()
#include "osapi.h" //os_memcpy
#define pheadbuffer "Connection: keep-alive\r\n\
Cache-Control: no-cache\r\n\
User-Agent: Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.101 Safari/537.36 \r\n\
Accept: */*\r\n\
Accept-Encoding: gzip,deflate\r\n\
Accept-Language: en-US,en;q=0.8\r\n\r\n"
/* dummy comment to debug npp code highlighting */
static void ICACHE_FLASH_ATTR ota_finished_callback(void *arg) {
struct upgrade_server_info *update = arg;
if (update->upgrade_flag == true) {
os_printf("[OTA]success; rebooting!\n");
system_upgrade_reboot();
}
else { os_printf("[OTA]failed!\n"); }
os_free(update->pespconn);
os_free(update->url);
os_free(update);
}
static void ICACHE_FLASH_ATTR handleUpgrade(uint8_t serverVersion, const char *server_ip, uint16_t port, const char *path) {
const char* file;
os_printf("handleUpgrade()\r\n");
uint8_t userBin = system_upgrade_userbin_check();
switch( userBin ) {
case UPGRADE_FW_BIN1: file = "user2.bin"; break;
case UPGRADE_FW_BIN2: file = "user1.bin"; break;
default: os_printf("[OTA]Invalid userbin number!\n"); return;
}
os_printf( "[OTA]current fw is %s\r\n" , file );
uint16_t version=1;
if (serverVersion <= version) {
os_printf("[OTA]No update. Server version:%d, local version %d\n", serverVersion, version);
return;
}
os_printf("[OTA]Upgrade available version: %d\n", serverVersion);
struct upgrade_server_info* update = (struct upgrade_server_info *)os_zalloc(sizeof(struct upgrade_server_info));
update->pespconn = (struct espconn *)os_zalloc(sizeof(struct espconn));
os_memcpy(update->ip, server_ip, 4);
update->port = port;
os_printf("[OTA]Server "IPSTR":%d. Path: %s%s\n", IP2STR(update->ip), update->port, path, file);
update->check_cb = ota_finished_callback;
update->check_times = 120000;
update->url = (uint8 *)os_zalloc(512);
os_sprintf( update->url , "GET /%s HTTP/1.1\r\nHost:
your.site.com:80\r\n"pheadbuffer, file );
os_printf( "[OTA][URL] %s" , update->url );
if (system_upgrade_start(update) == false) {
os_printf("[OTA]Could not start upgrade\n");
os_free(update->pespconn);
os_free(update->url);
os_free(update);
}
else { os_printf("[OTA]Upgrading...\n"); }
}
void ICACHE_FLASH_ATTR doFotaUpdate() {
const char remote_ip[4] = {8, 8, 8, 8};
handleUpgrade( 2, remote_ip , 80 , "/" );
return;
}
答案 1 :(得分:0)
我在Debian上使用node.js
版本12.x
的服务器,并且遇到了同样的问题。升级时失败,并显示Please check the bin file
消息。
然后我将node.js
降级为6.x
版本,它开始工作了!
我也尝试了node.js
版8.x
,它再次给出了错误。