mirror of
				https://github.com/esp8266/Arduino.git
				synced 2025-11-03 14:33:37 +03:00 
			
		
		
		
	Updater.cpp:
- use new AutoInterruptLock - add delay to give the RTOS some time to handle TCP WiFiClient.cpp - add stopAllexcepted to cancel all TCP excepted one ClientContext.h - add getLocalPort() ESP8266HTTPUpdate.cpp - close all not needed TCP and UDP osapi.h - missing commit from SDK
This commit is contained in:
		@@ -1,6 +1,7 @@
 | 
				
			|||||||
#include "Updater.h"
 | 
					#include "Updater.h"
 | 
				
			||||||
#include "Arduino.h"
 | 
					#include "Arduino.h"
 | 
				
			||||||
#include "eboot_command.h"
 | 
					#include "eboot_command.h"
 | 
				
			||||||
 | 
					#include "interrupts.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
//#define DEBUG_UPDATER Serial
 | 
					//#define DEBUG_UPDATER Serial
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -111,18 +112,26 @@ bool UpdaterClass::end(bool evenIfRemaining){
 | 
				
			|||||||
  return true;
 | 
					  return true;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
bool UpdaterClass::_writeBuffer(){
 | 
					bool UpdaterClass::_writeBuffer() {
 | 
				
			||||||
  noInterrupts();
 | 
					    int rc = 0;
 | 
				
			||||||
  int rc = SPIEraseSector(_currentAddress/FLASH_SECTOR_SIZE);
 | 
					    delay(2); // give the rtos some time to handle TCP
 | 
				
			||||||
  interrupts();
 | 
					    {
 | 
				
			||||||
  yield();
 | 
					        AutoInterruptLock(15);
 | 
				
			||||||
  if(!rc){
 | 
					        rc = SPIEraseSector(_currentAddress / FLASH_SECTOR_SIZE);
 | 
				
			||||||
    noInterrupts();
 | 
					 | 
				
			||||||
    rc = SPIWrite(_currentAddress, _buffer, _bufferLen);
 | 
					 | 
				
			||||||
    interrupts();
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  interrupts();
 | 
					
 | 
				
			||||||
  if (rc) {
 | 
					    delay(2); // give the rtos some time to handle TCP
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if(!rc) {
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            AutoInterruptLock(15);
 | 
				
			||||||
 | 
					            rc = SPIWrite(_currentAddress, _buffer, _bufferLen);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    delay(2); // give the rtos some time to handle TCP
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if(rc) {
 | 
				
			||||||
        _error = UPDATE_ERROR_WRITE;
 | 
					        _error = UPDATE_ERROR_WRITE;
 | 
				
			||||||
        _currentAddress = (_startAddress + _size);
 | 
					        _currentAddress = (_startAddress + _size);
 | 
				
			||||||
#ifdef DEBUG_UPDATER
 | 
					#ifdef DEBUG_UPDATER
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -11,6 +11,8 @@
 | 
				
			|||||||
#define UPDATE_ERROR_SIZE   4
 | 
					#define UPDATE_ERROR_SIZE   4
 | 
				
			||||||
#define UPDATE_ERROR_STREAM 5
 | 
					#define UPDATE_ERROR_STREAM 5
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define DEBUG_UPDATER Serial1
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class UpdaterClass {
 | 
					class UpdaterClass {
 | 
				
			||||||
  public:
 | 
					  public:
 | 
				
			||||||
    UpdaterClass();
 | 
					    UpdaterClass();
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -2,8 +2,11 @@
 | 
				
			|||||||
#define ARD_DEBUG_H
 | 
					#define ARD_DEBUG_H
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <stddef.h>
 | 
					#include <stddef.h>
 | 
				
			||||||
// #define DEBUGV(...) ets_printf(__VA_ARGS__)
 | 
					//#define DEBUGV(...) ets_printf(__VA_ARGS__)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifndef DEBUGV
 | 
				
			||||||
#define DEBUGV(...)
 | 
					#define DEBUGV(...)
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#ifdef __cplusplus
 | 
					#ifdef __cplusplus
 | 
				
			||||||
void hexdump(uint8_t *mem, uint32_t len, uint8_t cols = 16);
 | 
					void hexdump(uint8_t *mem, uint32_t len, uint8_t cols = 16);
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -284,3 +284,27 @@ void WiFiClient::stopAll()
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void WiFiClient::stopAllexcepted(WiFiClient * exC) {
 | 
				
			||||||
 | 
					    for (WiFiClient* it = _s_first; it; it = it->_next) {
 | 
				
			||||||
 | 
					        ClientContext* c = it->_client;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if(c && exC->_client) {
 | 
				
			||||||
 | 
					            if(exC->_client->getRemoteAddress() == c->getRemoteAddress()) {
 | 
				
			||||||
 | 
					                if(exC->_client->getRemotePort() == c->getRemotePort()) {
 | 
				
			||||||
 | 
					                    if(exC->_client->getLocalPort() == c->getLocalPort()) {
 | 
				
			||||||
 | 
					                        // ignore this
 | 
				
			||||||
 | 
					                        c = NULL;
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (c) {
 | 
				
			||||||
 | 
					            c->abort();
 | 
				
			||||||
 | 
					            c->unref();
 | 
				
			||||||
 | 
					            it->_client = 0;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -91,6 +91,7 @@ public:
 | 
				
			|||||||
  using Print::write;
 | 
					  using Print::write;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  static void stopAll();
 | 
					  static void stopAll();
 | 
				
			||||||
 | 
					  static void stopAllexcepted(WiFiClient * c);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
private:
 | 
					private:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -125,6 +125,12 @@ class ClientContext {
 | 
				
			|||||||
            return _pcb->remote_port;
 | 
					            return _pcb->remote_port;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        uint16_t getLocalPort() {
 | 
				
			||||||
 | 
					            if(!_pcb) return 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            return _pcb->local_port;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        size_t getSize() const {
 | 
					        size_t getSize() const {
 | 
				
			||||||
            if(!_rx_buf) return 0;
 | 
					            if(!_rx_buf) return 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -128,10 +128,17 @@ t_httpUpdate_return ESP8266HTTPUpdate::update(const char * host, uint16_t port,
 | 
				
			|||||||
                    ret = HTTP_UPDATE_FAILD;
 | 
					                    ret = HTTP_UPDATE_FAILD;
 | 
				
			||||||
                    DEBUG_HTTP_UPDATE("[httpUpdate] FreeSketchSpace to low (%d) needed: %d\n", ESP.getFreeSketchSpace(), len);
 | 
					                    DEBUG_HTTP_UPDATE("[httpUpdate] FreeSketchSpace to low (%d) needed: %d\n", ESP.getFreeSketchSpace(), len);
 | 
				
			||||||
                } else {
 | 
					                } else {
 | 
				
			||||||
                    if(ESP.updateSketch(tcp, len)) {
 | 
					
 | 
				
			||||||
                        // may never reached!
 | 
					                    WiFiUDP::stopAll();
 | 
				
			||||||
 | 
					                    WiFiClient::stopAllexcepted(&tcp);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                    delay(100);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                    if(ESP.updateSketch(tcp, len, false, false)) {
 | 
				
			||||||
                        ret = HTTP_UPDATE_OK;
 | 
					                        ret = HTTP_UPDATE_OK;
 | 
				
			||||||
                        DEBUG_HTTP_UPDATE("[httpUpdate] Update ok\n");
 | 
					                        DEBUG_HTTP_UPDATE("[httpUpdate] Update ok\n");
 | 
				
			||||||
 | 
					                        tcp.stop();
 | 
				
			||||||
 | 
					                        ESP.restart();
 | 
				
			||||||
                    } else {
 | 
					                    } else {
 | 
				
			||||||
                        ret = HTTP_UPDATE_FAILD;
 | 
					                        ret = HTTP_UPDATE_FAILD;
 | 
				
			||||||
                        DEBUG_HTTP_UPDATE("[httpUpdate] Update failed\n");
 | 
					                        DEBUG_HTTP_UPDATE("[httpUpdate] Update failed\n");
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -28,6 +28,8 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
#include <Arduino.h>
 | 
					#include <Arduino.h>
 | 
				
			||||||
#include <ESP8266WiFi.h>
 | 
					#include <ESP8266WiFi.h>
 | 
				
			||||||
 | 
					#include <WiFiUdp.h>
 | 
				
			||||||
 | 
					#include <WiFiClient.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
//#define DEBUG_HTTP_UPDATE(...) Serial1.printf( __VA_ARGS__ )
 | 
					//#define DEBUG_HTTP_UPDATE(...) Serial1.printf( __VA_ARGS__ )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -46,7 +46,7 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
#ifdef USE_OPTIMIZE_PRINTF
 | 
					#ifdef USE_OPTIMIZE_PRINTF
 | 
				
			||||||
#define os_printf(fmt, ...) do {	\
 | 
					#define os_printf(fmt, ...) do {	\
 | 
				
			||||||
	static const char flash_str[] ICACHE_RODATA_ATTR = fmt;	\
 | 
						static const char flash_str[] ICACHE_RODATA_ATTR __attribute__((aligned(4))) = fmt;	\
 | 
				
			||||||
	os_printf_plus(flash_str, ##__VA_ARGS__);	\
 | 
						os_printf_plus(flash_str, ##__VA_ARGS__);	\
 | 
				
			||||||
	} while(0)
 | 
						} while(0)
 | 
				
			||||||
#else
 | 
					#else
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user