summaryrefslogtreecommitdiff
path: root/cleopatre/tools/openocd-r668/config/gen_ocd_config
blob: a0d96b23ac755680e0f893d7fbddc6d67f49b82e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
#!/bin/bash

usage_board()
{
    echo "Define a default board or, flash type and JTAG speed using:"
    echo "  -b/--board SPK300g|SPK300|SPK310|SCR310_AD98[65|67|68]|SPR300|SPR310|MSK500|MSK501|MCR500|MCR510"
    echo "  or"
    echo "  -f/--flash <name>, <name> can be found in tools/openocd-r668/src/flash/spc300.h file of the bundle (default is m25p64)"
    echo "  -s/--speed: in kHz, usage is 5000 for a clock input of 37,5MHz (default is 500)"
    echo ""
}

usage_probe()
{
    echo "Define the JTAG probe using:"
    echo "  -p/--probe baiwen|olimex|amontec"
    echo ""
}

pathcaller=${0%/*}

cd $pathcaller

if [ ! -f generic.cfg ]; then
    echo "Cannot find script model $pathcaller/generic.cfg"
    echo ""
    exit 1;
fi
if [ ! -f reset_300.ocd ]; then
    echo "Cannot find OCD script $pathcaller/reset_300.ocd"
    echo ""
    exit 1;
fi
if [ ! -f reset_500.ocd ]; then
    echo "Cannot find OCD script $pathcaller/reset_500.ocd"
    echo ""
    exit 1;
fi
if [ ! -f reset_init_sdram_32.ocd ]; then
    echo "Cannot find OCD script $pathcaller/reset_init_sdram_32.ocd"
    echo ""
    exit 1;
fi
if [ ! -f reset_init_sdram_16.ocd ]; then
    echo "Cannot find OCD script $pathcaller/reset_init_sdram_16.ocd"
    echo ""
    exit 1;
fi

while true
do
    case $# in 0) break;; esac
    case $1 in
    -b|--board) shift; board=$1; shift ;;
    -p|--probe) shift; probe=$1; shift ;;
    -f|--flash) shift; flash=$1; shift ;;
    -s|--speed) shift; speed=$1; shift ;;
    -e|--empty) empty=true; shift ;;
    -w|--sdram-width) shift; sdram_width=$1; shift ;;
    -ne|--not-empty) empty=false; shift ;;
    -h|--help) echo; usage_board; usage_probe;
        echo -n "[-e/--empty (default) | -ne/--not-empty], "
        echo -n "to define if flash is empty or not, ";
        echo "and thus determinates which '.ocd' file will be used (only for SPC300 board)"
        echo -n "  -e/--empty: if flash is empty, SDRAM controller has to be initialized ";
        echo "('reset_init_sdram.ocd' will be used)";
        echo -n "  -ne/--not-empty: if flash is not empty, ";
        echo -n "i.e. already contains u-boot or NVRAM, ";
        echo -n "SDRAM controller should not be initialized again ";
        echo "('reset_300.ocd' will be used)";
        echo "Use -w [16|32] to register SDRAM width (default 32)"
        echo "";
        exit 1;;
    -|--) shift; break;;
    *) break ;;
    esac
done

if [ -z $sdram_width ]; then
    sdram_width=32
fi

if [ -z $probe ]; then
    echo
    echo "Probe not defined"; usage_probe;
    exit 1;
else
    case $probe in
        baiwen)
            probe=BAIWEN;
            layout=jtagkey;
            vid=0x1457;
            pid=0x5118;
            ;;
        olimex)
            probe=OLIMEX;
            layout=olimex-jtag;
            vid=0x15ba;
            pid=0x0003;
            ;;
        amontec)
            probe=AMONTEC;
            layout=jtagkey;
            vid=0x0403;
            pid=0xcff8;
            ;;
        *)
            echo
            echo "Error probe definition";
            usage_probe;
            exit 1;;
    esac
fi

if [ -z $board ]; then
    echo
    echo "!!! Board option is mandatory"
    exit 1;
else
    if [ $flash ]; then
        force_flash=$flash
    fi
    if [ $speed ]; then
        force_speed=$speed
    fi
    case $board in
        S??3[01]0*)
          wa_base_addr="0x40000000"
          wa_sz="0x0000F000"
          flash_base_addr="0x30000000"
          flash_sz="0x800000"
          flash_options="12500000 0"
          reset_config="srst_only srst_pulls_trst"
          nsrst_delay=0
          ntrst_delay=0
          reset_mode="reset_and_init"
          ;;
        M??5[01][01]*)
          wa_base_addr="0x20000000"
          wa_sz="0x00002000"
          flash_base_addr="0x30000000"
          flash_sz="0x1000000"
          flash_options="4166666 0"
          reset_config="trst_and_srst"
          nsrst_delay=250
          ntrst_delay=250
          reset_mode="reset_init"
          empty=false
          ;;
        *) echo; echo "Error board definition"; usage_board; exit 1;;
    esac

if [ -z $empty ]; then
    empty=true;
    echo
    echo "!!! Default flash empty flag is true! SDRAM controller will be reset"
fi
if [ $empty == true ]; then
    file_ocd=$pathcaller\/reset_init_sdram_$sdram_width.ocd
else
    file_ocd=$pathcaller\/reset_300.ocd
fi

    case $board in
        SPK300g|SPK300|SPK310|SPR310) 
          flash=m25p64
          speed=5000
          ;;
        SCR310_AD9867)
          flash=at26df321
          speed=5000
          ;;
        SCR310_AD9865|SCR310_AD9868)
          flash=at26df321
          speed=2500
          ;;
        SPR300)
          flash=m25p32
          speed=5000
          ;;
        MSK500|MSK501|MCR500|MCR510)
          speed=1000
          flash=w25q128
          file_ocd=$pathcaller\/reset_500.ocd
          ;;
        *) echo; echo "Error board definition"; usage_board; exit 1;;
    esac
    if [ $force_flash ]; then
        flash=$force_flash
    fi
    if [ $force_speed ]; then
        speed=$force_speed
    fi
fi

echo
echo "PROBE = $probe:"
echo "  LAYOUT=$layout"
echo "  VID=$vid"
echo "  PID=$pid"
echo "BOARD=$board"
echo "FLASH=$flash"
echo "SPEED=$speed"
echo "EMPTYFLASH=$empty:"
echo "SDRAM_WIDTH=$sdram_width:"
echo "  reset_filepath=${file_ocd}"
echo

if [ $board ]; then
    if [ $force_flash ]; then
        generated=$probe\_$board\_$flash.cfg
    else
        generated=$probe\_$board.cfg
    fi
else
    generated=$probe\_$flash.cfg
fi

cp generic.cfg $generated
sed -i "s/\$PROBE/$probe/g" $generated
sed -i "s/\$LAYOUT/$layout/g" $generated
sed -i "s/\$VID/$vid/g" $generated
sed -i "s/\$PID/$pid/g" $generated
sed -i "s/\$SPEED/$speed/g" $generated
sed -i "s/\$PATH_OCD/${file_ocd////\/}/g" $generated
sed -i "s/\$WA_BASE_ADDR/$wa_base_addr/g" $generated
sed -i "s/\$WA_SZ/$wa_sz/g" $generated
sed -i "s/\$NTRST_DELAY/$ntrst_delay/g" $generated
sed -i "s/\$NSRST_DELAY/$nsrst_delay/g" $generated
sed -i "s/\$RESET_CONFIG/$reset_config/g" $generated
sed -i "s/\$RESET_MODE/$reset_mode/g" $generated
sed -i "s/\$FLASH_OPTIONS/$flash_options/g" $generated
sed -i "s/\$FLASH_BASE_ADDR/$flash_base_addr/g" $generated
sed -i "s/\$FLASH_SZ/$flash_sz/g" $generated
sed -i "s/\$FLASH/$flash/g" $generated
echo "--- File $generated successfully generated"
echo