OTA: Add TFTP client mode, expand ota_basic example.
This commit is contained in:
parent
a3956af4ca
commit
e671927bd0
3 changed files with 162 additions and 6 deletions
|
@ -18,6 +18,45 @@
|
|||
#include "rboot.h"
|
||||
#include "rboot-api.h"
|
||||
|
||||
#define TFTP_IMAGE_SERVER "192.168.1.23"
|
||||
#define TFTP_IMAGE_FILENAME1 "firmware1.bin"
|
||||
#define TFTP_IMAGE_FILENAME2 "firmware2.bin"
|
||||
|
||||
void tftp_client_task(void *pvParameters)
|
||||
{
|
||||
printf("TFTP client task starting...\n");
|
||||
rboot_config conf;
|
||||
conf = rboot_get_config();
|
||||
int slot = (conf.current_rom + 1) % conf.count;
|
||||
printf("Image will be saved in OTA slot %d.\n", slot);
|
||||
if(slot == conf.current_rom) {
|
||||
printf("FATAL ERROR: Only one OTA slot is configured!\n");
|
||||
while(1) {}
|
||||
}
|
||||
|
||||
/* Alternate between trying two different filenames. Probalby want to change this if making a practical
|
||||
example!
|
||||
|
||||
Note: example will reboot into FILENAME1 if it is successfully downloaded, but FILENAME2 is ignored.
|
||||
*/
|
||||
while(1) {
|
||||
printf("Downloading %s to slot %d...\n", TFTP_IMAGE_FILENAME1, slot);
|
||||
int res = ota_tftp_download(TFTP_IMAGE_SERVER, TFTP_PORT, TFTP_IMAGE_FILENAME1, 1000, slot);
|
||||
printf("ota_tftp_download %s result %d\n", TFTP_IMAGE_FILENAME1, res);
|
||||
if(res == 0) {
|
||||
printf("Rebooting into slot %d...\n", slot);
|
||||
rboot_set_current_rom(slot);
|
||||
sdk_system_restart();
|
||||
}
|
||||
vTaskDelay(5000 / portTICK_RATE_MS);
|
||||
|
||||
printf("Downloading %s to slot %d...\n", TFTP_IMAGE_FILENAME2, slot);
|
||||
res = ota_tftp_download(TFTP_IMAGE_SERVER, TFTP_PORT, TFTP_IMAGE_FILENAME2, 1000, slot);
|
||||
printf("ota_tftp_download %s result %d\n", TFTP_IMAGE_FILENAME2, res);
|
||||
vTaskDelay(5000 / portTICK_RATE_MS);
|
||||
}
|
||||
}
|
||||
|
||||
void user_init(void)
|
||||
{
|
||||
uart_set_baud(0, 115200);
|
||||
|
@ -39,4 +78,5 @@ void user_init(void)
|
|||
sdk_wifi_station_set_config(&config);
|
||||
|
||||
ota_tftp_init_server(TFTP_PORT);
|
||||
xTaskCreate(&tftp_client_task, (signed char *)"tftp_client", 1024, NULL, 2, NULL);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue