annotate packages/redboot/current/src/mcopy.c @ 3249:6e9f1cd4ed38

Fix compiler warning about variable set but not used. [ Bugzilla 1001865 ]
author vae
date Sat, 15 Jun 2013 20:22:36 +0000
parents 74dbf4c3f2e1
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1087
549ccefb35ed Add RedBoot mcopy command
msalter
parents:
diff changeset
1 //==========================================================================
549ccefb35ed Add RedBoot mcopy command
msalter
parents:
diff changeset
2 //
549ccefb35ed Add RedBoot mcopy command
msalter
parents:
diff changeset
3 // mcopy.c
549ccefb35ed Add RedBoot mcopy command
msalter
parents:
diff changeset
4 //
549ccefb35ed Add RedBoot mcopy command
msalter
parents:
diff changeset
5 // RedBoot memory copy (mcopy) routine
549ccefb35ed Add RedBoot mcopy command
msalter
parents:
diff changeset
6 //
549ccefb35ed Add RedBoot mcopy command
msalter
parents:
diff changeset
7 //==========================================================================
2729
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 1513
diff changeset
8 // ####ECOSGPLCOPYRIGHTBEGIN####
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 1513
diff changeset
9 // -------------------------------------------
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 1513
diff changeset
10 // This file is part of eCos, the Embedded Configurable Operating System.
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 1513
diff changeset
11 // Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
1087
549ccefb35ed Add RedBoot mcopy command
msalter
parents:
diff changeset
12 //
2729
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 1513
diff changeset
13 // eCos is free software; you can redistribute it and/or modify it under
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 1513
diff changeset
14 // the terms of the GNU General Public License as published by the Free
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 1513
diff changeset
15 // Software Foundation; either version 2 or (at your option) any later
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 1513
diff changeset
16 // version.
1087
549ccefb35ed Add RedBoot mcopy command
msalter
parents:
diff changeset
17 //
2729
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 1513
diff changeset
18 // eCos is distributed in the hope that it will be useful, but WITHOUT
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 1513
diff changeset
19 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 1513
diff changeset
20 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 1513
diff changeset
21 // for more details.
1087
549ccefb35ed Add RedBoot mcopy command
msalter
parents:
diff changeset
22 //
2729
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 1513
diff changeset
23 // You should have received a copy of the GNU General Public License
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 1513
diff changeset
24 // along with eCos; if not, write to the Free Software Foundation, Inc.,
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 1513
diff changeset
25 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
1087
549ccefb35ed Add RedBoot mcopy command
msalter
parents:
diff changeset
26 //
2729
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 1513
diff changeset
27 // As a special exception, if other files instantiate templates or use
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 1513
diff changeset
28 // macros or inline functions from this file, or you compile this file
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 1513
diff changeset
29 // and link it with other works to produce a work based on this file,
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 1513
diff changeset
30 // this file does not by itself cause the resulting work to be covered by
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 1513
diff changeset
31 // the GNU General Public License. However the source code for this file
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 1513
diff changeset
32 // must still be made available in accordance with section (3) of the GNU
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 1513
diff changeset
33 // General Public License v2.
1087
549ccefb35ed Add RedBoot mcopy command
msalter
parents:
diff changeset
34 //
2729
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 1513
diff changeset
35 // This exception does not invalidate any other reasons why a work based
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 1513
diff changeset
36 // on this file might be covered by the GNU General Public License.
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 1513
diff changeset
37 // -------------------------------------------
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 1513
diff changeset
38 // ####ECOSGPLCOPYRIGHTEND####
1087
549ccefb35ed Add RedBoot mcopy command
msalter
parents:
diff changeset
39 //==========================================================================
549ccefb35ed Add RedBoot mcopy command
msalter
parents:
diff changeset
40 //#####DESCRIPTIONBEGIN####
549ccefb35ed Add RedBoot mcopy command
msalter
parents:
diff changeset
41 //
549ccefb35ed Add RedBoot mcopy command
msalter
parents:
diff changeset
42 // Author(s): msalter
549ccefb35ed Add RedBoot mcopy command
msalter
parents:
diff changeset
43 // Contributors: msalter
549ccefb35ed Add RedBoot mcopy command
msalter
parents:
diff changeset
44 // Date: 2003-07-01
549ccefb35ed Add RedBoot mcopy command
msalter
parents:
diff changeset
45 // Purpose:
549ccefb35ed Add RedBoot mcopy command
msalter
parents:
diff changeset
46 // Description:
549ccefb35ed Add RedBoot mcopy command
msalter
parents:
diff changeset
47 //
549ccefb35ed Add RedBoot mcopy command
msalter
parents:
diff changeset
48 // This code is part of RedBoot (tm).
549ccefb35ed Add RedBoot mcopy command
msalter
parents:
diff changeset
49 //
549ccefb35ed Add RedBoot mcopy command
msalter
parents:
diff changeset
50 //####DESCRIPTIONEND####
549ccefb35ed Add RedBoot mcopy command
msalter
parents:
diff changeset
51 //
549ccefb35ed Add RedBoot mcopy command
msalter
parents:
diff changeset
52 //==========================================================================
549ccefb35ed Add RedBoot mcopy command
msalter
parents:
diff changeset
53
549ccefb35ed Add RedBoot mcopy command
msalter
parents:
diff changeset
54 #include <redboot.h>
549ccefb35ed Add RedBoot mcopy command
msalter
parents:
diff changeset
55
549ccefb35ed Add RedBoot mcopy command
msalter
parents:
diff changeset
56 static void
549ccefb35ed Add RedBoot mcopy command
msalter
parents:
diff changeset
57 do_mcopy(int argc, char *argv[])
549ccefb35ed Add RedBoot mcopy command
msalter
parents:
diff changeset
58 {
549ccefb35ed Add RedBoot mcopy command
msalter
parents:
diff changeset
59 struct option_info opts[6];
549ccefb35ed Add RedBoot mcopy command
msalter
parents:
diff changeset
60 unsigned long src, dst, len, end;
549ccefb35ed Add RedBoot mcopy command
msalter
parents:
diff changeset
61 bool src_set, dst_set, len_set;
549ccefb35ed Add RedBoot mcopy command
msalter
parents:
diff changeset
62 bool sz32, sz16, sz8;
549ccefb35ed Add RedBoot mcopy command
msalter
parents:
diff changeset
63 int incr = 1;
549ccefb35ed Add RedBoot mcopy command
msalter
parents:
diff changeset
64
549ccefb35ed Add RedBoot mcopy command
msalter
parents:
diff changeset
65 init_opts(&opts[0], 's', true, OPTION_ARG_TYPE_NUM,
1513
c4355f101bf6 Cleanups to remove warnings
gthomas
parents: 1087
diff changeset
66 (void *)&src, (bool *)&src_set, "base address");
1087
549ccefb35ed Add RedBoot mcopy command
msalter
parents:
diff changeset
67 init_opts(&opts[1], 'l', true, OPTION_ARG_TYPE_NUM,
1513
c4355f101bf6 Cleanups to remove warnings
gthomas
parents: 1087
diff changeset
68 (void *)&len, (bool *)&len_set, "length");
1087
549ccefb35ed Add RedBoot mcopy command
msalter
parents:
diff changeset
69 init_opts(&opts[2], 'd', true, OPTION_ARG_TYPE_NUM,
1513
c4355f101bf6 Cleanups to remove warnings
gthomas
parents: 1087
diff changeset
70 (void *)&dst, (bool *)&dst_set, "base address");
1087
549ccefb35ed Add RedBoot mcopy command
msalter
parents:
diff changeset
71 init_opts(&opts[3], '4', false, OPTION_ARG_TYPE_FLG,
549ccefb35ed Add RedBoot mcopy command
msalter
parents:
diff changeset
72 (void *)&sz32, (bool *)0, "copy 32 bit data");
549ccefb35ed Add RedBoot mcopy command
msalter
parents:
diff changeset
73 init_opts(&opts[4], '2', false, OPTION_ARG_TYPE_FLG,
1513
c4355f101bf6 Cleanups to remove warnings
gthomas
parents: 1087
diff changeset
74 (void *)&sz16, (bool *)0, "copy 16 bit data");
1087
549ccefb35ed Add RedBoot mcopy command
msalter
parents:
diff changeset
75 init_opts(&opts[5], '1', false, OPTION_ARG_TYPE_FLG,
1513
c4355f101bf6 Cleanups to remove warnings
gthomas
parents: 1087
diff changeset
76 (void *)&sz8, (bool *)0, "copy 8 bit data");
1087
549ccefb35ed Add RedBoot mcopy command
msalter
parents:
diff changeset
77 if (!scan_opts(argc, argv, 1, opts, 6, 0, 0, "")) {
549ccefb35ed Add RedBoot mcopy command
msalter
parents:
diff changeset
78 return;
549ccefb35ed Add RedBoot mcopy command
msalter
parents:
diff changeset
79 }
549ccefb35ed Add RedBoot mcopy command
msalter
parents:
diff changeset
80
549ccefb35ed Add RedBoot mcopy command
msalter
parents:
diff changeset
81 // Must have src, dst, len. No more than one size specifier.
549ccefb35ed Add RedBoot mcopy command
msalter
parents:
diff changeset
82 if (!src_set || !dst_set || !len_set || (sz32 + sz16 + sz8) > 1) {
549ccefb35ed Add RedBoot mcopy command
msalter
parents:
diff changeset
83 diag_printf("usage: mcopy -s <addr> -d <addr> -l <length> [-1|-2|-4]\n");
549ccefb35ed Add RedBoot mcopy command
msalter
parents:
diff changeset
84 return;
549ccefb35ed Add RedBoot mcopy command
msalter
parents:
diff changeset
85 }
549ccefb35ed Add RedBoot mcopy command
msalter
parents:
diff changeset
86
549ccefb35ed Add RedBoot mcopy command
msalter
parents:
diff changeset
87 // adjust incr and len for data size
549ccefb35ed Add RedBoot mcopy command
msalter
parents:
diff changeset
88 if (sz16) {
549ccefb35ed Add RedBoot mcopy command
msalter
parents:
diff changeset
89 len = (len + 1) & ~1;
549ccefb35ed Add RedBoot mcopy command
msalter
parents:
diff changeset
90 incr = 2;
549ccefb35ed Add RedBoot mcopy command
msalter
parents:
diff changeset
91 } else if (sz32 || !sz8) {
549ccefb35ed Add RedBoot mcopy command
msalter
parents:
diff changeset
92 len = (len + 3) & ~3;
549ccefb35ed Add RedBoot mcopy command
msalter
parents:
diff changeset
93 incr = 4;
549ccefb35ed Add RedBoot mcopy command
msalter
parents:
diff changeset
94 }
549ccefb35ed Add RedBoot mcopy command
msalter
parents:
diff changeset
95
549ccefb35ed Add RedBoot mcopy command
msalter
parents:
diff changeset
96 end = src + len;
549ccefb35ed Add RedBoot mcopy command
msalter
parents:
diff changeset
97
549ccefb35ed Add RedBoot mcopy command
msalter
parents:
diff changeset
98 // If overlapping areas, must copy backwards.
549ccefb35ed Add RedBoot mcopy command
msalter
parents:
diff changeset
99 if (dst > src && dst < (src + len)) {
549ccefb35ed Add RedBoot mcopy command
msalter
parents:
diff changeset
100 end = src - incr;
549ccefb35ed Add RedBoot mcopy command
msalter
parents:
diff changeset
101 src += (len - incr);
549ccefb35ed Add RedBoot mcopy command
msalter
parents:
diff changeset
102 dst += (len - incr);
549ccefb35ed Add RedBoot mcopy command
msalter
parents:
diff changeset
103 incr = -incr;
549ccefb35ed Add RedBoot mcopy command
msalter
parents:
diff changeset
104 }
549ccefb35ed Add RedBoot mcopy command
msalter
parents:
diff changeset
105
549ccefb35ed Add RedBoot mcopy command
msalter
parents:
diff changeset
106 if (sz8) {
549ccefb35ed Add RedBoot mcopy command
msalter
parents:
diff changeset
107 while (src != end) {
549ccefb35ed Add RedBoot mcopy command
msalter
parents:
diff changeset
108 *(cyg_uint8 *)dst = *(cyg_uint8 *)src;
549ccefb35ed Add RedBoot mcopy command
msalter
parents:
diff changeset
109 src += incr;
549ccefb35ed Add RedBoot mcopy command
msalter
parents:
diff changeset
110 dst += incr;
549ccefb35ed Add RedBoot mcopy command
msalter
parents:
diff changeset
111 }
549ccefb35ed Add RedBoot mcopy command
msalter
parents:
diff changeset
112 } else if (sz16) {
549ccefb35ed Add RedBoot mcopy command
msalter
parents:
diff changeset
113 while (src != end) {
549ccefb35ed Add RedBoot mcopy command
msalter
parents:
diff changeset
114 *(cyg_uint16 *)dst = *(cyg_uint16 *)src;
549ccefb35ed Add RedBoot mcopy command
msalter
parents:
diff changeset
115 src += incr;
549ccefb35ed Add RedBoot mcopy command
msalter
parents:
diff changeset
116 dst += incr;
549ccefb35ed Add RedBoot mcopy command
msalter
parents:
diff changeset
117 }
549ccefb35ed Add RedBoot mcopy command
msalter
parents:
diff changeset
118 } else {
549ccefb35ed Add RedBoot mcopy command
msalter
parents:
diff changeset
119 // Default - 32 bits
549ccefb35ed Add RedBoot mcopy command
msalter
parents:
diff changeset
120 while (src != end) {
549ccefb35ed Add RedBoot mcopy command
msalter
parents:
diff changeset
121 *(cyg_uint32 *)dst = *(cyg_uint32 *)src;
549ccefb35ed Add RedBoot mcopy command
msalter
parents:
diff changeset
122 src += incr;
549ccefb35ed Add RedBoot mcopy command
msalter
parents:
diff changeset
123 dst += incr;
549ccefb35ed Add RedBoot mcopy command
msalter
parents:
diff changeset
124 }
549ccefb35ed Add RedBoot mcopy command
msalter
parents:
diff changeset
125 }
549ccefb35ed Add RedBoot mcopy command
msalter
parents:
diff changeset
126 }
549ccefb35ed Add RedBoot mcopy command
msalter
parents:
diff changeset
127
549ccefb35ed Add RedBoot mcopy command
msalter
parents:
diff changeset
128
549ccefb35ed Add RedBoot mcopy command
msalter
parents:
diff changeset
129 RedBoot_cmd("mcopy",
549ccefb35ed Add RedBoot mcopy command
msalter
parents:
diff changeset
130 "Copy memory from one address to another",
549ccefb35ed Add RedBoot mcopy command
msalter
parents:
diff changeset
131 "-s <location> -d <location> -l <length> [-1|-2|-4]",
549ccefb35ed Add RedBoot mcopy command
msalter
parents:
diff changeset
132 do_mcopy
549ccefb35ed Add RedBoot mcopy command
msalter
parents:
diff changeset
133 );