spl.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /* Copyright 2014 Freescale Semiconductor, Inc.
  2. *
  3. * SPDX-License-Identifier: GPL-2.0+
  4. */
  5. #include <common.h>
  6. #include <malloc.h>
  7. #include <ns16550.h>
  8. #include <nand.h>
  9. #include <i2c.h>
  10. #include <mmc.h>
  11. #include <fsl_esdhc.h>
  12. #include <spi_flash.h>
  13. #include "../common/sleep.h"
  14. DECLARE_GLOBAL_DATA_PTR;
  15. phys_size_t get_effective_memsize(void)
  16. {
  17. return CONFIG_SYS_L3_SIZE;
  18. }
  19. unsigned long get_board_sys_clk(void)
  20. {
  21. return CONFIG_SYS_CLK_FREQ;
  22. }
  23. unsigned long get_board_ddr_clk(void)
  24. {
  25. return CONFIG_DDR_CLK_FREQ;
  26. }
  27. void board_init_f(ulong bootflag)
  28. {
  29. u32 plat_ratio, sys_clk, ccb_clk;
  30. ccsr_gur_t *gur = (void *)CONFIG_SYS_MPC85xx_GUTS_ADDR;
  31. /* Memcpy existing GD at CONFIG_SPL_GD_ADDR */
  32. memcpy((void *)CONFIG_SPL_GD_ADDR, (void *)gd, sizeof(gd_t));
  33. /* Update GD pointer */
  34. gd = (gd_t *)(CONFIG_SPL_GD_ADDR);
  35. console_init_f();
  36. #ifdef CONFIG_DEEP_SLEEP
  37. /* disable the console if boot from deep sleep */
  38. if (is_warm_boot())
  39. fsl_dp_disable_console();
  40. #endif
  41. /* initialize selected port with appropriate baud rate */
  42. sys_clk = get_board_sys_clk();
  43. plat_ratio = (in_be32(&gur->rcwsr[0]) >> 25) & 0x1f;
  44. ccb_clk = sys_clk * plat_ratio / 2;
  45. NS16550_init((NS16550_t)CONFIG_SYS_NS16550_COM1,
  46. ccb_clk / 16 / CONFIG_BAUDRATE);
  47. #if defined(CONFIG_SPL_MMC_BOOT)
  48. puts("\nSD boot...\n");
  49. #elif defined(CONFIG_SPL_SPI_BOOT)
  50. puts("\nSPI boot...\n");
  51. #elif defined(CONFIG_SPL_NAND_BOOT)
  52. puts("\nNAND boot...\n");
  53. #endif
  54. relocate_code(CONFIG_SPL_RELOC_STACK, (gd_t *)CONFIG_SPL_GD_ADDR, 0x0);
  55. }
  56. void board_init_r(gd_t *gd, ulong dest_addr)
  57. {
  58. bd_t *bd;
  59. bd = (bd_t *)(gd + sizeof(gd_t));
  60. memset(bd, 0, sizeof(bd_t));
  61. gd->bd = bd;
  62. bd->bi_memstart = CONFIG_SYS_INIT_L3_ADDR;
  63. bd->bi_memsize = CONFIG_SYS_L3_SIZE;
  64. probecpu();
  65. get_clocks();
  66. mem_malloc_init(CONFIG_SPL_RELOC_MALLOC_ADDR,
  67. CONFIG_SPL_RELOC_MALLOC_SIZE);
  68. #ifdef CONFIG_SPL_NAND_BOOT
  69. nand_spl_load_image(CONFIG_ENV_OFFSET, CONFIG_ENV_SIZE,
  70. (uchar *)CONFIG_ENV_ADDR);
  71. #endif
  72. #ifdef CONFIG_SPL_MMC_BOOT
  73. mmc_initialize(bd);
  74. mmc_spl_load_image(CONFIG_ENV_OFFSET, CONFIG_ENV_SIZE,
  75. (uchar *)CONFIG_ENV_ADDR);
  76. #endif
  77. #ifdef CONFIG_SPL_SPI_BOOT
  78. spi_spl_load_image(CONFIG_ENV_OFFSET, CONFIG_ENV_SIZE,
  79. (uchar *)CONFIG_ENV_ADDR);
  80. #endif
  81. gd->env_addr = (ulong)(CONFIG_ENV_ADDR);
  82. gd->env_valid = 1;
  83. i2c_init_all();
  84. gd->ram_size = initdram(0);
  85. #ifdef CONFIG_SPL_MMC_BOOT
  86. mmc_boot();
  87. #elif defined(CONFIG_SPL_SPI_BOOT)
  88. spi_boot();
  89. #elif defined(CONFIG_SPL_NAND_BOOT)
  90. nand_boot();
  91. #endif
  92. }