Added espFsInit call

pull/30/head
Jindra Dolezy 10 years ago
parent 7e21cbe3ca
commit d8afde3cc1
  1. 29
      espfs/espfs.c
  2. 10
      espfs/espfs.h
  3. 1
      espfs/espfsformat.h
  4. 7
      espfs/espfstest/main.c
  5. 17
      espfs/espfstest/style.css
  6. 7
      user/user_main.c

@ -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_printf printf
#define ICACHE_FLASH_ATTR
extern char* espFsData;
#endif
#include "espfsformat.h"
@ -46,7 +45,7 @@ extern char* espFsData;
#include "heatshrink_decoder.h"
#endif
static char* espFsData = NULL;
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.
*/
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*
//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.
EspFsFile ICACHE_FLASH_ATTR *espFsOpen(char *fileName) {
#ifdef __ets__
char *p=(char *)(ESPFS_POS+0x40200000);
#else
if (espFsData == NULL) {
os_printf("Call espFsInit first!\n");
return NULL;
}
char *p=espFsData;
#endif
char *hpos;
char namebuf[256];
EspFsHeader h;
@ -116,7 +131,7 @@ EspFsFile ICACHE_FLASH_ATTR *espFsOpen(char *fileName) {
hpos=p;
//Grab the next file header.
os_memcpy(&h, p, sizeof(EspFsHeader));
if (h.magic!=0x73665345) {
if (h.magic!=ESPFS_MAGIC) {
os_printf("Magic mismatch. EspFS image broken.\n");
return NULL;
}

@ -4,13 +4,15 @@
//Define this if you want to be able to use Heatshrink-compressed espfs images.
#define ESPFS_HEATSHRINK
//Pos of esp fs in flash
#define ESPFS_POS 0x12000
#define ESPFS_SIZE 0x2E000
typedef enum {
ESPFS_INIT_RESULT_OK,
ESPFS_INIT_RESULT_NO_IMAGE,
ESPFS_INIT_RESULT_BAD_ALIGN,
} EspFsInitResult;
typedef struct EspFsFile EspFsFile;
EspFsInitResult espFsInit(void *flashAddress);
EspFsFile *espFsOpen(char *fileName);
int espFsRead(EspFsFile *fh, char *buff, int len);
void espFsClose(EspFsFile *fh);

@ -18,6 +18,7 @@ with the FLAG_LASTFILE flag set.
#define FLAG_LASTFILE (1<<0)
#define COMPRESS_NONE 0
#define COMPRESS_HEATSHRINK 1
#define ESPFS_MAGIC 0x73665345
typedef struct {
int32_t magic;

@ -22,6 +22,7 @@ int main(int argc, char **argv) {
char buff[128];
EspFsFile *ef;
off_t size;
EspFsInitResult ir;
if (argc!=3) {
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);
}
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]);
if (ef==NULL) {
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
}

@ -19,6 +19,7 @@
#include "cgiflash.h"
#include "stdout.h"
#include "auth.h"
#include "espfs.h"
//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
@ -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) {
stdoutInit();
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);
os_printf("\nReady\n");
}

Loading…
Cancel
Save