comparison packages/redboot/current/src/main.c @ 264:57f3c72256bb

Reorg CLI functions into separate files. Update CDL. Fix macros in scripts.
author gthomas
date Tue, 06 Aug 2002 14:29:11 +0000
parents d2c90368aeef
children 906a5d289c6d
comparison
equal deleted inserted replaced
263:c0d53837cb68 264:57f3c72256bb
7 //========================================================================== 7 //==========================================================================
8 //####ECOSGPLCOPYRIGHTBEGIN#### 8 //####ECOSGPLCOPYRIGHTBEGIN####
9 // ------------------------------------------- 9 // -------------------------------------------
10 // This file is part of eCos, the Embedded Configurable Operating System. 10 // This file is part of eCos, the Embedded Configurable Operating System.
11 // Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc. 11 // Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
12 // Copyright (C) 2002 Gary Thomas
12 // 13 //
13 // eCos is free software; you can redistribute it and/or modify it under 14 // eCos is free software; you can redistribute it and/or modify it under
14 // the terms of the GNU General Public License as published by the Free 15 // the terms of the GNU General Public License as published by the Free
15 // Software Foundation; either version 2 or (at your option) any later version. 16 // Software Foundation; either version 2 or (at your option) any later version.
16 // 17 //
66 #ifdef CYGBLD_HAL_PLATFORM_STUB_H 67 #ifdef CYGBLD_HAL_PLATFORM_STUB_H
67 #include CYGBLD_HAL_PLATFORM_STUB_H 68 #include CYGBLD_HAL_PLATFORM_STUB_H
68 #else 69 #else
69 #include <cyg/hal/plf_stub.h> 70 #include <cyg/hal/plf_stub.h>
70 #endif 71 #endif
72 // GDB interfaces
73 extern void breakpoint(void);
71 #endif 74 #endif
72 75
73 // Builtin Self Test (BIST) 76 // Builtin Self Test (BIST)
74 externC void bist(void); 77 externC void bist(void);
75
76 #ifdef CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS
77 // GDB interfaces
78 extern void breakpoint(void);
79 #endif
80 78
81 // CLI command processing (defined in this file) 79 // CLI command processing (defined in this file)
82 RedBoot_cmd("version", 80 RedBoot_cmd("version",
83 "Display RedBoot version information", 81 "Display RedBoot version information",
84 "", 82 "",
91 ); 89 );
92 RedBoot_cmd("go", 90 RedBoot_cmd("go",
93 "Execute code at a location", 91 "Execute code at a location",
94 "[-w <timeout>] [entry]", 92 "[-w <timeout>] [entry]",
95 do_go 93 do_go
96 );
97 RedBoot_cmd("dump",
98 "Display (hex dump) a range of memory",
99 "-b <location> [-l <length>] [-s] [-1|2|4]",
100 do_dump
101 );
102 RedBoot_cmd("x",
103 "Display (hex dump) a range of memory",
104 "-b <location> [-l <length>] [-s] [-1|2|4]",
105 do_x
106 );
107 #ifdef CYGBLD_BUILD_REDBOOT_WITH_CKSUM
108 RedBoot_cmd("cksum",
109 "Compute a 32bit checksum [POSIX algorithm] for a range of memory",
110 "-b <location> -l <length>",
111 do_cksum
112 );
113 #endif
114 #ifdef CYGBLD_BUILD_REDBOOT_WITH_MFILL
115 RedBoot_cmd("mfill",
116 "Fill a block of memory with a pattern",
117 "-b <location> -l <length> -p <pattern> [-1|-2|-4]",
118 do_mfill
119 );
120 #endif
121 #ifdef CYGBLD_BUILD_REDBOOT_WITH_MCMP
122 RedBoot_cmd("mcmp",
123 "Compare two blocks of memory",
124 "-s <location> -d <location> -l <length> [-1|-2|-4]",
125 do_mcmp
126 );
127 #endif
128 RedBoot_cmd("cache",
129 "Manage machine caches",
130 "[ON | OFF]",
131 do_caches
132 ); 94 );
133 #ifdef HAL_PLATFORM_RESET 95 #ifdef HAL_PLATFORM_RESET
134 RedBoot_cmd("reset", 96 RedBoot_cmd("reset",
135 "Reset the system", 97 "Reset the system",
136 "", 98 "",
367 } 329 }
368 } 330 }
369 } 331 }
370 332
371 void 333 void
372 do_caches(int argc, char *argv[])
373 {
374 unsigned long oldints;
375 int dcache_on=0, icache_on=0;
376
377 if (argc == 2) {
378 if (strcasecmp(argv[1], "on") == 0) {
379 HAL_DISABLE_INTERRUPTS(oldints);
380 HAL_ICACHE_ENABLE();
381 HAL_DCACHE_ENABLE();
382 HAL_RESTORE_INTERRUPTS(oldints);
383 } else if (strcasecmp(argv[1], "off") == 0) {
384 HAL_DISABLE_INTERRUPTS(oldints);
385 HAL_DCACHE_SYNC();
386 HAL_ICACHE_DISABLE();
387 HAL_DCACHE_DISABLE();
388 HAL_DCACHE_SYNC();
389 HAL_ICACHE_INVALIDATE_ALL();
390 HAL_DCACHE_INVALIDATE_ALL();
391 HAL_RESTORE_INTERRUPTS(oldints);
392 } else {
393 diag_printf("Invalid cache mode: %s\n", argv[1]);
394 }
395 } else {
396 #ifdef HAL_DCACHE_IS_ENABLED
397 HAL_DCACHE_IS_ENABLED(dcache_on);
398 #endif
399 #ifdef HAL_ICACHE_IS_ENABLED
400 HAL_ICACHE_IS_ENABLED(icache_on);
401 #endif
402 diag_printf("Data cache: %s, Instruction cache: %s\n",
403 dcache_on?"On":"Off", icache_on?"On":"Off");
404 }
405 }
406
407 void
408 show_help(struct cmd *cmd, struct cmd *cmd_end, char *which, char *pre) 334 show_help(struct cmd *cmd, struct cmd *cmd_end, char *which, char *pre)
409 { 335 {
410 bool show; 336 bool show;
411 int len = 0; 337 int len = 0;
412 338
440 } 366 }
441 cmd = __RedBoot_CMD_TAB__; 367 cmd = __RedBoot_CMD_TAB__;
442 show_help(cmd, &__RedBoot_CMD_TAB_END__, which, ""); 368 show_help(cmd, &__RedBoot_CMD_TAB_END__, which, "");
443 return; 369 return;
444 } 370 }
445
446 void
447 do_dump(int argc, char *argv[])
448 {
449 struct option_info opts[6];
450 unsigned long base, len;
451 bool base_set, len_set;
452 static unsigned long _base, _len;
453 static char _size = 1;
454 bool srec_dump, set_32bit, set_16bit, set_8bit;
455 int i, n, off, cksum;
456 cyg_uint8 ch;
457
458 init_opts(&opts[0], 'b', true, OPTION_ARG_TYPE_NUM,
459 (void **)&base, (bool *)&base_set, "base address");
460 init_opts(&opts[1], 'l', true, OPTION_ARG_TYPE_NUM,
461 (void **)&len, (bool *)&len_set, "length");
462 init_opts(&opts[2], 's', false, OPTION_ARG_TYPE_FLG,
463 (void **)&srec_dump, 0, "dump data using Morotola S-records");
464 init_opts(&opts[3], '4', false, OPTION_ARG_TYPE_FLG,
465 (void *)&set_32bit, (bool *)0, "dump 32 bit units");
466 init_opts(&opts[4], '2', false, OPTION_ARG_TYPE_FLG,
467 (void **)&set_16bit, (bool *)0, "dump 16 bit units");
468 init_opts(&opts[5], '1', false, OPTION_ARG_TYPE_FLG,
469 (void **)&set_8bit, (bool *)0, "dump 8 bit units");
470 if (!scan_opts(argc, argv, 1, opts, 6, 0, 0, "")) {
471 return;
472 }
473 if (!base_set) {
474 if (_base == 0) {
475 diag_printf("Dump what [location]?\n");
476 return;
477 }
478 base = _base;
479 if (!len_set) {
480 len = _len;
481 len_set = true;
482 }
483 }
484
485 if (set_32bit) {
486 _size = 4;
487 } else if (set_16bit) {
488 _size = 2;
489 } else if (set_8bit) {
490 _size = 1;
491 }
492
493 if (!len_set) {
494 len = 32;
495 }
496 if (srec_dump) {
497 off = 0;
498 while (off < len) {
499 n = (len > 16) ? 16 : len;
500 cksum = n+5;
501 diag_printf("S3%02X%08X", n+5, off+base);
502 for (i = 0; i < 4; i++) {
503 cksum += (((base+off)>>(i*8)) & 0xFF);
504 }
505 for (i = 0; i < n; i++) {
506 ch = *(cyg_uint8 *)(base+off+i);
507 diag_printf("%02X", ch);
508 cksum += ch;
509 }
510 diag_printf("%02X\n", ~cksum & 0xFF);
511 off += n;
512 }
513 } else {
514 switch( _size ) {
515 case 1:
516 diag_dump_buf((void *)base, len);
517 break;
518 case 2:
519 diag_dump_buf_16bit((void *)base, len);
520 break;
521 case 4:
522 diag_dump_buf_32bit((void *)base, len);
523 break;
524 }
525 }
526 _base = base + len;
527 _len = len;
528 }
529
530 // Simple alias for the dump command
531 void
532 do_x(int argc, char *argv[])
533 {
534 do_dump(argc, argv);
535 }
536
537 #ifdef CYGBLD_BUILD_REDBOOT_WITH_CKSUM
538 void
539 do_cksum(int argc, char *argv[])
540 {
541 // Compute a CRC, using the POSIX 1003 definition
542 extern unsigned long
543 posix_crc32(unsigned char *s, int len);
544
545 struct option_info opts[2];
546 unsigned long base, len, crc;
547 bool base_set, len_set;
548
549 init_opts(&opts[0], 'b', true, OPTION_ARG_TYPE_NUM,
550 (void **)&base, (bool *)&base_set, "base address");
551 init_opts(&opts[1], 'l', true, OPTION_ARG_TYPE_NUM,
552 (void **)&len, (bool *)&len_set, "length");
553 if (!scan_opts(argc, argv, 1, opts, 2, 0, 0, "")) {
554 return;
555 }
556 if (!base_set || !len_set) {
557 if (load_address >= (CYG_ADDRESS)ram_start &&
558 load_address_end < (CYG_ADDRESS)ram_end &&
559 load_address < load_address_end) {
560 base = load_address;
561 len = load_address_end - load_address;
562 diag_printf("Computing cksum for area %p-%p\n",
563 base, load_address_end);
564 } else {
565 diag_printf("usage: cksum -b <addr> -l <length>\n");
566 return;
567 }
568 }
569 crc = posix_crc32((unsigned char *)base, len);
570 diag_printf("POSIX cksum = %lu %lu (0x%08lx 0x%08lx)\n", crc, len, crc, len);
571 }
572 #endif
573
574 #ifdef CYGBLD_BUILD_REDBOOT_WITH_MFILL
575 void
576 do_mfill(int argc, char *argv[])
577 {
578 // Fill a region of memory with a pattern
579 struct option_info opts[6];
580 unsigned long base, pat;
581 long len;
582 bool base_set, len_set, pat_set;
583 bool set_32bit, set_16bit, set_8bit;
584
585 init_opts(&opts[0], 'b', true, OPTION_ARG_TYPE_NUM,
586 (void **)&base, (bool *)&base_set, "base address");
587 init_opts(&opts[1], 'l', true, OPTION_ARG_TYPE_NUM,
588 (void **)&len, (bool *)&len_set, "length");
589 init_opts(&opts[2], 'p', true, OPTION_ARG_TYPE_NUM,
590 (void **)&pat, (bool *)&pat_set, "pattern");
591 init_opts(&opts[3], '4', false, OPTION_ARG_TYPE_FLG,
592 (void *)&set_32bit, (bool *)0, "fill 32 bit units");
593 init_opts(&opts[4], '2', false, OPTION_ARG_TYPE_FLG,
594 (void **)&set_16bit, (bool *)0, "fill 16 bit units");
595 init_opts(&opts[5], '1', false, OPTION_ARG_TYPE_FLG,
596 (void **)&set_8bit, (bool *)0, "fill 8 bit units");
597 if (!scan_opts(argc, argv, 1, opts, 6, 0, 0, "")) {
598 return;
599 }
600 if (!base_set || !len_set) {
601 diag_printf("usage: mfill -b <addr> -l <length> [-p <pattern>] [-1|-2|-4]\n");
602 return;
603 }
604 if (!pat_set) {
605 pat = 0;
606 }
607 // No checks here
608 if (set_8bit) {
609 // Fill 8 bits at a time
610 while ((len -= sizeof(cyg_uint8)) >= 0) {
611 *((cyg_uint8 *)base)++ = (cyg_uint8)pat;
612 }
613 } else if (set_16bit) {
614 // Fill 16 bits at a time
615 while ((len -= sizeof(cyg_uint16)) >= 0) {
616 *((cyg_uint16 *)base)++ = (cyg_uint16)pat;
617 }
618 } else {
619 // Default - 32 bits
620 while ((len -= sizeof(cyg_uint32)) >= 0) {
621 *((cyg_uint32 *)base)++ = (cyg_uint32)pat;
622 }
623 }
624 }
625 #endif
626
627 #ifdef CYGBLD_BUILD_REDBOOT_WITH_MCMP
628 void
629 do_mcmp(int argc, char *argv[])
630 {
631 // Fill a region of memory with a pattern
632 struct option_info opts[6];
633 unsigned long src_base, dst_base;
634 long len;
635 bool src_base_set, dst_base_set, len_set;
636 bool set_32bit, set_16bit, set_8bit;
637
638 init_opts(&opts[0], 's', true, OPTION_ARG_TYPE_NUM,
639 (void **)&src_base, (bool *)&src_base_set, "base address");
640 init_opts(&opts[1], 'l', true, OPTION_ARG_TYPE_NUM,
641 (void **)&len, (bool *)&len_set, "length");
642 init_opts(&opts[2], 'd', true, OPTION_ARG_TYPE_NUM,
643 (void **)&dst_base, (bool *)&dst_base_set, "base address");
644 init_opts(&opts[3], '4', false, OPTION_ARG_TYPE_FLG,
645 (void *)&set_32bit, (bool *)0, "fill 32 bit units");
646 init_opts(&opts[4], '2', false, OPTION_ARG_TYPE_FLG,
647 (void **)&set_16bit, (bool *)0, "fill 16 bit units");
648 init_opts(&opts[5], '1', false, OPTION_ARG_TYPE_FLG,
649 (void **)&set_8bit, (bool *)0, "fill 8 bit units");
650 if (!scan_opts(argc, argv, 1, opts, 6, 0, 0, "")) {
651 return;
652 }
653 if (!src_base_set || !dst_base_set || !len_set) {
654 diag_printf("usage: mcmp -s <addr> -d <addr> -l <length> [-1|-2|-4]\n");
655 return;
656 }
657 // No checks here
658 if (set_8bit) {
659 // Compare 8 bits at a time
660 while ((len -= sizeof(cyg_uint8)) >= 0) {
661 if (*((cyg_uint8 *)src_base)++ != *((cyg_uint8 *)dst_base)++) {
662 ((cyg_uint8 *)src_base)--;
663 ((cyg_uint8 *)dst_base)--;
664 diag_printf("Buffers don't match - %p=0x%02x, %p=0x%02x\n",
665 src_base, *((cyg_uint8 *)src_base),
666 dst_base, *((cyg_uint8 *)dst_base));
667 return;
668 }
669 }
670 } else if (set_16bit) {
671 // Compare 16 bits at a time
672 while ((len -= sizeof(cyg_uint16)) >= 0) {
673 if (*((cyg_uint16 *)src_base)++ != *((cyg_uint16 *)dst_base)++) {
674 ((cyg_uint16 *)src_base)--;
675 ((cyg_uint16 *)dst_base)--;
676 diag_printf("Buffers don't match - %p=0x%04x, %p=0x%04x\n",
677 src_base, *((cyg_uint16 *)src_base),
678 dst_base, *((cyg_uint16 *)dst_base));
679 return;
680 }
681 }
682 } else {
683 // Default - 32 bits
684 while ((len -= sizeof(cyg_uint32)) >= 0) {
685 if (*((cyg_uint32 *)src_base)++ != *((cyg_uint32 *)dst_base)++) {
686 ((cyg_uint32 *)src_base)--;
687 ((cyg_uint32 *)dst_base)--;
688 diag_printf("Buffers don't match - %p=0x%08x, %p=0x%08x\n",
689 src_base, *((cyg_uint32 *)src_base),
690 dst_base, *((cyg_uint32 *)dst_base));
691 return;
692 }
693 }
694 }
695 }
696 #endif
697 371
698 void 372 void
699 do_go(int argc, char *argv[]) 373 do_go(int argc, char *argv[])
700 { 374 {
701 typedef void code_fun(void); 375 typedef void code_fun(void);