spl.c 2.9 KB

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