# How to host OTA Patch

**URL:** <https://forums.freertos.org/t/how-to-host-ota-patch/16052>\
**Category:** AWS\
**Created:** [October 24, 2022, 11:10pm UTC](https://forums.freertos.org/t/how-to-host-ota-patch/16052 "2022-10-24T23:10:41Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![DoubleH](https://avatars.discourse-cdn.com/v4/letter/d/958977/32.png) [@DoubleH](https://forums.freertos.org/u/DoubleH)\
**Post date:** [October 24, 2022, 11:10pm UTC](https://forums.freertos.org/t/how-to-host-ota-patch/16052/1 "2022-10-24T23:10:41Z")

</div>

Hello,

I’m looking to update the OTA demo to perform a host ota update. I’m following the blog post [how-to-perform-secondary-processor-over-the-air-updates-with-freertos](https://aws.amazon.com/blogs/iot/how-to-perform-secondary-processor-over-the-air-updates-with-freertos/)

I’m working with AFR 202107.00 which I think maybe part of the problem as it doesn’t have the function vRunOTAUpdateDemo() within it nor the aws\_iot\_ota\_update\_demo.c to patch, but the blog post says any AFR later than 201908.00 should work.

The blog post talks about patching in [this file](https://raw.githubusercontent.com/aws-samples/amazon-freertos-ota-scripts/master/patches/secondaryota.patch) but I have no idea what that means. I’m hoping someone here can enlighten me on this 🙂 Maybe someone has another blog/guide on how to do this or a gitlab repo with a working example?

I now see this has an open issues ticket too [issues ticket](https://github.com/aws-samples/amazon-freertos-ota-scripts/issues/4)

---

<div class="post-metadata">

**Author:** ![DavidGC-FreeRTOS](https://avatars.discourse-cdn.com/v4/letter/d/8dc957/32.png) [@DavidGC-FreeRTOS](https://forums.freertos.org/u/DavidGC-FreeRTOS)\
**Post date:** [October 25, 2022, 12:52am UTC](https://forums.freertos.org/t/how-to-host-ota-patch/16052/2 "2022-10-25T00:52:04Z")

</div>

Hi @DoubleH

I would recommend using the latest version of the OTA library if possible as the blog post is a few years old and there’s been various fixes and improvements to the libraries since.

With regards to [latest OTA library](https://github.com/aws/ota-for-aws-iot-embedded-sdk), downloading firmware for a secondary processor should be doable through PAL changes alone. Before calling `OTA_Init` user must set the OTA agent interfaces. Among those user defined functions is [pal.writeBlock](https://github.com/aws/aws-iot-device-sdk-embedded-C/blob/main/demos/ota/ota_demo_core_mqtt/ota_demo_core_mqtt.c#L1495) for example. The function signature for this takes `OtaFileContext_t` as an argument, which you can use to extract `OtaFileContext_t::fileType`. This argument is seeded with the `fileId` that came with initial OTA job document.

One way to do this would be to assign some file type value that distinguishes “OTA for secondary” type jobs, then use that value from `OtaFileContext_t` throughout the PAL whenever you need different logic for the controller, such as writing to a different channel. There’s other PAL functions that may provide useful hooks for preparing the controller, such as `pal.createFile` and `pal.closeFile` for download.

---

<div class="post-metadata">

**Author:** ![DoubleH](https://avatars.discourse-cdn.com/v4/letter/d/958977/32.png) [@DoubleH](https://forums.freertos.org/u/DoubleH)\
**Post date:** [October 27, 2022, 8:33pm UTC](https://forums.freertos.org/t/how-to-host-ota-patch/16052/3 "2022-10-27T20:33:01Z")

</div>

> [@DavidGC-FreeRTOS](#):
>
> I would recommend using the latest version of the OTA library if possible as the blog post is a few years old and there’s been various fixes and improvements to the libraries since.
> 
> With regards to [latest OTA library](https://github.com/aws/ota-for-aws-iot-embedded-sdk), downloading firmware for a secondary processor should be doable through PAL changes alone. Before calling `OTA_Init` user must set the OTA agent interfaces. Among those user defined functions is [pal.writeBlock](https://github.com/aws/aws-iot-device-sdk-embedded-C/blob/main/demos/ota/ota_demo_core_mqtt/ota_demo_core_mqtt.c#L1495) for example. The function signature for this takes `OtaFileContext_t` as an argument, which you can use to extract `OtaFileContext_t::fileType`. This argument is seeded with the `fileId` that came with initial OTA job document.
> 
> One way to do this would be to assign some file type value that distinguishes “OTA for secondary” type jobs, then use that value from `OtaFileContext_t` throughout the PAL whenever you need different logic for the controller, such as writing to a different channel. There’s other PAL functions that may provide useful hooks for preparing the controller, such as `pal.createFile` and `pal.closeFile` for download.

Nice, I’ll test this out in the coming weeks. Thank!
