imgtec-ci20: genimage config/ u-boot env
[openadk.git] / package / mopd / src / common / dl.c
blob58774dc14337c42167be3700311d623a205125f4
1 /* $NetBSD: dl.c,v 1.3 1997/10/16 23:24:31 lukem Exp $ */
3 /*
4 * Copyright (c) 1993-95 Mats O Jansson. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. All advertising materials mentioning features or use of this software
15 * must display the following acknowledgement:
16 * This product includes software developed by Mats O Jansson.
17 * 4. The name of the author may not be used to endorse or promote products
18 * derived from this software without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 #include <sys/cdefs.h>
33 #ifndef lint
34 static char rcsid[]="$NetBSD: dl.c,v 1.3 1997/10/16 23:24:31 lukem Exp $";
35 #endif
37 #include "os.h"
38 #include "dl.h"
39 #include "get.h"
40 #include "mopdef.h"
41 #include "print.h"
43 void
44 mopDumpDL(fd, pkt, trans)
45 FILE *fd;
46 u_char *pkt;
47 int trans;
49 int i,index = 0;
50 u_int32_t tmpl;
51 u_char tmpc,c,program[257],code,*ucp;
52 u_short len,tmps,moplen;
54 len = mopGetLength(pkt, trans);
56 switch (trans) {
57 case TRANS_8023:
58 index = 22;
59 moplen = len - 8;
60 break;
61 default:
62 index = 16;
63 moplen = len;
65 code = mopGetChar(pkt,&index);
67 /* see above, if (len < 8) then moplen ends up around 65535 */
68 if (moplen > len) moplen = len;
70 switch (code) {
71 case MOP_K_CODE_MLT:
73 tmpc = mopGetChar(pkt,&index); /* Load Number */
74 (void)fprintf(fd,"Load Number : %02x\n",tmpc);
76 if (moplen > 6) {
77 tmpl = mopGetLong(pkt,&index);/* Load Address */
78 (void)fprintf(fd,"Load Address : %08x\n", tmpl);
81 if (moplen > 10) {
82 #ifndef SHORT_PRINT
83 for (i = 0; i < (moplen - 10); i++) {
84 if ((i % 16) == 0) {
85 if ((i / 16) == 0) {
86 (void)fprintf(fd,
87 "Image Data : %04x ",
88 moplen-10);
89 } else {
90 (void)fprintf(fd,
91 " ");
95 (void)fprintf(fd, "%02x ",
96 mopGetChar(pkt,&index));
97 if ((i % 16) == 15)
98 (void)fprintf(fd,"\n");
101 if ((i % 16) != 15)
102 (void)fprintf(fd,"\n");
103 #else
104 index = index + moplen - 10;
105 #endif
108 tmpl = mopGetLong(pkt,&index); /* Load Address */
109 (void)fprintf(fd,"Xfer Address : %08x\n", tmpl);
111 break;
112 case MOP_K_CODE_DCM:
114 /* Empty Message */
116 break;
117 case MOP_K_CODE_MLD:
119 tmpc = mopGetChar(pkt,&index); /* Load Number */
120 (void)fprintf(fd,"Load Number : %02x\n",tmpc);
122 tmpl = mopGetLong(pkt,&index); /* Load Address */
123 (void)fprintf(fd,"Load Address : %08x\n", tmpl);
125 if (moplen > 6) {
126 #ifndef SHORT_PRINT
127 for (i = 0; i < (moplen - 6); i++) {
128 if ((i % 16) == 0) {
129 if ((i / 16) == 0) {
130 (void)fprintf(fd,
131 "Image Data : %04x ",
132 moplen-6);
133 } else {
134 (void)fprintf(fd,
135 " ");
138 (void)fprintf(fd,"%02x ",
139 mopGetChar(pkt,&index));
140 if ((i % 16) == 15)
141 (void)fprintf(fd,"\n");
144 if ((i % 16) != 15)
145 (void)fprintf(fd,"\n");
146 #else
147 index = index + moplen - 6;
148 #endif
151 break;
152 case MOP_K_CODE_ASV:
154 /* Empty Message */
156 break;
157 case MOP_K_CODE_RMD:
159 tmpl = mopGetLong(pkt,&index); /* Memory Address */
160 (void)fprintf(fd,"Mem Address : %08x\n", tmpl);
162 tmps = mopGetShort(pkt,&index); /* Count */
163 (void)fprintf(fd,"Count : %04x (%d)\n",tmps,tmps);
165 break;
166 case MOP_K_CODE_RPR:
168 tmpc = mopGetChar(pkt,&index); /* Device Type */
169 (void)fprintf(fd, "Device Type : %02x ",tmpc);
170 mopPrintDevice(fd, tmpc); (void)fprintf(fd, "\n");
172 tmpc = mopGetChar(pkt,&index); /* Format Version */
173 (void)fprintf(fd,"Format : %02x\n",tmpc);
175 tmpc = mopGetChar(pkt,&index); /* Program Type */
176 (void)fprintf(fd,"Program Type : %02x ",tmpc);
177 mopPrintPGTY(fd, tmpc); (void)fprintf(fd, "\n");
179 program[0] = 0;
180 tmpc = mopGetChar(pkt,&index); /* Software ID Len */
181 for (i = 0; i < tmpc; i++) {
182 program[i] = mopGetChar(pkt,&index);
183 program[i+1] = '\0';
186 (void)fprintf(fd,"Software : %02x '%s'\n",tmpc,program);
188 tmpc = mopGetChar(pkt,&index); /* Processor */
189 (void)fprintf(fd,"Processor : %02x ",tmpc);
190 mopPrintBPTY(fd, tmpc); (void)fprintf(fd, "\n");
192 mopPrintInfo(fd, pkt, &index, moplen, code, trans);
194 break;
195 case MOP_K_CODE_RML:
197 tmpc = mopGetChar(pkt,&index); /* Load Number */
198 (void)fprintf(fd,"Load Number : %02x\n",tmpc);
200 tmpc = mopGetChar(pkt,&index); /* Error */
201 (void)fprintf(fd,"Error : %02x (",tmpc);
202 if ((tmpc == 0)) {
203 (void)fprintf(fd,"no error)\n");
204 } else {
205 (void)fprintf(fd,"error)\n");
208 break;
209 case MOP_K_CODE_RDS:
211 tmpc = mopGetChar(pkt,&index); /* Device Type */
212 (void)fprintf(fd, "Device Type : %02x ",tmpc);
213 mopPrintDevice(fd, tmpc); (void)fprintf(fd, "\n");
215 tmpc = mopGetChar(pkt,&index); /* Format Version */
216 (void)fprintf(fd,"Format : %02x\n",tmpc);
218 tmpl = mopGetLong(pkt,&index); /* Memory Size */
219 (void)fprintf(fd,"Memory Size : %08x\n", tmpl);
221 tmpc = mopGetChar(pkt,&index); /* Bits */
222 (void)fprintf(fd,"Bits : %02x\n",tmpc);
224 mopPrintInfo(fd, pkt, &index, moplen, code, trans);
226 break;
227 case MOP_K_CODE_MDD:
229 tmpl = mopGetLong(pkt,&index); /* Memory Address */
230 (void)fprintf(fd,"Mem Address : %08x\n", tmpl);
232 if (moplen > 5) {
233 #ifndef SHORT_PRINT
234 for (i = 0; i < (moplen - 5); i++) {
235 if ((i % 16) == 0) {
236 if ((i / 16) == 0) {
237 (void)fprintf(fd,
238 "Image Data : %04x ",
239 moplen-5);
240 } else {
241 (void)fprintf(fd,
242 " ");
245 (void)fprintf(fd,"%02x ",
246 mopGetChar(pkt,&index));
247 if ((i % 16) == 15)
248 (void)fprintf(fd,"\n");
250 if ((i % 16) != 15)
251 (void)fprintf(fd,"\n");
252 #else
253 index = index + moplen - 5;
254 #endif
257 break;
258 case MOP_K_CODE_PLT:
260 tmpc = mopGetChar(pkt,&index); /* Load Number */
261 (void)fprintf(fd,"Load Number : %02x\n",tmpc);
263 tmpc = mopGetChar(pkt,&index); /* Parameter Type */
264 while (tmpc != MOP_K_PLTP_END) {
265 c = mopGetChar(pkt,&index); /* Parameter Length */
266 switch(tmpc) {
267 case MOP_K_PLTP_TSN: /* Target Name */
268 (void)fprintf(fd,"Target Name : %02x '",
269 tmpc);
270 for (i = 0; i < ((int) c); i++) {
271 (void)fprintf(fd,"%c",
272 mopGetChar(pkt,&index));
274 (void)fprintf(fd,"'\n");
275 break;
276 case MOP_K_PLTP_TSA: /* Target Address */
277 (void)fprintf(fd,"Target Addr : %02x ",c);
278 for (i = 0; i < ((int) c); i++) {
279 (void)fprintf(fd,"%02x ",
280 mopGetChar(pkt,&index));
282 (void)fprintf(fd,"\n");
283 break;
284 case MOP_K_PLTP_HSN: /* Host Name */
285 (void)fprintf(fd,"Host Name : %02x '",
286 tmpc);
287 for (i = 0; i < ((int) c); i++) {
288 (void)fprintf(fd,"%c",
289 mopGetChar(pkt,&index));
291 (void)fprintf(fd,"'\n");
292 break;
293 case MOP_K_PLTP_HSA: /* Host Address */
294 (void)fprintf(fd,"Host Addr : %02x ",c);
295 for (i = 0; i < ((int) c); i++) {
296 (void)fprintf(fd,"%02x ",
297 mopGetChar(pkt,&index));
299 (void)fprintf(fd,"\n");
300 break;
301 case MOP_K_PLTP_HST: /* Host Time */
302 ucp = pkt + index; index = index + 10;
303 (void)fprintf(fd,"Host Time : ");
304 mopPrintTime(fd, ucp);
305 (void)fprintf(fd,"\n");
306 break;
307 default:
308 break;
310 tmpc = mopGetChar(pkt,&index);/* Parameter Type */
313 tmpl = mopGetLong(pkt,&index); /* Transfer Address */
314 (void)fprintf(fd,"Transfer Addr: %08x\n", tmpl);
316 break;
317 default:
318 break;