#!/bin/sh

blocks=56
offset=4	# 0 for manufacturer ID (0x0089)


hex()
{
	( echo obase=16; echo $1; ) | bc -q
}


(
	cat <<EOF
cable milkymist
detect
instruction CFG_OUT  000100 BYPASS
instruction CFG_IN   000101 BYPASS
pld load fjmem.bit
initbus fjmem opcode=000010
frequency 6000000
detectflash 0
poke 0 0x90
EOF
	a=$offset
	i=0
	while [ $i -lt $blocks ]; do
		echo peek 0x`hex $a`
		a=`expr $a + 128 \* 1024`
		i=`expr $i + 1`
	done
echo poke 0 0xff
) | jtag -q
