spl.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright 2015 Freescale Semiconductor, Inc.
  4. *
  5. * Author: Chunhe Lan <Chunhe.Lan@freescale.com>
  6. */
  7. #include <common.h>
  8. #include <clock_legacy.h>
  9. #include <console.h>
  10. #include <env_internal.h>
  11. #include <init.h>
  12. #include <asm/spl.h>
  13. #include <malloc.h>
  14. #include <ns16550.h>
  15. #include <nand.h>
  16. #include <mmc.h>
  17. #include <fsl_esdhc.h>
  18. #include <i2c.h>
  19. #include "t4rdb.h"
  20. #define FSL_CORENET_CCSR_PORSR1_RCW_MASK 0xFF800000
  21. DECLARE_GLOBAL_DATA_PTR;
  22. phys_size_t get_effective_memsize(void)
  23. {
  24. return CONFIG_SYS_L3_SIZE;
  25. }
  26. unsigned long get_board_sys_clk(void)
  27. {
  28. return CONFIG_SYS_CLK_FREQ;
  29. }
  30. unsigned long get_board_ddr_clk(void)
  31. {
  32. return CONFIG_DDR_CLK_FREQ;
  33. }
  34. void board_init_f(ulong bootflag)
  35. {
  36. u32 plat_ratio, sys_clk, ccb_clk;
  37. ccsr_gur_t *gur = (void *)CONFIG_SYS_MPC85xx_GUTS_ADDR;
  38. /* Memcpy existing GD at CONFIG_SPL_GD_ADDR */
  39. memcpy((void *)CONFIG_SPL_GD_ADDR, (void *)gd, sizeof(gd_t));
  40. /* Update GD pointer */
  41. gd = (gd_t *)(CONFIG_SPL_GD_ADDR);
  42. /* compiler optimization barrier needed for GCC >= 3.4 */
  43. __asm__ __volatile__("" : : : "memory");
  44. console_init_f();
  45. /* initialize selected port with appropriate baud rate */
  46. sys_clk = get_board_sys_clk();
  47. plat_ratio = (in_be32(&gur->rcwsr[0]) >> 25) & 0x1f;
  48. ccb_clk = sys_clk * plat_ratio / 2;
  49. NS16550_init((NS16550_t)CONFIG_SYS_NS16550_COM1,
  50. ccb_clk / 16 / CONFIG_BAUDRATE);
  51. puts("\nSD boot...\n");
  52. relocate_code(CONFIG_SPL_RELOC_STACK, (gd_t *)CONFIG_SPL_GD_ADDR, 0x0);
  53. }
  54. void board_init_r(gd_t *gd, ulong dest_addr)
  55. {
  56. struct bd_info *bd;
  57. bd = (struct bd_info *)(gd + sizeof(gd_t));
  58. memset(bd, 0, sizeof(struct bd_info));
  59. gd->bd = bd;
  60. arch_cpu_init();
  61. get_clocks();
  62. mem_malloc_init(CONFIG_SPL_RELOC_MALLOC_ADDR,
  63. CONFIG_SPL_RELOC_MALLOC_SIZE);
  64. gd->flags |= GD_FLG_FULL_MALLOC_INIT;
  65. mmc_initialize(bd);
  66. mmc_spl_load_image(CONFIG_ENV_OFFSET, CONFIG_ENV_SIZE,
  67. (uchar *)SPL_ENV_ADDR);
  68. gd->env_addr = (ulong)(SPL_ENV_ADDR);
  69. gd->env_valid = ENV_VALID;
  70. i2c_init_all();
  71. dram_init();
  72. mmc_boot();
  73. }