Skip to content

Commit db83f2a

Browse files
author
Sebastien Bourdeauducq
committedFeb 15, 2013
add m1nor
1 parent 183e58f commit db83f2a

File tree

1 file changed

+132
-0
lines changed

1 file changed

+132
-0
lines changed
 

‎m1nor

+132
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
#!/bin/sh
2+
#
3+
# m1nor - Flash a file to M1 NOR partition selected by the file name
4+
#
5+
# Written 2011 by Werner Almesberger
6+
# Copyright 2011 by Werner Almesberger
7+
#
8+
# This program is free software; you can redistribute it and/or modify
9+
# it under the terms of the GNU General Public License as published by
10+
# the Free Software Foundation; either version 2 of the License, or
11+
# (at your option) any later version.
12+
#
13+
14+
#
15+
# According to
16+
# http://www.milkymist.org/wiki/index.php?title=Flashing_the_Milkymist_One#Flash_Memory_Distribution
17+
#
18+
# standby.fpg 0x0000 0000 640k
19+
# soc-rescue.fpg 0x000A 0000 1536k
20+
# bios-rescue.bin 0x0022 0000 128k
21+
# splash-rescue.raw 0x0024 0000 640k
22+
# flickernoise.fbi(res) 0x002E 0000 4096k
23+
# soc.fpg 0x006E 0000 1536k alias: system.fpg
24+
# bios.bin 0x0086 0000 128k
25+
# splash.raw 0x0088 0000 640k
26+
# flickernoise.fbi 0x0092 0000 4096k
27+
# (data) 0x00D2 0000 19328k
28+
#
29+
30+
classify()
31+
{
32+
if [ ! -r "$1" ]; then
33+
echo "$1: cannot read" 1>&2
34+
exit 1
35+
fi
36+
37+
b=${1##*/}
38+
if [ "${b#standby}" != "$b" ]; then off=0x0; ext=.fpg
39+
elif [ "${b#soc-rescue}" != "$b" ]; then off=0xa0000; ext=.fpg
40+
elif [ "${b#bios-rescue}" != "$b" ]; then off=0x220000; ext=.bin
41+
elif [ "${b#splash-rescue}" != "$b" ]; then off=0x240000; ext=.raw
42+
elif [ "${b#flickernoise-rescue}" != "$b" ]; then off=0x2e0000; ext=.fbi
43+
elif [ "${b#soc}" != "$b" ]; then off=0x6e0000; ext=.fpg
44+
elif [ "${b#system}" != "$b" ]; then off=0x6e0000; ext=.fpg
45+
elif [ "${b#bios}" != "$b" ]; then off=0x860000; ext=.bin
46+
elif [ "${b#splash}" != "$b" ]; then off=0x880000; ext=.raw
47+
elif [ "${b#flickernoise}" != "$b" ]; then off=0x920000; ext=.fbi
48+
elif [ "${b#data}" != "$b" ]; then off=0xd20000; ext=
49+
else
50+
echo "$1: unrecognized file name" 1>&2
51+
exit 1
52+
fi
53+
54+
if [ "$ext" -a "${1%$ext}" = "$1" ]; then
55+
echo "$1: extension mismatch (expected $ext)" 1>&2
56+
exit 1
57+
fi
58+
}
59+
60+
61+
if [ -z "$1" ]; then
62+
echo "usage: $0 filename ..." 1>&2
63+
exit 1
64+
fi
65+
66+
if [ "$FJMEM_BIT" ]; then
67+
fjmem=$FJMEM_BIT
68+
else
69+
fjmem=
70+
for n in /usr/local/share/milkymist/fjmem.bit \
71+
$HOME/.qi/milkymist/*/*/fjmem.bit; do
72+
if [ -r "$n" ]; then
73+
fjmem="$n"
74+
break
75+
fi
76+
done
77+
if [ -z "$fjmem" ]; then
78+
echo "cannot find fjmem.bit (consider setting FJMEM_BIT)" 1>&2
79+
exit 1
80+
fi
81+
fi
82+
83+
for n in "$@"; do
84+
classify "$n"
85+
done
86+
87+
(
88+
cat <<EOF
89+
cable milkymist
90+
detect
91+
instruction CFG_OUT 000100 BYPASS
92+
instruction CFG_IN 000101 BYPASS
93+
pld load "$fjmem"
94+
initbus fjmem opcode=000010
95+
frequency 6000000
96+
detectflash 0
97+
endian big
98+
EOF
99+
for n in "$@"; do
100+
classify "$n"
101+
echo flashmem "$off" "$n" noverify
102+
done
103+
echo lockflash 0 55
104+
echo detectflash 0
105+
echo pld reconfigure
106+
) | jtag -q || exit
107+
108+
#
109+
# Fun fact: a direct flashmem-lockflash-pld reconfigure sequence leaves
110+
# the FPGA in a weird state from which it can't boot out of standby, neither
111+
# via JTAG (pld load ...) or by pressing the middle button.
112+
#
113+
# The only thing that seems to help is to run "detectflash" after the locking.
114+
# (Tried "peek", "usleep", "pld readreg", ... without success.)
115+
#
116+
117+
#
118+
# FIXME: the exit code of "jtag" doesn't indicate whether the session was
119+
# successful.
120+
#
121+
122+
first=true
123+
for n in "$@"; do
124+
classify "$n"
125+
echo -n "Flashed $n at offset $off" 1>&2
126+
if $first; then
127+
echo " using $fjmem" 1>&2
128+
else
129+
echo 1>&2
130+
fi
131+
first=false
132+
done

0 commit comments

Comments
 (0)
Please sign in to comment.