Added espFsInit call
This commit is contained in:
+22
-7
@@ -35,7 +35,6 @@ It's written for use with httpd, but doesn't need to be used as such.
|
|||||||
#define os_strcpy strcpy
|
#define os_strcpy strcpy
|
||||||
#define os_printf printf
|
#define os_printf printf
|
||||||
#define ICACHE_FLASH_ATTR
|
#define ICACHE_FLASH_ATTR
|
||||||
extern char* espFsData;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "espfsformat.h"
|
#include "espfsformat.h"
|
||||||
@@ -46,7 +45,7 @@ extern char* espFsData;
|
|||||||
#include "heatshrink_decoder.h"
|
#include "heatshrink_decoder.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
static char* espFsData = NULL;
|
||||||
|
|
||||||
|
|
||||||
struct EspFsFile {
|
struct EspFsFile {
|
||||||
@@ -74,6 +73,22 @@ Accessing the flash through the mem emulation at 0x40200000 is a bit hairy: All
|
|||||||
a memory exception, crashing the program.
|
a memory exception, crashing the program.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
EspFsInitResult espFsInit(void *flashAddress) {
|
||||||
|
// base address must be aligned to 4 bytes
|
||||||
|
if (((int)flashAddress & 3) != 0) {
|
||||||
|
return ESPFS_INIT_RESULT_BAD_ALIGN;
|
||||||
|
}
|
||||||
|
|
||||||
|
// check if there is valid header at address
|
||||||
|
EspFsHeader testHeader;
|
||||||
|
os_memcpy(&testHeader, flashAddress, sizeof(EspFsHeader));
|
||||||
|
if (testHeader.magic != ESPFS_MAGIC) {
|
||||||
|
return ESPFS_INIT_RESULT_NO_IMAGE;
|
||||||
|
}
|
||||||
|
|
||||||
|
espFsData = (char *)flashAddress;
|
||||||
|
return ESPFS_INIT_RESULT_OK;
|
||||||
|
}
|
||||||
|
|
||||||
//Copies len bytes over from dst to src, but does it using *only*
|
//Copies len bytes over from dst to src, but does it using *only*
|
||||||
//aligned 32-bit reads. Yes, it's no too optimized but it's short and sweet and it works.
|
//aligned 32-bit reads. Yes, it's no too optimized but it's short and sweet and it works.
|
||||||
@@ -100,11 +115,11 @@ void ICACHE_FLASH_ATTR memcpyAligned(char *dst, char *src, int len) {
|
|||||||
|
|
||||||
//Open a file and return a pointer to the file desc struct.
|
//Open a file and return a pointer to the file desc struct.
|
||||||
EspFsFile ICACHE_FLASH_ATTR *espFsOpen(char *fileName) {
|
EspFsFile ICACHE_FLASH_ATTR *espFsOpen(char *fileName) {
|
||||||
#ifdef __ets__
|
if (espFsData == NULL) {
|
||||||
char *p=(char *)(ESPFS_POS+0x40200000);
|
os_printf("Call espFsInit first!\n");
|
||||||
#else
|
return NULL;
|
||||||
|
}
|
||||||
char *p=espFsData;
|
char *p=espFsData;
|
||||||
#endif
|
|
||||||
char *hpos;
|
char *hpos;
|
||||||
char namebuf[256];
|
char namebuf[256];
|
||||||
EspFsHeader h;
|
EspFsHeader h;
|
||||||
@@ -116,7 +131,7 @@ EspFsFile ICACHE_FLASH_ATTR *espFsOpen(char *fileName) {
|
|||||||
hpos=p;
|
hpos=p;
|
||||||
//Grab the next file header.
|
//Grab the next file header.
|
||||||
os_memcpy(&h, p, sizeof(EspFsHeader));
|
os_memcpy(&h, p, sizeof(EspFsHeader));
|
||||||
if (h.magic!=0x73665345) {
|
if (h.magic!=ESPFS_MAGIC) {
|
||||||
os_printf("Magic mismatch. EspFS image broken.\n");
|
os_printf("Magic mismatch. EspFS image broken.\n");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|||||||
+6
-4
@@ -4,13 +4,15 @@
|
|||||||
//Define this if you want to be able to use Heatshrink-compressed espfs images.
|
//Define this if you want to be able to use Heatshrink-compressed espfs images.
|
||||||
#define ESPFS_HEATSHRINK
|
#define ESPFS_HEATSHRINK
|
||||||
|
|
||||||
//Pos of esp fs in flash
|
typedef enum {
|
||||||
#define ESPFS_POS 0x12000
|
ESPFS_INIT_RESULT_OK,
|
||||||
#define ESPFS_SIZE 0x2E000
|
ESPFS_INIT_RESULT_NO_IMAGE,
|
||||||
|
ESPFS_INIT_RESULT_BAD_ALIGN,
|
||||||
|
} EspFsInitResult;
|
||||||
|
|
||||||
typedef struct EspFsFile EspFsFile;
|
typedef struct EspFsFile EspFsFile;
|
||||||
|
|
||||||
|
EspFsInitResult espFsInit(void *flashAddress);
|
||||||
EspFsFile *espFsOpen(char *fileName);
|
EspFsFile *espFsOpen(char *fileName);
|
||||||
int espFsRead(EspFsFile *fh, char *buff, int len);
|
int espFsRead(EspFsFile *fh, char *buff, int len);
|
||||||
void espFsClose(EspFsFile *fh);
|
void espFsClose(EspFsFile *fh);
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ with the FLAG_LASTFILE flag set.
|
|||||||
#define FLAG_LASTFILE (1<<0)
|
#define FLAG_LASTFILE (1<<0)
|
||||||
#define COMPRESS_NONE 0
|
#define COMPRESS_NONE 0
|
||||||
#define COMPRESS_HEATSHRINK 1
|
#define COMPRESS_HEATSHRINK 1
|
||||||
|
#define ESPFS_MAGIC 0x73665345
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int32_t magic;
|
int32_t magic;
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ int main(int argc, char **argv) {
|
|||||||
char buff[128];
|
char buff[128];
|
||||||
EspFsFile *ef;
|
EspFsFile *ef;
|
||||||
off_t size;
|
off_t size;
|
||||||
|
EspFsInitResult ir;
|
||||||
|
|
||||||
if (argc!=3) {
|
if (argc!=3) {
|
||||||
printf("Usage: %s espfs-image file\nExpands file from the espfs-image archive.\n", argv[0]);
|
printf("Usage: %s espfs-image file\nExpands file from the espfs-image archive.\n", argv[0]);
|
||||||
@@ -40,6 +41,12 @@ int main(int argc, char **argv) {
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ir=espFsInit(espFsData);
|
||||||
|
if (ir != ESPFS_INIT_RESULT_OK) {
|
||||||
|
printf("Couldn't init espfs filesystem (code %d)\n", ir);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
ef=espFsOpen(argv[2]);
|
ef=espFsOpen(argv[2]);
|
||||||
if (ef==NULL) {
|
if (ef==NULL) {
|
||||||
printf("Couldn't find %s in image.\n", argv[2]);
|
printf("Couldn't find %s in image.\n", argv[2]);
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
|
||||||
|
body {
|
||||||
|
background-color: #404040;
|
||||||
|
font-family: sans-serif;
|
||||||
|
}
|
||||||
|
|
||||||
|
#main {
|
||||||
|
background-color: #d0d0FF;
|
||||||
|
-moz-border-radius: 5px;
|
||||||
|
-webkit-border-radius: 5px;
|
||||||
|
border-radius: 5px;
|
||||||
|
border: 2px solid #000000;
|
||||||
|
width: 800px;
|
||||||
|
margin: 0 auto;
|
||||||
|
padding: 20px
|
||||||
|
}
|
||||||
|
|
||||||
+6
-1
@@ -19,6 +19,7 @@
|
|||||||
#include "cgiflash.h"
|
#include "cgiflash.h"
|
||||||
#include "stdout.h"
|
#include "stdout.h"
|
||||||
#include "auth.h"
|
#include "auth.h"
|
||||||
|
#include "espfs.h"
|
||||||
|
|
||||||
//Function that tells the authentication system what users/passwords live on the system.
|
//Function that tells the authentication system what users/passwords live on the system.
|
||||||
//This is disabled in the default build; if you want to try it, enable the authBasic line in
|
//This is disabled in the default build; if you want to try it, enable the authBasic line in
|
||||||
@@ -73,10 +74,14 @@ HttpdBuiltInUrl builtInUrls[]={
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
//Main routine. Initialize stdout, the I/O and the webserver and we're done.
|
//Main routine. Initialize stdout, the I/O, filesystem and the webserver and we're done.
|
||||||
void user_init(void) {
|
void user_init(void) {
|
||||||
stdoutInit();
|
stdoutInit();
|
||||||
ioInit();
|
ioInit();
|
||||||
|
|
||||||
|
// 0x40200000 is the base address for spi flash memory mapping, 0x12000 is the position
|
||||||
|
// where image is written in flash
|
||||||
|
espFsInit((void*)(0x40200000 + 0x12000));
|
||||||
httpdInit(builtInUrls, 80);
|
httpdInit(builtInUrls, 80);
|
||||||
os_printf("\nReady\n");
|
os_printf("\nReady\n");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user