esp-aws-iot: "Factory" partition and "otadata partition is invalid, factory/ota_0 is boot partition" - OTA fails (CA-302)

**Platform : ESP32

Branch : https://github.com/espressif/esp-aws-iot/tree/release/202210.01-LTS

ESP_IDF : esp-idf-v4.4.4**

Problem :
OTA Agent fails to boot the downloaded image if partition csv contains ‘factory’ partition. If ‘factory’ partition is removed from csv then the OTA agent works OK.

Partition table that FAILS

# Name,   Type, SubType, Offset,  Size, Flags
# Note: if you have increased the bootloader size, make sure to update the offsets to avoid overlap
nvs,      data, nvs,     0x9000,   16k,
otadata,  data, ota,     0xd000,   8K,
phy_init, data, phy,     0xf000,   4k,
factory,  app,  factory, 0x10000,  2M,
ota_0,    app,  ota_0,   0x210000, 2M,
ota_1,    app,  ota_1,   0x410000, 2M,
storage,  data, spiffs,          , 1M,

Partition table that SUCCEEDS

# Name,   Type, SubType, Offset,  Size, Flags
# Note: if you have increased the bootloader size, make sure to update the offsets to avoid overlap,,,,
nvs,      data, nvs,     0x9000,   16k,
otadata,  data, ota,     0xd000,   8K,
phy_init, data, phy,     0xf000,   4k,
ota_0,    app,  ota_0,   0x210000, 2M,
ota_1,    app,  ota_1,   0x410000, 2M,
storage,  data, spiffs,          , 1M,

Debug

On initialising the OTA agent we get this warning

I (49719) mqtt-agent: establishing a TLS session to a14vwue44pf12r-ats.iot.eu-west-2.amazonaws.com:8883 ...
I (51179) mqtt-agent: establishing a MQTT connection for client: 78218443E4AC ...
I (51579) coreMQTT: MQTT connection established with the broker.
I (51579) mqtt-agent: session present: 0
I (51579) mqtt-agent: connected to AWS endpoint
I (52739) zappi: set rssi:-72
I (53139) AWS_OTA: otaPal_GetPlatformImageState
**I (53139) esp_ota_ops: aws_esp_ota_get_boot_flags: 1
W (53149) esp_ota_ops: otadata partition is invalid, factory/ota_0 is boot partition**

This warning is traced to line 77 of aws_esp_ota_ops.c in _esp_get_otadata_partition().

Call stack appears to be _esp_get_otadata_partition() -> ota_select_valid() ->

On the reboot after the download

 (21094) coreMQTT: Ack packet deserialized with result: MQTTSuccess.
I (21094) coreMQTT: State record updated. New state=MQTTPublishDone.
I (21094) coreMQTT: De-serialized incoming PUBLISH packet: DeserializerResult=MQTTSuccess.
I (21104) coreMQTT: State record updated. New state=MQTTPublishDone.
I (21114) mqtt-agent: incoming publish passed to subscription manager
I (21104) mqtt-ota: sent PUBLISH packet to broker $aws/things/78218443E4AC/jobs/AFR_OTA-78218443E4AC-V003-3/update to broker
I (21124) AWS_OTA: Job parsing success: OtaJobParseErr_t=OtaJobParseErrNone, Job name=AFR_OTA-78218443E4AC-V003-3
I (21144) AWS_OTA: otaPal_GetPlatformImageState
**I (21144) esp_ota_ops: aws_esp_ota_get_boot_flags: 1**
**I (21174) esp_ota_ops: [0] aflags/seq:0xffffffff/0x1, pflags/seq:0xffffffff/0x0**
I (21174) mqtt-ota: received OtaJobEventProcessed callback from OTA Agent.
I (21174) AWS_OTA: Current State=[CreatingFile], Event=[ReceivedJobDocument], New state=[CreatingFile]
I (21184) AWS_OTA: Beginning self-test.
I (21184) AWS_OTA: otaPal_GetPlatformImageState
I (21194) esp_ota_ops: aws_esp_ota_get_boot_flags: 1
**I (21214) esp_ota_ops: [0] aflags/seq:0xffffffff/0x1, pflags/seq:0xffffffff/0x0**
W (21214) AWS_OTA: Rejecting new image and rebooting:The job is in the self-test state while the platform is not.
I (21214) AWS_OTA: otaPal_SetPlatformImageState, 3
W (21224) AWS_OTA: Set image as invalid!
I (21224) esp_ota_ops: aws_esp_ota_get_boot_flags: 1
I (21254) esp_ota_ops: [0] aflags/seq:0xffffffff/0x1, pflags/seq:0xffffffff/0x0
W (21254) AWS_OTA: Image not in self test mode 4294967295
I (21254) esp_ota_ops: aws_esp_ota_get_boot_flags: 1
I (21264) esp_ota_ops: [0] aflags/seq:0xffffffff/0x1, pflags/seq:0xffffffff/0x0
I (21264) mqtt-ota: publishing.... to topic $aws/things/78218443E4AC/jobs/AFR_OTA-78218443E4AC-V003-3/update
I (22114) coreMQTT: Publishing message to $aws/things/78218443E4AC/jobs/AFR_OTA-78218443E4AC-V003-3/update.

I have seen references to this issue here https://github.com/aws/amazon-freertos/issues/1429 dating to 2019 but was supposedly fixed?

I would be grateful if you would look into this. Thanks.

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Comments: 16

Most upvoted comments

I use a table that is slightly more complex than this one and I never have a problem with it – but I don’t call an agent in my AWS IOT project.

The formatting doesn’t hold here so the columns are not nice to look at. What you are seeing here are sizes – but NOT offsets.

Name, Type, SubType, Offset, Size, Flags nvs, data, nvs, , 0x006000, nvs_key, data, nvs_keys, , 0x001000, encrypted phy_init, data, phy, , 0x001000, encrypted otadata, data, ota, , 0x002000, factory, app, factory, , 0x271000, ota_0, app, ota_0, , 0x67D000, ota_1, app, ota_1, , 0x67D000,