chmorgan / esphttpd-freertos

freertos example of libesphttpd for esp32 and esp8266
53 stars 14 forks source link

CMake and update to latest espfs #18

Closed jkent closed 4 years ago

jkent commented 4 years ago

I've tested this with the master branch of my libesphttpd fork: https://github.com/jkent/libesphttpd

chmorgan commented 4 years ago

@jkent let me know if you'd like to be added as a maintainer of this and the library repos. @phatpaul is a maintainer now so he would have to be ok with it as well. You both are using this a lot more than I am and I'd like to make sure its in good hands and well maintained.

phatpaul commented 4 years ago

It's OK with me, you seem very capable. I also have limited time to devote to maintenance, so I welcome the help.

chmorgan commented 4 years ago

@jkent interested in being added as a maintainer to this and the other related project repos?

jkent commented 4 years ago

Sure, that's fine. Thank you.

Jeff Kent 309-740-7022


On Fri, Jan 10, 2020 at 7:47 PM Chris Morgan notifications@github.com wrote:

@jkent https://github.com/jkent interested in being added as a maintainer to this and the other related project repos?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/chmorgan/esphttpd-freertos/pull/18?email_source=notifications&email_token=AAEH7M2PGRLYXVG5A4AMWQTQ5EQJ5A5CNFSM4I4PO6X2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEIVV3HA#issuecomment-573267356, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAEH7M2GGNGPNXZI2Q7FYD3Q5EQJ5ANCNFSM4I4PO6XQ .

chmorgan commented 4 years ago

@jkent added!

phatpaul commented 4 years ago

I'm having trouble using esp_vfs_espfs_register().

I tried:

    static EspFs espfs;
    esp_vfs_espfs_conf_t espfs_vfs_conf = {
        .base_path = ESPFS_BASE_PATH,
        .fs = &espfs,
        .max_files = 5};
    //espFsInit((void*)(image_espfs_start)); -- next call will do this
    esp_vfs_espfs_register(&espfs_vfs_conf);

But I got compiler error: error: storage size of 'espfs' isn't known

Seems struct EspFs is private? Will you please add an example of using EspFs via VFS in this repo?

phatpaul commented 4 years ago

I moved

#include "esp_partition.h" // for spi_flash_mmap_handle_t
struct EspFs {
    const void *memAddr;
    spi_flash_mmap_handle_t mmapHandle;
    size_t length;
    size_t numFiles;
};

from espfs_priv.h to espfs.h. Now it compiles, but then I get a core panic when I try to open a file.

Guru Meditation Error: Core  1 panic'ed (LoadProhibited). Exception was unhandled.
Core 1 register dump:
PC      : 0x40183250  PS      : 0x00060030  A0      : 0x8018302f  A1      : 0x3ffce680
0x40183250: espFsOpen at C:/msys32/home/labview/lumitec-dev-fw-plibox-esp32/esp-eth-libesphttpd/components/esp
fs/src/espfs.c:414

A2      : 0x00000001  A3      : 0x3ffce8e3  A4      : 0x00000000  A5      : 0x3ffc4b14
A6      : 0x00000000  A7      : 0x00000004  A8      : 0x6e6f006e  A9      : 0x00000073
A10     : 0x00000000  A11     : 0x00000001  A12     : 0x3ffce8e1  A13     : 0x00000000
A14     : 0x00000001  A15     : 0x00000000  SAR     : 0x00000004  EXCCAUSE: 0x0000001c
EXCVADDR: 0x00000001  LBEG    : 0x40091f91  LEND    : 0x40091fa1  LCOUNT  : 0xfffffffa
0x40091f91: strlen at /home/jeroen/esp8266/esp32/newlib_xtensa-2.2.0-bin/newlib_xtensa-2.2.0/xtensa-esp32-elf/
newlib/libc/machine/xtensa/../../../../.././newlib/libc/machine/xtensa/strlen.S:84

0x40091fa1: strlen at /home/jeroen/esp8266/esp32/newlib_xtensa-2.2.0-bin/newlib_xtensa-2.2.0/xtensa-esp32-elf/
newlib/libc/machine/xtensa/../../../../.././newlib/libc/machine/xtensa/strlen.S:96

ELF file SHA256: b539de45a025bdea63cf12dcf2b33252628d49d87602b293f0a3e75f296c7910

Backtrace: 0x40183250:0x3ffce680 0x4018302c:0x3ffce7b0 0x40133391:0x3ffce7d0 0x4000bd67:0x3ffce7f0 0x401191c2:
0x3ffce810 0x40119279:0x3ffce840 0x4010e2d7:0x3ffce860
0x40183250: espFsOpen at C:/msys32/home/labview/lumitec-dev-fw-plibox-esp32/esp-eth-libesphttpd/components/esp
fs/src/espfs.c:414

0x4018302c: vfs_espfs_open at C:/msys32/home/labview/lumitec-dev-fw-plibox-esp32/esp-eth-libesphttpd/component
s/espfs/src/espfs_vfs.c:60

0x40133391: esp_vfs_open at C:/msys32/home/labview/lumitec-dev-fw-plibox-esp32/Tools/esp-idf/components/vfs/vf
s.c:734

0x401191c2: _fopen_r at /home/jeroen/esp8266/esp32/newlib_xtensa-2.2.0-bin/newlib_xtensa-2.2.0/xtensa-esp32-el
f/newlib/libc/stdio/../../../.././newlib/libc/stdio/fopen.c:141

0x40119279: fopen at /home/jeroen/esp8266/esp32/newlib_xtensa-2.2.0-bin/newlib_xtensa-2.2.0/xtensa-esp32-elf/n
ewlib/libc/stdio/../../../.././newlib/libc/stdio/fopen.c:181

0x4010e2d7: startup_task at C:/msys32/home/labview/lumitec-dev-fw-plibox-esp32/esp-eth-libesphttpd/main/main.c
:445 (discriminator 4)

Rebooting...
phatpaul commented 4 years ago

Making progress. I did:

    // Mount trivial read-only filesystem: espfs
    EspFsConfig espfs_conf = {
            .memAddr = espfs_image_bin,
    };
    EspFs* fs = espFsInit(&espfs_conf);
    esp_vfs_espfs_conf_t espfs_vfs_conf = {
        .base_path = ESPFS_BASE_PATH,
        .fs = fs,
        .max_files = 5};
    esp_vfs_espfs_register(&espfs_vfs_conf);

Now I see

E (81) espfs: Magic not found at 0x3f425df8
abort() was called at PC 0x4018378b on core 0
0x4018378b: esp_vfs_espfs_register at C:/msys32/home/labview/lumitec-dev-fw-plibox-esp32/esp-eth-libesphttpd/c
omponents/espfs/src/espfs_vfs.c:166 (discriminator 1)

ELF file SHA256: a743a595335be5b926eb7938f1d6f071ea202c5c7692cce7d9de80fa6cc25042

Backtrace: 0x4008f483:0x3ffbbd40 0x4008f639:0x3ffbbd60 0x4018378b:0x3ffbbd80 0x4010eafc:0x3ffbbe40 0x400d05c4:
0x3ffbbee0
0x4008f483: invoke_abort at C:/msys32/home/labview/lumitec-dev-fw-plibox-esp32/Tools/esp-idf/components/esp32/
panic.c:709

0x4008f639: abort at C:/msys32/home/labview/lumitec-dev-fw-plibox-esp32/Tools/esp-idf/components/esp32/panic.c
:709

0x4018378b: esp_vfs_espfs_register at C:/msys32/home/labview/lumitec-dev-fw-plibox-esp32/esp-eth-libesphttpd/c
omponents/espfs/src/espfs_vfs.c:166 (discriminator 1)

So it seems my espfs image is empty? I'm guessing so because build\espfs\espfs_image.bin is 0bytes.

phatpaul commented 4 years ago

I noticed the makefile is now using symbolic links, which doesn't work on Windows 7. I tested that and it just copies the file initially. Any changes to the original file don't reflect in the link. ln -s ../mkespfsimage/mkespfsimage bin/

jkent commented 4 years ago

You're using it correctly. I'm sorry about being absent, my back decided to spasm last night and back pain has kept me away from the keyboard. I thought msys2 worked with symlinks. I'm not really a windows user, so I didn't get around to testing. Let me know what you need me to do.

jkent commented 4 years ago

I will put setting up CI on the TODO list, at least that way we can tell if things build cross-platform

phatpaul commented 4 years ago

No worries @jkent. I'm only working on this weekdays 9-5 anyway.

I'm not seeing how/if the symlink is breaking the build on windows. What's the purpose of the symlink anyway? Where is the bin/ folder that it's linking to?

BTW, I've been planning to learn how to set up CI for my own project. I'll be interested to see what you propose.

phatpaul commented 4 years ago

At the end of espfs/component.mk: I had to add a mkdir to create the bin dir. I had to add ".exe" to the mkespfsimage file, since CC adds that extension on windows. Obviously that's not portable.

    mkdir -p bin
    ln -s ../mkespfsimage/mkespfsimage.exe bin/

Also I got error on python 2.7 doesn't understand exist_ok. At the end of espfs/tools/build-image.py:

#os.makedirs('include', exist_ok=True)
# python 2.7 doesn't understand exist_ok
path = 'include'
try: 
    os.makedirs(path)
except OSError:
    if not os.path.isdir(path):
        raise

Now it builds, and looks like there is data in the espfs_image.bin but it still crashes...

phatpaul commented 4 years ago

The WDT triggers and then eventually there is a panic (LoadProhibited) and reboot. It gets stuck in this do{}while loop in espFsInit():

    uint32_t entry_length = sizeof(*h) + h->nameLen + h->fileLenComp;
    fs->length = entry_length;
    fs->numFiles = 0;

    do {
        fs->numFiles++;
        h = (void*)h + entry_length;
        entry_length = sizeof(*h) + h->nameLen + h->fileLenComp;
        if (entry_length % 4) {
            entry_length += 4 - (entry_length % 4);
        }
        fs->length += entry_length;
    } while (!(h->flags & FLAG_LASTFILE));

    fs->memAddr = memAddr;
    fs->mmapHandle = mmapHandle;

I don't have JTAG debugging hooked-up at the moment. Any idea why it's stuck here?

jkent commented 4 years ago

This is familiar -- the loop is running away I believe. Is your espfs image empty (with just one header?)?

phatpaul commented 4 years ago

No, the image is not empty. The magic is there, and the end of image marker is there.

Here's the end of the image in the user.bin (combined): The FLAG_LASTFILE marker is there at byte 0001FCB4.

0001FCA0 | 97 D1 76 BC 8D FE 02 42 CF C7 B2 94 04 00 00 00 | —Ñv¼þ.BÏDz”....
0001FCB0 | 45 53 66 73 01 00 00 00 00 00 00 00 00 00 00 00 | ESfs............
0001FCC0 | 65 6D 61 63 00 1B 5B 30 3B 33 31 6D 45 20 28 25 | emac..[0;31mE (%
jkent commented 4 years ago

I'll look over this either later this evening or tomorrow. I feel that I've made a mess of things. Anxiety is a little high. I'll try to repro the problem too.

chmorgan commented 4 years ago

It’s only code. Worst case is having to roll back to an old rev while you debug.

On Mon, Jan 20, 2020 at 6:14 PM Jeff Kent notifications@github.com wrote:

I'll look over this either later this evening or tomorrow. I feel that I've made a mess of things. Anxiety is a little high. I'll try to repro the problem too.

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/chmorgan/esphttpd-freertos/pull/18?email_source=notifications&email_token=AAJH4ABKBUEAJBK7466COVDQ6YV37A5CNFSM4I4PO6X2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEJOAT3A#issuecomment-576457196, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAJH4AAEATWLUSBOITPXTFDQ6YV37ANCNFSM4I4PO6XQ .

phatpaul commented 4 years ago

No worries. I've got it working for me. See my PR https://github.com/jkent/esp32-espfs/pull/16

No rush with the CI, but I'm still interested when you have time.