Update the 8266 stuff to my newest build.

This commit is contained in:
cnlohr 2015-08-16 00:54:18 -04:00
parent 30648367b7
commit a1a3d94e28
13 changed files with 424 additions and 47 deletions

View file

@ -1,8 +1,7 @@
all : image.elf
FW_FILE_1:=0x00000.bin FW_FILE_1:=0x00000.bin
FW_FILE_2:=0x40000.bin FW_FILE_2:=0x40000.bin
TARGET_OUT:=image.elf TARGET_OUT:=image.elf
all : $(TARGET_OUT) $(FW_FILE_1) $(FW_FILE_2)
SRCS:=driver/uart.c \ SRCS:=driver/uart.c \
@ -24,7 +23,7 @@ SRCS:=driver/uart.c \
GCC_FOLDER:=~/esp8266/esp-open-sdk/xtensa-lx106-elf GCC_FOLDER:=~/esp8266/esp-open-sdk/xtensa-lx106-elf
ESPTOOL_PY:=~/esp8266/esptool/esptool.py ESPTOOL_PY:=~/esp8266/esptool/esptool.py
FW_TOOL:=~/esp8266/other/esptool/esptool FW_TOOL:=~/esp8266/other/esptool/esptool
SDK:=/home/cnlohr/esp8266/esp_iot_sdk_v1.2.0 SDK:=/home/cnlohr/esp8266/esp_iot_sdk_v1.3.0
PORT:=/dev/ttyUSB0 PORT:=/dev/ttyUSB0
#PORT:=/dev/ttyACM0 #PORT:=/dev/ttyACM0

View file

@ -128,7 +128,7 @@ int ICACHE_FLASH_ATTR issue_command(char * buffer, int retsize, char *pusrdata,
buffend += ets_sprintf( buffend, "!FM%d\r\n", r ); buffend += ets_sprintf( buffend, "!FM%d\r\n", r );
break; break;
} }
case 'w': case 'W': //Flash Write (FW#\n) <- # = byte pos. case 'w': case 'W': //Flash Write (FW#\n) <- # = byte pos. Reads until end-of-packet.
if( colon ) if( colon )
{ {
colon++; colon++;
@ -149,6 +149,48 @@ int ICACHE_FLASH_ATTR issue_command(char * buffer, int retsize, char *pusrdata,
} }
buffend += ets_sprintf(buffend, "!FW\r\n" ); buffend += ets_sprintf(buffend, "!FW\r\n" );
break; break;
case 'x': case 'X': //Flash Write Hex (FX#\t#\tDATTAAAAA) <- a = byte pos. b = length (in hex-pairs). Generally used for web-browser.
if( colon )
{
int i;
int siz = 0;
colon++;
char * colon2 = (char *) ets_strstr( (char*)colon, "\t" );
if( colon2 )
{
*colon2 = 0;
siz = my_atoi( colon );
}
//nr = place to write.
//siz = size to write.
//colon2 = data start.
if( colon2 && nr >= 524288)
{
colon2++;
int datlen = ((int)len - (colon2 - pusrdata))/2;
if( datlen > siz ) datlen = siz;
for( i = 0; i < datlen; i++ )
{
int8_t r1 = fromhex1( *(colon2++) );
int8_t r2 = fromhex1( *(colon2++) );
if( r1 == -1 || r2 == -1 ) goto failfx;
buffend[i] = (r1 << 4) | r2;
}
//ets_memcpy( buffer, colon2, datlen );
EnterCritical();
spi_flash_write( nr, (uint32*)buffend, (datlen/4)*4 );
ExitCritical();
buffend += ets_sprintf(buffend, "FX%d\t%d\r\n", nr, siz );
break;
}
}
failfx:
buffend += ets_sprintf(buffend, "!FX\r\n" );
break;
case 'r': case 'R': //Flash Read (FR#\n) <- # = sector. case 'r': case 'R': //Flash Read (FR#\n) <- # = sector.
if( colon ) if( colon )
{ {

View file

@ -45,7 +45,7 @@ void SHA1Transform(uint32 state[5], const uint8 buffer[64]);
//SPI_FLASH_SEC_SIZE 4096 //SPI_FLASH_SEC_SIZE 4096
void SPIEraseSector(uint16 sec); //Doesn't work? void SPIEraseSector(uint16 sec);
void SPIEraseArea(uint32 start,uint32 len); //Doesn't work? void SPIEraseArea(uint32 start,uint32 len); //Doesn't work?
void SPIEraseBlock(uint16 blk); void SPIEraseBlock(uint16 blk);
void SPIWrite(uint32 des_addr, uint32_t *src_addr, uint32_t size); void SPIWrite(uint32 des_addr, uint32_t *src_addr, uint32_t size);

View file

@ -7,7 +7,7 @@
#include <stdio.h> #include <stdio.h>
#define SRCSIZE 4096 #define SRCSIZE 4096
#define BLKSIZE 65536
static const char * key = ""; static const char * key = "";
static int keylen = 0; static int keylen = 0;
@ -211,30 +211,39 @@ static int MyRewriteFlash( char * command, int commandlen )
//Disable all interrupts. //Disable all interrupts.
ets_intr_lock(); ets_intr_lock();
ipl = (size1/SRCSIZE)+1; uart_tx_one_char( 'A' );
p = to1/SRCSIZE;
int j;
ipl = (size1/BLKSIZE)+1;
p = to1/BLKSIZE;
for( i = 0; i < ipl; i++ ) for( i = 0; i < ipl; i++ )
{ {
SPIEraseSector( p++ ); SPIEraseBlock( p++ );
SPIWrite( to1, (uint32_t*)(0x40200000 + from1), SRCSIZE );
to1 += SRCSIZE; for( j = 0; j < BLKSIZE/SRCSIZE; j++ )
from1 += SRCSIZE; {
SPIWrite( to1, (uint32_t*)(0x40200000 + from1), SRCSIZE );
to1 += SRCSIZE;
from1 += SRCSIZE;
}
} }
uart_tx_one_char( 'B' ); uart_tx_one_char( 'B' );
ipl = (size2/SRCSIZE)+1; ipl = (size2/BLKSIZE)+1;
p = to2/SRCSIZE; p = to2/BLKSIZE;
for( i = 0; i < ipl; i++ ) for( i = 0; i < ipl; i++ )
{ {
SPIEraseSector( p++ ); SPIEraseBlock( p++ );
SPIWrite( to2, (uint32_t*)(0x40200000 + from2), SRCSIZE ); for( j = 0; j < BLKSIZE/SRCSIZE; j++ )
to2 += SRCSIZE; {
from2 += SRCSIZE; SPIWrite( to2, (uint32_t*)(0x40200000 + from2), SRCSIZE );
to2 += SRCSIZE;
from2 += SRCSIZE;
}
} }
uart_tx_one_char( 'R' ); uart_tx_one_char( 'C' );
void(*rebootme)() = (void(*)())0x40000080; void(*rebootme)() = (void(*)())0x40000080;

View file

@ -515,12 +515,14 @@ void ICACHE_FLASH_ATTR WebSocketGotData( uint8_t c )
break; break;
case 5: //Established connection. case 5: //Established connection.
{ {
//XXX TODO: Seems to malfunction on large-ish packets. I know it has problems with 140-byte payloads.
if( curlen < 5 ) //Can't interpret packet. if( curlen < 5 ) //Can't interpret packet.
break; break;
uint8_t fin = c & 1; uint8_t fin = c & 1;
uint8_t opcode = c << 4; uint8_t opcode = c << 4;
uint32_t payloadlen = *(curdata++); uint16_t payloadlen = *(curdata++);
curlen--; curlen--;
if( !(payloadlen & 0x80) ) if( !(payloadlen & 0x80) )
{ {
@ -529,6 +531,8 @@ void ICACHE_FLASH_ATTR WebSocketGotData( uint8_t c )
break; break;
} }
payloadlen &= 0x7f;
if( payloadlen == 127 ) if( payloadlen == 127 )
{ {
//Very long payload. //Very long payload.
@ -543,10 +547,6 @@ void ICACHE_FLASH_ATTR WebSocketGotData( uint8_t c )
curdata += 2; curdata += 2;
curlen -= 2; curlen -= 2;
} }
else
{
payloadlen &= 0x7f;
}
wsmask[0] = curdata[0]; wsmask[0] = curdata[0];
wsmask[1] = curdata[1]; wsmask[1] = curdata[1];
@ -556,10 +556,21 @@ void ICACHE_FLASH_ATTR WebSocketGotData( uint8_t c )
curlen -= 4; curlen -= 4;
wsmaskplace = 0; wsmaskplace = 0;
//XXX Warning: When packets get larger, they may split the
//websockets packets into multiple parts. We could handle this
//but at the cost of prescious RAM. I am chosing to just drop those
//packets on the floor, and restarting the connection.
if( curlen < payloadlen )
{
HTDEBUG( "Websocket Fragmented. %d %d\n", curlen, payloadlen );
curhttp->state = HTTP_WAIT_CLOSE;
return;
}
WebSocketData( payloadlen ); WebSocketData( payloadlen );
curlen -= payloadlen; curlen -= payloadlen;
curdata += payloadlen; curdata += payloadlen;
break; break;
} }
default: default:

View file

@ -68,11 +68,26 @@ char tohex1( uint8_t i )
return (i<10)?('0'+i):('a'-10+i); return (i<10)?('0'+i):('a'-10+i);
} }
int8_t fromhex1( char c )
{
if( c >= '0' && c <= '9' )
return c - '0';
else if( c >= 'a' && c <= 'f' )
return c - 'a' + 10;
else if( c >= 'A' && c <= 'F' )
return c - 'A' + 10;
else
return -1;
}
void ICACHE_FLASH_ATTR EndTCPWrite( struct espconn * conn ) void ICACHE_FLASH_ATTR EndTCPWrite( struct espconn * conn )
{ {
if(generic_ptr!=generic_buffer) if(generic_ptr!=generic_buffer)
espconn_sent(conn,generic_buffer,generic_ptr-generic_buffer); {
int r = espconn_sent(conn,generic_buffer,generic_ptr-generic_buffer);
}
} }
@ -93,6 +108,9 @@ void PushBlob( const uint8 * buffer, int len )
int8_t TCPCanSend( struct espconn * conn, int size ) int8_t TCPCanSend( struct espconn * conn, int size )
{ {
#ifdef SAFESEND
return TCPDoneSend( conn );
#else
struct espconn_packet infoarg; struct espconn_packet infoarg;
sint8 r = espconn_get_packet_info(conn, &infoarg); sint8 r = espconn_get_packet_info(conn, &infoarg);
@ -100,6 +118,7 @@ int8_t TCPCanSend( struct espconn * conn, int size )
return 1; return 1;
else else
return 0; return 0;
#endif
} }
int8_t ICACHE_FLASH_ATTR TCPDoneSend( struct espconn * conn ) int8_t ICACHE_FLASH_ATTR TCPDoneSend( struct espconn * conn )

View file

@ -5,6 +5,7 @@
#ifndef _MYSTUFF_H #ifndef _MYSTUFF_H
#define _MYSTUFF_H #define _MYSTUFF_H
#include <mem.h> #include <mem.h>
#include <c_types.h> #include <c_types.h>
#include <user_interface.h> #include <user_interface.h>
@ -12,6 +13,14 @@
#include <espconn.h> #include <espconn.h>
#include <esp8266_rom.h> #include <esp8266_rom.h>
//XXX WARNING As of 1.3.0, "cansend" doesn't work.
//the SDK seems to misbehave when trying to send without a full
//response packet.
#define SAFESEND
extern char generic_print_buffer[384]; extern char generic_print_buffer[384];
extern const char * enctypes[6];// = { "open", "wep", "wpa", "wpa2", "wpa_wpa2", 0 }; extern const char * enctypes[6];// = { "open", "wep", "wpa", "wpa2", "wpa_wpa2", 0 };
@ -19,6 +28,7 @@ extern const char * enctypes[6];// = { "open", "wep", "wpa", "wpa2", "wpa_wpa2",
#define printf( ... ) ets_sprintf( generic_print_buffer, __VA_ARGS__ ); uart0_sendStr( generic_print_buffer ); #define printf( ... ) ets_sprintf( generic_print_buffer, __VA_ARGS__ ); uart0_sendStr( generic_print_buffer );
char tohex1( uint8_t i ); char tohex1( uint8_t i );
int8_t fromhex1( char c ); //returns -1 if not hex char.
int32 my_atoi( const char * in ); int32 my_atoi( const char * in );
void Uint32To10Str( char * out, uint32 dat ); void Uint32To10Str( char * out, uint32 dat );

View file

@ -10,6 +10,7 @@
* 2014/3/12, v1.0 create this file. * 2014/3/12, v1.0 create this file.
* [various] Not released, Modified by Charles Lohr to change the RX behavior * [various] Not released, Modified by Charles Lohr to change the RX behavior
*******************************************************************************/ *******************************************************************************/
#include <c_types.h>
#include <osapi.h> #include <osapi.h>
#include <ets_sys.h> #include <ets_sys.h>
#include <driver/uart.h> #include <driver/uart.h>

Binary file not shown.

View file

@ -1,13 +1,13 @@
all : execute_reflash page.dat push all : execute_reflash page.mpfs push
IP?=192.168.4.1 IP?=192.168.4.1
mfsmaker : mfsmaker.c mfsmaker : mfsmaker.c
gcc -o $@ $^ gcc -o $@ $^
page.dat : mfsmaker page page.mpfs : mfsmaker page
# cat to_compress/*.js | gzip -9 > page/compressed.js.gz # cat to_compress/*.js | gzip -9 > page/compressed.js.gz
./mfsmaker page page.dat ./mfsmaker page page.mpfs
pushtodev : pushtodev.c pushtodev : pushtodev.c
gcc -o $@ $^ gcc -o $@ $^
@ -15,8 +15,8 @@ pushtodev : pushtodev.c
execute_reflash : execute_reflash.c md5.c execute_reflash : execute_reflash.c md5.c
gcc -o $@ $^ gcc -o $@ $^
push : pushtodev page.dat push : pushtodev page.mpfs
./pushtodev $(IP) 1048576 page.dat ./pushtodev $(IP) 1048576 page.mpfs
clean : clean :
rm -rf mfsmaker page.dat pushtodev execute_reflash rm -rf mfsmaker page.mpfs pushtodev execute_reflash

View file

@ -107,7 +107,7 @@ int main( int argc, char ** argv )
int rs = buf.st_size; int rs = buf.st_size;
rs = (rs+1+MFS_SECTOR)&(~(MFS_SECTOR-1)); rs = (rs+1+MFS_SECTOR)&(~(MFS_SECTOR-1));
datapointer += rs; datapointer += rs;
printf( "%s: %d (%d)\n", thisfile, rs, datapointer ); printf( "%s: %d (%ld)\n", thisfile, rs, datapointer );
} }
} }
} }
@ -121,7 +121,7 @@ int main( int argc, char ** argv )
mfsfat[i].start = ENDIAN(mfsfat[i].start + rs ); mfsfat[i].start = ENDIAN(mfsfat[i].start + rs );
} }
printf( "%d %d\n", rs, datapointer ); printf( "%d %ld\n", rs, datapointer );
FILE * f = fopen( argv[2], "w" ); FILE * f = fopen( argv[2], "w" );

View file

@ -13,6 +13,7 @@ td { vertical-align: top; }
.collapsible { display:none; } .collapsible { display:none; }
.inbutton { background-color:blue; } .inbutton { background-color:blue; }
#SystemMessage { position: fixed; top: 5px; background-color: DarkSlateBlue; color: #ffffff; left: 5px; display:none; } #SystemMessage { position: fixed; top: 5px; background-color: DarkSlateBlue; color: #ffffff; left: 5px; display:none; }
.dragandrophandler { border:2px dotted #0B85A1; color:#92AAB0;vertical-align:middle;padding:10px 10px 10 10px;margin-bottom:10px;font-size:200%;}
</style> </style>
</head> </head>
<body> <body>

View file

@ -6,6 +6,10 @@ var output;
var websocket; var websocket;
var commsup = 0; var commsup = 0;
var mpfs_start_at = 1048576;
var flash_scratchpad_at = 524288;
var flash_blocksize = 65536;
var flash_sendsize = 256;
//Push objects that have: //Push objects that have:
// .request // .request
// .callback = function( ref (this object), data ); // .callback = function( ref (this object), data );
@ -93,20 +97,35 @@ function init()
<td align=center>13<input type=button id=ButtonGPIO13 value=0 onclick=\"TwiddleGPIO(13);\"><input type=button id=BGPIOIn13 value=In onclick=\"GPIOInput(13);\" class=\"inbutton\"></td> \ <td align=center>13<input type=button id=ButtonGPIO13 value=0 onclick=\"TwiddleGPIO(13);\"><input type=button id=BGPIOIn13 value=In onclick=\"GPIOInput(13);\" class=\"inbutton\"></td> \
<td align=center>14<input type=button id=ButtonGPIO14 value=0 onclick=\"TwiddleGPIO(14);\"><input type=button id=BGPIOIn14 value=In onclick=\"GPIOInput(14);\" class=\"inbutton\"></td> \ <td align=center>14<input type=button id=ButtonGPIO14 value=0 onclick=\"TwiddleGPIO(14);\"><input type=button id=BGPIOIn14 value=In onclick=\"GPIOInput(14);\" class=\"inbutton\"></td> \
<td align=center>15<input type=button id=ButtonGPIO15 value=0 onclick=\"TwiddleGPIO(15);\"><input type=button id=BGPIOIn15 value=In onclick=\"GPIOInput(15);\" class=\"inbutton\"></td> \ <td align=center>15<input type=button id=ButtonGPIO15 value=0 onclick=\"TwiddleGPIO(15);\"><input type=button id=BGPIOIn15 value=In onclick=\"GPIOInput(15);\" class=\"inbutton\"></td> \
</tr></table></div></td></tr>"); </tr></table></div></td></tr>\
\
<tr><td width=1>\
<input type=submit onclick=\"ShowHideEvent( 'SystemReflash' );\" value=\"System Reflash\"></td><td>\
<div id=SystemReflash class=\"collapsible\">\
<div id=InnerSystemReflash class=\"dragandrophandler\">\
<input id=\"dragndropersystem\" type=\"file\" multiple> <div id=innersystemflashtext>Drop or browse for system (0x000.. 0x400...) or web (.mpfs) reflash files.</div>\
</div></div></td></tr>\
");
MakeDragDrop( "InnerSystemReflash", DragDropSystemFiles );
$("#dragndropersystem").change(function() { DragDropSystemFiles(this.files ); });
$( ".collapsible" ).each(function( index ) { $( ".collapsible" ).each(function( index ) {
if( localStorage["sh" + this.id] > 0.5 ) if( localStorage["sh" + this.id] > 0.5 )
{ {
$( this ).show().toggleClass( 'opened' ); $( this ).show().toggleClass( 'opened' );
// console.log( "OPEN: " + this.id );
} }
}); });
$("#custom_command_response").val( "" ); $("#custom_command_response").val( "" );
//Preclude drag and drop on rest of document in event user misses firmware boxes.
donothing = function(e) {e.stopPropagation();e.preventDefault();};
$(document).on('drop', donothing );
$(document).on('dragover', donothing );
$(document).on('dragenter', donothing );
output = document.getElementById("output"); output = document.getElementById("output");
Ticker(); Ticker();
@ -146,7 +165,7 @@ function onClose(evt)
var msg = 0; var msg = 0;
var tickmessage = 0; var tickmessage = 0;
var lasthz = 0; var lasthz = 0;
var time_since_hz = 0;
function Ticker() function Ticker()
{ {
setTimeout( Ticker, 1000 ); setTimeout( Ticker, 1000 );
@ -155,14 +174,21 @@ function Ticker()
tickmessage = msg; tickmessage = msg;
if( lasthz == 0 ) if( lasthz == 0 )
{ {
$('#SystemStatusClicker').css("color", "red" ); time_since_hz++;
$('#SystemStatusClicker').prop( "value", "System Offline" ); if( time_since_hz > 3 )
if( commsup != 0 && !is_waiting_on_stations ) IssueSystemMessage( "Comms Lost." ); {
commsup = 0; $('#SystemStatusClicker').css("color", "red" );
StartWebSocket(); $('#SystemStatusClicker').prop( "value", "System Offline" );
if( commsup != 0 && !is_waiting_on_stations ) IssueSystemMessage( "Comms Lost." );
commsup = 0;
StartWebSocket();
}
else
$('#SystemStatusClicker').prop( "value", "System " + 0 + "Hz" );
} }
else else
{ {
time_since_hz = 0;
$('#SystemStatusClicker').prop( "value", "System " + lasthz + "Hz" ); $('#SystemStatusClicker').prop( "value", "System " + lasthz + "Hz" );
} }
} }
@ -250,6 +276,52 @@ function IssueCustomCommand()
function MakeDragDrop( divname, callback )
{
var obj = $("#" + divname);
obj.on('dragenter', function (e)
{
e.stopPropagation();
e.preventDefault();
$(this).css('border', '2px solid #0B85A1');
});
obj.on('dragover', function (e)
{
e.stopPropagation();
e.preventDefault();
});
obj.on('dragend', function (e)
{
e.stopPropagation();
e.preventDefault();
$(this).css('border', '2px dotted #0B85A1');
});
obj.on('drop', function (e)
{
$(this).css('border', '2px dotted #0B85A1');
e.preventDefault();
var files = e.originalEvent.dataTransfer.files;
//We need to send dropped files to Server
callback(files);
});
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
///Below here are mostly just events...
did_wifi_get_config = false; did_wifi_get_config = false;
is_data_ticker_running = false; is_data_ticker_running = false;
is_waiting_on_stations = false; is_waiting_on_stations = false;
@ -396,7 +468,7 @@ function GPIOInput( gp )
} }
function GPIOUpdate(req,data) { function GPIOUpdate(req,data) {
var secs = data.split( ":" ); var secs = data.split( "\t" );
var op = 0; var op = 0;
var n = Number(secs[2]); var n = Number(secs[2]);
var m = Number(secs[1]); var m = Number(secs[1]);
@ -436,11 +508,11 @@ function GPIOUpdate(req,data) {
b.attr( "value", "in" ); b.attr( "value", "in" );
} }
} }
} }
if( IsTabOpen('GPIOs') ) if( IsTabOpen('GPIOs') )
{
QueueOperation( "GS", GPIOUpdate ); QueueOperation( "GS", GPIOUpdate );
}
} }
function GPIODataTicker() function GPIODataTicker()
@ -462,6 +534,147 @@ function GPIODataTickerStart()
function SystemPushImageProgress( is_ok, comment, pushop )
{
if( !is_ok )
{
$("#innersystemflashtext").html( "Failed: " + comment );
return;
}
$("#innersystemflashtext").html( comment );
if( pushop.place == pushop.padlen )
{
if( pushop.ctx.current_state == 0 ) //File 1 is completing.
{
pushop.ctx.current_state = 1;
pushop.ctx.file1wassize = pushop.padlen;
pushop.ctx.file1md5 = faultylabs.MD5( pushop.paddata ).toLowerCase();
var reader = new FileReader();
reader.onload = function(e) {
$("#innersystemflashtext").html( "Pusing second half..." );
PushImageTo( e.target.result, flash_scratchpad_at + 0x40000, SystemPushImageProgress, pushop.ctx );
}
reader.readAsArrayBuffer( pushop.ctx.file2 );
}
else if( pushop.ctx.current_state == 1 )
{
var f1s = pushop.ctx.file1wassize;
var f1m = pushop.ctx.file1md5;
var f2s = pushop.padlen;
var f2m = faultylabs.MD5( pushop.paddata ).toLowerCase();
$("#innersystemflashtext").html( "Issuing reflash. Do not expect a response." );
var stf = "FM" + flash_scratchpad_at + "\t0\t" + f1s + "\t" + f1m + "\t" + (flash_scratchpad_at+0x40000) + "\t" + 0x40000 + "\t" + f2s + "\t" + f2m + "\n";
var fun = function( fsrd, flashresponse ) { $("#innerflashtext").html( (flashresponse[0] == '!')?"Flashing failed.":"Flash success." ) };
QueueOperation( stf, fun);
}
return false;
}
return true;
}
function WebPagePushImageFunction( ok, comment, pushop )
{
if( pushop.place == pushop.padlen )
{
$("#innersystemflashtext").html("Push complete. Reload page.");
}
else
{
$("#innersystemflashtext").html(comment);
}
return true;
}
function DragDropSystemFiles( file )
{
if( file.length == 1 )
{
//webpage ".mpfs" file.
var fn = file[0].name;
if( fn.substr( fn.length - 5 ) != ".mpfs" )
{
$("#innersystemflashtext").html( "Web files are .mfps files." );
return;
}
$("#innersystemflashtext").html( "Opening " + fn );
var reader = new FileReader();
reader.onload = function(e) {
PushImageTo( e.target.result, mpfs_start_at, WebPagePushImageFunction );
}
reader.readAsArrayBuffer( file[0] );
}
else if( file.length == 2 )
{
var file1 = null;
var file2 = null;
for( var i = 0; i < file.length; i++ )
{
if( file[i].name.substr( 0, 7 ) == "0x00000" ) file1 = file[i];
if( file[i].name.substr( 0, 7 ) == "0x40000" ) file2 = file[i];
}
if( !file1 )
{
$("#innersystemflashtext").html( "Could not find a 0x00000... file." ); return;
}
if( !file2 )
{
$("#innersystemflashtext").html( "Could not find a 0x40000... file." ); return;
}
if( file1.size > 65536 )
{
$("#innersystemflashtext").html( "0x00000 needs to fit in IRAM. Too big." ); return;
}
if( file2.size > 262144 )
{
$("#innersystemflashtext").html( "0x40000 needs to fit in 256kB. Too big." ); return;
}
//Files check out. Start pushing.
$("#innersystemflashtext").html( "Starting." );
var reader = new FileReader();
reader.onload = function(e) {
var ctx = new Object();
ctx.file1 = file1;
ctx.file2 = file2;
ctx.current_state = 0;
PushImageTo( e.target.result, flash_scratchpad_at, SystemPushImageProgress, ctx );
}
reader.readAsArrayBuffer( file[0] );
return;
}
else
{
$("#innersystemflashtext").html( "Cannot accept anything other than 1 or 2 files." );
}
}
@ -471,3 +684,75 @@ function tohex8( c )
var hex = c.toString(16); var hex = c.toString(16);
return hex.length == 1 ? "0" + hex : hex; return hex.length == 1 ? "0" + hex : hex;
} }
function ContinueSystemFlash( fsrd, flashresponse, pushop )
{
if( flashresponse[0] == '!' )
{
pushop.status_callback( 0, flashresponse, pushop );
console.log( flashresponse );
return;
}
var cont = pushop.status_callback( 1, flashresponse, pushop );
if( !cont ) return;
if( pushop.place >= pushop.padlen ) return;
//If we are coming from a write, and now we need to erase the next block, do so.
if( ( pushop.place % flash_blocksize ) == 0 && flashresponse[1] != 'B' )
{
QueueOperation( "FB" + ((pushop.place+pushop.base_address)/flash_blocksize), function( x, y ) { ContinueSystemFlash( x, y, pushop ); } );
}
else //Done erasing the next block, or coming off a write we don't need to erase?
{
var addy = pushop.place + pushop.base_address;
var sendstr = "FX" + addy + "\t" + flash_sendsize + "\t";
for( var i = 0; i < flash_sendsize; i++ )
{
sendstr += tohex8( pushop.paddata[pushop.place++] );
}
QueueOperation( sendstr, function( x, y ) { ContinueSystemFlash( x, y, pushop ); } );
}
}
//The signature for status callback is: function AVRStatusCallback( is_ok, comment, pushop )
//If pushop.place == pushop.padlen, no further callbacks will continue, even if true is returned.
//you must return "true." Returning false will cease further pushing.
//This function returns an object with all properties about the transfer.
//WARNING: "location" must be block (65536) aligned.
function PushImageTo( arraydata, location, status_callback, ctx )
{
if( location & 0xffff != 0 )
{
console.log( "Error: to address not 65,536 aligned." );
return null;
}
var pushop = Object();
pushop.padlen = Math.floor(((arraydata.byteLength-1)/flash_sendsize)+1)*flash_sendsize;
pushop.paddata = new Uint8Array( pushop.padlen, 0 );
pushop.paddata.set( new Uint8Array( arraydata ), 0 );
pushop.status_callback = status_callback;
pushop.place = 0;
pushop.base_address = location;
pushop.ctx = ctx;
ContinueSystemFlash( null, "Starting", pushop );
return pushop;
}
/* MD5 implementation minified from: http://blog.faultylabs.com/files/md5.js
Javascript MD5 library - version 0.4 Coded (2011) by Luigi Galli - LG@4e71.org - http://faultylabs.com
Thanks to: Roberto Viola The below code is PUBLIC DOMAIN - NO WARRANTY!
*/
"undefined"==typeof faultylabs&&(faultylabs={}),faultylabs.MD5=function(n){function r(n){var r=(n>>>0).toString(16);return"00000000".substr(0,8-r.length)+r}function t(n){for(var r=[],t=0;t<n.length;t++)r=r.concat(s(n[t]));return r}function e(n){for(var r=[],t=0;8>t;t++)r.push(255&n),n>>>=8;return r}function o(n,r){return n<<r&4294967295|n>>>32-r}function a(n,r,t){return n&r|~n&t}function f(n,r,t){return t&n|~t&r}function u(n,r,t){return n^r^t}function i(n,r,t){return r^(n|~t)}function c(n,r){return n[r+3]<<24|n[r+2]<<16|n[r+1]<<8|n[r]}function s(n){for(var r=[],t=0;t<n.length;t++)if(n.charCodeAt(t)<=127)r.push(n.charCodeAt(t));else for(var e=encodeURIComponent(n.charAt(t)).substr(1).split("%"),o=0;o<e.length;o++)r.push(parseInt(e[o],16));return r}function l(){for(var n="",t=0,e=0,o=3;o>=0;o--)e=arguments[o],t=255&e,e>>>=8,t<<=8,t|=255&e,e>>>=8,t<<=8,t|=255&e,e>>>=8,t<<=8,t|=e,n+=r(t);return n}function y(n){for(var r=new Array(n.length),t=0;t<n.length;t++)r[t]=n[t];return r}function h(n,r){return 4294967295&n+r}function p(){function n(n,r,t,e){var a=m;m=U,U=d,d=h(d,o(h(b,h(n,h(r,t))),e)),b=a}var r=A.length;A.push(128);var t=A.length%64;if(t>56){for(var s=0;64-t>s;s++)A.push(0);t=A.length%64}for(s=0;56-t>s;s++)A.push(0);A=A.concat(e(8*r));var y=1732584193,p=4023233417,g=2562383102,v=271733878,b=0,d=0,U=0,m=0;for(s=0;s<A.length/64;s++){b=y,d=p,U=g,m=v;var I=64*s;n(a(d,U,m),3614090360,c(A,I),7),n(a(d,U,m),3905402710,c(A,I+4),12),n(a(d,U,m),606105819,c(A,I+8),17),n(a(d,U,m),3250441966,c(A,I+12),22),n(a(d,U,m),4118548399,c(A,I+16),7),n(a(d,U,m),1200080426,c(A,I+20),12),n(a(d,U,m),2821735955,c(A,I+24),17),n(a(d,U,m),4249261313,c(A,I+28),22),n(a(d,U,m),1770035416,c(A,I+32),7),n(a(d,U,m),2336552879,c(A,I+36),12),n(a(d,U,m),4294925233,c(A,I+40),17),n(a(d,U,m),2304563134,c(A,I+44),22),n(a(d,U,m),1804603682,c(A,I+48),7),n(a(d,U,m),4254626195,c(A,I+52),12),n(a(d,U,m),2792965006,c(A,I+56),17),n(a(d,U,m),1236535329,c(A,I+60),22),n(f(d,U,m),4129170786,c(A,I+4),5),n(f(d,U,m),3225465664,c(A,I+24),9),n(f(d,U,m),643717713,c(A,I+44),14),n(f(d,U,m),3921069994,c(A,I),20),n(f(d,U,m),3593408605,c(A,I+20),5),n(f(d,U,m),38016083,c(A,I+40),9),n(f(d,U,m),3634488961,c(A,I+60),14),n(f(d,U,m),3889429448,c(A,I+16),20),n(f(d,U,m),568446438,c(A,I+36),5),n(f(d,U,m),3275163606,c(A,I+56),9),n(f(d,U,m),4107603335,c(A,I+12),14),n(f(d,U,m),1163531501,c(A,I+32),20),n(f(d,U,m),2850285829,c(A,I+52),5),n(f(d,U,m),4243563512,c(A,I+8),9),n(f(d,U,m),1735328473,c(A,I+28),14),n(f(d,U,m),2368359562,c(A,I+48),20),n(u(d,U,m),4294588738,c(A,I+20),4),n(u(d,U,m),2272392833,c(A,I+32),11),n(u(d,U,m),1839030562,c(A,I+44),16),n(u(d,U,m),4259657740,c(A,I+56),23),n(u(d,U,m),2763975236,c(A,I+4),4),n(u(d,U,m),1272893353,c(A,I+16),11),n(u(d,U,m),4139469664,c(A,I+28),16),n(u(d,U,m),3200236656,c(A,I+40),23),n(u(d,U,m),681279174,c(A,I+52),4),n(u(d,U,m),3936430074,c(A,I),11),n(u(d,U,m),3572445317,c(A,I+12),16),n(u(d,U,m),76029189,c(A,I+24),23),n(u(d,U,m),3654602809,c(A,I+36),4),n(u(d,U,m),3873151461,c(A,I+48),11),n(u(d,U,m),530742520,c(A,I+60),16),n(u(d,U,m),3299628645,c(A,I+8),23),n(i(d,U,m),4096336452,c(A,I),6),n(i(d,U,m),1126891415,c(A,I+28),10),n(i(d,U,m),2878612391,c(A,I+56),15),n(i(d,U,m),4237533241,c(A,I+20),21),n(i(d,U,m),1700485571,c(A,I+48),6),n(i(d,U,m),2399980690,c(A,I+12),10),n(i(d,U,m),4293915773,c(A,I+40),15),n(i(d,U,m),2240044497,c(A,I+4),21),n(i(d,U,m),1873313359,c(A,I+32),6),n(i(d,U,m),4264355552,c(A,I+60),10),n(i(d,U,m),2734768916,c(A,I+24),15),n(i(d,U,m),1309151649,c(A,I+52),21),n(i(d,U,m),4149444226,c(A,I+16),6),n(i(d,U,m),3174756917,c(A,I+44),10),n(i(d,U,m),718787259,c(A,I+8),15),n(i(d,U,m),3951481745,c(A,I+36),21),y=h(y,b),p=h(p,d),g=h(g,U),v=h(v,m)}return l(v,g,p,y).toUpperCase()}var A=null,g=null;return"string"==typeof n?A=s(n):n.constructor==Array?0===n.length?A=n:"string"==typeof n[0]?A=t(n):"number"==typeof n[0]?A=n:g=typeof n[0]:"undefined"!=typeof ArrayBuffer?n instanceof ArrayBuffer?A=y(new Uint8Array(n)):n instanceof Uint8Array||n instanceof Int8Array?A=y(n):n instanceof Uint32Array||n instanceof Int32Array||n instanceof Uint16Array||n instanceof Int16Array||n instanceof Float32Array||n instanceof Float64Array?A=y(new Uint8Array(n.buffer)):g=typeof n:g=typeof n,g&&alert("MD5 type mismatch, cannot process "+g),p()};