qemu-riscv.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (C) 2018, Bin Meng <bmeng.cn@gmail.com>
  4. */
  5. #include <common.h>
  6. #include <dm.h>
  7. #include <env.h>
  8. #include <fdtdec.h>
  9. #include <spl.h>
  10. #include <init.h>
  11. #include <virtio_types.h>
  12. #include <virtio.h>
  13. int board_init(void)
  14. {
  15. /*
  16. * Make sure virtio bus is enumerated so that peripherals
  17. * on the virtio bus can be discovered by their drivers
  18. */
  19. virtio_init();
  20. return 0;
  21. }
  22. int board_late_init(void)
  23. {
  24. ulong kernel_start;
  25. ofnode chosen_node;
  26. int ret;
  27. chosen_node = ofnode_path("/chosen");
  28. if (!ofnode_valid(chosen_node)) {
  29. debug("No chosen node found, can't get kernel start address\n");
  30. return 0;
  31. }
  32. #ifdef CONFIG_ARCH_RV64I
  33. ret = ofnode_read_u64(chosen_node, "riscv,kernel-start",
  34. (u64 *)&kernel_start);
  35. #else
  36. ret = ofnode_read_u32(chosen_node, "riscv,kernel-start",
  37. (u32 *)&kernel_start);
  38. #endif
  39. if (ret) {
  40. debug("Can't find kernel start address in device tree\n");
  41. return 0;
  42. }
  43. env_set_hex("kernel_start", kernel_start);
  44. return 0;
  45. }
  46. /*
  47. * QEMU specifies the location of Linux (supplied with the -kernel argument)
  48. * in the device tree using the riscv,kernel-start and riscv,kernel-end
  49. * properties. We currently rely on the SBI implementation of BBL to run
  50. * Linux and therefore embed Linux as payload in BBL. This causes an issue,
  51. * because BBL detects the kernel properties in the device tree and ignores
  52. * the Linux payload as a result. To work around this issue, we clear the
  53. * kernel properties before booting Linux.
  54. *
  55. * This workaround can be removed, once we do not require BBL for its SBI
  56. * implementation anymore.
  57. */
  58. int ft_board_setup(void *blob, bd_t *bd)
  59. {
  60. int chosen_offset, ret;
  61. chosen_offset = fdt_path_offset(blob, "/chosen");
  62. if (chosen_offset < 0)
  63. return 0;
  64. #ifdef CONFIG_ARCH_RV64I
  65. ret = fdt_setprop_u64(blob, chosen_offset, "riscv,kernel-start", 0);
  66. #else
  67. ret = fdt_setprop_u32(blob, chosen_offset, "riscv,kernel-start", 0);
  68. #endif
  69. if (ret)
  70. return ret;
  71. #ifdef CONFIG_ARCH_RV64I
  72. ret = fdt_setprop_u64(blob, chosen_offset, "riscv,kernel-end", 0);
  73. #else
  74. ret = fdt_setprop_u32(blob, chosen_offset, "riscv,kernel-end", 0);
  75. #endif
  76. if (ret)
  77. return ret;
  78. return 0;
  79. }
  80. #ifdef CONFIG_SPL
  81. u32 spl_boot_device(void)
  82. {
  83. /* RISC-V QEMU only supports RAM as SPL boot device */
  84. return BOOT_DEVICE_RAM;
  85. }
  86. #endif
  87. #ifdef CONFIG_SPL_LOAD_FIT
  88. int board_fit_config_name_match(const char *name)
  89. {
  90. /* boot using first FIT config */
  91. return 0;
  92. }
  93. #endif