Can I change the size of flash writes during OTA?

nickm2018 wrote on August 30, 2018:

My custom device uses external flash which has a sector size of 4k bytes. Is it possible to change the write chunks from 1K to 4K to better utilize my hardware, or is this defined by the OTA service running on the Server? My images are nearly 1Mbyte so this would improve the ota process by decreasing the total # of read/erase/write cycles.

I found otaconfigLOG2_FILE_BLOCK_SIZE in aws_ota_agent_internal.h but if I change it to 12 to get 4096, data is never written to my flash, as it appears to skip the write in aws_ota_agent.c, prvIngestDataBlock by failing this checkā€¦

if ( ( ( ( uint32_t )ulBlockIndex < iLastBlock ) && ( ulBlockSize == OTA_FILE_BLOCK_SIZE ) ) ||
( ( ( uint32_t )ulBlockIndex == iLastBlock ) && ( ( uint32_t )ulBlockSize == ( C->ulFileSize - ( iLastBlock * OTA_FILE_BLOCK_SIZE ) ) ) ) )

SarenaAtAws wrote on September 01, 2018:

Using the Windows Simulator project I verified that we can receive 4kB blocks in the OTA Agent (aws_ota_agent.c). I did the following in preparation for receiving 4kB sized files:

Updated aws_bufferpool_config.h:

#define bufferpoolconfigBUFFER_SIZE    ( 4096 + 256 )

Updated aws_mqtt_agent_config.h:

#define mqttconfigRX_BUFFER_SIZE         ( 4096 + 256 )

Updated aws_ota_agent_config.h:

#define otaconfigLOG2_FILE_BLOCK_SIZE           12UL

When a block is received from the OTA service we reach prvIngestDataBlock() and move from line 2383:
if ( ( ( ( uint32_t )ulBlockIndex < iLastBlock ) && ( ulBlockSize == OTA_FILE_BLOCK_SIZE ) ) ||
( ( ( uint32_t )ulBlockIndex == iLastBlock ) && ( ( uint32_t )ulBlockSize == ( C->ulFileSize - ( iLastBlock * OTA_FILE_BLOCK_SIZE ) ) ) ) )
{

And the expected logs shown are:


93 4402 \[MQTT] Received fixed header, 4230 bytes to receive.
94 4404 \[OTA Task] \[prvIngestDataBlock] Received file block 0, size 4096
95 4404 \[OTA Task] \[prvIngestDataBlock] Remaining: 207
96 4423 \[IP-task] Socket sending wakeup to MQTT task.
97 4423 \[MQTT] Received message 0 from queue.
98 4423 \[MQTT] Received fixed header, 4230 bytes to receive.
99 4425 \[OTA Task] \[prvIngestDataBlock] Received file block 1, size 4096
100 4425 \[OTA Task] \[prvIngestDataBlock] Remaining: 206

Currently by default MQTT logs are turned off. It will be helpful if you turn them on to see if the issue with receiving the blocks is from your mqtt buffer sizes:
Please update the following line in aws_mqtt_config.h:

#define mqttconfigENABLE_DEBUG_LOGS    1

Let me know if this helps!

Thanks,
Sarena

nickm2018 wrote on September 04, 2018:

@SarenaAtAws
Perfect answer! I missed the step of extending the buffer spaces.