1 |
786 |
skrzyp |
//==========================================================================
|
2 |
|
|
//
|
3 |
|
|
// mcopy.c
|
4 |
|
|
//
|
5 |
|
|
// RedBoot memory copy (mcopy) routine
|
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, 2003 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): msalter
|
43 |
|
|
// Contributors: msalter
|
44 |
|
|
// Date: 2003-07-01
|
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 |
|
|
static void
|
57 |
|
|
do_mcopy(int argc, char *argv[])
|
58 |
|
|
{
|
59 |
|
|
struct option_info opts[6];
|
60 |
|
|
unsigned long src, dst, len, end;
|
61 |
|
|
bool src_set, dst_set, len_set;
|
62 |
|
|
bool sz32, sz16, sz8;
|
63 |
|
|
int incr = 1;
|
64 |
|
|
|
65 |
|
|
init_opts(&opts[0], 's', true, OPTION_ARG_TYPE_NUM,
|
66 |
|
|
(void *)&src, (bool *)&src_set, "base address");
|
67 |
|
|
init_opts(&opts[1], 'l', true, OPTION_ARG_TYPE_NUM,
|
68 |
|
|
(void *)&len, (bool *)&len_set, "length");
|
69 |
|
|
init_opts(&opts[2], 'd', true, OPTION_ARG_TYPE_NUM,
|
70 |
|
|
(void *)&dst, (bool *)&dst_set, "base address");
|
71 |
|
|
init_opts(&opts[3], '4', false, OPTION_ARG_TYPE_FLG,
|
72 |
|
|
(void *)&sz32, (bool *)0, "copy 32 bit data");
|
73 |
|
|
init_opts(&opts[4], '2', false, OPTION_ARG_TYPE_FLG,
|
74 |
|
|
(void *)&sz16, (bool *)0, "copy 16 bit data");
|
75 |
|
|
init_opts(&opts[5], '1', false, OPTION_ARG_TYPE_FLG,
|
76 |
|
|
(void *)&sz8, (bool *)0, "copy 8 bit data");
|
77 |
|
|
if (!scan_opts(argc, argv, 1, opts, 6, 0, 0, "")) {
|
78 |
|
|
return;
|
79 |
|
|
}
|
80 |
|
|
|
81 |
|
|
// Must have src, dst, len. No more than one size specifier.
|
82 |
|
|
if (!src_set || !dst_set || !len_set || (sz32 + sz16 + sz8) > 1) {
|
83 |
|
|
diag_printf("usage: mcopy -s <addr> -d <addr> -l <length> [-1|-2|-4]\n");
|
84 |
|
|
return;
|
85 |
|
|
}
|
86 |
|
|
|
87 |
|
|
// adjust incr and len for data size
|
88 |
|
|
if (sz16) {
|
89 |
|
|
len = (len + 1) & ~1;
|
90 |
|
|
incr = 2;
|
91 |
|
|
} else if (sz32 || !sz8) {
|
92 |
|
|
len = (len + 3) & ~3;
|
93 |
|
|
incr = 4;
|
94 |
|
|
}
|
95 |
|
|
|
96 |
|
|
end = src + len;
|
97 |
|
|
|
98 |
|
|
// If overlapping areas, must copy backwards.
|
99 |
|
|
if (dst > src && dst < (src + len)) {
|
100 |
|
|
end = src - incr;
|
101 |
|
|
src += (len - incr);
|
102 |
|
|
dst += (len - incr);
|
103 |
|
|
incr = -incr;
|
104 |
|
|
}
|
105 |
|
|
|
106 |
|
|
if (sz8) {
|
107 |
|
|
while (src != end) {
|
108 |
|
|
*(cyg_uint8 *)dst = *(cyg_uint8 *)src;
|
109 |
|
|
src += incr;
|
110 |
|
|
dst += incr;
|
111 |
|
|
}
|
112 |
|
|
} else if (sz16) {
|
113 |
|
|
while (src != end) {
|
114 |
|
|
*(cyg_uint16 *)dst = *(cyg_uint16 *)src;
|
115 |
|
|
src += incr;
|
116 |
|
|
dst += incr;
|
117 |
|
|
}
|
118 |
|
|
} else {
|
119 |
|
|
// Default - 32 bits
|
120 |
|
|
while (src != end) {
|
121 |
|
|
*(cyg_uint32 *)dst = *(cyg_uint32 *)src;
|
122 |
|
|
src += incr;
|
123 |
|
|
dst += incr;
|
124 |
|
|
}
|
125 |
|
|
}
|
126 |
|
|
}
|
127 |
|
|
|
128 |
|
|
|
129 |
|
|
RedBoot_cmd("mcopy",
|
130 |
|
|
"Copy memory from one address to another",
|
131 |
|
|
"-s <location> -d <location> -l <length> [-1|-2|-4]",
|
132 |
|
|
do_mcopy
|
133 |
|
|
);
|