spl.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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 <ns16550.h>
  8. #include <malloc.h>
  9. #include <mmc.h>
  10. #include <nand.h>
  11. #include <i2c.h>
  12. #include <fsl_esdhc.h>
  13. #include <spi_flash.h>
  14. #include "../common/spl.h"
  15. DECLARE_GLOBAL_DATA_PTR;
  16. phys_size_t get_effective_memsize(void)
  17. {
  18. return CONFIG_SYS_L2_SIZE;
  19. }
  20. void board_init_f(ulong bootflag)
  21. {
  22. u32 plat_ratio;
  23. ccsr_gur_t *gur = (void *)CONFIG_SYS_MPC85xx_GUTS_ADDR;
  24. struct fsl_ifc ifc = {(void *)CONFIG_SYS_IFC_ADDR, (void *)NULL};
  25. console_init_f();
  26. /* Clock configuration to access CPLD using IFC(GPCM) */
  27. setbits_be32(&ifc.gregs->ifc_gcr, 1 << IFC_GCR_TBCTL_TRN_TIME_SHIFT);
  28. #ifdef CONFIG_TARGET_P1010RDB_PB
  29. setbits_be32(&gur->pmuxcr2, MPC85xx_PMUXCR2_GPIO01_DRVVBUS);
  30. #endif
  31. /* initialize selected port with appropriate baud rate */
  32. plat_ratio = in_be32(&gur->porpllsr) & MPC85xx_PORPLLSR_PLAT_RATIO;
  33. plat_ratio >>= 1;
  34. gd->bus_clk = CONFIG_SYS_CLK_FREQ * plat_ratio;
  35. NS16550_init((NS16550_t)CONFIG_SYS_NS16550_COM1,
  36. gd->bus_clk / 16 / CONFIG_BAUDRATE);
  37. #ifdef CONFIG_SPL_MMC_BOOT
  38. puts("\nSD boot...\n");
  39. #elif defined(CONFIG_SPL_SPI_BOOT)
  40. puts("\nSPI Flash boot...\n");
  41. #endif
  42. /* copy code to RAM and jump to it - this should not return */
  43. /* NOTE - code has to be copied out of NAND buffer before
  44. * other blocks can be read.
  45. */
  46. relocate_code(CONFIG_SPL_RELOC_STACK, 0, CONFIG_SPL_RELOC_TEXT_BASE);
  47. }
  48. void board_init_r(gd_t *gd, ulong dest_addr)
  49. {
  50. /* Pointer is writable since we allocated a register for it */
  51. gd = (gd_t *)CONFIG_SPL_GD_ADDR;
  52. bd_t *bd;
  53. memset(gd, 0, sizeof(gd_t));
  54. bd = (bd_t *)(CONFIG_SPL_GD_ADDR + sizeof(gd_t));
  55. memset(bd, 0, sizeof(bd_t));
  56. gd->bd = bd;
  57. bd->bi_memstart = CONFIG_SYS_INIT_L2_ADDR;
  58. bd->bi_memsize = CONFIG_SYS_L2_SIZE;
  59. probecpu();
  60. get_clocks();
  61. mem_malloc_init(CONFIG_SPL_RELOC_MALLOC_ADDR,
  62. CONFIG_SPL_RELOC_MALLOC_SIZE);
  63. gd->flags |= GD_FLG_FULL_MALLOC_INIT;
  64. #ifndef CONFIG_SPL_NAND_BOOT
  65. env_init();
  66. #endif
  67. #ifdef CONFIG_SPL_MMC_BOOT
  68. mmc_initialize(bd);
  69. #endif
  70. /* relocate environment function pointers etc. */
  71. #ifdef CONFIG_SPL_NAND_BOOT
  72. nand_spl_load_image(CONFIG_ENV_OFFSET, CONFIG_ENV_SIZE,
  73. (uchar *)CONFIG_ENV_ADDR);
  74. gd->env_addr = (ulong)(CONFIG_ENV_ADDR);
  75. gd->env_valid = 1;
  76. #else
  77. env_relocate();
  78. #endif
  79. i2c_init_all();
  80. gd->ram_size = initdram(0);
  81. #ifdef CONFIG_SPL_NAND_BOOT
  82. puts("\nTertiary program loader running in sram...");
  83. #else
  84. puts("\nSecond program loader running in sram...");
  85. #endif
  86. #ifdef CONFIG_SPL_MMC_BOOT
  87. mmc_boot();
  88. #elif defined(CONFIG_SPL_SPI_BOOT)
  89. fsl_spi_boot();
  90. #elif defined(CONFIG_SPL_NAND_BOOT)
  91. nand_boot();
  92. #endif
  93. }