spl.c 2.9 KB

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