proc program_device {filename flashstart} {
halt
wait_halt
load_image $filename $flashstart
sleep 10
reset halt
resume
sleep 10
shutdown
};
Invoke openocd with option ...
-c "program_device bin/main.ihx 0"
bin/main.ihx
is your hex file
openocd -f scripts/interface/stlink.cfg -f scripts/target/stm8s.cfg -c "init" -c "program_device bin/main.ihx 0"