memcpy_mpc5200.c 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*
  2. * (C) Copyright 2010
  3. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  4. *
  5. * See file CREDITS for list of people who contributed to this
  6. * project.
  7. *
  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.
  12. *
  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.
  17. *
  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,
  21. * MA 02111-1307 USA
  22. */
  23. /*
  24. * This is a workaround for issues on the MPC5200, where unaligned
  25. * 32-bit-accesses to the local bus will deliver corrupted data. This
  26. * happens for example when trying to use memcpy() from an odd NOR
  27. * flash address; the behaviour can be also seen when using "md" on an
  28. * odd NOR flash address (but there it is not a bug in U-Boot, which
  29. * only shows the behaviour of this processor).
  30. *
  31. * For memcpy(), we test if either the source or the target address
  32. * are not 32 bit aligned, and - if so - if the source address is in
  33. * NOR flash: in this case we perform a byte-wise (slow) then; for
  34. * aligned operations of non-flash areas we use the optimized (fast)
  35. * real __memcpy(). This way we minimize the performance impact of
  36. * this workaround.
  37. *
  38. */
  39. #include <common.h>
  40. #include <flash.h>
  41. #include <linux/types.h>
  42. void *memcpy(void *trg, const void *src, size_t len)
  43. {
  44. extern void* __memcpy(void *, const void *, size_t);
  45. char *s = (char *)src;
  46. char *t = (char *)trg;
  47. void *dest = (void *)src;
  48. /*
  49. * Check is source address is in flash:
  50. * If not, we use the fast assembler code
  51. */
  52. if (((((unsigned long)s & 3) == 0) /* source aligned */
  53. && /* AND */
  54. (((unsigned long)t & 3) == 0)) /* target aligned, */
  55. || /* or */
  56. (addr2info((ulong)s) == NULL)) { /* source not in flash */
  57. return __memcpy(trg, src, len);
  58. }
  59. /*
  60. * Copying from flash, perform byte by byte copy.
  61. */
  62. while (len-- > 0)
  63. *t++ = *s++;
  64. return dest;
  65. }