Modularize esp8266 components

This commit is contained in:
con-f-use 2016-08-19 00:13:41 +02:00
parent 1dd31cc7c3
commit 63be61e225
42 changed files with 65 additions and 4026 deletions

View file

@ -1,23 +0,0 @@
include ../makeconf.inc # Look here for user configuration
.PHONY : all clean push
all : execute_reflash push
CC = gcc
mfsmaker : mfsmaker.c
pushtodev : pushtodev.c
execute_reflash : execute_reflash.c md5.c
page.mpfs : mfsmaker page
# cat to_compress/*.js | gzip -9 > page/compressed.js.gz
./mfsmaker page page.mpfs
#mfsmaker pushtodev execute_reflash:
# $(CC) $(CFLAGS) -o $@ $^
push : pushtodev page.mpfs
./pushtodev $(IP) $(PAGE_OFFSET) page.mpfs
clean :
$(RM) mfsmaker page.mpfs pushtodev execute_reflash

1
embedded8266/web/Makefile Symbolic link
View file

@ -0,0 +1 @@
../esp82xx/web/Makefile

View file

@ -1,274 +0,0 @@
//Copyright 2015 <>< Charles Lohr Under the MIT/x11 License, NewBSD License or
// ColorChord License. You Choose.
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/time.h>
#include <sys/poll.h>
#include <sys/types.h>
#include <stdlib.h>
#include <string.h>
#include "md5.h"
#define BLOCK_SIZE 65536
#define SECTOR_SIZE 4096
#define PADDING 1024
#ifndef MSG_NOSIGNAL
#define MSG_NOSIGNAL 0x0 //Don't request NOSIGNAL on systems where this is not implemented.
#endif
int sockfd;
struct sockaddr_in servaddr,cliaddr;
int PushMatch( const char * match )
{
struct timeval tva, tvb;
gettimeofday( &tva, 0 );
gettimeofday( &tvb, 0 );
while( tvb.tv_sec - tva.tv_sec < 3 )
{
struct pollfd ufds;
ufds.fd = sockfd;
ufds.events = POLLIN;
int rv = poll(&ufds, 1, 100);
if( rv > 0 )
{
char recvline[10000];
int n=recvfrom(sockfd,recvline,10000,0,NULL,NULL);
// printf( "%s === %s\n", recvline, match );
if( strncmp( recvline, match, strlen( match ) ) == 0 )
{
printf( "Ok - " ); fflush( stdout );
return 0;
}
}
gettimeofday( &tvb, 0 );
}
return 1;
}
uint32_t Push( uint32_t offset, const char * file )
{
char sendline[1000];
char recvline[1000];
if( offset <= 0 )
{
fprintf( stderr, "Error: Cannot write to address 0 or before.\n" );
exit(-2);
}
FILE * f = fopen( file, "rb" );
if( !f || feof( f ) )
{
fprintf( stderr, "Error: cannot open file.\n" );
exit(-3);
}
int devo = 0;
int lastblock = -1;
while( !feof( f ) )
{
int tries;
int thissuccess;
char buffer[PADDING];
char bufferout[2000];
int reads = fread( buffer, 1, PADDING, f );
int sendplace = offset + devo;
int sendsize = PADDING;//reads;
int block = sendplace / BLOCK_SIZE;
memset( buffer + reads, 0, sendsize-reads );
if( block != lastblock )
{
char se[64];
int sel = sprintf( se, "FB%d\r\n", block );
thissuccess = 0;
for( tries = 0; tries < 10; tries++ )
{
char match[75];
printf( "Erase: %d\n", block );
sendto( sockfd, se, sel, MSG_NOSIGNAL, (struct sockaddr *)&servaddr,sizeof(servaddr));
sprintf( match, "FB%d", block );
if( PushMatch(match) == 0 ) { thissuccess = 1; break; }
printf( "Retry.\n" );
}
if( !thissuccess )
{
fprintf( stderr, "Error: Timeout in communications.\n" );
exit( -6 );
}
lastblock = block;
}
int r = sprintf( bufferout, "FW%d\t%d\t", sendplace, sendsize );
memcpy( bufferout + r, buffer, sendsize );
printf( "bufferout: %d %d\n", sendplace, sendsize );
thissuccess = 0;
for( tries = 0; tries < 10; tries++ )
{
char match[75];
sendto( sockfd, bufferout, sendsize + r, MSG_NOSIGNAL, (struct sockaddr *)&servaddr,sizeof(servaddr));
sprintf( match, "FW%d", sendplace );
if( PushMatch(match) == 0 ) { thissuccess = 1; break; }
printf( "Retry.\n" );
}
if( !thissuccess )
{
fprintf( stderr, "Error: Timeout in communications.\n" );
exit( -6 );
}
if( reads != 0 )
devo += sendsize;
}
return devo;
}
void ComputeMD5WithKey( char * md5retText, const char * filename, const char * key )
{
uint8_t retmd5[16];
MD5_CTX ctx;
FILE * f = fopen( filename, "rb" );
if( !f )
{
fprintf( stderr, "Error opening %s\n", filename );
exit( -9 );
}
fseek( f, 0, SEEK_END );
int l = ftell( f );
printf("MD5 Size: %d\n", l );
int padl = ((l-1) / PADDING)*PADDING+PADDING;
printf("MD5 Pad: %d\n", padl );
fseek( f, 0, SEEK_SET );
uint8_t data[padl];
fread( data, l, 1, f );
fclose( f );
memset( data+l, 0, padl-l );
MD5_Init( &ctx );
if( !strlen(key) )
MD5_Update( &ctx, key, strlen( key ) );
MD5_Update( &ctx, data, padl );
MD5_Final( retmd5, &ctx );
for( l = 0; l < 16; l++ )
{
sprintf( md5retText + l*2, "%02x", retmd5[l] );
}
return;
}
uint32_t roundup( uint32_t r )
{
return ((r-1)&(~0xFFF))+0x1000;
}
int main(int argc, char**argv)
{
int n;
char sendline[1000];
char recvline[1000];
char md5_f1[48];
char md5_f2[48];
if (argc < 4 )
{
printf("usage: pushtodev [IP address] [file_lower] [file_upper] [key (optional)]\n");
exit(-1);
}
const char * file1 = argv[2];
const char * file2 = argv[3];
sockfd=socket(AF_INET,SOCK_DGRAM,0);
bzero(&servaddr,sizeof(servaddr));
servaddr.sin_family = AF_INET;
servaddr.sin_addr.s_addr=inet_addr(argv[1]);
servaddr.sin_port=htons(7878);
uint32_t fs1 = Push( 0x080000, file1 );
uint32_t fs2 = Push( 0x0c0000, file2 );
if( !fs1 || !fs2 )
{
fprintf( stderr, "Error: File size not acceptable.\n" );
return 0;
}
const char * dat = "";
if( argc == 5 )
{
dat = argv[4];
}
ComputeMD5WithKey( md5_f1, file1, dat );
ComputeMD5WithKey( md5_f2, file2, dat );
printf( "%s %s\n", md5_f1, md5_f2 );
//FM[from_address]\t[to_address]\t[size]\t[MD5(key+data)]\t[from_address]\t[to_address]\t[size]\t[MD5(key+data)]
char cmd[1024];
sprintf( cmd, "FM%d\t%d\t%d\t%s\t%d\t%d\t%d\t%s\n",
0x080000,
0x000000,
fs1, //roundup( fs1 ),
md5_f1,
0x0C0000,
0x040000,
fs2, //roundup( fs2 ),
md5_f2 );
printf( "Issuing: %s\n", cmd );
sendto( sockfd, cmd, strlen(cmd), MSG_NOSIGNAL, (struct sockaddr *)&servaddr,sizeof(servaddr));
usleep(10000);
sendto( sockfd, cmd, strlen(cmd), MSG_NOSIGNAL, (struct sockaddr *)&servaddr,sizeof(servaddr));
struct pollfd ufds;
ufds.fd = sockfd;
ufds.events = POLLIN;
int rv = poll(&ufds, 1, 100);
if( rv > 0 )
{
char recvline[10000];
int n=recvfrom(sockfd,recvline,10000,0,NULL,NULL);
printf( "Response: %s\n",recvline );
return 0;
}
else
{
printf( "Timeout. Good? Maybe?\n" );
return 0;
}
return 0;
}

View file

@ -0,0 +1 @@
../esp82xx/web/execute_reflash.c

View file

@ -1,296 +0,0 @@
/*
* This is an OpenSSL-compatible implementation of the RSA Data Security, Inc.
* MD5 Message-Digest Algorithm (RFC 1321).
*
* Homepage:
* http://openwall.info/wiki/people/solar/software/public-domain-source-code/md5
*
* Author:
* Alexander Peslyak, better known as Solar Designer <solar at openwall.com>
*
* This software was written by Alexander Peslyak in 2001. No copyright is
* claimed, and the software is hereby placed in the public domain.
* In case this attempt to disclaim copyright and place the software in the
* public domain is deemed null and void, then the software is
* Copyright (c) 2001 Alexander Peslyak and it is hereby released to the
* general public under the following terms:
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted.
*
* There's ABSOLUTELY NO WARRANTY, express or implied.
*
* (This is a heavily cut-down "BSD license".)
*
* This differs from Colin Plumb's older public domain implementation in that
* no exactly 32-bit integer data type is required (any 32-bit or wider
* unsigned integer data type will do), there's no compile-time endianness
* configuration, and the function prototypes match OpenSSL's. No code from
* Colin Plumb's implementation has been reused; this comment merely compares
* the properties of the two independent implementations.
*
* The primary goals of this implementation are portability and ease of use.
* It is meant to be fast, but not as fast as possible. Some known
* optimizations are not included to reduce source code size and avoid
* compile-time configuration.
*/
#ifndef HAVE_OPENSSL
#include <string.h>
#include "md5.h"
/*
* The basic MD5 functions.
*
* F and G are optimized compared to their RFC 1321 definitions for
* architectures that lack an AND-NOT instruction, just like in Colin Plumb's
* implementation.
*/
#define F(x, y, z) ((z) ^ ((x) & ((y) ^ (z))))
#define G(x, y, z) ((y) ^ ((z) & ((x) ^ (y))))
#define H(x, y, z) (((x) ^ (y)) ^ (z))
#define H2(x, y, z) ((x) ^ ((y) ^ (z)))
#define I(x, y, z) ((y) ^ ((x) | ~(z)))
/*
* The MD5 transformation for all four rounds.
*/
#define STEP(f, a, b, c, d, x, t, s) \
(a) += f((b), (c), (d)) + (x) + (t); \
(a) = (((a) << (s)) | (((a) & 0xffffffff) >> (32 - (s)))); \
(a) += (b);
/*
* SET reads 4 input bytes in little-endian byte order and stores them
* in a properly aligned word in host byte order.
*
* The check for little-endian architectures that tolerate unaligned
* memory accesses is just an optimization. Nothing will break if it
* doesn't work.
*/
#if defined(__i386__) || defined(__x86_64__) || defined(__vax__)
#define SET(n) \
(*(MD5_u32plus *)&ptr[(n) * 4])
#define GET(n) \
SET(n)
#else
#define SET(n) \
(ctx->block[(n)] = \
(MD5_u32plus)ptr[(n) * 4] | \
((MD5_u32plus)ptr[(n) * 4 + 1] << 8) | \
((MD5_u32plus)ptr[(n) * 4 + 2] << 16) | \
((MD5_u32plus)ptr[(n) * 4 + 3] << 24))
#define GET(n) \
(ctx->block[(n)])
#endif
/*
* This processes one or more 64-byte data blocks, but does NOT update
* the bit counters. There are no alignment requirements.
*/
static const void *body(MD5_CTX *ctx, const void *data, unsigned long size)
{
const unsigned char *ptr;
MD5_u32plus a, b, c, d;
MD5_u32plus saved_a, saved_b, saved_c, saved_d;
ptr = (const unsigned char *)data;
a = ctx->a;
b = ctx->b;
c = ctx->c;
d = ctx->d;
do {
saved_a = a;
saved_b = b;
saved_c = c;
saved_d = d;
/* Round 1 */
STEP(F, a, b, c, d, SET(0), 0xd76aa478, 7)
STEP(F, d, a, b, c, SET(1), 0xe8c7b756, 12)
STEP(F, c, d, a, b, SET(2), 0x242070db, 17)
STEP(F, b, c, d, a, SET(3), 0xc1bdceee, 22)
STEP(F, a, b, c, d, SET(4), 0xf57c0faf, 7)
STEP(F, d, a, b, c, SET(5), 0x4787c62a, 12)
STEP(F, c, d, a, b, SET(6), 0xa8304613, 17)
STEP(F, b, c, d, a, SET(7), 0xfd469501, 22)
STEP(F, a, b, c, d, SET(8), 0x698098d8, 7)
STEP(F, d, a, b, c, SET(9), 0x8b44f7af, 12)
STEP(F, c, d, a, b, SET(10), 0xffff5bb1, 17)
STEP(F, b, c, d, a, SET(11), 0x895cd7be, 22)
STEP(F, a, b, c, d, SET(12), 0x6b901122, 7)
STEP(F, d, a, b, c, SET(13), 0xfd987193, 12)
STEP(F, c, d, a, b, SET(14), 0xa679438e, 17)
STEP(F, b, c, d, a, SET(15), 0x49b40821, 22)
/* Round 2 */
STEP(G, a, b, c, d, GET(1), 0xf61e2562, 5)
STEP(G, d, a, b, c, GET(6), 0xc040b340, 9)
STEP(G, c, d, a, b, GET(11), 0x265e5a51, 14)
STEP(G, b, c, d, a, GET(0), 0xe9b6c7aa, 20)
STEP(G, a, b, c, d, GET(5), 0xd62f105d, 5)
STEP(G, d, a, b, c, GET(10), 0x02441453, 9)
STEP(G, c, d, a, b, GET(15), 0xd8a1e681, 14)
STEP(G, b, c, d, a, GET(4), 0xe7d3fbc8, 20)
STEP(G, a, b, c, d, GET(9), 0x21e1cde6, 5)
STEP(G, d, a, b, c, GET(14), 0xc33707d6, 9)
STEP(G, c, d, a, b, GET(3), 0xf4d50d87, 14)
STEP(G, b, c, d, a, GET(8), 0x455a14ed, 20)
STEP(G, a, b, c, d, GET(13), 0xa9e3e905, 5)
STEP(G, d, a, b, c, GET(2), 0xfcefa3f8, 9)
STEP(G, c, d, a, b, GET(7), 0x676f02d9, 14)
STEP(G, b, c, d, a, GET(12), 0x8d2a4c8a, 20)
/* Round 3 */
STEP(H, a, b, c, d, GET(5), 0xfffa3942, 4)
STEP(H2, d, a, b, c, GET(8), 0x8771f681, 11)
STEP(H, c, d, a, b, GET(11), 0x6d9d6122, 16)
STEP(H2, b, c, d, a, GET(14), 0xfde5380c, 23)
STEP(H, a, b, c, d, GET(1), 0xa4beea44, 4)
STEP(H2, d, a, b, c, GET(4), 0x4bdecfa9, 11)
STEP(H, c, d, a, b, GET(7), 0xf6bb4b60, 16)
STEP(H2, b, c, d, a, GET(10), 0xbebfbc70, 23)
STEP(H, a, b, c, d, GET(13), 0x289b7ec6, 4)
STEP(H2, d, a, b, c, GET(0), 0xeaa127fa, 11)
STEP(H, c, d, a, b, GET(3), 0xd4ef3085, 16)
STEP(H2, b, c, d, a, GET(6), 0x04881d05, 23)
STEP(H, a, b, c, d, GET(9), 0xd9d4d039, 4)
STEP(H2, d, a, b, c, GET(12), 0xe6db99e5, 11)
STEP(H, c, d, a, b, GET(15), 0x1fa27cf8, 16)
STEP(H2, b, c, d, a, GET(2), 0xc4ac5665, 23)
/* Round 4 */
STEP(I, a, b, c, d, GET(0), 0xf4292244, 6)
STEP(I, d, a, b, c, GET(7), 0x432aff97, 10)
STEP(I, c, d, a, b, GET(14), 0xab9423a7, 15)
STEP(I, b, c, d, a, GET(5), 0xfc93a039, 21)
STEP(I, a, b, c, d, GET(12), 0x655b59c3, 6)
STEP(I, d, a, b, c, GET(3), 0x8f0ccc92, 10)
STEP(I, c, d, a, b, GET(10), 0xffeff47d, 15)
STEP(I, b, c, d, a, GET(1), 0x85845dd1, 21)
STEP(I, a, b, c, d, GET(8), 0x6fa87e4f, 6)
STEP(I, d, a, b, c, GET(15), 0xfe2ce6e0, 10)
STEP(I, c, d, a, b, GET(6), 0xa3014314, 15)
STEP(I, b, c, d, a, GET(13), 0x4e0811a1, 21)
STEP(I, a, b, c, d, GET(4), 0xf7537e82, 6)
STEP(I, d, a, b, c, GET(11), 0xbd3af235, 10)
STEP(I, c, d, a, b, GET(2), 0x2ad7d2bb, 15)
STEP(I, b, c, d, a, GET(9), 0xeb86d391, 21)
a += saved_a;
b += saved_b;
c += saved_c;
d += saved_d;
ptr += 64;
} while (size -= 64);
ctx->a = a;
ctx->b = b;
ctx->c = c;
ctx->d = d;
return ptr;
}
void MD5_Init(MD5_CTX *ctx)
{
ctx->a = 0x67452301;
ctx->b = 0xefcdab89;
ctx->c = 0x98badcfe;
ctx->d = 0x10325476;
ctx->lo = 0;
ctx->hi = 0;
}
void MD5_Update(MD5_CTX *ctx, const void *data, unsigned long size)
{
MD5_u32plus saved_lo;
unsigned long used, available;
saved_lo = ctx->lo;
if ((ctx->lo = (saved_lo + size) & 0x1fffffff) < saved_lo)
ctx->hi++;
ctx->hi += size >> 29;
used = saved_lo & 0x3f;
if (used) {
available = 64 - used;
if (size < available) {
memcpy(&ctx->buffer[used], data, size);
return;
}
memcpy(&ctx->buffer[used], data, available);
data = (const unsigned char *)data + available;
size -= available;
body(ctx, ctx->buffer, 64);
}
if (size >= 64) {
data = body(ctx, data, size & ~(unsigned long)0x3f);
size &= 0x3f;
}
memcpy(ctx->buffer, data, size);
}
void MD5_Final(unsigned char *result, MD5_CTX *ctx)
{
unsigned long used, available;
used = ctx->lo & 0x3f;
ctx->buffer[used++] = 0x80;
available = 64 - used;
if (available < 8) {
memset(&ctx->buffer[used], 0, available);
body(ctx, ctx->buffer, 64);
used = 0;
available = 64;
}
memset(&ctx->buffer[used], 0, available - 8);
ctx->lo <<= 3;
ctx->buffer[56] = ctx->lo;
ctx->buffer[57] = ctx->lo >> 8;
ctx->buffer[58] = ctx->lo >> 16;
ctx->buffer[59] = ctx->lo >> 24;
ctx->buffer[60] = ctx->hi;
ctx->buffer[61] = ctx->hi >> 8;
ctx->buffer[62] = ctx->hi >> 16;
ctx->buffer[63] = ctx->hi >> 24;
body(ctx, ctx->buffer, 64);
result[0] = ctx->a;
result[1] = ctx->a >> 8;
result[2] = ctx->a >> 16;
result[3] = ctx->a >> 24;
result[4] = ctx->b;
result[5] = ctx->b >> 8;
result[6] = ctx->b >> 16;
result[7] = ctx->b >> 24;
result[8] = ctx->c;
result[9] = ctx->c >> 8;
result[10] = ctx->c >> 16;
result[11] = ctx->c >> 24;
result[12] = ctx->d;
result[13] = ctx->d >> 8;
result[14] = ctx->d >> 16;
result[15] = ctx->d >> 24;
memset(ctx, 0, sizeof(*ctx));
}
#endif

1
embedded8266/web/md5.c Symbolic link
View file

@ -0,0 +1 @@
../esp82xx/web/md5.c

View file

@ -1,45 +0,0 @@
/*
* This is an OpenSSL-compatible implementation of the RSA Data Security, Inc.
* MD5 Message-Digest Algorithm (RFC 1321).
*
* Homepage:
* http://openwall.info/wiki/people/solar/software/public-domain-source-code/md5
*
* Author:
* Alexander Peslyak, better known as Solar Designer <solar at openwall.com>
*
* This software was written by Alexander Peslyak in 2001. No copyright is
* claimed, and the software is hereby placed in the public domain.
* In case this attempt to disclaim copyright and place the software in the
* public domain is deemed null and void, then the software is
* Copyright (c) 2001 Alexander Peslyak and it is hereby released to the
* general public under the following terms:
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted.
*
* There's ABSOLUTELY NO WARRANTY, express or implied.
*
* See md5.c for more information.
*/
#ifdef HAVE_OPENSSL
#include <openssl/md5.h>
#elif !defined(_MD5_H)
#define _MD5_H
/* Any 32-bit or wider unsigned integer data type will do */
typedef unsigned int MD5_u32plus;
typedef struct {
MD5_u32plus lo, hi;
MD5_u32plus a, b, c, d;
unsigned char buffer[64];
MD5_u32plus block[16];
} MD5_CTX;
extern void MD5_Init(MD5_CTX *ctx);
extern void MD5_Update(MD5_CTX *ctx, const void *data, unsigned long size);
extern void MD5_Final(unsigned char *result, MD5_CTX *ctx);
#endif

1
embedded8266/web/md5.h Symbolic link
View file

@ -0,0 +1 @@
../esp82xx/web/md5.h

View file

@ -1,146 +0,0 @@
//Copyright 2015 <>< Charles Lohr Under the MIT/x11 License, NewBSD License or
// ColorChord License. You Choose.
#include <stdio.h>
#include <dirent.h>
#include <sys/stat.h>
#include <string.h>
#include <stdint.h>
#define SPI_FLASH_SEC_SIZE 4096
#define MFS_STARTFLASHSECTOR 0x100
#define MFS_START (MFS_STARTFLASHSECTOR*SPI_FLASH_SEC_SIZE)
#define MFS_SECTOR 256
#define MFS_FILENAMELEN 32-8
#define ENTRIES 8192
#define ENDIAN(x) x//htonl
struct MFSFileEntry
{
char name[MFS_FILENAMELEN];
uint32_t start; //From beginning of mfs thing.
uint32_t len;
} mfsfat[ENTRIES];
unsigned char mfsdata[131072*8];
unsigned long fatpointer = 0;
unsigned long datapointer = 0;
int main( int argc, char ** argv )
{
int i;
DIR *d;
struct dirent *dir;
if( argc != 3 )
{
fprintf( stderr, "Error: [tool] [directory to pack] [output packed .dat file]\n" );
return -1;
}
d = opendir( argv[1] );
if (!d)
{
fprintf( stderr, "Error: cannot open folder for packing.\n" );
return -2;
}
memcpy( mfsfat[fatpointer].name, "MPFSMPFS", 8 );
mfsfat[fatpointer].start = 0;
mfsfat[fatpointer].len = 0;
fatpointer++;
while ((dir = readdir(d)) != NULL)
{
if( dir->d_type & DT_REG )
{
char thisfile[1024];
struct stat buf;
int dlen = strlen( dir->d_name );
int sprret = snprintf( thisfile, 1023, "%s/%s", argv[1], dir->d_name );
if( sprret > 1023 || sprret < 1 )
{
fprintf( stderr, "Error processing \"%s\" (snprintf)\n", dir->d_name );
continue;
}
int statret = stat( thisfile, &buf );
if( statret )
{
fprintf( stderr, "Error processing \"%s\" (stat)\n", dir->d_name );
continue;
}
if( dlen >= MFS_FILENAMELEN )
{
fprintf( stderr, "Warning: Fle \"%s\" too long.\n", dir->d_name );
continue;
}
if( fatpointer > ENTRIES )
{
fprintf( stderr, "Warning: Not enough entries to fit \"%s\".\n", dir->d_name );
continue;
}
if( buf.st_size + datapointer > sizeof( mfsdata ) )
{
fprintf( stderr, "Error: no space left.\n" );
return -1;
}
memcpy( mfsfat[fatpointer].name, dir->d_name, dlen );
mfsfat[fatpointer].start = datapointer;
mfsfat[fatpointer].len = ENDIAN( buf.st_size );
fatpointer++;
if( buf.st_size )
{
FILE * f = fopen( thisfile, "rb" );
if( !f )
{
fprintf( stderr, "Error: cannot open \"%s\" for reading.\n", dir->d_name );
return -9;
}
fread( &mfsdata[datapointer], 1, buf.st_size, f );
fclose( f );
int rs = buf.st_size;
rs = (rs+1+MFS_SECTOR)&(~(MFS_SECTOR-1));
datapointer += rs;
printf( "%s: %d (%ld)\n", thisfile, rs, datapointer );
}
}
}
closedir(d);
int rs = (fatpointer+1)*sizeof(struct MFSFileEntry);
rs = (rs+1+MFS_SECTOR)&(~(MFS_SECTOR-1));
for( i = 0; i < fatpointer; i++ )
{
mfsfat[i].start = ENDIAN(mfsfat[i].start + rs );
}
printf( "%d %ld\n", rs, datapointer );
FILE * f = fopen( argv[2], "w" );
if( !f || ferror( f ) )
{
fprintf( stderr, "Error: cannot open \"%s\" for writing.\n", argv[2] );
}
fwrite( mfsfat, rs, 1, f );
fwrite( mfsdata, datapointer, 1, f );
fclose( f );
return 0;
}

1
embedded8266/web/mfsmaker.c Symbolic link
View file

@ -0,0 +1 @@
../esp82xx/web/mfsmaker.c

View file

@ -1,11 +1,11 @@
<html>
<!-- Copyright (C) 2015 <>< Charles Lohr, see LICENSE file for more info.
This particular file may be licensed under the MIT/x11, New BSD or ColorChord Licenses. -->
<!-- Copyright (C) 2015 <>< Charles Lohr, see LICENSE file for more info. -->
<head>
<title>ColorChord Control Panel</title>
<script language="javascript" type="text/javascript" src=jquery-2.1.4.min.js.gz></script>
<script language="javascript" type="text/javascript" src={{PAGE_JQUERYFL}}></script>
<script language="javascript" type="text/javascript" src=menuinterface.js></script>
<script language="javascript" type="text/javascript" src=main.js></script>
{{PAGE_SCRIPT}}
<meta charset="UTF-8">
<style>
table { width: 100%; }
@ -82,7 +82,11 @@ input[type="range"]:before {left:0em; content: attr(min);}input[type="range"]:af
</table>
<p><font size=-2>Copyright (C) 2015 &lt&gt&lt Charles Lohr, See LICENSE file for more info.</font></p>
<font size=-2>
<p>Copyright (C) 2015-2016 &lt&gt&lt Charles Lohr, See LICENSE file for more info.</p>
<p id=version><font size=-2>{{VERSSTR}}</font></p>
<p style="margin-left: auto; float: left; font-size: 70%; text-align: left;"><a href={{PROJECT_URL}}><img src="https://raw.githubusercontent.com/github-archive/media/master/octocats/blacktocat-16.png" style="height: 1em;" alt="github-logo">{{PROJECT_NAME}}</a></p>
</font>
<div id=SystemMessage>...</div>
</body>
</html>

View file

@ -0,0 +1 @@
../../esp82xx/web/page/jquery-2.1.4.min.js.gz

View file

@ -47,6 +47,13 @@ function QueueOperation( command, callback )
function init()
{
GPIOlines = '';
for(var i=0; i<16; ++i)
GPIOlines += "<td align=center>"+ i
+ "<input type=button id=ButtonGPIO"+ i +" value=0 onclick=\"TwiddleGPIO("+ i +");\">"
+ "<input type=button id=BGPIOIn"+ i +" value=In onclick=\"GPIOInput("+ i +");\" class=\"inbutton\">"
+ "</td>";
$('#MainMenu > tbody:first-child').before( "\
<tr><td width=1> \
<input type=submit onclick=\"ShowHideEvent( 'SystemStatus' );\" value='System Status' id=SystemStatusClicker></td><td> \
@ -85,28 +92,17 @@ function init()
<tr><td width=1> \
<input type=submit onclick=\"ShowHideEvent( 'GPIOs' ); GPIODataTicker();\" value=\"GPIOs\"></td><td> \
<div id=GPIOs class=\"collapsible\"> \
<table width=100% border=1><tr> \
<td align=center>0<input type=button id=ButtonGPIO0 value=0 onclick=\"TwiddleGPIO(0);\"><input type=button id=BGPIOIn0 value=In onclick=\"GPIOInput(0);\" class=\"inbutton\"></td> \
<td align=center>1<input type=button id=ButtonGPIO1 value=0 onclick=\"TwiddleGPIO(1);\"><input type=button id=BGPIOIn1 value=In onclick=\"GPIOInput(1);\" class=\"inbutton\"></td> \
<td align=center>2<input type=button id=ButtonGPIO2 value=0 onclick=\"TwiddleGPIO(2);\"><input type=button id=BGPIOIn2 value=In onclick=\"GPIOInput(2);\" class=\"inbutton\"></td> \
<td align=center>3<input type=button id=ButtonGPIO3 value=0 onclick=\"TwiddleGPIO(3);\"><input type=button id=BGPIOIn3 value=In onclick=\"GPIOInput(3);\" class=\"inbutton\"></td> \
<td align=center>4<input type=button id=ButtonGPIO4 value=0 onclick=\"TwiddleGPIO(4);\"><input type=button id=BGPIOIn4 value=In onclick=\"GPIOInput(4);\" class=\"inbutton\"></td> \
<td align=center>5<input type=button id=ButtonGPIO5 value=0 onclick=\"TwiddleGPIO(5);\"><input type=button id=BGPIOIn5 value=In onclick=\"GPIOInput(5);\" class=\"inbutton\"></td> \
<td>...</td> \
<td align=center>12<input type=button id=ButtonGPIO12 value=0 onclick=\"TwiddleGPIO(12);\"><input type=button id=BGPIOIn12 value=In onclick=\"GPIOInput(12);\" 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>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>\
<table width=100% border=1><tr>" +
GPIOlines
+ "</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>\
");
</div></div></td></tr>"
);
MakeDragDrop( "InnerSystemReflash", DragDropSystemFiles );
$("#dragndropersystem").change(function() { DragDropSystemFiles(this.files ); });

View file

@ -1,236 +0,0 @@
//Unless what else is individually marked, all code in this file is
//Copyright 2015 <>< Charles Lohr Under the MIT/x11 License, NewBSD License or
// ColorChord License. You Choose.
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <stdio.h>
#include <sys/time.h>
#include <sys/poll.h>
#include <sys/types.h>
#include <stdlib.h>
#include <string.h>
#define sector_SIZE 4096
#ifndef MSG_NOSIGNAL
#define MSG_NOSIGNAL 0x0 //Don't request NOSIGNAL on systems where this is not implemented.
#endif
int sockfd;
char recvline[10000];
int PushMatch( const char * match )
{
struct timeval tva, tvb;
gettimeofday( &tva, 0 );
gettimeofday( &tvb, 0 );
while( tvb.tv_sec - tva.tv_sec < 3 ) //3 second timeout.
{
struct pollfd ufds;
ufds.fd = sockfd;
ufds.events = POLLIN;
int rv = poll(&ufds, 1, 500);
if( rv > 0 )
{
// tbuf = recvline;
int n=recvfrom(sockfd,recvline,10000,0,NULL,NULL);
// printf( "!!%d ->%s\n", n,recvline );
// printf( "%s === %s\n", recvline, match );
if( strncmp( recvline, match, strlen( match ) ) == 0 )
{
// printf( "Ok\n" ); fflush( stdout );
return 0;
}
}
gettimeofday( &tvb, 0 );
}
return 1;
}
int main(int argc, char**argv)
{
int n;
struct sockaddr_in servaddr,cliaddr;
char sendline[1000];
// char recvline[1000];
if (argc != 4)
{
printf("usage: pushtodev [IP address] [address offset] [file]\n");
exit(-1);
}
int offset = atoi( argv[2] );
const char * file = argv[3];
if( offset <= 0 )
{
fprintf( stderr, "Error: Cannot write to address 0 or before.\n" );
exit(-2);
}
FILE * f = fopen( file, "rb" );
if( !f || feof( f ) )
{
fprintf( stderr, "Error: cannot open file.\n" );
exit(-3);
}
sockfd=socket(AF_INET,SOCK_DGRAM,0);
bzero(&servaddr,sizeof(servaddr));
servaddr.sin_family = AF_INET;
servaddr.sin_addr.s_addr=inet_addr(argv[1]);
servaddr.sin_port=htons(7878);
int devo = 0;
int lastsector_block = -1;
int resend_times = 0;
int r;
while( !feof( f ) )
{
int tries;
int thissuccess;
char buffer[1024];
char bufferout[1600];
int reads = fread( buffer, 1, 1024, f );
int sendplace = offset + devo;
int sendsize = reads;
#ifdef SECTOR
int sector = sendplace / sector_SIZE;
if( sector != lastsector_block )
{
char se[64];
int sel = sprintf( se, "FE%d\r\n", sector );
thissuccess = 0;
for( tries = 0; tries < 10; tries++ )
{
char match[75];
printf( "Erase: %d\n", sector );
sendto( sockfd, se, sel, MSG_NOSIGNAL, (struct sockaddr *)&servaddr,sizeof(servaddr));
sprintf( match, "FE%d", sector );
if( PushMatch(match) == 0 ) { thissuccess = 1; break; }
printf( "Retry.\n" );
}
if( !thissuccess )
{
fprintf( stderr, "Error: Timeout in communications.\n" );
exit( -6 );
}
lastsector_block = sector;
}
#else //block
int block = sendplace / 65536;
if( block != lastsector_block )
{
char se[64];
int sel = sprintf( se, "FB%d\r\n", block );
thissuccess = 0;
for( tries = 0; tries < 10; tries++ )
{
char match[75];
printf( "Erase: %d\n", block );
sendto( sockfd, se, sel, MSG_NOSIGNAL, (struct sockaddr *)&servaddr,sizeof(servaddr));
sprintf( match, "FB%d", block );
if( PushMatch(match) == 0 ) { thissuccess = 1; break; }
printf( "Retry.\n" );
}
if( !thissuccess )
{
fprintf( stderr, "Error: Timeout in communications.\n" );
exit( -6 );
}
lastsector_block = block;
}
#endif
resend_times = 0;
resend:
r = sprintf( bufferout, "FW%d\t%d\t", sendplace, sendsize );
printf( "bufferout: %d %d %s\n", sendplace, sendsize, bufferout );
memcpy( bufferout + r, buffer, sendsize );
thissuccess = 0;
for( tries = 0; tries < 10; tries++ )
{
char match[75];
sendto( sockfd, bufferout, reads + r, MSG_NOSIGNAL, (struct sockaddr *)&servaddr,sizeof(servaddr));
sprintf( match, "FW%d", sendplace );
if( PushMatch(match) == 0 ) { thissuccess = 1; break; }
printf( "Retry.\n" );
}
if( !thissuccess )
{
fprintf( stderr, "Error: Timeout in communications.\n" );
exit( -6 );
}
/*
printf( "Verifying..." );
fflush( stdout );
int r = sprintf( bufferout, "FR%d:%d", sendplace, sendsize );
bufferout[r] = 0;
thissuccess = 0;
for( tries = 0; tries < 10; tries++ )
{
char match[1600];
sendto( sockfd, bufferout, r, MSG_NOSIGNAL, (struct sockaddr *)&servaddr,sizeof(servaddr));
devo += reads;
sprintf( match, "FR%08d", sendplace );
if( PushMatch(match) == 0 ) {
//Check data...
//printf( "RR:%s\n", recvline );
char * colon1 = strchr( recvline, ':' );
char * colon2 = (colon1)?strchr( colon1+1, ':' ):0;
//printf( "::%p %p \"%s\"\n", colon1, colon2,recvline );
if( colon2 )
{
if( memcmp( colon2+1, buffer, sendsize ) == 0 )
thissuccess = 1;
}
if( !thissuccess )
{
if( resend_times > 2 )
{
break;
}
resend_times++;
goto resend;
}
break;
}
printf( "Retry.\n" );
}
if( !thissuccess )
{
fprintf( stderr, "Error: Fault verifying.\n" );
exit( -6 );
}
*/
devo += reads;
}
return 0;
}

View file

@ -0,0 +1 @@
../esp82xx/web/pushtodev.c