Refactored MCU flashing protection

pull/193/head
cskarai 8 years ago committed by Thorsten von Eicken
parent a3b38459ad
commit 60f47ba8bc
  1. 14
      serial/serbridge.c
  2. 2
      serial/serbridge.h
  3. 2
      serial/slip.c
  4. 2
      web-server/web-server.c

@ -23,7 +23,7 @@ static struct espconn serbridgeConn2; // programming port
static esp_tcp serbridgeTcp1, serbridgeTcp2;
static int8_t mcu_reset_pin, mcu_isp_pin;
extern uint8_t slip_disabled; // disable slip to allow flashing of attached MCU
uint8_t in_mcu_flashing; // for disabling slip during MCU flashing
void (*programmingCB)(char *buffer, short length) = NULL;
@ -124,14 +124,14 @@ telnetUnwrap(uint8_t *inBuf, int len, uint8_t state)
#ifdef SERBR_DBG
else { os_printf("MCU isp: no pin\n"); }
#endif
slip_disabled++;
in_mcu_flashing++;
break;
case RTS_OFF:
if (mcu_isp_pin >= 0) {
GPIO_OUTPUT_SET(mcu_isp_pin, 1);
os_delay_us(100L);
}
if (slip_disabled > 0) slip_disabled--;
if (in_mcu_flashing > 0) in_mcu_flashing--;
break;
}
state = TN_end;
@ -222,7 +222,7 @@ serbridgeRecvCb(void *arg, char *data, unsigned short len)
//if (mcu_isp_pin >= 0) GPIO_OUTPUT_SET(mcu_isp_pin, 1);
os_delay_us(1000L); // wait a millisecond before writing to the UART below
conn->conn_mode = cmPGM;
slip_disabled++; // disable SLIP so it doesn't interfere with flashing
in_mcu_flashing++; // disable SLIP so it doesn't interfere with flashing
#ifdef SKIP_AT_RESET
serledFlash(50); // short blink on serial LED
return;
@ -355,7 +355,7 @@ serbridgeUartCb(char *buf, short length)
{
if (programmingCB) {
programmingCB(buf, length);
} else if (!flashConfig.slip_enable || slip_disabled > 0) {
} else if (!flashConfig.slip_enable || in_mcu_flashing > 0) {
//os_printf("SLIP: disabled got %d\n", length);
console_process(buf, length);
} else {
@ -505,7 +505,7 @@ serbridgeInit(int port1, int port2)
espconn_regist_time(&serbridgeConn2, SER_BRIDGE_TIMEOUT, 0);
}
int ICACHE_FLASH_ATTR serbridgeInProgramming()
int ICACHE_FLASH_ATTR serbridgeInMCUFlashing()
{
return slip_disabled;
return in_mcu_flashing;
}

@ -36,7 +36,7 @@ void ICACHE_FLASH_ATTR serbridgeInitPins(void);
void ICACHE_FLASH_ATTR serbridgeUartCb(char *buf, short len);
void ICACHE_FLASH_ATTR serbridgeReset();
int ICACHE_FLASH_ATTR serbridgeInProgramming();
int ICACHE_FLASH_ATTR serbridgeInMCUFlashing();
// callback when receiving UART chars when in programming mode
extern void (*programmingCB)(char *buffer, short length);

@ -13,8 +13,6 @@
#define DBG(format, ...) do { } while(0)
#endif
uint8_t slip_disabled; // temporarily disable slip to allow flashing of attached MCU
extern void ICACHE_FLASH_ATTR console_process(char *buf, short len);
// This SLIP parser tries to conform to RFC 1055 https://tools.ietf.org/html/rfc1055.

@ -167,7 +167,7 @@ static int ICACHE_FLASH_ATTR WEB_handleJSONRequest(HttpdConnData *connData)
errorResponse(connData, 500, "No MCU callback is registered!");
return HTTPD_CGI_DONE;
}
if( serbridgeInProgramming() )
if( serbridgeInMCUFlashing() )
{
errorResponse(connData, 500, "Slip disabled at uploading program onto the MCU!");
return HTTPD_CGI_DONE;

Loading…
Cancel
Save