nekromant / esp8266-frankenstein

Alternative firmware for ESP8266 modules
318 stars 71 forks source link

filesystem.espfs #94

Open GTP95 opened 6 years ago

GTP95 commented 6 years ago

Just two more questions: at which address should I flash the filesystem.espfs file? Do I flash it the same way as binary files using the write_flash option of esptool or should I use write_mem instead? Sorry but I don't know esptool well and it's documentation doesn't explain the difference between write_flash and write_mem.

nekromant commented 6 years ago

filesystem.espfs stores all the static pages served via web. It is flashed in the next block after the firmware, the actual offset is calculated dynamically. Right now you can download the filesystem file via tftp. There's also a webdl command for that, but it's currently crashing.

You can find out the right address from the fk boot log and use write_flash afterwards.

GTP95 commented 6 years ago

I'm still facing problems with flashing. I can't flash it on an ESP-07, it fails with a "waiting for packet header" error at 93% or 95% depending most of the times on the baud rate I use, but this one doesn't really count since maybe it's memory is already damaged (I can't run a simple sketch, but Arduino IDE is still able to flash it). But what is strange is that I have a nodemcu v3 board (or similar clone with an ESP-12N mounted on it, not sure it's original) that I can flash fine, but right after flashing it I get the following serial output endlessly repeated:

Fatal exception (28): epc1=0x4000228b, epc2=0x00000000, epc3=0x00000000, excvaddr=0x000000b5, depc=0x00000000

and after a reset nothing is printed, just the usual strange output you get during reset. I'm using the following command to flash it with the following output:

$ esptool.py -p /dev/ttyUSB0 write_flash 0x00000 frank-0x00000.bin 0x10000 frank-0x10000.bin esptool.py v1.3 Connecting.... Auto-detected Flash size: 32m Running Cesanta flasher stub... Flash params set to 0x0040 Wrote 49152 bytes at 0x0 in 4.3 seconds (92.0 kbit/s)... Wrote 307200 bytes at 0x10000 in 26.6 seconds (92.3 kbit/s)... Leaving...

I'm doing something wrong? Is there anything else I could try? Thanks for your support and have a nice day

EDIT: according to this thread, this error happens when a program tries to read form an invalid memory address: http://www.esp8266.com/viewtopic.php?f=34&t=4665

GTP95 commented 6 years ago

UPDATE: seems that the issue is solved (on the nodemcu) by specifying the "dio" flashing mode, now after flashing I get the following output:

load 0x40100000, len 28448, room

What should I do now? By flashing micropython I figured out that after resetting the board if everything went fine I was supposed to be dropped to frankenstein's shell but this didn't happened, got a neverending output instead.

nekromant commented 6 years ago

If you are stuck in a bootloop most likely you are missing esp-init-data.bin. See nodemcu docs, where they describe flashing one. Try to fix that one first and flash without dio mode. something tells me dio mode didn't flash anything valid, so you were just stuck in rom code. See: https://github.com/nodemcu/nodemcu-firmware/blob/master/docs/en/flash.md#sdk-init-data

If wifi commands in frankenstein work weird after flashing, not connecting automatically, causing random reboots - please wipe THE WHOLE FLASH clean. wifi configurations stored from earlier sdk version tend to screw things up in newer SDKs.

GTP95 commented 6 years ago

Hello again, I just tried to flash a brand new esp8266 using nodemcu flasher (https://github.com/nodemcu/nodemcu-flasher) (esptool was failing as previously described). The tool flashed it without trowing errors (but was really quick) but once rebooted I got seemingly random characters. I tried to set my terminal to 9600 and 115200 baud but didn't got any intelligible output, which is the default baud rate of your firmware?

nekromant commented 6 years ago

It should be 115200! ROM loader spews out some debugging at weird 78kbps or so, so a little bit of gibberish at the start is expected with esp8266 on any firmware. But frankenstein than switches to 115200. See: https://github.com/nekromant/esp8266-frankenstein/blob/master/src/main.c#L245

GTP95 commented 6 years ago

Could you please tell me which board/chip do you use to test your firmware and which tool do you use to flash it? If it's esptool, could you please post the full command so I can see all the switches that you use and the options that you pass? Sorry for all the questions but not being able to flash it is really frustrating.

nekromant commented 6 years ago

I'm using a variety of esp8266 modules. with 4MiB and 512KB flash along with esptool.py. Basically for a completely blank device you'll need to run three commands:

esptool.py write_flash 0x0 frank-0x00000.bin
esptool.py write_flash 0x10000 frank-0x10000.bin
esptool.py write_flash 0x7c000 esp_init_data_default.bin

The address of the last one for esp_init_data_default.bin is dependent on flash size. (NodeMCU flash.md has a good table of those):

The filesystem is more tricky than that. You have to boot it once, and look at what address the firmware expects to see the filesystem, and flash it there. espfs support is still somewhat buggy.

GTP95 commented 6 years ago

I updated esptool to the latest version available on pip, now on the nodemcu clone I don't get anymore the "Fatal exception (28)" error, but after reset I don't get any intelligible output. But while doing my tests I found out that there are different versions of esp_init_data_default.bin around, could you please point me to the one you're using, so I can be 100% sure we are using exactly the same binary files? Thank you. I also plan to buy an original nodemcu and a bunch of esp-01 to do some other tests.

GTP95 commented 6 years ago

Good news: I was able to flash all files but the filesystem using the nodemcu flasher on the nodemcu clone, and I got to the point where the serial output is this: dld▒▒;▒$▒f▒▒͡▒size: 4194304 bytes, esp calibration data at sector @ 0x003fb000 env: Environment @ 0x003fa000 size 4096 bytes (4092 real) === Current environment === sta-mode dhcp prompt frankenstein default-mode APSTA sta-ip 192.168.0.123 sta-mask 255.255.255.0 sta-gw 192.168.0.1 log-level 3 sta-auto 0 ap-ip 192.168.1.1 ap-mask 255.255.255.0 ap-gw 192.168.1.1 hostname frankenstein bootdelay 5 telnet-port 23 telnet-autostart CONFIG_ENV_DEFAULT_TELNET_AUTOSTART telnet-drop 60 tftp-server 192.168.1.215 tftp-dir / tftp-file antares.com === 373/4092 bytes used === ` I then tryied to flash the filesystem at 0x003fb000 but it times out every time. Is this the right address? If yes, could you please elaborate on the upload via tftp?

nekromant commented 6 years ago
  1. tftp is broken right now due to some changes in the SDK.
  2. 0x003fb000 is NOT the correct address for filesystem.espfs. Factory calibration data resides there.

This line should print you the correct address: https://github.com/nekromant/esp8266-frankenstein/blob/79094836653ca921f704bde759ba4bacf3ef8fff/src/main.c#L107

Basically the flash layout in frankenstein is somewhat like this (from start to end of flash)

FIRMWARE (IRAM PART) | FIRMWARE ICACHE_FLASH | FILESYSTEM DATA | ENVIRONMENT | ESP CALIBRATION DATA