spl.c 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (C) 2022-2023 StarFive Technology Co., Ltd.
  4. * Author: yanhong <yanhong.wang@starfivetech.com>
  5. *
  6. */
  7. #include <common.h>
  8. #include <init.h>
  9. #include <spl.h>
  10. #include <log.h>
  11. #include <linux/delay.h>
  12. #include <image.h>
  13. #include <asm/arch/spl.h>
  14. #include <asm/io.h>
  15. #define MODE_SELECT_REG 0x1702002c
  16. int spl_board_init_f(void)
  17. {
  18. int ret;
  19. ret = spl_soc_init();
  20. if (ret) {
  21. debug("JH7110 SPL init failed: %d\n", ret);
  22. return ret;
  23. }
  24. return 0;
  25. }
  26. u32 spl_boot_device(void)
  27. {
  28. int boot_mode = 0;
  29. boot_mode = readl((const volatile void *)MODE_SELECT_REG) & 0xF;
  30. switch (boot_mode) {
  31. case 0:
  32. return BOOT_DEVICE_SPI;
  33. case 1:
  34. return BOOT_DEVICE_MMC2;
  35. case 2:
  36. return BOOT_DEVICE_MMC1;
  37. case 4:
  38. return BOOT_DEVICE_UART;
  39. default:
  40. debug("Unsupported boot device 0x%x.\n",
  41. boot_mode);
  42. return BOOT_DEVICE_NONE;
  43. }
  44. }
  45. struct image_header *spl_get_load_buffer(ssize_t offset, size_t size)
  46. {
  47. return (struct image_header *)(STARFIVE_SPL_BOOT_LOAD_ADDR);
  48. }
  49. void board_init_f(ulong dummy)
  50. {
  51. int ret;
  52. ret = spl_early_init();
  53. if (ret)
  54. panic("spl_early_init() failed: %d\n", ret);
  55. arch_cpu_init_dm();
  56. preloader_console_init();
  57. ret = spl_board_init_f();
  58. if (ret) {
  59. debug("spl_board_init_f init failed: %d\n", ret);
  60. return;
  61. }
  62. }
  63. #ifdef CONFIG_SPL_LOAD_FIT
  64. int board_fit_config_name_match(const char *name)
  65. {
  66. /* boot using first FIT config */
  67. return 0;
  68. }
  69. #endif