Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to recover from infinite reboot loops in NodeMCU?

Tags:

loops

reboot

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?

like image 649
Urmil Parikh Avatar asked Apr 18 '15 19:04

Urmil Parikh


3 Answers

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.

like image 192
Urmil Parikh Avatar answered Nov 20 '22 09:11

Urmil Parikh


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

like image 39
Goutham Rapol Avatar answered Nov 20 '22 10:11

Goutham Rapol


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.
like image 1
jrheling Avatar answered Nov 20 '22 10:11

jrheling