//Cgi that allows the ESPFS image to be replaced via http POST int ICACHE_FLASH_ATTR cgiUploadRaw(HttpdConnData *connData) { if (connData->conn==NULL) { //Connection aborted. Clean up. return HTTPD_CGI_DONE; } int part = get_updatable_partition(); if (connData->post->processed == 0 && connData->getArgs!=0){ // First run, init the partition and prep if necessary part = connData->getArgs[0] - '0'; // Turn for arg (should be partition ID) into partition index os_printf("\nFlashing partition: %d\n", part); } SpiFlashOpResult ret; // The source should be 4byte aligned, so go ahead an flash whatever we have ret=flash_binary(connData->post->buff, connData->post->buffLen, part); if (ret != connData->post->buffLen){ os_printf("Error writing to the flash\n"); return HTTPD_CGI_DONE; } // Count bytes for data connData->post->processed += ret; os_printf("Wrote %d bytes (%dB of %d)\n", connData->post->buffSize, connData->post->processed, connData->post->len);//&connData->postBuff)); if (connData->post->processed == connData->post->len){ httpdSend(connData, "Finished uploading", -1); reset_flash(); return HTTPD_CGI_DONE; } else { return HTTPD_CGI_MORE; } }
// Do not run this method from within the Flash memory void print_flash_info() { reset_flash(); write_flash_unlock_sequence(); write_flash_command((unsigned char) FLASH_CMD_AUTOSELECT); unsigned short manuf_id = FLASH_EXTRACT(0x00); print_string("Flash Device Information (AUTOSELECT)\r\n"); print_string("Manufacturer ID: "); print_hex_unsigned(manuf_id); if ((manuf_id) == 0x01) print_string(" (Spansion)\r\n"); else print_string(" (Unknown)\r\n"); print_string("Device ID: "); //unsigned short dev_id_1 = FLASH_EXTRACT(0x01); unsigned short dev_id_2 = FLASH_EXTRACT(0x0E); //unsigned short dev_id_3 = FLASH_EXTRACT(0x0F); switch (dev_id_2) { case 0x28: print_string(" S29GL01GP - 1 Gb\r\n"); break; case 0x23: print_string(" S29GL512P - 512 Mb\r\n"); break; case 0x22: print_string(" S29GL256P - 256 Mb\r\n"); break; case 0x21: print_string(" S29GL128P - 128 Mb\r\n"); break; default: print_string(" Unknown\r\n"); break; } // Reset flash reset_flash(); }
uint8_t Init_Flash(){ read_flash(); if(!CheckMagicCode()){ reset_flash(); write_flash(); }else{ if(option.isISP == true){ option.isISP = false; write_flash(); ReinvokeISP(); } } return option.isOpposite; }
int erase_chip_flash() { int z; reset_flash(); write_flash_unlock_sequence(); write_flash_command((unsigned char) FLASH_CMD_ERASE_SETUP); write_flash_unlock_sequence(); write_flash_command((unsigned char) FLASH_CMD_CHIP_ERASE); DELAY(200); /*if (poll_status(FLASH_OP_ERASE, SECTOR_ADDRESS(0x00), 0) != 0) { write_flash_command((unsigned char) FLASH_CMD_RESET); return -1; }*/ print_string("OK\r\n"); return 0; }
void flash_reset(void) { reset_flash(); }
uint32_t IsConfig_Command(uint8_t *command, uint32_t size) { //Write Setting if (command[0] == 'W') { if (command[1] == 'S') { if (WS_Command(&command[2], size - 2)) SetOK(); else SetERR(); return 1; } else if (command[1] == 'C') { if (WC_Command(&command[2], size - 2)) SetOK(); else SetERR(); return 1; } else if (command[1] == 'O') { if (WO_Command(&command[2], size - 2)) SetOK(); else SetERR(); return 1; } else if (command[1] == 'H') { if (WH_Command(&command[2], size - 2)) SetOK(); else SetERR(); return 1; } } //Read Setting else if (command[0] == 'R') { if (command[1] == 'S') { RS_Command(ReadSetting, 30); return 1; } else if (command[1] == 'C') { RC_Command(ReadSetting, 30); return 1; } else if (command[1] == 'H') { RH_Command(&command[2], size - 2); return 1; } } //System else if (command[0] == 'S') { if (command[1] == 'R') { SetOK(); SendSerial(ReadSetting, 3); _delay_ms(100); NVIC_SystemReset(); } else if (command[1] == 'V') { write_flash(); SetOK(); return 1; } else if (command[1] == 'F') { reset_flash(); SetOK(); return 1; } } //Firmware else if (command[0] == 'F') { if (command[1] == 'U') { SetOK(); option.isISP = true; write_flash(); SendSerial(ReadSetting, 3); _delay_ms(100); NVIC_SystemReset(); //ReinvokeISP(); } else if (command[1] == 'V') { FV_Command(ReadSetting, 30); return 1; } } return 0; }
/* cgiUploadRaw */ int ICACHE_FLASH_ATTR cgiUploadRaw(HttpdConnection * ptConnection) { int iRet = 0; if (NULL == ptConnection->ptEspConnection) { /* connection aborted - clean up */ iRet = HTTPD_CGI_DONE; goto lblCleanup; } int iPartition = get_updatable_partition(); if ((0 == ptConnection->ptPost->cbProcessed) && (0 != ptConnection->pbGetArguments)) { /* first call - initialize partition and prepare if necessary */ /* convert to index */ iPartition = ptConnection->pbGetArguments[0] - '0'; #ifdef CGIFLASH_DEBUG os_printf("cgiUploadRaw: flashing partition %d\n", iPartition); #endif } SpiFlashOpResult cbFlashedBytes; /* source should be 4 byte aligned */ cbFlashedBytes = flash_binary(ptConnection->ptPost->pbBuffer, ptConnection->ptPost->cbBufferLength, iPartition); if (cbFlashedBytes != ptConnection->ptPost->cbBufferLength) { #ifdef CGIFLASH_DEBUG os_printf("cgiUploadRaw: error - wrote less bytes than required\n"); #endif iRet = HTTPD_CGI_DONE; goto lblCleanup; } /* update flashed bytes count */ ptConnection->ptPost->cbProcessed += cbFlashedBytes; #ifdef CGIFLASH_DEBUG os_printf("cgiUploadRaw: wrote %d bytes (%d of %d)\n", ptConnection->ptPost->cbMaxBufferSize, ptConnection->ptPost->cbProcessed, ptConnection->ptPost->cbPostLength); #endif /* check if reached write target */ if (ptConnection->ptPost->cbProcessed == ptConnection->ptPost->cbPostLength) { httpdSend(ptConnection, FINISHED_UPLOADING_STRING, -1); reset_flash(); iRet = HTTPD_CGI_DONE; goto lblCleanup; } else { iRet = HTTPD_CGI_MORE; goto lblCleanup; } lblCleanup: return iRet; }