OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [redboot/] [current/] [src/] [dump.c] - Blame information for rev 786

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
//==========================================================================
2
//
3
//      dump.c
4
//
5
//      RedBoot dump support
6
//
7
//==========================================================================
8
// ####ECOSGPLCOPYRIGHTBEGIN####                                            
9
// -------------------------------------------                              
10
// This file is part of eCos, the Embedded Configurable Operating System.   
11
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
12
//
13
// 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
// Software Foundation; either version 2 or (at your option) any later      
16
// version.                                                                 
17
//
18
// eCos is distributed in the hope that it will be useful, but WITHOUT      
19
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or    
20
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License    
21
// for more details.                                                        
22
//
23
// You should have received a copy of the GNU General Public License        
24
// along with eCos; if not, write to the Free Software Foundation, Inc.,    
25
// 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.            
26
//
27
// As a special exception, if other files instantiate templates or use      
28
// macros or inline functions from this file, or you compile this file      
29
// and link it with other works to produce a work based on this file,       
30
// this file does not by itself cause the resulting work to be covered by   
31
// the GNU General Public License. However the source code for this file    
32
// must still be made available in accordance with section (3) of the GNU   
33
// General Public License v2.                                               
34
//
35
// This exception does not invalidate any other reasons why a work based    
36
// on this file might be covered by the GNU General Public License.         
37
// -------------------------------------------                              
38
// ####ECOSGPLCOPYRIGHTEND####                                              
39
//==========================================================================
40
//#####DESCRIPTIONBEGIN####
41
//
42
// Author(s):    gthomas
43
// Contributors: gthomas
44
// Date:         2002-08-06
45
// Purpose:      
46
// Description:  
47
//              
48
// This code is part of RedBoot (tm).
49
//
50
//####DESCRIPTIONEND####
51
//
52
//==========================================================================
53
 
54
#include <redboot.h>
55
 
56
RedBoot_cmd("dump",
57
            "Display (hex dump) a range of memory",
58
            "-b <location> [-l <length>] [-s] [-1|-2|-4]",
59
            do_dump
60
    );
61
RedBoot_cmd("x",
62
            "Display (hex dump) a range of memory",
63
            "-b <location> [-l <length>] [-s] [-1|-2|-4]",
64
            do_x
65
    );
66
 
67
void
68
do_dump(int argc, char *argv[])
69
{
70
    struct option_info opts[6];
71
    unsigned long base, len;
72
    bool base_set, len_set;
73
    static unsigned long _base, _len;
74
    static char _size = 1;
75
    bool srec_dump, set_32bit, set_16bit, set_8bit;
76
    int i, n, off, cksum;
77
    cyg_uint8 ch;
78
 
79
    init_opts(&opts[0], 'b', true, OPTION_ARG_TYPE_NUM,
80
              (void *)&base, (bool *)&base_set, "base address");
81
    init_opts(&opts[1], 'l', true, OPTION_ARG_TYPE_NUM,
82
              (void *)&len, (bool *)&len_set, "length");
83
    init_opts(&opts[2], 's', false, OPTION_ARG_TYPE_FLG,
84
              (void *)&srec_dump, 0, "dump data using Morotola S-records");
85
    init_opts(&opts[3], '4', false, OPTION_ARG_TYPE_FLG,
86
              (void *)&set_32bit, (bool *)0, "dump 32 bit units");
87
    init_opts(&opts[4], '2', false, OPTION_ARG_TYPE_FLG,
88
              (void *)&set_16bit, (bool *)0, "dump 16 bit units");
89
    init_opts(&opts[5], '1', false, OPTION_ARG_TYPE_FLG,
90
              (void *)&set_8bit, (bool *)0, "dump 8 bit units");
91
    if (!scan_opts(argc, argv, 1, opts, 6, 0, 0, "")) {
92
        return;
93
    }
94
    if (!base_set) {
95
        if (_base == 0) {
96
            diag_printf("Dump what [location]?\n");
97
            return;
98
        }
99
        base = _base;
100
        if (!len_set) {
101
            len = _len;
102
            len_set = true;
103
        }
104
    }
105
 
106
    if (set_32bit) {
107
      _size = 4;
108
    } else if (set_16bit) {
109
      _size = 2;
110
    } else if (set_8bit) {
111
      _size = 1;
112
    }
113
 
114
    if (!len_set) {
115
        len = 32;
116
    }
117
    if (srec_dump) {
118
        off = 0;
119
        while (off < len) {
120
            n = (len > 16) ? 16 : len;
121
            cksum = n+5;
122
            diag_printf("S3%02X%08lX", n+5, off+base);
123
            for (i = 0;  i < 4;  i++) {
124
                cksum += (((base+off)>>(i*8)) & 0xFF);
125
            }
126
            for (i = 0;  i < n;  i++) {
127
                ch = *(cyg_uint8 *)(base+off+i);
128
                diag_printf("%02X", ch);
129
                cksum += ch;
130
            }
131
            diag_printf("%02X\n", ~cksum & 0xFF);
132
            off += n;
133
        }
134
    } else {
135
        switch( _size ) {
136
        case 1:
137
            diag_dump_buf((void *)base, len);
138
            break;
139
        case 2:
140
            diag_dump_buf_16bit((void *)base, len);
141
            break;
142
        case 4:
143
            diag_dump_buf_32bit((void *)base, len);
144
            break;
145
        }
146
    }
147
    _base = base + len;
148
    _len = len;
149
}
150
 
151
// Simple alias for the dump command
152
void
153
do_x(int argc, char *argv[])
154
{
155
    do_dump(argc, argv);
156
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.