main.c revision 1.3 1 1.3 igy /* $NetBSD: main.c,v 1.3 2003/06/24 12:27:04 igy Exp $ */
2 1.1 igy
3 1.1 igy /*
4 1.1 igy * Copyright (c) 2002 The NetBSD Foundation, Inc.
5 1.1 igy * All rights reserved.
6 1.1 igy *
7 1.1 igy * This code is derived from software contributed to The NetBSD Foundation
8 1.1 igy * by Naoto Shimazaki of YOKOGAWA Electric Corporation.
9 1.1 igy *
10 1.1 igy * Redistribution and use in source and binary forms, with or without
11 1.1 igy * modification, are permitted provided that the following conditions
12 1.1 igy * are met:
13 1.1 igy * 1. Redistributions of source code must retain the above copyright
14 1.1 igy * notice, this list of conditions and the following disclaimer.
15 1.1 igy * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 igy * notice, this list of conditions and the following disclaimer in the
17 1.1 igy * documentation and/or other materials provided with the distribution.
18 1.1 igy * 3. All advertising materials mentioning features or use of this software
19 1.1 igy * must display the following acknowledgement:
20 1.1 igy * This product includes software developed by the NetBSD
21 1.1 igy * Foundation, Inc. and its contributors.
22 1.1 igy * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.1 igy * contributors may be used to endorse or promote products derived
24 1.1 igy * from this software without specific prior written permission.
25 1.1 igy *
26 1.1 igy * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.1 igy * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.1 igy * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.1 igy * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.1 igy * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.1 igy * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.1 igy * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.1 igy * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.1 igy * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.1 igy * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.1 igy * POSSIBILITY OF SUCH DAMAGE.
37 1.1 igy */
38 1.1 igy
39 1.1 igy /*
40 1.1 igy * Boot loader for L-Card+
41 1.1 igy *
42 1.1 igy * ROM Map
43 1.1 igy * -------
44 1.1 igy * ROM1
45 1.1 igy * BFFF FFFF ------------------------------
46 1.1 igy *
47 1.1 igy * reserved
48 1.1 igy *
49 1.1 igy * BF80 0000 ------------------------------
50 1.1 igy *
51 1.1 igy * ROM0
52 1.1 igy * BFFF FFFF ------------------------------
53 1.1 igy *
54 1.1 igy * user storage (max 2Mbytes)
55 1.1 igy *
56 1.1 igy * BFE0 0000 ------------------------------
57 1.1 igy *
58 1.1 igy * reserved
59 1.1 igy *
60 1.1 igy * BFD4 0000 ------------------------------
61 1.1 igy *
62 1.1 igy * boot params
63 1.1 igy *
64 1.1 igy * BFD2 0000 ------------------------------
65 1.1 igy *
66 1.1 igy * second boot loader (mirror image)
67 1.1 igy * or Linux Kernel
68 1.1 igy *
69 1.1 igy * BFD0 0000 ------------------------------
70 1.1 igy *
71 1.1 igy * first boot loader (L-Card+ original loader)
72 1.1 igy *
73 1.1 igy * reset vector
74 1.1 igy * BFC0 0000 ------------------------------
75 1.1 igy *
76 1.1 igy * gziped kernel image (max 4Mbytes)
77 1.1 igy *
78 1.1 igy * BF80 0000 ------------------------------
79 1.1 igy *
80 1.1 igy *
81 1.1 igy *
82 1.1 igy * RAM Map
83 1.1 igy * -------
84 1.1 igy *
85 1.1 igy * 80FF FFFF ------------------------------
86 1.1 igy * ROM ICE work
87 1.1 igy * 80FF FE00 ------------------------------
88 1.1 igy * ROM ICE stack
89 1.1 igy * 80FF FDA8 ------------------------------
90 1.1 igy *
91 1.1 igy *
92 1.1 igy *
93 1.1 igy * kernel
94 1.1 igy * 8004 0000 ------------------------------
95 1.1 igy * kernel stack (growing to lower)
96 1.1 igy *
97 1.1 igy *
98 1.1 igy * boot loader heap (growing to upper)
99 1.1 igy * boot loader text & data (at exec time)
100 1.1 igy * 8000 1000 ------------------------------
101 1.1 igy * vector table
102 1.1 igy * 8000 0000 ------------------------------
103 1.1 igy *
104 1.1 igy * virtual memory space
105 1.1 igy *
106 1.1 igy * 0000 0000 ------------------------------
107 1.1 igy *
108 1.1 igy *
109 1.1 igy *
110 1.1 igy * ROMCS0 <-> ROMCS3 mapping
111 1.1 igy *
112 1.1 igy * ROMCS0 ROMCS3
113 1.1 igy * BE7F FFFF <-> BFFF FFFF
114 1.1 igy * BE40 0000 <-> BFC0 0000 reset vector
115 1.1 igy * BE00 0000 <-> BF80 0000
116 1.1 igy *
117 1.1 igy *
118 1.1 igy */
119 1.1 igy
120 1.1 igy #include <lib/libsa/stand.h>
121 1.1 igy #include <lib/libsa/loadfile.h>
122 1.1 igy #include <lib/libkern/libkern.h>
123 1.1 igy
124 1.1 igy #include <hpcmips/vr/vripreg.h>
125 1.1 igy #include <hpcmips/vr/cmureg.h>
126 1.1 igy #include <hpcmips/vr/vr4181giureg.h>
127 1.1 igy
128 1.1 igy #include "extern.h"
129 1.1 igy #include "i28f128reg.h"
130 1.1 igy
131 1.1 igy #define VRETIMEL 0x0b0000c0
132 1.1 igy #define VRETIMEM 0x0b0000c2
133 1.1 igy #define VRETIMEH 0x0b0000c4
134 1.1 igy
135 1.1 igy /* XXX */
136 1.1 igy #define ISABRGCTL 0x00
137 1.1 igy #define ISABRGSTS 0x02
138 1.1 igy #define XISACTL 0x04
139 1.1 igy
140 1.1 igy #define BOOTTIMEOUT 9 /* must less than 10 */
141 1.1 igy #define LINEBUFLEN 80
142 1.1 igy
143 1.1 igy extern const char bootprog_rev[];
144 1.1 igy extern const char bootprog_name[];
145 1.1 igy extern const char bootprog_date[];
146 1.1 igy extern const char bootprog_maker[];
147 1.1 igy
148 1.1 igy static void command_help(char *opt);
149 1.1 igy static void command_dump(char *opt);
150 1.1 igy static void command_boot(char *opt);
151 1.1 igy static void command_load(char *opt);
152 1.1 igy static void command_fill(char *opt);
153 1.1 igy static void command_write(char *opt);
154 1.1 igy
155 1.1 igy static struct bootmenu_command commands[] = {
156 1.1 igy { "?", command_help },
157 1.1 igy { "h", command_help },
158 1.1 igy { "d", command_dump },
159 1.1 igy { "b", command_boot },
160 1.1 igy { "l", command_load },
161 1.1 igy { "f", command_fill },
162 1.1 igy { "w", command_write },
163 1.1 igy { NULL, NULL },
164 1.1 igy };
165 1.1 igy
166 1.1 igy static void
167 1.1 igy print_banner(void)
168 1.1 igy {
169 1.1 igy printf("\n");
170 1.1 igy printf(">> %s, Revision %s\n", bootprog_name, bootprog_rev);
171 1.1 igy printf(">> (%s, %s)\n", bootprog_maker, bootprog_date);
172 1.1 igy #if 0
173 1.1 igy printf(">> Memory: %d/%d k\n", getbasemem(), getextmem());
174 1.1 igy #endif
175 1.1 igy }
176 1.1 igy
177 1.1 igy #if 1
178 1.1 igy void foo(void);
179 1.1 igy void foo(void)
180 1.1 igy {
181 1.1 igy extern int start[];
182 1.1 igy extern int edata[];
183 1.1 igy
184 1.1 igy int *p = (int*)0xbfc01000;
185 1.1 igy int *q = start;
186 1.1 igy int *f = edata;
187 1.1 igy
188 1.1 igy do {
189 1.1 igy *q++ = *p++;
190 1.1 igy } while (q < f);
191 1.1 igy }
192 1.1 igy #endif
193 1.1 igy
194 1.1 igy static void
195 1.1 igy init_devices(void)
196 1.1 igy {
197 1.1 igy /* Init RTC */
198 1.1 igy REGWRITE_2(VRETIMEH, 0, 0);
199 1.1 igy REGWRITE_2(VRETIMEM, 0, 0);
200 1.1 igy REGWRITE_2(VRETIMEL, 0, 0);
201 1.1 igy
202 1.1 igy
203 1.1 igy /*
204 1.1 igy * CLKSPEEDREG 0x6012
205 1.1 igy * DIV DIV2 mode
206 1.1 igy * CLKSP 18 (0x12)
207 1.1 igy * PClock (CPU clock) 65.536MHz
208 1.1 igy * PClock = (18.432MHz / CLKSP) x 64
209 1.1 igy * = (18.432MHz / 18) x 64
210 1.1 igy * = 65.536MHz
211 1.1 igy * TClock (peripheral clock) 32.768MHz
212 1.1 igy * TClock = PClock / DIV
213 1.1 igy * = 65.536MHz / 2
214 1.1 igy * = 32.768MHz
215 1.1 igy */
216 1.1 igy
217 1.1 igy /*
218 1.1 igy * setup ISA BUS clock freqency
219 1.1 igy *
220 1.1 igy * set PCLK (internal peripheral clock) to 32.768MHz (TClock / 1)
221 1.1 igy * set External ISA bus clock to 10.922MHz (TClock / 3)
222 1.1 igy */
223 1.1 igy REGWRITE_2(VR4181_ISABRG_ADDR, ISABRGCTL, 0x0003);
224 1.1 igy REGWRITE_2(VR4181_ISABRG_ADDR, XISACTL, 0x0401);
225 1.1 igy
226 1.1 igy /*
227 1.1 igy * setup peripheral's clock supply
228 1.1 igy *
229 1.1 igy * CSU: disable
230 1.1 igy * AIU: enable (AIU, ADU, ADU18M)
231 1.1 igy * PIU: disable
232 1.1 igy * SIU: enable (SIU18M)
233 1.1 igy */
234 1.1 igy REGWRITE_2(VR4181_CMU_ADDR, 0, CMUMASK_SIU | CMUMASK_AIU);
235 1.1 igy
236 1.1 igy /*
237 1.1 igy * setup GPIO
238 1.1 igy */
239 1.1 igy #if 0
240 1.1 igy /* L-Card+ generic setup */
241 1.1 igy /*
242 1.1 igy * pin mode comment
243 1.1 igy * GP0 : GPI not used
244 1.1 igy * GP1 : GPI not used
245 1.1 igy * GP2 : GPO LED6 (0: on 1: off)
246 1.1 igy * GP3 : PCS0 chip select for CS8900A Lan controller
247 1.1 igy * GP4 : GPI IRQ input from CS8900A
248 1.1 igy * GP5 : GPI not used
249 1.1 igy * GP6 : GPI not used
250 1.1 igy * GP7 : GPI reserved by TANBAC TB0193
251 1.1 igy */
252 1.1 igy REGWRITE_2(VR4181_GIU81_ADDR, VR4181GIU_PIOD_L_REG_W, 0xffff);
253 1.1 igy REGWRITE_2(VR4181_GIU81_ADDR, VR4181GIU_MODE0_REG_W,
254 1.1 igy GP3_PCS0 | GP2_GPO);
255 1.1 igy /*
256 1.1 igy * pin mode comment
257 1.1 igy * GP8 : GPO LED5 (0: on 1: off)
258 1.1 igy * GP9 : GPI CD2
259 1.1 igy * GP10: GPI CD1
260 1.1 igy * GP11: GPI not used
261 1.1 igy * GP12: GPI not used
262 1.1 igy * GP13: GPI not used
263 1.1 igy * GP14: GPI not used
264 1.1 igy * GP15: GPI not used
265 1.1 igy */
266 1.1 igy REGWRITE_2(VR4181_GIU81_ADDR, VR4181GIU_MODE1_REG_W, GP8_GPO);
267 1.1 igy /*
268 1.1 igy * pin mode comment
269 1.1 igy * GP16: IORD ISA bus
270 1.1 igy * GP17: IOWR ISA bus
271 1.1 igy * GP18: IORDY ISA bus
272 1.1 igy * GP19: GPI not used
273 1.1 igy * GP20: GPI not used
274 1.1 igy * GP21: RESET resets CS8900A
275 1.1 igy * GP22: ROMCS0 ROM chip select
276 1.1 igy * GP23: ROMCS1 ROM chip select
277 1.1 igy */
278 1.1 igy REGWRITE_2(VR4181_GIU81_ADDR, VR4181GIU_MODE2_REG_W,
279 1.1 igy GP23_ROMCS1 | GP22_ROMCS0 | GP21_RESET
280 1.1 igy | GP18_IORDY | GP17_IOWR | GP16_IORD);
281 1.1 igy /*
282 1.1 igy * GP24: ROMCS2 ROM chip select
283 1.1 igy * GP25: RxD1 SIU1
284 1.1 igy * GP26: TxD1 SIU1
285 1.1 igy * GP27: RTS1 SIU1
286 1.1 igy * GP28: CTS1 SIU1
287 1.1 igy * GP29: GPI LED3
288 1.1 igy * GP30: GPI reserved by TANBAC TB0193
289 1.1 igy * GP31: GPI LED4
290 1.1 igy */
291 1.1 igy REGWRITE_2(VR4181_GIU81_ADDR, VR4181GIU_MODE3_REG_W,
292 1.1 igy GP30_GPI
293 1.1 igy | GP28_CTS1 | GP27_RTS1 | GP26_TxD1 | GP25_RxD1
294 1.1 igy | GP24_ROMCS2);
295 1.1 igy #else
296 1.1 igy /* e-care node specific setup */
297 1.1 igy /*
298 1.1 igy * pin mode comment
299 1.1 igy * GP0 : GPO ECNRTC_RST
300 1.1 igy * GP1 : GPO ECNRTC_CLK
301 1.1 igy * GP2 : GPO LED6 (0: on 1: off)
302 1.1 igy * GP3 : PCS0 chip select for CS8900A Lan controller
303 1.1 igy * GP4 : GPI IRQ input from CS8900A
304 1.1 igy * GP5 : GPO ECNRTC_DIR
305 1.1 igy * GP6 : GPO ECNRTC_OUT
306 1.1 igy * GP7 : GPI reserved by TANBAC TB0193
307 1.1 igy */
308 1.1 igy REGWRITE_2(VR4181_GIU81_ADDR, VR4181GIU_PIOD_L_REG_W, 0xffff);
309 1.1 igy REGWRITE_2(VR4181_GIU81_ADDR, VR4181GIU_MODE0_REG_W,
310 1.1 igy GP6_GPO | GP5_GPO | GP3_PCS0
311 1.1 igy | GP2_GPO | GP1_GPO | GP0_GPO);
312 1.1 igy
313 1.1 igy /*
314 1.1 igy * pin mode comment
315 1.1 igy * GP8 : GPO LED5 (0: on 1: off)
316 1.1 igy * GP9 : GPI CD2
317 1.1 igy * GP10: GPI CD1
318 1.1 igy * GP11: GPI not used
319 1.1 igy * GP12: GPI ECNRTC_IN
320 1.1 igy * GP13: GPI not used
321 1.1 igy * GP14: GPI not used
322 1.1 igy * GP15: GPI not used
323 1.1 igy */
324 1.1 igy REGWRITE_2(VR4181_GIU81_ADDR, VR4181GIU_MODE1_REG_W,
325 1.1 igy GP12_GPI | GP8_GPO);
326 1.1 igy
327 1.1 igy /*
328 1.1 igy * pin mode comment
329 1.1 igy * GP16: IORD ISA bus
330 1.1 igy * GP17: IOWR ISA bus
331 1.1 igy * GP18: IORDY ISA bus
332 1.1 igy * GP19: GPI not used
333 1.1 igy * GP20: GPI not used
334 1.1 igy * GP21: RESET resets CS8900A
335 1.1 igy * GP22: ROMCS0 ROM chip select
336 1.1 igy * GP23: ROMCS1 ROM chip select
337 1.1 igy */
338 1.1 igy REGWRITE_2(VR4181_GIU81_ADDR, VR4181GIU_MODE2_REG_W,
339 1.1 igy GP23_ROMCS1 | GP22_ROMCS0 | GP21_RESET
340 1.1 igy | GP18_IORDY | GP17_IOWR | GP16_IORD);
341 1.1 igy /*
342 1.1 igy * GP24: ROMCS2 ROM chip select
343 1.1 igy * GP25: RxD1 SIU1
344 1.1 igy * GP26: TxD1 SIU1
345 1.1 igy * GP27: RTS1 SIU1
346 1.1 igy * GP28: CTS1 SIU1
347 1.1 igy * GP29: GPI LED3
348 1.1 igy * GP30: GPI reserved by TANBAC TB0193
349 1.1 igy * GP31: GPI LED4
350 1.1 igy */
351 1.1 igy REGWRITE_2(VR4181_GIU81_ADDR, VR4181GIU_MODE3_REG_W,
352 1.1 igy GP30_GPI
353 1.1 igy | GP28_CTS1 | GP27_RTS1 | GP26_TxD1 | GP25_RxD1
354 1.1 igy | GP24_ROMCS2);
355 1.1 igy #endif
356 1.1 igy
357 1.1 igy #if 0
358 1.1 igy /*
359 1.1 igy * setup interrupt
360 1.1 igy *
361 1.1 igy * I4TYP: falling edge trigger
362 1.1 igy * GIMSK4: unmask
363 1.1 igy * GIEN4: enable
364 1.1 igy * other: unused, mask, disable
365 1.1 igy */
366 1.1 igy REGWRITE_2(VR4181_GIU81_ADDR, VR4181GIU_INTTYP_L_REG_W,
367 1.1 igy I4TYP_HIGH_LEVEL);
368 1.1 igy REGWRITE_2(VR4181_GIU81_ADDR, VR4181GIU_INTMASK_REG_W,
369 1.1 igy 0xffffU & ~GIMSK4);
370 1.1 igy REGWRITE_2(VR4181_GIU81_ADDR, VR4181GIU_INTEN_REG_W, GIEN4);
371 1.1 igy #endif
372 1.1 igy
373 1.1 igy /*
374 1.1 igy * programmable chip select
375 1.1 igy *
376 1.1 igy * PCS0 is used to select CS8900A Ethernet controller
377 1.1 igy * on TB0193
378 1.1 igy *
379 1.1 igy * PCS0:
380 1.1 igy * 0x14010000 - 0x14010fff
381 1.1 igy * I/O access, 16bit cycle, both of read/write
382 1.1 igy * PCS1: unused
383 1.1 igy */
384 1.1 igy REGWRITE_2(VR4181_GIU81_ADDR, VR4181GIU_PCS0STRA_REG_W, 0x0000);
385 1.1 igy REGWRITE_2(VR4181_GIU81_ADDR, VR4181GIU_PCS0STPA_REG_W, 0x0fff);
386 1.1 igy REGWRITE_2(VR4181_GIU81_ADDR, VR4181GIU_PCS0HIA_REG_W, 0x1401);
387 1.1 igy REGWRITE_2(VR4181_GIU81_ADDR, VR4181GIU_PCSMODE_REG_W,
388 1.1 igy PCS0MIOB_IO | PCS0DSIZE_16BIT | PCS0MD_READWRITE);
389 1.1 igy }
390 1.1 igy
391 1.1 igy /*
392 1.1 igy * chops the head from the arguments and returns the arguments if any,
393 1.1 igy * or possibly an empty string.
394 1.1 igy */
395 1.1 igy static char *
396 1.1 igy get_next_arg(char *arg)
397 1.1 igy {
398 1.1 igy char *opt;
399 1.1 igy
400 1.1 igy if ((opt = strchr(arg, ' ')) == NULL) {
401 1.1 igy opt = "";
402 1.1 igy } else {
403 1.1 igy *opt++ = '\0';
404 1.1 igy }
405 1.1 igy
406 1.1 igy /* trim leading blanks */
407 1.1 igy while (*opt == ' ')
408 1.1 igy opt++;
409 1.1 igy
410 1.1 igy return opt;
411 1.1 igy }
412 1.1 igy
413 1.1 igy static void
414 1.1 igy command_help(char *opt)
415 1.1 igy {
416 1.1 igy printf("commands are:\n"
417 1.1 igy "boot: b\n"
418 1.1 igy "dump: d addr [addr]\n"
419 1.1 igy "fill: f addr addr char\n"
420 1.1 igy "load: l [offset] (with following S-Record)\n"
421 1.1 igy "write: w dst src len\n"
422 1.1 igy "help: h|?\n");
423 1.1 igy }
424 1.1 igy
425 1.1 igy static void
426 1.1 igy bad_param(void)
427 1.1 igy {
428 1.1 igy printf("bad param\n");
429 1.1 igy command_help(NULL);
430 1.1 igy }
431 1.1 igy
432 1.1 igy static const u_int8_t print_cnv[] = {
433 1.1 igy '0', '1', '2', '3', '4', '5', '6', '7',
434 1.1 igy '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
435 1.1 igy
436 1.1 igy static void
437 1.1 igy printhexul(u_int32_t n)
438 1.1 igy {
439 1.1 igy int i;
440 1.1 igy
441 1.1 igy for (i = 28; i >= 0; i -= 4)
442 1.1 igy putchar(print_cnv[(n >> i) & 0x0f]);
443 1.1 igy }
444 1.1 igy
445 1.1 igy static void
446 1.1 igy printhexuc(u_int8_t n)
447 1.1 igy {
448 1.1 igy int i;
449 1.1 igy
450 1.1 igy for (i = 4; i >= 0; i -= 4)
451 1.1 igy putchar(print_cnv[(n >> i) & 0x0f]);
452 1.1 igy }
453 1.1 igy
454 1.1 igy static void
455 1.1 igy command_dump(char *opt)
456 1.1 igy {
457 1.1 igy char *endptr;
458 1.1 igy const char *p;
459 1.1 igy const char *line_fence;
460 1.1 igy const char *limit;
461 1.1 igy
462 1.1 igy p = (const char *) strtoul(opt, &endptr, 16);
463 1.1 igy if (opt == endptr) {
464 1.1 igy bad_param();
465 1.1 igy return;
466 1.1 igy }
467 1.1 igy
468 1.1 igy opt = get_next_arg(opt);
469 1.1 igy limit = (const char *) strtoul(opt, &endptr, 16);
470 1.1 igy if (opt == endptr) {
471 1.1 igy limit = p + 256;
472 1.1 igy }
473 1.1 igy
474 1.1 igy for (;;) {
475 1.1 igy printhexul((u_int32_t) p);
476 1.1 igy putchar(' ');
477 1.1 igy line_fence = p + 16;
478 1.1 igy while (p < line_fence) {
479 1.1 igy printhexuc(*p++);
480 1.1 igy putchar(' ');
481 1.1 igy if (p >= limit) {
482 1.1 igy putchar('\n');
483 1.1 igy return;
484 1.1 igy }
485 1.1 igy }
486 1.1 igy putchar('\n');
487 1.1 igy if (ISKEY) {
488 1.1 igy if (getchar() == '\x03')
489 1.1 igy break;
490 1.1 igy }
491 1.1 igy }
492 1.1 igy }
493 1.1 igy
494 1.1 igy static void
495 1.1 igy command_boot(char *opt)
496 1.1 igy {
497 1.1 igy u_long marks[MARK_MAX];
498 1.1 igy
499 1.1 igy marks[MARK_START] = 0;
500 1.1 igy if (loadfile("n", marks, LOAD_KERNEL))
501 1.1 igy panic("loadfile failed");
502 1.1 igy start_netbsd();
503 1.1 igy /* no return */
504 1.1 igy }
505 1.1 igy
506 1.1 igy /*
507 1.1 igy * loading S-Record
508 1.1 igy */
509 1.1 igy static int
510 1.1 igy load_srec(char *offset)
511 1.1 igy {
512 1.1 igy char s2lbuf[9];
513 1.1 igy char c;
514 1.1 igy char rectype;
515 1.1 igy u_int32_t reclen;
516 1.1 igy u_int32_t reclen_bk;
517 1.1 igy u_int32_t recaddr;
518 1.1 igy char *endptr;
519 1.1 igy char *p;
520 1.1 igy u_int32_t sum;
521 1.1 igy int err = 0;
522 1.1 igy
523 1.1 igy for (;;) {
524 1.1 igy /*
525 1.1 igy * the first step is to read a S-Record.
526 1.1 igy */
527 1.1 igy if ((c = getchar()) != 'S')
528 1.1 igy goto out;
529 1.1 igy
530 1.1 igy rectype = getchar();
531 1.1 igy
532 1.1 igy s2lbuf[0] = getchar();
533 1.1 igy s2lbuf[1] = getchar();
534 1.1 igy s2lbuf[2] = '\0';
535 1.1 igy reclen_bk = reclen = strtoul(s2lbuf, &endptr, 16);
536 1.1 igy if (endptr != &s2lbuf[2])
537 1.1 igy goto out;
538 1.1 igy sum = reclen;
539 1.1 igy
540 1.1 igy p = s2lbuf;
541 1.1 igy
542 1.1 igy switch (rectype) {
543 1.1 igy case '0':
544 1.1 igy /* just ignore */
545 1.1 igy do {
546 1.1 igy c = getchar();
547 1.1 igy } while (c != '\r' && c != '\n');
548 1.1 igy continue;
549 1.1 igy
550 1.1 igy case '3':
551 1.1 igy *p++ = getchar();
552 1.1 igy *p++ = getchar();
553 1.1 igy reclen--;
554 1.1 igy /* FALLTHRU */
555 1.1 igy case '2':
556 1.1 igy *p++ = getchar();
557 1.1 igy *p++ = getchar();
558 1.1 igy reclen--;
559 1.1 igy /* FALLTHRU */
560 1.1 igy case '1':
561 1.1 igy *p++ = getchar();
562 1.1 igy *p++ = getchar();
563 1.1 igy *p++ = getchar();
564 1.1 igy *p++ = getchar();
565 1.1 igy *p = '\0';
566 1.1 igy reclen -= 2;
567 1.1 igy
568 1.1 igy recaddr = strtoul(s2lbuf, &endptr, 16);
569 1.1 igy if (endptr != p)
570 1.1 igy goto out;
571 1.1 igy sum += (recaddr >> 24) & 0xff;
572 1.1 igy sum += (recaddr >> 16) & 0xff;
573 1.1 igy sum += (recaddr >> 8) & 0xff;
574 1.1 igy sum += recaddr & 0xff;
575 1.1 igy
576 1.1 igy p = offset + recaddr;
577 1.1 igy /*
578 1.1 igy * XXX
579 1.1 igy * address range is must be chaked here!
580 1.1 igy */
581 1.1 igy reclen--;
582 1.1 igy s2lbuf[2] = '\0';
583 1.1 igy while (reclen > 0) {
584 1.1 igy s2lbuf[0] = getchar();
585 1.1 igy s2lbuf[1] = getchar();
586 1.1 igy *p = (u_int8_t) strtoul(s2lbuf, &endptr, 16);
587 1.1 igy if (endptr != &s2lbuf[2])
588 1.1 igy goto out;
589 1.1 igy sum += *p++;
590 1.1 igy reclen--;
591 1.1 igy }
592 1.1 igy break;
593 1.1 igy
594 1.1 igy case '7':
595 1.1 igy case '8':
596 1.1 igy case '9':
597 1.1 igy goto out2;
598 1.1 igy
599 1.1 igy default:
600 1.1 igy goto out;
601 1.1 igy }
602 1.1 igy
603 1.1 igy s2lbuf[0] = getchar();
604 1.1 igy s2lbuf[1] = getchar();
605 1.1 igy s2lbuf[2] = '\0';
606 1.1 igy sum += (strtoul(s2lbuf, &endptr, 16) & 0xff);
607 1.1 igy sum &= 0xff;
608 1.1 igy if (sum != 0xff) {
609 1.1 igy printf("checksum error\n");
610 1.1 igy err = 1;
611 1.1 igy goto out2;
612 1.1 igy }
613 1.1 igy
614 1.1 igy c = getchar();
615 1.1 igy if (c != '\r' && c != '\n')
616 1.1 igy goto out;
617 1.1 igy }
618 1.1 igy /* never reach */
619 1.1 igy return 1;
620 1.1 igy
621 1.1 igy out:
622 1.1 igy printf("invalid S-Record\n");
623 1.1 igy err = 1;
624 1.1 igy
625 1.1 igy out2:
626 1.1 igy do {
627 1.1 igy c = getchar();
628 1.1 igy } while (c != '\r' && c != '\n');
629 1.1 igy
630 1.1 igy return err;
631 1.1 igy }
632 1.1 igy
633 1.1 igy static void
634 1.1 igy command_load(char *opt)
635 1.1 igy {
636 1.1 igy char *endptr;
637 1.1 igy char *offset;
638 1.1 igy
639 1.1 igy offset = (char *) strtoul(opt, &endptr, 16);
640 1.1 igy if (opt == endptr)
641 1.1 igy offset = 0;
642 1.1 igy load_srec(offset);
643 1.1 igy }
644 1.1 igy
645 1.1 igy static void
646 1.1 igy command_fill(char *opt)
647 1.1 igy {
648 1.1 igy char *endptr;
649 1.1 igy char *p;
650 1.1 igy char *limit;
651 1.1 igy int c;
652 1.1 igy
653 1.1 igy p = (char *) strtoul(opt, &endptr, 16);
654 1.1 igy if (opt == endptr) {
655 1.1 igy bad_param();
656 1.1 igy return;
657 1.1 igy }
658 1.1 igy
659 1.1 igy opt = get_next_arg(opt);
660 1.1 igy limit = (char *) strtoul(opt, &endptr, 16);
661 1.1 igy if (opt == endptr) {
662 1.1 igy bad_param();
663 1.1 igy return;
664 1.1 igy }
665 1.1 igy
666 1.1 igy opt = get_next_arg(opt);
667 1.1 igy c = strtoul(opt, &endptr, 16);
668 1.1 igy if (opt == endptr)
669 1.1 igy c = '\0';
670 1.1 igy
671 1.1 igy memset(p, c, limit - p);
672 1.1 igy }
673 1.1 igy
674 1.1 igy
675 1.1 igy static void
676 1.1 igy command_write(char *opt)
677 1.1 igy {
678 1.1 igy char *endptr;
679 1.1 igy u_int32_t src;
680 1.1 igy u_int32_t dst;
681 1.1 igy size_t len;
682 1.1 igy int status;
683 1.1 igy
684 1.1 igy dst = strtoul(opt, &endptr, 16);
685 1.1 igy if (opt == endptr)
686 1.1 igy goto out;
687 1.1 igy
688 1.1 igy opt = get_next_arg(opt);
689 1.1 igy src = strtoul(opt, &endptr, 16);
690 1.1 igy if (opt == endptr)
691 1.1 igy goto out;
692 1.1 igy
693 1.1 igy opt = get_next_arg(opt);
694 1.1 igy len = strtoul(opt, &endptr, 16);
695 1.1 igy if (opt == endptr)
696 1.1 igy goto out;
697 1.1 igy
698 1.1 igy if ((dst & I28F128_BLOCK_MASK) != 0) {
699 1.1 igy printf("dst addr must be aligned to block boundary (0x%x)\n",
700 1.1 igy I28F128_BLOCK_SIZE);
701 1.1 igy return;
702 1.1 igy }
703 1.1 igy
704 1.1 igy if (i28f128_probe((void *) dst)) {
705 1.1 igy printf("dst addr is not a intel 28F128\n");
706 1.1 igy } else {
707 1.1 igy printf("intel 28F128 detected\n");
708 1.1 igy }
709 1.1 igy
710 1.1 igy if ((status = i28f128_region_write((void *) dst, (void *) src, len))
711 1.1 igy != 0) {
712 1.1 igy printf("write mem to flash failed status = %x\n", status);
713 1.1 igy return;
714 1.1 igy }
715 1.1 igy
716 1.2 igy printf("verifying...");
717 1.2 igy if (memcmp((void *) dst, (void *) src, len)) {
718 1.2 igy printf("verify error\n");
719 1.2 igy return;
720 1.2 igy }
721 1.2 igy printf("ok\n");
722 1.2 igy
723 1.2 igy printf("writing memory to flash succeeded\n");
724 1.1 igy return;
725 1.1 igy
726 1.1 igy out:
727 1.1 igy bad_param();
728 1.1 igy return;
729 1.1 igy }
730 1.1 igy
731 1.1 igy static void
732 1.1 igy bootmenu(void)
733 1.1 igy {
734 1.1 igy char input[LINEBUFLEN];
735 1.1 igy char *cmd;
736 1.1 igy char *opt;
737 1.1 igy int i;
738 1.1 igy
739 1.1 igy for (;;) {
740 1.1 igy
741 1.1 igy /* input a line */
742 1.1 igy input[0] = '\0';
743 1.1 igy printf("> ");
744 1.1 igy gets(input);
745 1.1 igy cmd = input;
746 1.1 igy
747 1.1 igy /* skip leading whitespace. */
748 1.1 igy while(*cmd == ' ')
749 1.1 igy cmd++;
750 1.1 igy
751 1.1 igy if(*cmd) {
752 1.1 igy /* here, some command entered */
753 1.1 igy
754 1.1 igy opt = get_next_arg(cmd);
755 1.1 igy
756 1.1 igy /* dispatch command */
757 1.1 igy for (i = 0; commands[i].c_name != NULL; i++) {
758 1.1 igy if (strcmp(cmd, commands[i].c_name) == 0) {
759 1.1 igy commands[i].c_fn(opt);
760 1.1 igy break;
761 1.1 igy }
762 1.1 igy }
763 1.1 igy if (commands[i].c_name == NULL) {
764 1.1 igy printf("unknown command\n");
765 1.1 igy command_help(NULL);
766 1.1 igy }
767 1.1 igy }
768 1.1 igy
769 1.1 igy }
770 1.1 igy }
771 1.1 igy
772 1.1 igy static char
773 1.1 igy awaitkey(void)
774 1.1 igy {
775 1.1 igy int i;
776 1.1 igy int j;
777 1.1 igy char c = 0;
778 1.1 igy
779 1.1 igy while (ISKEY)
780 1.1 igy getchar();
781 1.1 igy
782 1.1 igy for (i = BOOTTIMEOUT; i > 0; i--) {
783 1.1 igy printf("%d\b", i);
784 1.1 igy for (j = 0; j < 1000000; j++) {
785 1.1 igy if (ISKEY) {
786 1.1 igy while (ISKEY)
787 1.1 igy c = getchar();
788 1.1 igy goto out;
789 1.1 igy }
790 1.1 igy }
791 1.1 igy }
792 1.1 igy
793 1.1 igy out:
794 1.1 igy printf("0\n");
795 1.1 igy return(c);
796 1.3 igy }
797 1.3 igy
798 1.3 igy __dead void
799 1.3 igy _rtt(void)
800 1.3 igy {
801 1.3 igy for (;;)
802 1.3 igy ;
803 1.1 igy }
804 1.1 igy
805 1.1 igy int
806 1.1 igy main(void)
807 1.1 igy {
808 1.1 igy char c;
809 1.1 igy
810 1.1 igy init_devices();
811 1.1 igy
812 1.1 igy comcninit();
813 1.1 igy
814 1.1 igy print_banner();
815 1.1 igy
816 1.1 igy c = awaitkey();
817 1.1 igy if (c != '\r' && c != '\n' && c != '\0') {
818 1.1 igy printf("type \"?\" or \"h\" for help.\n");
819 1.1 igy bootmenu(); /* does not return */
820 1.1 igy }
821 1.1 igy
822 1.1 igy command_boot(NULL);
823 1.1 igy /* never reach */
824 1.1 igy return 0;
825 1.1 igy }
826