spl.c 2.0 KB

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