spl.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /* Copyright 2013 Freescale Semiconductor, Inc.
  2. *
  3. * SPDX-License-Identifier: GPL-2.0+
  4. */
  5. #include <common.h>
  6. #include <console.h>
  7. #include <environment.h>
  8. #include <ns16550.h>
  9. #include <malloc.h>
  10. #include <mmc.h>
  11. #include <nand.h>
  12. #include <i2c.h>
  13. DECLARE_GLOBAL_DATA_PTR;
  14. phys_size_t get_effective_memsize(void)
  15. {
  16. return CONFIG_SYS_L2_SIZE;
  17. }
  18. void board_init_f(ulong bootflag)
  19. {
  20. u32 plat_ratio;
  21. ccsr_gur_t *gur = (void *)CONFIG_SYS_MPC85xx_GUTS_ADDR;
  22. console_init_f();
  23. /* initialize selected port with appropriate baud rate */
  24. plat_ratio = in_be32(&gur->porpllsr) & MPC85xx_PORPLLSR_PLAT_RATIO;
  25. plat_ratio >>= 1;
  26. gd->bus_clk = CONFIG_SYS_CLK_FREQ * plat_ratio;
  27. NS16550_init((NS16550_t)CONFIG_SYS_NS16550_COM1,
  28. gd->bus_clk / 16 / CONFIG_BAUDRATE);
  29. /* copy code to RAM and jump to it - this should not return */
  30. /* NOTE - code has to be copied out of NAND buffer before
  31. * other blocks can be read.
  32. */
  33. relocate_code(CONFIG_SPL_RELOC_STACK, 0, CONFIG_SPL_RELOC_TEXT_BASE);
  34. }
  35. void board_init_r(gd_t *gd, ulong dest_addr)
  36. {
  37. /* Pointer is writable since we allocated a register for it */
  38. gd = (gd_t *)CONFIG_SPL_GD_ADDR;
  39. bd_t *bd;
  40. memset(gd, 0, sizeof(gd_t));
  41. bd = (bd_t *)(CONFIG_SPL_GD_ADDR + sizeof(gd_t));
  42. memset(bd, 0, sizeof(bd_t));
  43. gd->bd = bd;
  44. bd->bi_memstart = CONFIG_SYS_INIT_L2_ADDR;
  45. bd->bi_memsize = CONFIG_SYS_L2_SIZE;
  46. arch_cpu_init();
  47. get_clocks();
  48. mem_malloc_init(CONFIG_SPL_RELOC_MALLOC_ADDR,
  49. CONFIG_SPL_RELOC_MALLOC_SIZE);
  50. gd->flags |= GD_FLG_FULL_MALLOC_INIT;
  51. /* relocate environment function pointers etc. */
  52. nand_spl_load_image(CONFIG_ENV_OFFSET, CONFIG_ENV_SIZE,
  53. (uchar *)CONFIG_ENV_ADDR);
  54. gd->env_addr = (ulong)(CONFIG_ENV_ADDR);
  55. gd->env_valid = ENV_VALID;
  56. i2c_init_all();
  57. dram_init();
  58. #ifdef CONFIG_SPL_NAND_BOOT
  59. puts("TPL\n");
  60. #else
  61. puts("SPL\n");
  62. #endif
  63. nand_boot();
  64. }