in components/ota_pal/source/ota_pal.c [1017:1083]
static int prvApplyPatch( void )
{
int ret = 0;
esp_partition_context_t sourceCtx = { 0 }, patchCtx = { 0 }, targetCtx = { 0} ;
unsigned char *source_buffer = NULL, *patch_buffer = NULL, *target_buffer = NULL;
/* Set source partition context.*/
sourceCtx.partition = esp_ota_get_running_partition();
sourceCtx.size = prvGetRunningPartitionSize();
source_buffer = (unsigned char *)pvPortMalloc( PATCH_BUFFER_SIZE );
if ( source_buffer == NULL )
{
LogError( ( "pvPortMalloc failed allocating %d bytes for source_buffer.", PATCH_BUFFER_SIZE ) );
return -1;
}
/* Set desitination partition context.*/
patchCtx.partition = ota_ctx.patch_partition;
patchCtx.size = ota_ctx.data_write_len;
patch_buffer = (unsigned char *)pvPortMalloc( PATCH_BUFFER_SIZE );
if ( patch_buffer == NULL )
{
LogError( ( "pvPortMalloc failed allocating %d bytes for patch_buffer.", PATCH_BUFFER_SIZE ) );
free( source_buffer );
return -1;
}
/* Set target partition context.*/
targetCtx.partition = ota_ctx.update_partition;
target_buffer = (unsigned char *)pvPortMalloc( PATCH_BUFFER_SIZE );
if ( target_buffer == NULL )
{
LogError( ( "pvPortMalloc failed allocating %d bytes for target_buffer.", PATCH_BUFFER_SIZE ) );
free( source_buffer );
free( patch_buffer );
return -1;
}
/* Set janpatch context.*/
janpatch_ctx jCtx =
{
{ source_buffer, PATCH_BUFFER_SIZE, 0xffffffff, 0, NULL, 0 },
{ patch_buffer, PATCH_BUFFER_SIZE, 0xffffffff, 0, NULL, 0 } ,
{ target_buffer, PATCH_BUFFER_SIZE, 0xffffffff, 0, NULL, 0 },
&prvfread,
&prvfwrite,
&prvfseek,
&prvftell,
&prvPatchProgress,
0
};
/* Patch the base version.*/
ret = janpatch( jCtx, &sourceCtx, &patchCtx, &targetCtx );
if( ret == 0 )
{
ota_ctx.data_write_len = targetCtx.offset;
}
/* Release the buffers. */
free( source_buffer );
free( patch_buffer );
free( target_buffer );
return ret;
}