How to recover from infinite reboot loops in NodeMCU?
Asked Answered
S

4

7

My NodeMCU program has gone in to infinite reboot loop.

My code is functionally working but any action I try to do, e.g. file.remove("init.lua") or even just =node.heap(), it panics and reboots saying: PANIC: unprotected error in call to Lua API (not enough memory).

Because of this, I'm not able to change any code or delete init.lua to stop automatic code execution.

How do I recover?

Snubnosed answered 18/4, 2015 at 19:32 Comment(2)
Don’t use a init-file in the development phase. Name it init_start.lua or similiar and use the dofile-command to execute it manually. As soon as your development is done and everthing is working, you can rename it and make use of the automatic execution.Och
I was following such, but I wrote init.lua for standalone testing and now I'm locked out :(Snubnosed
S
7

I tried re-flashing another version of NodeMCU, but it started emitting garbage in serial port.

Then, I recalled that NodeMCU had two extra files: blank.bin and esp_init_data_default.bin.

I flashed them at 0x7E000 and 0x7C000 respectively.

They are also available as INTERNAL://BLANK and INTERNAL://DEFAULT in the NodeMCU flasher.

This booted the new NodeMCU firmware, all my files were gone and I'm out of infinite reboot loop.

Snubnosed answered 21/4, 2015 at 7:41 Comment(4)
There is a problem with nodemcu not clearing the ram properly. This is what causes the infinite reboot.Palomo
Writing this as of Jan 2016 - the above problem still exists in NodeMCU and the above solution still works.Trioxide
Where did you find those addresses (0x7e000 and 0x7c000) - is there a doc I find more on these?Imbalance
You can refer memory map here: github.com/esp8266/esp8266-wiki/wiki/Memory-Map The addresses may change based on your flash size.Snubnosed
E
5

Flash the following files:

0x00000.bin to 0x00000

0x10000.bin to 0x10000

And, the address for esp_init_data_default.bin depends on the size of your module's flash.

0x7c000 for 512 kB, modules like ESP-01, -03, -07 etc.

0xfc000 for 1 MB, modules like ESP8285, PSF-A85

0x1fc000 for 2 MB

0x3fc000 for 4 MB, modules like ESP-12E, NodeMCU devkit 1.0, WeMos D1 mini

Then, after flashing those binaries format its file system (run "file.format()" using ESPlorer) before flashing any other binaries.

Downloads Link

Earleanearleen answered 26/11, 2016 at 15:42 Comment(0)
I
1

I've just finished working through a similar problem. In my case it was end-user error that caused a need to forcibly wipe init.lua, but I think both problems could be solved similarly. (For completeness, my problem was putting a far-too-short dsleep() call in init.lua, leaving the board resetting itself immediately upon starting init.lua.)

I tried flashing new NodeMCU firmware, writing blank.bin and esp_init_data_default.bin to 0x7E000 and 0x7C000, and also writing 0x00000.bin to 0x00000 and 0x10000.bin to 0x10000. None of these things helped in my case.

My hardware is an Adafruit Huzzah ESP8266 breakout (ESP-12), with 4MB of flash.

What worked for me was:

  1. Download the NONOS SDK from Espressif (I used version 1.5.2 from http://bbs.espressif.com/viewtopic.php?f=46&t=1702).
  2. Unzip it to get at boot_v1.2.bin, user1.1024.new.2.bin, blank.bin, and esp_init_data_default.bin (under bin/ and bin/at/).
  3. Flash the following files to the specified memory locations:
    1. boot_v1.2.bin to 0x00000
    2. user1.1024.new.2.bin to 0x010000
    3. esp_init_data_default.bin to 0xfc000
    4. blank.bin to 0x7e000
    5. Note about flashing:
      • I used esptool.py 1.2.1.
      • Because of the nature of my problem, I was only able to write changes to the flash when in programming mode (i.e. after booting with GPIO0 held down to GND).
      • I found that I needed to reset the board between each step (else invocations of esptool.py after the first would fail).
  4. Erased the flash. esptool.py --port <your/port> erase_flash
  5. Then I was able to write a new firmware. I used a stock nodeMCU 0.9.5 just to isolate variables, but I strongly suspect any firmware would work at this point.
Irade answered 6/1, 2017 at 3:7 Comment(0)
D
0

The only think that worked for me was python flash tool esptool in ubuntu, windows flashtool never deleted init.lua and reboot loop.

Commands (ubuntu):

git clone https://github.com/themadinventor/esptool.git
cd esptool
python esptool.py -h
ls -l /dev/tty*

nodemcu_latest.bin can be downloaded from github or anywhere.

sudo python esptool.py -p /dev/ttyUSB0 --baud 460800 write_flash --flash_size=8m 0 nodemcu_latest.bin
Damiandamiani answered 27/4, 2016 at 8:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.