Almost functional OTA support
ota_basic example can receive new image via TCP. However - writing to flash with interrupts disabled causes data loss, and the TCP flow is very slow to recover. Linux sender quickly ramps up RTT timer to very long retry intervals, crippling performance & throughput. Running the update without the flash writes causes the data to be received quickly, so this is definitely an issue with the time taken for the erase cycle. Progress towards #10
This commit is contained in:
parent
3797cf5357
commit
147257efa4
10 changed files with 449 additions and 0 deletions
5
examples/ota_basic/Makefile
Normal file
5
examples/ota_basic/Makefile
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
PROGRAM=ota_basic
|
||||
OTA=1
|
||||
EXTRA_COMPONENTS=extras/rboot-ota
|
||||
include ../../common.mk
|
||||
|
||||
90
examples/ota_basic/ota_basic.c
Normal file
90
examples/ota_basic/ota_basic.c
Normal file
|
|
@ -0,0 +1,90 @@
|
|||
/* A very simple OTA example
|
||||
*
|
||||
* Binds a TCP socket, reads an image from it and then flashes live.
|
||||
*
|
||||
* This lets you flash from the command line via netcat.
|
||||
*
|
||||
* NOT SUITABLE TO PUT ON THE INTERNET OR INTO A PRODUCTION ENVIRONMENT!!!!
|
||||
*/
|
||||
#include "espressif/esp_common.h"
|
||||
#include "espressif/sdk_private.h"
|
||||
#include "FreeRTOS.h"
|
||||
#include "task.h"
|
||||
#include "esp8266.h"
|
||||
#include "rboot-ota.h"
|
||||
|
||||
#include "lwip/err.h"
|
||||
#include "lwip/sockets.h"
|
||||
#include "lwip/sys.h"
|
||||
#include "lwip/netdb.h"
|
||||
#include "lwip/dns.h"
|
||||
|
||||
#define FWPORT 12550
|
||||
|
||||
#if !defined(WIFI_SSID) || !defined(WIFI_PASS)
|
||||
#error "Please define macros WIFI_SSID & WIFI_PASS (here, or better in a local.h file at root level or in program dir."
|
||||
#endif
|
||||
|
||||
void simpleOTATask(void *pvParameters)
|
||||
{
|
||||
printf("Listening for firmware on port %d...\r\n", FWPORT);
|
||||
int s = socket(AF_INET, SOCK_STREAM, 0);
|
||||
if(s < 0) {
|
||||
printf("... Failed to allocate socket.\r\n");
|
||||
return;
|
||||
}
|
||||
|
||||
struct sockaddr_in s_addr = {
|
||||
.sin_family = AF_INET,
|
||||
.sin_addr = {
|
||||
.s_addr = INADDR_ANY,
|
||||
},
|
||||
.sin_port = htons(FWPORT),
|
||||
};
|
||||
if(bind(s, (struct sockaddr *) &s_addr, sizeof(s_addr)) < 0)
|
||||
{
|
||||
printf("... Failed to bind.\r\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if(listen(s, 0) == -1) {
|
||||
printf("... Failed to listen.\r\n");
|
||||
return;
|
||||
}
|
||||
|
||||
int client;
|
||||
while((client = accept(s, NULL, NULL)) != 0)
|
||||
{
|
||||
printf("Got new socket. Trying OTA update...\r\n");
|
||||
|
||||
int slot = rboot_ota_update(client, -1, false);
|
||||
close(client);
|
||||
if(slot < 0) {
|
||||
printf("OTA update failed. :(.\r\n");
|
||||
continue;
|
||||
}
|
||||
printf("OTA succeeded at slot %d!\r\n", slot);
|
||||
//rboot_set_current_rom(slot);
|
||||
//sdk_system_restart();
|
||||
}
|
||||
printf("Failed to accept.\r\n");
|
||||
close(s);
|
||||
return;
|
||||
}
|
||||
|
||||
void user_init(void)
|
||||
{
|
||||
sdk_uart_div_modify(0, UART_CLK_FREQ / 115200);
|
||||
|
||||
printf("OTA Basic demo. Currently running on slot %d / %d.\r\n",
|
||||
rboot_get_current_rom(), RBOOT_MAX_ROMS);
|
||||
|
||||
struct sdk_station_config config = {
|
||||
.ssid = WIFI_SSID,
|
||||
.password = WIFI_PASS,
|
||||
};
|
||||
sdk_wifi_set_opmode(STATION_MODE);
|
||||
sdk_wifi_station_set_config(&config);
|
||||
|
||||
xTaskCreate(simpleOTATask, (signed char *)"simpleOTATask", 512, NULL, 2, NULL);
|
||||
}
|
||||
9
examples/ota_basic/ota_basic.def
Normal file
9
examples/ota_basic/ota_basic.def
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
cpu xtensa
|
||||
|
||||
# Show up to this many raw bytes of code/data
|
||||
show bytes 4
|
||||
|
||||
# ELF file
|
||||
# See example.def if you want to load raw binaries instead
|
||||
load build/ota_basic.out elf
|
||||
|
||||
7
examples/ota_basic/test.c
Normal file
7
examples/ota_basic/test.c
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
extern void wDev_ProcessFiq(void);
|
||||
|
||||
void call_wdev(void)
|
||||
{
|
||||
wDev_ProcessFiq();
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue