spl.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright 2013 Freescale Semiconductor, Inc.
  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. #include <fsl_esdhc.h>
  14. #include <spi_flash.h>
  15. #include "../common/spl.h"
  16. DECLARE_GLOBAL_DATA_PTR;
  17. phys_size_t get_effective_memsize(void)
  18. {
  19. return CONFIG_SYS_L2_SIZE;
  20. }
  21. void board_init_f(ulong bootflag)
  22. {
  23. u32 plat_ratio, bus_clk;
  24. ccsr_gur_t *gur = (void *)CONFIG_SYS_MPC85xx_GUTS_ADDR;
  25. console_init_f();
  26. /* Set pmuxcr to allow both i2c1 and i2c2 */
  27. setbits_be32(&gur->pmuxcr, in_be32(&gur->pmuxcr) | 0x1000);
  28. setbits_be32(&gur->pmuxcr,
  29. in_be32(&gur->pmuxcr) | MPC85xx_PMUXCR_SD_DATA);
  30. /* Read back the register to synchronize the write. */
  31. in_be32(&gur->pmuxcr);
  32. #ifdef CONFIG_SPL_SPI_BOOT
  33. clrbits_be32(&gur->pmuxcr, MPC85xx_PMUXCR_SD_DATA);
  34. #endif
  35. /* initialize selected port with appropriate baud rate */
  36. plat_ratio = in_be32(&gur->porpllsr) & MPC85xx_PORPLLSR_PLAT_RATIO;
  37. plat_ratio >>= 1;
  38. bus_clk = CONFIG_SYS_CLK_FREQ * plat_ratio;
  39. gd->bus_clk = bus_clk;
  40. NS16550_init((NS16550_t)CONFIG_SYS_NS16550_COM1,
  41. bus_clk / 16 / CONFIG_BAUDRATE);
  42. #ifdef CONFIG_SPL_MMC_BOOT
  43. puts("\nSD boot...\n");
  44. #elif defined(CONFIG_SPL_SPI_BOOT)
  45. puts("\nSPI Flash boot...\n");
  46. #endif
  47. /* copy code to RAM and jump to it - this should not return */
  48. /* NOTE - code has to be copied out of NAND buffer before
  49. * other blocks can be read.
  50. */
  51. relocate_code(CONFIG_SPL_RELOC_STACK, 0, CONFIG_SPL_RELOC_TEXT_BASE);
  52. }
  53. void board_init_r(gd_t *gd, ulong dest_addr)
  54. {
  55. /* Pointer is writable since we allocated a register for it */
  56. gd = (gd_t *)CONFIG_SPL_GD_ADDR;
  57. bd_t *bd;
  58. memset(gd, 0, sizeof(gd_t));
  59. bd = (bd_t *)(CONFIG_SPL_GD_ADDR + sizeof(gd_t));
  60. memset(bd, 0, sizeof(bd_t));
  61. gd->bd = bd;
  62. bd->bi_memstart = CONFIG_SYS_INIT_L2_ADDR;
  63. bd->bi_memsize = CONFIG_SYS_L2_SIZE;
  64. arch_cpu_init();
  65. get_clocks();
  66. mem_malloc_init(CONFIG_SPL_RELOC_MALLOC_ADDR,
  67. CONFIG_SPL_RELOC_MALLOC_SIZE);
  68. gd->flags |= GD_FLG_FULL_MALLOC_INIT;
  69. #ifndef CONFIG_SPL_NAND_BOOT
  70. env_init();
  71. #endif
  72. #ifdef CONFIG_SPL_MMC_BOOT
  73. mmc_initialize(bd);
  74. #endif
  75. /* relocate environment function pointers etc. */
  76. #ifdef CONFIG_SPL_NAND_BOOT
  77. nand_spl_load_image(CONFIG_ENV_OFFSET, CONFIG_ENV_SIZE,
  78. (uchar *)CONFIG_ENV_ADDR);
  79. gd->env_addr = (ulong)(CONFIG_ENV_ADDR);
  80. gd->env_valid = ENV_VALID;
  81. #else
  82. env_relocate();
  83. #endif
  84. #ifdef CONFIG_SYS_I2C
  85. i2c_init_all();
  86. #else
  87. i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
  88. #endif
  89. dram_init();
  90. #ifdef CONFIG_SPL_NAND_BOOT
  91. puts("Tertiary program loader running in sram...");
  92. #else
  93. puts("Second program loader running in sram...\n");
  94. #endif
  95. #ifdef CONFIG_SPL_MMC_BOOT
  96. mmc_boot();
  97. #elif defined(CONFIG_SPL_SPI_BOOT)
  98. fsl_spi_boot();
  99. #elif defined(CONFIG_SPL_NAND_BOOT)
  100. nand_boot();
  101. #endif
  102. }