Hey AgentSmithers,
Thanks for your interest !
I post below the very same code I use (I made it minimalistic so that it is easier to post). I simply replaced the user_main.c of the NONOS_SDK_2.2.0/examples/IoTDemo project by this one, and I build it with ./gen_misc.sh without any errors, using the procedure describe in Espressif's documentation ("ESP8266 SDKGetting Started Guide"), using the virtual machine and environment provided by Espressif.
I compiled version 1 and 2 of this same application with the options:
SPI Speed : 40MHz
SPI Mode : QIO
SPI Flash Size & Map: 32Mbit(512KB+512KB)
I flashed boot_v1.7.bin first at address 0x00000, then the user1.app (originally named user1.4096.new.4.bin, I gave it a shorter nickname

) at 0x01000.
On a local machine (actually a Raspeberry PI) where I put the binaries user1.app and user2.app, I run the very useful and simple Python HTTP server, listenning on port 8070:
And here I'm still wroking on how to get clues...
NB1: A function from the SDK prints "server do not support HEAD method now send GET message". However the SimpleHTTPServer does support HEAD requests: a HEAD request with curl complete successfully with no error, and the logs of the server indicate a successful answer to the ESP... Could the problem be here ?
NB2: You said
The process of SPIWriting the Data is specific to your code
Do you mean I must write "manually" each bytes of the new app to the SPI flash with the SPI functions ? If so, what are the OTA upgrade functions for ? I though they were already supposed to manage it.
NB3: I saw you already spent a large amount of time helping other people on this forum (and sometimes on others websites

), that's very appreciable and kind. Thanks. Really.
-------------------
Here is my code, if you want to give it a try:
Code: Select all
/*
* FOTA test code: once it's connected to Wifi, it starts the FOTA process:
* it connects to a local server to retrieve the new bin to flash and upgrades. That's all.
* Core code based on https://harizanov.com/2015/06/firmware-over-the-air-fota-for-esp8266-soc/
*/
#include "ets_sys.h"
#include "osapi.h"
#include "gpio.h"
#include "os_type.h"
#include "user_interface.h"
#include "mem.h"
#include "upgrade.h"
#include "ip_addr.h"
#include "espconn.h"
uint32 priv_param_start_sec;
char ssid[32] = "MyWifiSSID";
char password[64] = "superpassword";
/**
* @brief Was present in IoT_Demo/user/user_main.c on which this code is based...
*/
uint32 ICACHE_FLASH_ATTR user_rf_cal_sector_set(void)
{
enum flash_size_map size_map = system_get_flash_size_map();
uint32 rf_cal_sec = 0;
switch (size_map) {
case FLASH_SIZE_4M_MAP_256_256:
rf_cal_sec = 128 - 5;
priv_param_start_sec = 0x3C;
break;
case FLASH_SIZE_8M_MAP_512_512:
rf_cal_sec = 256 - 5;
priv_param_start_sec = 0x7C;
break;
case FLASH_SIZE_16M_MAP_512_512:
rf_cal_sec = 512 - 5;
priv_param_start_sec = 0x7C;
break;
case FLASH_SIZE_16M_MAP_1024_1024:
rf_cal_sec = 512 - 5;
priv_param_start_sec = 0xFC;
break;
case FLASH_SIZE_32M_MAP_512_512:
rf_cal_sec = 1024 - 5;
priv_param_start_sec = 0x7C;
break;
case FLASH_SIZE_32M_MAP_1024_1024:
rf_cal_sec = 1024 - 5;
priv_param_start_sec = 0xFC;
break;
case FLASH_SIZE_64M_MAP_1024_1024:
rf_cal_sec = 2048 - 5;
priv_param_start_sec = 0xFC;
break;
case FLASH_SIZE_128M_MAP_1024_1024:
rf_cal_sec = 4096 - 5;
priv_param_start_sec = 0xFC;
break;
default:
rf_cal_sec = 0;
priv_param_start_sec = 0;
break;
}
return rf_cal_sec;
}
/**
* @brief Was present in IoT_Demo/user/user_main.c on wich this code is based...
*/
void ICACHE_FLASH_ATTR user_rf_pre_init(void)
{
}
/**
* @brief Callback function called when the upgrade process ended, because of
* timeout or upgrade finished ?
*/
static void OtaFinishedCallback(void *arg)
{
struct upgrade_server_info *update = arg;
if (update->upgrade_flag == true)
{
os_printf("[OTA] Success, now rebooting!\n");
system_upgrade_reboot();
}
else
{
os_printf("[OTA] Failed!\n");
}
}
/**
* @brief Start the OTA upgrade process.
*
*/
static void HandleUpgrade(const uint8 *server_ip, uint16_t port, const char *path)
{
const char* file;
uint8_t userBin = system_upgrade_userbin_check();
/* Check wich slot/bin is currently running to determine the new bin to download */
switch(userBin)
{
case UPGRADE_FW_BIN1: file = "user2.app"; break;
case UPGRADE_FW_BIN2: file = "user1.app"; break;
default:
os_printf("[OTA] Invalid userbin number! \n");
return;
}
/* Set the info about source server and upgrade process properties */
struct upgrade_server_info* update = (struct upgrade_server_info *)os_zalloc(sizeof(struct upgrade_server_info));
os_memcpy(update->ip, server_ip, 4);
update->pespconn = (struct espconn *)os_zalloc(sizeof(struct espconn));
update->port = port;
update->check_cb = OtaFinishedCallback;
update->check_times = 60000;
update->url = (uint8 *)os_zalloc(512);
os_sprintf((char*)update->url, "GET %s%s HTTP/1.0\r\nHost: "IPSTR":%d\r\nConnection: close\r\n\r\n",
path, file, IP2STR(update->ip), update->port);
os_printf("[OTA] Server "IPSTR":%d. Path: %s%s\n", IP2STR(update->ip), update->port, path, file);
os_printf("Request: %s \n", update->url);
/* Debug */
if (system_upgrade_start(update) == false) os_printf("[OTA] Could not start upgrade\n");
else os_printf("[OTA] Started upgrading...\n");
}
/**
* @brief Callback function called when the wifi connection is fully operational.
* Launch the OTA upgrade.
*
*/
void WifiConnectedCb(System_Event_t *event)
{
/* Run OTA process only when we are fully connected to WiFi */
if(event->event == EVENT_STAMODE_GOT_IP)
{
os_printf("Connected to Wifi (EVENT_STAMODE_GOT_IP) \n");
os_printf("Now Testing FOTA... \n");
uint8 serverIp[] = {192, 168, 0, 106};
uint16 port = 8070;
char path[] = "pato/espOtaTest/";
HandleUpgrade(serverIp, port, path);
}
}
/**
* @brief Called when system is fully initialized. Here we do our custom initialization
* like connecting to wifi and setting timers.
*/
void PostInitCb()
{
/* Connect to WiFi */
os_printf("I'm version 1 ! \n");
os_printf("Setting up the Esp as a Wifi station... \n");
struct station_config stationConfig;
os_memcpy(stationConfig.ssid, ssid, 32);
os_memcpy(stationConfig.password, password, 64);
wifi_set_opmode_current(STATION_MODE);
wifi_station_set_config(&stationConfig);
wifi_set_event_handler_cb(WifiConnectedCb);
wifi_station_connect();
os_printf("Connecting to WiFi... \n");
}
/**
* @brief Main entry point of our programm
*/
void user_init()
{
system_init_done_cb(PostInitCb);
}