Thank you Radek,
I have found the cause. Indeed my erase and program operation was already successful, yet in the debug window of codewarrior5.1 debugger hiwave.exe, the flash value was not updated after erase or program, it's still the value burned in when BDM download. After the flash data copied to a buffer to check, it's alreay the value programmed in. I do not know it's Hiwave's restriction or the flash memory refresh can be enabled by certain register or setting.
I'm sorry the code I attached is a temporary test version, there was several bugs in it. I re-attached the flash operation code for DP512 which is used in our BCU (Battery controller unit) CAN bootloader, it's tested worked well in last week end on our BMS (Battery management system) product.
In addition, reading through the S12DP512 flash specification, the erase or program should have no limitaion on same block of the execution code and target flash, below is copied from S12FTS512K4V1.pdf
"All Flash blocks can be programmed or erased at the same time. However, it is not possible to read from
a Flash block while it is being erased or programmed "
also in your code, your execution code is on 0xc000, and your target flash is on 0x398000, Flash_Erase_Sector(0x398000), which are sectors of block 0 of DP512.
In my bootloader code, the flash driver is on RAM to run, it should be safe.