Working TFTP server based OTA updates

Tested with 16MBit flash configuration, two rboot update slots.

Closes #10
This commit is contained in:
Angus Gratton 2015-08-04 14:50:50 +10:00
parent 6887a8119a
commit 19b8383069
8 changed files with 586 additions and 176 deletions

View file

@ -11,73 +11,26 @@
#include "FreeRTOS.h"
#include "task.h"
#include "esp8266.h"
#include "ota-tftp.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);
rboot_config_t conf = rboot_get_config();
printf("\r\n\r\nOTA Basic demo.\r\nCurrently running on flash slot %d / %d.\r\n\r\n",
conf.current_rom, conf.count);
printf("Image addresses in flash:\r\n");
for(int i = 0; i <conf.count; i++) {
printf("%c%d: offset 0x%08lx\r\n", i == conf.current_rom ? '*':' ', i, conf.roms[i]);
}
struct sdk_station_config config = {
.ssid = WIFI_SSID,
@ -86,5 +39,5 @@ void user_init(void)
sdk_wifi_set_opmode(STATION_MODE);
sdk_wifi_station_set_config(&config);
xTaskCreate(simpleOTATask, (signed char *)"simpleOTATask", 512, NULL, 2, NULL);
ota_tftp_init_server(TFTP_PORT);
}