|
|
@ -21,6 +21,8 @@ |
|
|
|
#define DBG(format, ...) do { } while(0) |
|
|
|
#define DBG(format, ...) do { } while(0) |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define DBG_GPIO5 0 // define to 1 to use GPIO5 to trigger scope
|
|
|
|
|
|
|
|
|
|
|
|
//===== global state
|
|
|
|
//===== global state
|
|
|
|
|
|
|
|
|
|
|
|
static ETSTimer optibootTimer; |
|
|
|
static ETSTimer optibootTimer; |
|
|
@ -71,7 +73,7 @@ static void ICACHE_FLASH_ATTR optibootInit() { |
|
|
|
ackWait = 0; |
|
|
|
ackWait = 0; |
|
|
|
errMessage[0] = 0; |
|
|
|
errMessage[0] = 0; |
|
|
|
responseLen = 0; |
|
|
|
responseLen = 0; |
|
|
|
programmingCB = optibootUartRecv; |
|
|
|
programmingCB = NULL; |
|
|
|
if (optibootData != NULL) { |
|
|
|
if (optibootData != NULL) { |
|
|
|
if (optibootData->conn != NULL) |
|
|
|
if (optibootData->conn != NULL) |
|
|
|
optibootData->conn->cgiPrivData = (void *)-1; // signal that request has been aborted
|
|
|
|
optibootData->conn->cgiPrivData = (void *)-1; // signal that request has been aborted
|
|
|
@ -91,7 +93,9 @@ void ICACHE_FLASH_ATTR appendPretty(char *buf, char *raw, int max) { |
|
|
|
int i = 0; |
|
|
|
int i = 0; |
|
|
|
while (off < max-5) { |
|
|
|
while (off < max-5) { |
|
|
|
unsigned char c = raw[i++]; |
|
|
|
unsigned char c = raw[i++]; |
|
|
|
if (c >= ' ' && c <= '~') { |
|
|
|
if (c == 0) { |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} else if (c >= ' ' && c <= '~') { |
|
|
|
buf[off++] = c; |
|
|
|
buf[off++] = c; |
|
|
|
} else if (c == '\n') { |
|
|
|
} else if (c == '\n') { |
|
|
|
buf[off++] = '\\'; |
|
|
|
buf[off++] = '\\'; |
|
|
@ -103,7 +107,7 @@ void ICACHE_FLASH_ATTR appendPretty(char *buf, char *raw, int max) { |
|
|
|
buf[off++] = '\\'; |
|
|
|
buf[off++] = '\\'; |
|
|
|
buf[off++] = 'x'; |
|
|
|
buf[off++] = 'x'; |
|
|
|
buf[off++] = '0'+(unsigned char)((c>>4)+((c>>4)>9?7:0)); |
|
|
|
buf[off++] = '0'+(unsigned char)((c>>4)+((c>>4)>9?7:0)); |
|
|
|
buf[off++] = '0'+(unsigned char)((c&0xff)+((c&0xff)>9?7:0)); |
|
|
|
buf[off++] = '0'+(unsigned char)((c&0xf)+((c&0xf)>9?7:0)); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
buf[off] = 0; |
|
|
|
buf[off] = 0; |
|
|
@ -120,9 +124,12 @@ int ICACHE_FLASH_ATTR cgiOptibootSync(HttpdConnData *connData) { |
|
|
|
} else if (connData->requestType == HTTPD_METHOD_POST) { |
|
|
|
} else if (connData->requestType == HTTPD_METHOD_POST) { |
|
|
|
// issue reset
|
|
|
|
// issue reset
|
|
|
|
optibootInit(); |
|
|
|
optibootInit(); |
|
|
|
|
|
|
|
programmingCB = optibootUartRecv; |
|
|
|
serbridgeReset(); |
|
|
|
serbridgeReset(); |
|
|
|
|
|
|
|
#if DBG_GPIO5 |
|
|
|
makeGpio(5); |
|
|
|
makeGpio(5); |
|
|
|
gpio_output_set(0, (1<<5), (1<<5), 0); // output 0
|
|
|
|
gpio_output_set(0, (1<<5), (1<<5), 0); // output 0
|
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
// start sync timer
|
|
|
|
// start sync timer
|
|
|
|
os_timer_disarm(&optibootTimer); |
|
|
|
os_timer_disarm(&optibootTimer); |
|
|
@ -394,7 +401,9 @@ static bool pollAck() { |
|
|
|
char recv[16]; |
|
|
|
char recv[16]; |
|
|
|
uint16_t need = ackWait*2; |
|
|
|
uint16_t need = ackWait*2; |
|
|
|
uint16_t got = uart0_rx_poll(recv, need, 50000); |
|
|
|
uint16_t got = uart0_rx_poll(recv, need, 50000); |
|
|
|
|
|
|
|
#ifdef DBG_GPIO5 |
|
|
|
gpio_output_set(0, (1<<5), (1<<5), 0); // output 0
|
|
|
|
gpio_output_set(0, (1<<5), (1<<5), 0); // output 0
|
|
|
|
|
|
|
|
#endif |
|
|
|
if (got < need) { |
|
|
|
if (got < need) { |
|
|
|
os_strcpy(errMessage, "Timeout waiting for flash page to be programmed"); |
|
|
|
os_strcpy(errMessage, "Timeout waiting for flash page to be programmed"); |
|
|
|
return false; |
|
|
|
return false; |
|
|
@ -421,7 +430,9 @@ static bool ICACHE_FLASH_ATTR programPage(void) { |
|
|
|
DBG("OB pgm %d@0x%lx ackWait=%d\n", pgmLen, optibootData->address, ackWait); |
|
|
|
DBG("OB pgm %d@0x%lx ackWait=%d\n", pgmLen, optibootData->address, ackWait); |
|
|
|
|
|
|
|
|
|
|
|
// send address to optiboot (little endian format)
|
|
|
|
// send address to optiboot (little endian format)
|
|
|
|
|
|
|
|
#ifdef DBG_GPIO5 |
|
|
|
gpio_output_set((1<<5), 0, (1<<5), 0); // output 1
|
|
|
|
gpio_output_set((1<<5), 0, (1<<5), 0); // output 1
|
|
|
|
|
|
|
|
#endif |
|
|
|
ackWait++; |
|
|
|
ackWait++; |
|
|
|
uart0_write_char(STK_LOAD_ADDRESS); |
|
|
|
uart0_write_char(STK_LOAD_ADDRESS); |
|
|
|
uint16_t addr = optibootData->address >> 1; // word address
|
|
|
|
uint16_t addr = optibootData->address >> 1; // word address
|
|
|
@ -436,7 +447,9 @@ static bool ICACHE_FLASH_ATTR programPage(void) { |
|
|
|
armTimer(); |
|
|
|
armTimer(); |
|
|
|
|
|
|
|
|
|
|
|
// send page length (big-endian format, go figure...)
|
|
|
|
// send page length (big-endian format, go figure...)
|
|
|
|
|
|
|
|
#ifdef DBG_GPIO5 |
|
|
|
gpio_output_set((1<<5), 0, (1<<5), 0); // output 1
|
|
|
|
gpio_output_set((1<<5), 0, (1<<5), 0); // output 1
|
|
|
|
|
|
|
|
#endif |
|
|
|
ackWait++; |
|
|
|
ackWait++; |
|
|
|
uart0_write_char(STK_PROG_PAGE); |
|
|
|
uart0_write_char(STK_PROG_PAGE); |
|
|
|
uart0_write_char(pgmLen>>8); |
|
|
|
uart0_write_char(pgmLen>>8); |
|
|
@ -520,10 +533,10 @@ static short ICACHE_FLASH_ATTR skipInSync(char *buf, short length) { |
|
|
|
static void ICACHE_FLASH_ATTR optibootUartRecv(char *buf, short length) { |
|
|
|
static void ICACHE_FLASH_ATTR optibootUartRecv(char *buf, short length) { |
|
|
|
// append what we got to what we have accumulated
|
|
|
|
// append what we got to what we have accumulated
|
|
|
|
if (responseLen < RESP_SZ-1) { |
|
|
|
if (responseLen < RESP_SZ-1) { |
|
|
|
short cpy = RESP_SZ-1-responseLen; |
|
|
|
char *rb = responseBuf+responseLen; |
|
|
|
if (cpy > length) cpy = length; |
|
|
|
for (short i=0; i<length && (rb-responseBuf)<(RESP_SZ-1); i++) |
|
|
|
os_memcpy(responseBuf+responseLen, buf, cpy); |
|
|
|
if (buf[i] != 0) *rb++ = buf[i]; // don't copy NULL characters, TODO: fix it
|
|
|
|
responseLen += cpy; |
|
|
|
responseLen = rb-responseBuf; |
|
|
|
responseBuf[responseLen] = 0; // string terminator
|
|
|
|
responseBuf[responseLen] = 0; // string terminator
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|