comparison packages/redboot/current/src/load.c @ 124:0ec04793409a ecos-sw-2000-09-11

Merge from eCos master repository on 2000-09-11-03:00:13-BST
author jlarmour
date Mon, 11 Sep 2000 02:42:46 +0000
parents bd1a71e3e476
children 518f42066aba
comparison
equal deleted inserted replaced
123:9b71e8e665a3 124:0ec04793409a
42 //####DESCRIPTIONEND#### 42 //####DESCRIPTIONEND####
43 // 43 //
44 //========================================================================== 44 //==========================================================================
45 45
46 #include <redboot.h> 46 #include <redboot.h>
47
48 // Buffer used by redboot_getc
49 getc_info_t getc_info;
50
47 51
48 // Exported CLI function 52 // Exported CLI function
49 RedBoot_cmd("load", 53 RedBoot_cmd("load",
50 "Load a file", 54 "Load a file",
51 "[-v] [-r] [-b <mem_addr>] <file_name>", 55 "[-v] [-r] [-b <mem_addr>] <file_name>",
184 } 188 }
185 while ((c = (*getc)()) != '\n') offset++; 189 while ((c = (*getc)()) != '\n') offset++;
186 } 190 }
187 } 191 }
188 192
189 #define BUF_SIZE 256 193
190 static struct { 194 int
191 int (*fun)(char *, int len, int *err); 195 redboot_getc(void)
192 unsigned char buf[BUF_SIZE];
193 unsigned char *bufp;
194 int avail, len, err;
195 int verbose, tick;
196 } getc_info;
197
198 static int
199 getc(void)
200 { 196 {
201 static char spin[] = "|/-\\|-"; 197 static char spin[] = "|/-\\|-";
198 if (getc_info.avail < 0) {
199 return -1;
200 }
202 if (getc_info.avail == 0) { 201 if (getc_info.avail == 0) {
203 if (getc_info.verbose) { 202 if (getc_info.verbose) {
204 printf("%c\b", spin[getc_info.tick++]); 203 printf("%c\b", spin[getc_info.tick++]);
205 if (getc_info.tick >= sizeof(spin)) { 204 if (getc_info.tick >= sizeof(spin)) {
206 getc_info.tick = 0; 205 getc_info.tick = 0;
220 } 219 }
221 getc_info.avail--; 220 getc_info.avail--;
222 return *getc_info.bufp++; 221 return *getc_info.bufp++;
223 } 222 }
224 223
225 static void 224 void
226 getc_init(int (*fun)(char *, int, int *), int verbose) 225 redboot_getc_init(int (*fun)(char *, int, int *), int verbose)
227 { 226 {
228 getc_info.avail = 0; 227 getc_info.avail = 0;
229 getc_info.len = BUF_SIZE; 228 getc_info.len = BUF_SIZE;
230 getc_info.fun = fun; 229 getc_info.fun = fun;
231 getc_info.verbose = verbose; 230 getc_info.verbose = verbose;
232 getc_info.tick = 0; 231 getc_info.tick = 0;
233 } 232 }
234 233
235 static void 234 void
236 getc_rewind(void) 235 redboot_getc_rewind(void)
237 { 236 {
238 getc_info.bufp = getc_info.buf; 237 getc_info.bufp = getc_info.buf;
239 getc_info.avail = getc_info.len; 238 getc_info.avail = getc_info.len;
240 } 239 }
241 240
326 res = tftp_stream_open(filename, &host, TFTP_OCTET, &err); 325 res = tftp_stream_open(filename, &host, TFTP_OCTET, &err);
327 if (res < 0) { 326 if (res < 0) {
328 printf("Can't load '%s': %s\n", filename, tftp_error(err)); 327 printf("Can't load '%s': %s\n", filename, tftp_error(err));
329 return; 328 return;
330 } 329 }
331 getc_init(tftp_stream_read, verbose); 330 redboot_getc_init(tftp_stream_read, verbose);
332 for (i = 0; i < sizeof(type); i++) { 331 for (i = 0; i < sizeof(type); i++) {
333 if ((res = getc()) < 0) { 332 if ((res = redboot_getc()) < 0) {
334 err = getc_info.err; 333 err = getc_info.err;
335 break; 334 break;
336 } 335 }
337 type[i] = res; 336 type[i] = res;
338 } 337 }
345 #endif 344 #endif
346 if (mode == MODE_ZMODEM) { 345 if (mode == MODE_ZMODEM) {
347 printf("Sorry, zmodem download not yet available\n"); 346 printf("Sorry, zmodem download not yet available\n");
348 return; 347 return;
349 } 348 }
350 getc_rewind(); // Restore header to stream 349 redboot_getc_rewind(); // Restore header to stream
351 if (raw) { 350 if (raw) {
352 if (!base_addr_set) { 351 if (!base_addr_set) {
353 printf("Raw load requires a memory address\n"); 352 printf("Raw load requires a memory address\n");
354 } else { 353 } else {
355 unsigned char *mp = (unsigned char *)base; 354 unsigned char *mp = (unsigned char *)base;
356 while ((res = getc()) >= 0) { 355 while ((res = redboot_getc()) >= 0) {
357 *mp++ = res; 356 *mp++ = res;
358 } 357 }
359 printf("Raw file loaded %p-%p\n", (void *)base, (void *)mp); 358 printf("Raw file loaded %p-%p\n", (void *)base, (void *)mp);
360 } 359 }
361 } else { 360 } else {
362 // Treat data as some sort of executable image 361 // Treat data as some sort of executable image
363 if (strncmp(&type[1], "ELF", 3) == 0) { 362 if (strncmp(&type[1], "ELF", 3) == 0) {
364 load_elf_image(getc); 363 load_elf_image(redboot_getc);
365 } else if ((type[0] == 'S') && 364 } else if ((type[0] == 'S') &&
366 ((type[1] >= '0') && (type[1] <= '9'))) { 365 ((type[1] >= '0') && (type[1] <= '9'))) {
367 load_srec_image(getc, base); 366 load_srec_image(redboot_getc, base);
368 } else { 367 } else {
369 printf("Unrecognized image type: %lx\n", *(unsigned long *)type); 368 printf("Unrecognized image type: %lx\n", *(unsigned long *)type);
370 } 369 }
371 } 370 }
372 #ifdef CYGPKG_REDBOOT_NETWORKING 371 #ifdef CYGPKG_REDBOOT_NETWORKING