3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 * See file CREDITS for list of people who contributed to this
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
25 * This is a workaround for issues on the MPC5200, where unaligned
26 * 32-bit-accesses to the local bus will deliver corrupted data. This
27 * happens for example when trying to use memcpy() from an odd NOR
28 * flash address; the behaviour can be also seen when using "md" on an
29 * odd NOR flash address (but there it is not a bug in U-Boot, which
30 * only shows the behaviour of this processor).
32 * For memcpy(), we test if either the source or the target address
33 * are not 32 bit aligned, and - if so - if the source address is in
34 * NOR flash: in this case we perform a byte-wise (slow) then; for
35 * aligned operations of non-flash areas we use the optimized (fast)
36 * real __memcpy(). This way we minimize the performance impact of
43 #include <linux/types.h>
45 void *memcpy(void *trg, const void *src, size_t len)
47 extern void* __memcpy(void *, const void *, size_t);
48 char *s = (char *)src;
49 char *t = (char *)trg;
50 void *dest = (void *)src;
53 * Check is source address is in flash:
54 * If not, we use the fast assembler code
56 if (((((unsigned long)s & 3) == 0) /* source aligned */
58 (((unsigned long)t & 3) == 0)) /* target aligned, */
60 (addr2info((ulong)s) == NULL)) { /* source not in flash */
61 return __memcpy(trg, src, len);
65 * Copying from flash, perform byte by byte copy.