factory reset button not working

zliudr
Posts: 360
Joined: Thu Oct 03, 2019 5:15 am

factory reset button not working

Postby zliudr » Wed Jul 01, 2020 12:36 am

I am trying to make factory reset work but it's not working. OTA partition is loaded regardless the button being depressed.
I tested the buttons with my multimeter and read it within my firmware. When not held, it reads 1. When held, it reads 0. It's a simple button connecting pin 18 to ground.
I've set up the config as below:

Code: Select all

#
# Bootloader config
#
CONFIG_LOG_BOOTLOADER_LEVEL_NONE=
CONFIG_LOG_BOOTLOADER_LEVEL_ERROR=
CONFIG_LOG_BOOTLOADER_LEVEL_WARN=
CONFIG_LOG_BOOTLOADER_LEVEL_INFO=y
CONFIG_LOG_BOOTLOADER_LEVEL_DEBUG=
CONFIG_LOG_BOOTLOADER_LEVEL_VERBOSE=
CONFIG_LOG_BOOTLOADER_LEVEL=3
CONFIG_BOOTLOADER_VDDSDIO_BOOST_1_8V=
CONFIG_BOOTLOADER_VDDSDIO_BOOST_1_9V=y
CONFIG_BOOTLOADER_FACTORY_RESET=y
CONFIG_BOOTLOADER_NUM_PIN_FACTORY_RESET=18
CONFIG_BOOTLOADER_OTA_DATA_ERASE=y
CONFIG_BOOTLOADER_DATA_FACTORY_RESET="nvs"
CONFIG_BOOTLOADER_APP_TEST=y
CONFIG_BOOTLOADER_NUM_PIN_APP_TEST=19
CONFIG_BOOTLOADER_HOLD_TIME_GPIO=5
CONFIG_BOOTLOADER_WDT_ENABLE=y
CONFIG_BOOTLOADER_WDT_DISABLE_IN_USER_CODE=
CONFIG_BOOTLOADER_WDT_TIME_MS=9000
CONFIG_APP_ROLLBACK_ENABLE=y
CONFIG_APP_ANTI_ROLLBACK=
Somehow it's not working.

Here is my partition list printed by 2nd stage bootloader:

Code: Select all

I (50) boot: ## Label            Usage          Type ST Offset   Length
I (58) boot:  0 nvs              WiFi data        01 02 00009000 00004000
I (65) boot:  1 otadata          OTA data         01 00 0000d000 00002000
I (73) boot:  2 phy_init         RF data          01 01 0000f000 00001000
I (80) boot:  3 factory          factory app      00 00 00010000 00200000
I (88) boot:  4 ota_0            OTA app          00 10 00210000 00200000
I (95) boot:  5 ota_1            OTA app          00 11 00410000 00200000
I (103) boot:  6 storage          Unknown data     01 82 00610000 00900000
I (110) boot: End of partition table
I (114) esp_image: segment 0: paddr=0x00210020 vaddr=0x3f400020 size=0x545bc (345532) map
I (245) esp_image: segment 1: paddr=0x002645e4 vaddr=0x3ffb0000 size=0x03ba8 ( 15272) load
I (251) esp_image: segment 2: paddr=0x00268194 vaddr=0x40080000 size=0x00400 (  1024) load
I (252) esp_image: segment 3: paddr=0x0026859c vaddr=0x40080400 size=0x07a74 ( 31348) load
I (273) esp_image: segment 4: paddr=0x00270018 vaddr=0x400d0018 size=0xf6a48 (1010248) map
I (628) esp_image: segment 5: paddr=0x00366a68 vaddr=0x40087e74 size=0x116c0 ( 71360) load
I (673) boot: Loaded app from partition at offset 0x210000
As you can see, ota_0 got selected to run.

Here's some more printouts where I held down test button on GPIO19.

Code: Select all

I (151) gpio: GPIO[18]| InputEn: 1| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0
I (151) gpio: GPIO[19]| InputEn: 1| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0
I (161) __MAIN__: GPIO18: 1     GPIO19:0
GPIO18 reads correctly as well. I am using ESP_IDF release 3.3
Any help? Thanks.

zliudr
Posts: 360
Joined: Thu Oct 03, 2019 5:15 am

Re: factory reset button not working

Postby zliudr » Mon Aug 08, 2022 4:42 pm

It's been two years and this feature is still not working on my system.
I've upgraded to IDF V4.3 and just started experimenting with this factory reset again. I tried a couple of different pins, 18 and 19. Neither worked.

Does anyone have successful implementation of the factory reset feature?

The pin needs to be pulled to GND, right?

I had a factory app running at 0x10000 before OTA'd to 0x210000.

Console message:

Code: Select all

I (29) boot: ESP-IDF v4.3-beta1 2nd stage bootloader
I (29) boot: compile time 11:25:53
I (29) boot: chip revision: 3
I (32) boot_comm: chip revision: 3, min. bootloader chip revision: 0
I (40) boot.esp32: SPI Speed      : 40MHz
I (44) boot.esp32: SPI Mode       : DIO
I (49) boot.esp32: SPI Flash Size : 16MB
I (53) boot: Enabling RNG early entropy source...
I (59) boot: Partition Table:
I (62) boot: ## Label            Usage          Type ST Offset   Length
I (70) boot:  0 nvs              WiFi data        01 02 00009000 00004000
I (77) boot:  1 otadata          OTA data         01 00 0000d000 00002000
I (85) boot:  2 phy_init         RF data          01 01 0000f000 00001000
I (92) boot:  3 factory          factory app      00 00 00010000 00200000
I (99) boot:  4 ota_0            OTA app          00 10 00210000 00200000
I (107) boot:  5 ota_1            OTA app          00 11 00410000 00200000
I (114) boot:  6 storage          Unknown data     01 82 00610000 00900000
I (122) boot: End of partition table
I (126) boot_comm: chip revision: 3, min. application chip revision: 0
I (133) esp_image: segment 0: paddr=00210020 vaddr=3f400020 size=0c5c8h ( 50632) map
I (161) esp_image: segment 1: paddr=0021c5f0 vaddr=3ffb0000 size=02c78h ( 11384) load
I (166) esp_image: segment 2: paddr=0021f270 vaddr=40080000 size=00404h (  1028) load
I (167) esp_image: segment 3: paddr=0021f67c vaddr=40080404 size=0099ch (  2460) load
I (176) esp_image: segment 4: paddr=00220020 vaddr=400d0020 size=1d658h (120408) map
I (229) esp_image: segment 5: paddr=0023d680 vaddr=40080da0 size=0ec7ch ( 60540) load
I (264) boot: Loaded app from partition at offset 0x210000
I (264) boot: Disabling RNG early entropy source...

chegewara
Posts: 2371
Joined: Wed Jun 14, 2017 9:00 pm

Re: factory reset button not working

Postby chegewara » Mon Aug 08, 2022 5:32 pm

It is working pretty good for long time (few years i think). All you have to do is to check this option:

Code: Select all

Clear OTA data on factory reset (select factory partition)
For some time there is also to select pin active level, low or high:

Code: Select all

Factory reset GPIO level (Reset on GPIO low)
Factory reset does not has to mean to reboot from factory partition, it may just need to erase selected partitions, thats why you have to select the 1st option i mentioned.

zliudr
Posts: 360
Joined: Thu Oct 03, 2019 5:15 am

Re: factory reset button not working

Postby zliudr » Thu Aug 11, 2022 6:05 am

Thanks. Yes I have clear OTA selected. I also elected to erase nvs partition so the device's stored credentials should be erased in the event of factory reset (running factory partition). Unfortunately nothing happens. I had bootloader at Info level. Not erasing stuff or running factory partition.

I don't see pin level option. So should the pin be pulled low or high to cause factory reset?

Image

chegewara
Posts: 2371
Joined: Wed Jun 14, 2017 9:00 pm

Re: factory reset button not working

Postby chegewara » Thu Aug 11, 2022 6:33 am

As far as i remember it was LOW, the level option has been added about a year ago.
https://github.com/espressif/esp-idf/co ... 45c1917953

If you want to delete wifi credentials and other stored data you have also to add all nvs partitions you want to erase.
Factory reset of course works when you press "factory reset" before or in very short time after restart esp32.

I cant help you with VS code plugin, i am not using it, but here is quick test:

Code: Select all

I (29) boot: ESP-IDF v5.0-dev-4723-g30e8f19f5a 2nd stage bootloader
I (29) boot: compile time 08:23:17
I (29) boot: chip revision: V300
I (34) boot_comm: chip revision: 3, min. bootloader chip revision: 0
I (41) boot.esp32: SPI Speed      : 40MHz
I (46) boot.esp32: SPI Mode       : DIO
I (50) boot.esp32: SPI Flash Size : 4MB
I (55) boot: Enabling RNG early entropy source...
I (60) boot: Partition Table:
I (64) boot: ## Label            Usage          Type ST Offset   Length
I (71) boot:  0 nvs              WiFi data        01 02 00009000 00004000
I (78) boot:  1 otadata          OTA data         01 00 0000d000 00002000
I (86) boot:  2 phy_init         RF data          01 01 0000f000 00001000
I (93) boot:  3 factory          factory app      00 00 00010000 00100000
I (101) boot:  4 ota_0            OTA app          00 10 00110000 00100000
I (108) boot:  5 ota_1            OTA app          00 11 00210000 00100000
I (116) boot: End of partition table
I (120) boot: Defaulting to factory image
I (5125) boot: Detect a condition of the factory reset
I (5125) boot: Data partitions to erase: nvs
I (5125) boot_comm: ## Label            Usage Offset   Length   Cleaned
I (5191) boot_comm:  0 nvs              data  00009000 00004000 [yes]
I (5220) boot_comm:  1 otadata          data  0000d000 00002000 [yes]
I (5221) boot_comm:  2 phy_init         data  0000f000 00001000 [no]
I (5223) boot: Defaulting to factory image
I (5228) boot_comm: chip revision: 3, min. application chip revision: 0
I (5235) esp_image: segment 0: paddr=00010020 vaddr=3f400020 size=078ech ( 30956) map
I (5255) esp_image: segment 1: paddr=00017914 vaddr=3ffb0000 size=02650h (  9808) load
I (5259) esp_image: segment 2: paddr=00019f6c vaddr=40080000 size=060ach ( 24748) load
I (5274) esp_image: segment 3: paddr=00020020 vaddr=400d0020 size=15480h ( 87168) map
I (5305) esp_image: segment 4: paddr=000354a8 vaddr=400860ac size=0556ch ( 21868) load
I (5315) esp_image: segment 5: paddr=0003aa1c vaddr=50000000 size=00010h (    16) load
I (5321) boot: Loaded app from partition at offset 0x10000
I (5321) boot: Disabling RNG early entropy source...
I (5337) cpu_start: Pro cpu up.
I (5337) cpu_start: Starting app cpu, entry point is 0x4008105c
0x4008105c: call_start_cpu1 at /home/chegewara/esp/master/components/esp_system/port/cpu_start.c:142

I (0) cpu_start: App cpu up.
I (5351) cpu_start: Pro cpu start user code
I (5351) cpu_start: cpu freq: 160000000 Hz
I (5351) cpu_start: Application information:
I (5356) cpu_start: Project name:     demo2
I (5361) cpu_start: App version:      1
I (5366) cpu_start: Compile time:     Aug 11 2022 08:23:12
I (5372) cpu_start: ELF file SHA256:  e668fc4e384c1e0e...
I (5378) cpu_start: ESP-IDF:          v5.0-dev-4723-g30e8f19f5a
I (5385) heap_init: Initializing. RAM available for dynamic allocation:
I (5392) heap_init: At 3FFAE6E0 len 00001920 (6 KiB): DRAM
I (5398) heap_init: At 3FFB2F38 len 0002D0C8 (180 KiB): DRAM
I (5405) heap_init: At 3FFE0440 len 00003AE0 (14 KiB): D/IRAM
I (5411) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM
I (5418) heap_init: At 4008B618 len 000149E8 (82 KiB): IRAM
I (5425) spi_flash: detected chip: gd
I (5428) spi_flash: flash io: dio
W (5432) spi_flash: Detected size(16384k) larger than the size in the binary image header(4096k). Using the size in the binary image header.
I (5446) cpu_start: Starting scheduler on PRO CPU.
I (0) cpu_start: Starting scheduler on APP CPU.


avasilev
Posts: 2
Joined: Sun Jan 08, 2023 3:45 pm

Re: factory reset button not working

Postby avasilev » Sun Jan 08, 2023 3:52 pm

I'm having the same problem - I have tried with GPIO 16 and 17 - bridged the GPIO to Gnd. The bootloader ignores it, both when resetting via the reset button on the board and by power cycling. In the confiuration I have set:

Code: Select all

[*] GPIO triggers factory reset
(17)    Number of the GPIO input for factory reset
        Factory reset GPIO level (Reset on GPIO low)  --->
[*]     Clear OTA data on factory reset (select factory partition)
()      Comma-separated names of partitions to clear on factory reset
(5) Hold time of GPIO for reset/test mode (seconds)

avasilev
Posts: 2
Joined: Sun Jan 08, 2023 3:45 pm

Re: factory reset button not working

Postby avasilev » Sun Jan 08, 2023 5:41 pm

I have investigated further and it turns out that not all GPIO pins work for this function. For GPIO pins 16 and 17, the function

Code: Select all

bootloader_common_check_long_hold_gpio_level
in bootloader_start.c always reads HIGH level, even when I have verified with a multimeter that the pin reads 0V. I even put a 1 sec delay after pin init and before reading it - still the same result. Maybe there is a problem with the raw initialization of the GPIO input & pull-up mode. I'm not familiar with this low-level API, and it's not documented, but I noticed that commenting out the

Code: Select all

esp_rom_gpio_pad_pullup_only()
call in

Code: Select all

bootloader_common_check_long_hold_gpio_level
, the pin starts to always read low, even if I connect it to VCC.
Anyway, after some experimenting, I decided to try pin 22, and it worked. So my guess is that this function has not been tested for all possible pins, and not all GPIO pins (with pull-up) are initialized in the same way. You need to find a free pin that works. Hopefully Espressif make this work for all GPIOs with internal pull-ups. I also noticed some artifacts in the code, probably from patching-in the implementation of additional configuration - things like:

Code: Select all

            bool ota_data_erase = false;
#ifdef CONFIG_BOOTLOADER_OTA_DATA_ERASE
            ota_data_erase = true;
#endif

ESP_Sprite
Posts: 9749
Joined: Thu Nov 26, 2015 4:08 am

Re: factory reset button not working

Postby ESP_Sprite » Mon Jan 09, 2023 12:22 am

GPIO16/17 are used for PSRAM; if you have a module or devboard that has PSRAM (even if you don't use it), those pins could be not connected on the outside. You sure that that isn't your issue?

Who is online

Users browsing this forum: Baidu [Spider], Bing [Bot], MicroController and 118 guests