board_init.c 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /*
  2. * Code shared between SPL and U-Boot proper
  3. *
  4. * Copyright (c) 2015 Google, Inc
  5. * Written by Simon Glass <sjg@chromium.org>
  6. *
  7. * SPDX-License-Identifier: GPL-2.0+
  8. */
  9. #include <common.h>
  10. DECLARE_GLOBAL_DATA_PTR;
  11. /*
  12. * It isn't trivial to figure out whether memcpy() exists. The arch-specific
  13. * memcpy() is not normally available in SPL due to code size.
  14. */
  15. #if !defined(CONFIG_SPL_BUILD) || \
  16. (defined(CONFIG_SPL_LIBGENERIC_SUPPORT) && \
  17. !defined(CONFIG_USE_ARCH_MEMSET))
  18. #define _USE_MEMCPY
  19. #endif
  20. /* Unfortunately x86 can't compile this code as gd cannot be assigned */
  21. #ifndef CONFIG_X86
  22. __weak void arch_setup_gd(struct global_data *gd_ptr)
  23. {
  24. gd = gd_ptr;
  25. }
  26. #endif /* !CONFIG_X86 */
  27. ulong board_init_f_mem(ulong top)
  28. {
  29. struct global_data *gd_ptr;
  30. #ifndef _USE_MEMCPY
  31. int *ptr;
  32. #endif
  33. /* Leave space for the stack we are running with now */
  34. top -= 0x40;
  35. top -= sizeof(struct global_data);
  36. top = ALIGN(top, 16);
  37. gd_ptr = (struct global_data *)top;
  38. #ifdef _USE_MEMCPY
  39. memset(gd_ptr, '\0', sizeof(*gd));
  40. #else
  41. for (ptr = (int *)gd_ptr; ptr < (int *)(gd_ptr + 1); )
  42. *ptr++ = 0;
  43. #endif
  44. arch_setup_gd(gd_ptr);
  45. #if defined(CONFIG_SYS_MALLOC_F)
  46. top -= CONFIG_SYS_MALLOC_F_LEN;
  47. gd->malloc_base = top;
  48. #endif
  49. return top;
  50. }