Hi Muhammad bilal
First, as you are using the Jlink commander, could you try to send a "erase" command in the same tool, to see if this can mass erase the content in the flash, then if this method works, try the unlock kinetis. This is to see if your device has become irrecoverable.
Your flash algorithm shouldn't be the problem, the problem is what you are loading in the flash configuration field, in the address 0x0_040C (FSEC). I recommend you to check this links:
https://mcuoneclipse.com/2012/11/04/how-not-to-secure-my-microcontroller/
http://cache.nxp.com/files/microcontrollers/doc/app_note/AN4507.pdf
Both of them describes good practices when you program kinetis devices and tell you how to avoid the security lock.
Have a great day,
Jorge Alcala
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------