GPIO Based Factory Reset

Ritu21
Posts: 123
Joined: Sat Aug 04, 2018 9:58 am

GPIO Based Factory Reset

Postby Ritu21 » Thu May 30, 2019 9:53 am

Hi Team,

I am using OTA update in my project but I want to enable an option to move back to factory image. I found out below option but not sure of the same. Below is the link:

https://docs.espressif.com/projects/esp ... tory-reset

It is mentioned here that "To trigger a factory reset, this GPIO must be pulled low on reset." Here, reset means hard reboot??
OTA will work even after moving to factory image?
If not this method, let me know if there is any other way to do the same.

Thanks
Ritu.

Ritu21
Posts: 123
Joined: Sat Aug 04, 2018 9:58 am

Re: GPIO Based Factory Reset

Postby Ritu21 » Fri May 31, 2019 9:08 am

Waiting for response

Ritesh
Posts: 1383
Joined: Tue Sep 06, 2016 9:37 am
Location: India
Contact:

Re: GPIO Based Factory Reset

Postby Ritesh » Sat Jun 01, 2019 10:06 am

Hi,

First of all, Did you check how OTA is working into ESP32 with different partitions like Factory App, OTA_0 and OTA_1?

Also just want to make sure requirement like you want to switch to Factory Default Partition using some external input if you are running your current image into OTA_0 or OTA_1 partition as per your partition table mechanism?

Or you want something else?
Regards,
Ritesh Prajapati

Ritu21
Posts: 123
Joined: Sat Aug 04, 2018 9:58 am

Re: GPIO Based Factory Reset

Postby Ritu21 » Mon Jun 03, 2019 6:04 am

Hi Ritesh,

I want to move back to factory app if required.

Thanks
Ritu

Ritesh
Posts: 1383
Joined: Tue Sep 06, 2016 9:37 am
Location: India
Contact:

Re: GPIO Based Factory Reset

Postby Ritesh » Mon Jun 03, 2019 8:21 am

Ritu21 wrote:
Mon Jun 03, 2019 6:04 am
Hi Ritesh,

I want to move back to factory app if required.

Thanks
Ritu
So that Requirement is based on any event or button or something like that?
Regards,
Ritesh Prajapati

Ritu21
Posts: 123
Joined: Sat Aug 04, 2018 9:58 am

Re: GPIO Based Factory Reset

Postby Ritu21 » Mon Jun 03, 2019 8:24 am

Yes, something like when we give input from GPIO, device should restart from factory app.

Ritesh
Posts: 1383
Joined: Tue Sep 06, 2016 9:37 am
Location: India
Contact:

Re: GPIO Based Factory Reset

Postby Ritesh » Mon Jun 03, 2019 8:27 am

Ritu21 wrote:
Mon Jun 03, 2019 8:24 am
Yes, something like when we give input from GPIO, device should restart from factory app.
Ok. Then it is quite easy job to move your firmware into factory app which you are using.

So, Basically, which partition mechanism you are using? if you are using Default, OTA_0 and OTA_1 then you can do easily which you want in case to move your device to factory firmware.
Regards,
Ritesh Prajapati

Ritu21
Posts: 123
Joined: Sat Aug 04, 2018 9:58 am

Re: GPIO Based Factory Reset

Postby Ritu21 » Mon Jun 03, 2019 1:21 pm

Yes, I am using Factory, OTA_0, OTA_1 partitions for image update. How do we do that??

Ritesh
Posts: 1383
Joined: Tue Sep 06, 2016 9:37 am
Location: India
Contact:

Re: GPIO Based Factory Reset

Postby Ritesh » Mon Jun 03, 2019 1:59 pm

Ritu21 wrote:
Mon Jun 03, 2019 1:21 pm
Yes, I am using Factory, OTA_0, OTA_1 partitions for image update. How do we do that??
Please find below code sequence which we are using. but we are using for Default Partition and OTA_0. So, Same way you can use it for all 3 partitions in which you can set Default Partition as Factory Reset Partition while other OTA_0 and OTA_1 partitions can be used for Firmware Update support and switching for that.

esp_partition_t partition;
memset(&partition, 0, sizeof(esp_partition_t));

const esp_partition_t *partition1 = esp_ota_get_boot_partition();
if (partition1 == NULL) {
return FIRMWARE_UPDATE_FAIL;
}

if (partition1->subtype == ESP_PARTITION_SUBTYPE_APP_OTA_0) {
partition.type = ESP_PARTITION_TYPE_APP;
partition.subtype = ESP_PARTITION_SUBTYPE_APP_FACTORY;
partition.address = OTA_PARTITION_0_ADDR;
partition.size = OTA_PARTITION_SIZE;
strcpy(partition.label, "FACTORY_APP");
partition.encrypted = FAIL;
dest = OTA_PARTITION_0_ADDR;
} else if (partition1->subtype == ESP_PARTITION_SUBTYPE_APP_FACTORY) {
partition.type = ESP_PARTITION_TYPE_APP;
partition.subtype = ESP_PARTITION_SUBTYPE_APP_OTA_0;
partition.address = OTA_PARTITION_1_ADDR;
partition.size = OTA_PARTITION_SIZE;
strcpy(partition.label, "OTA_0_APP");
partition.encrypted = FAIL;
dest = OTA_PARTITION_1_ADDR;
}

spi_flash_erase_range
spi_flash_write
esp_ota_set_boot_partition
Restart ESP32 with some timer mechanism of 5 seconds or 10 seconds

Let me know if need any further help regarding same.
Regards,
Ritesh Prajapati

Ritu21
Posts: 123
Joined: Sat Aug 04, 2018 9:58 am

Re: GPIO Based Factory Reset

Postby Ritu21 » Tue Jun 04, 2019 5:31 am

In your code, you are first checking the present partition and accordingly changing the other partition, But I want to change to factory app, be it any partition. So, my code would be something like below:

esp_partition_t partition;
memset(&partition, 0, sizeof(esp_partition_t));

const esp_partition_t *partition1 = esp_ota_get_boot_partition();
if (partition1 == NULL) {
return FIRMWARE_UPDATE_FAIL;
}
if ((partition1->subtype == ESP_PARTITION_SUBTYPE_APP_OTA_0) || (partition1->subtype == ESP_PARTITION_SUBTYPE_APP_OTA_1)){
partition.type = ESP_PARTITION_TYPE_APP;
partition.subtype = ESP_PARTITION_SUBTYPE_APP_FACTORY;
partition.address = OTA_PARTITION_0_ADDR; /*why are you using ota_0 partition address*/
partition.size = OTA_PARTITION_SIZE; /*wht are you using ota partition size*/
strcpy(partition.label, "FACTORY_APP");
partition.encrypted = FAIL;
dest = OTA_PARTITION_0_ADDR;
}
else printf("Already running factory app\n");

Please check the above code and confirm.

Also, please let me know the GPIO configuration for this.I will be using pin 33/GPIO21.

Thanks
Ritu

Who is online

Users browsing this forum: No registered users and 160 guests