Page 2 of 3

Re: OTA and the otadata partition

Posted: Mon Oct 01, 2018 10:19 pm
by fly135
mzimmers wrote:After a few diversions, I'm ready to dig into this.

My partition table is set to "Factory app, two OTA definitions." Is there anything else I need to do before I can start using this?
How about OTADATA?

Code: Select all

# Name,   Type, SubType, Offset,  Size, Flags
# Note: if you change the phy_init or app partition offset, make sure to change the offset in Kconfig.projbuild
nvs,      data, nvs,     0x9000,  0x4000
otadata,  data, ota,     0xd000,  0x2000
phy_init, data, phy,     0xf000,  0x1000,
factory,  app,  factory, 0x10000, 2M,
storage,  data, spiffs,  ,        0xF0000,
ota_0,    0, ota_0,     0x400000, 2M,
ota_1,    0, ota_1,     0x600000, 2M,

Re: OTA and the otadata partition

Posted: Mon Oct 01, 2018 10:33 pm
by mzimmers
Yes, that's in my partitions list:

Code: Select all

I (34) boot: Partition Table:
I (37) boot: ## Label            Usage          Type ST Offset   Length
I (45) boot:  0 nvs              WiFi data        01 02 00009000 00004000
I (52) boot:  1 otadata          OTA data         01 00 0000d000 00002000
I (59) boot:  2 phy_init         RF data          01 01 0000f000 00001000
I (67) boot:  3 factory          factory app      00 00 00010000 00100000
I (74) boot:  4 ota_0            OTA app          00 10 00110000 00100000
I (82) boot:  5 ota_1            OTA app          00 11 00210000 00100000

Re: OTA and the otadata partition

Posted: Tue Oct 02, 2018 12:10 am
by fly135
Looks like you are good to start OTAing now.

Re: OTA and the otadata partition

Posted: Tue Oct 02, 2018 2:37 pm
by mzimmers
Once I've done an OTA update, how do I tell which location I'm running from? Are there any management tools for extracting information from the OTA data partition? I'm sure that eventually customers are going to want to know more about this.

Re: OTA and the otadata partition

Posted: Tue Oct 02, 2018 3:02 pm
by fly135
mzimmers wrote:Once I've done an OTA update, how do I tell which location I'm running from? Are there any management tools for extracting information from the OTA data partition? I'm sure that eventually customers are going to want to know more about this.
If you are running a terminal, look for a boot line that looks like this....
I (522) boot: Loaded app from partition at offset 0x10000
The offset will tell you which OTA partition is running. If you aren't running a terminal then your firmware can have a version number and you can report it through what ever means your device uses to interact with the humans.

John A

Re: OTA and the otadata partition

Posted: Mon Oct 29, 2018 5:23 pm
by mzimmers
After another interrupt, I'm finally ready to have a go. Here's what I'm thinking (the commented code is the esp OTA stuff that I'm about to try):

Code: Select all

            // initialize the socket.
            rc = setupSocket();
            if (rc == 0)
            {
                ESP_LOGI(TAG, "otaTask(): listening socket setup successfully.");

//                m_partInfo = const_cast<esp_partition_t *>(esp_ota_get_next_update_partition(nullptr));
//                if (m_partInfo != nullptr)
//                {
//                    rc = esp_ota_begin(m_partInfo, binSize, &m_handle);
//                    if (rc == ESP_OK)
                    {
                        rc = receive(binSize);
//                      esp_ota_end(m_handle); // do this to free memory used by OTA.
                        if (rc == ESP_OK)
                        {
//            	             esp_ota_set_boot_partition(m_partInfo);
                        }
                        else //if (rc != ESP_OK)
                        {
                            ESP_LOGE(TAG, "otaTask(): receive failed.");
                        }
                    }
//                    else
//                    {
//                        ESP_LOGE(TAG, "otaTask(): esp_ota_begin() error: %d %s", rc, strerror(rc));
//                    }
//                }
//                else
//                {
//                    ESP_LOGE(TAG, "otaTask(): esp_ota_get_next_update_partition() error.");
//                }
            }
            else
            {
                ESP_LOGE(TAG, "otaTask(): listening socket setup failed.");
            }

            // call closeSocket regardless of rc from setupSocket(),
            // as it may have created the socket but failed during a bind/listen/accept/etc.
            closeSocket();
Does this look about right?

Re: OTA and the otadata partition

Posted: Mon Oct 29, 2018 5:39 pm
by fly135
You seem pretty intent on doing this the hard way. I don't see where you are setting the boot partition.

John A

Re: OTA and the otadata partition

Posted: Mon Oct 29, 2018 5:47 pm
by mzimmers
Hi John - it wasn't my choice; the boss didn't like the web-based option.

My set partition was in there; the comment was just intented too far to be easily seen. I've fixed that in the code above.

Can I use esp_ota_set_boot_partition() to set the partition to the factory partition? It doesn't say I can't anywhere, but given this is an OTA facility, I'm wondering.

Re: OTA and the otadata partition

Posted: Mon Oct 29, 2018 6:46 pm
by fly135
You need to set the boot partition to the partition returned by esp_ota_get_next_update_partition. So you would not be getting the factory partition from that call. Bottom line is IDK. You could grab the code in esp_ota_ops.c and modify to see if you can make it work. But it's not going to do it as is.

Yeah, I see the call now.

John A

Re: OTA and the otadata partition

Posted: Mon Oct 29, 2018 7:17 pm
by chegewara
mzimmers wrote: Can I use esp_ota_set_boot_partition() to set the partition to the factory partition? It doesn't say I can't anywhere, but given this is an OTA facility, I'm wondering.
Yes, you can. Only you have to do is to pass any valid partition (factory partition in this case) as a parameter.