Hi Mariya,
My colleague Witek wrote application note AN4406
https://www.nxp.com/docs/en/application-note/AN4406.pdf.
This is a programmer that runs on Kinetis K40, and programs any other Kinetis device using the EzPort interface. The code was developed on the old KwikStik development board but would be portable to any Kinetis device.
There was some activity in May 2025 on the project:
https://community.nxp.com/t5/Kinetis-Microcontrollers/Where-can-I-find-the-source-files-for-CodeWarr...
You asked about SWD programmers. I have written a SWD programmer - based on Kinetis KL82Z custom board and with code written in MCUXpresso IDE. I have tested it with KL82Z, LPC55S69, Nordic nrf52840 and an STM32 (forget which one). It was written from "first principles" using the ARM technical documentation for the SWD interface and details about Kinetis MDM-AP available in the public domain. I also used the (Keil MDK) projects for CMSIS-DAP as a reference. All this was written commercially for a client and I am not able to share the source code with you. But I want to reassure you that it is possible for you to write a SWD programmer.
But maybe easiest to stick with EzPort if your Kinetis devices support it.
Good luck!