qemu-riscv.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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 <fdtdec.h>
  8. #include <virtio_types.h>
  9. #include <virtio.h>
  10. int board_init(void)
  11. {
  12. /*
  13. * Make sure virtio bus is enumerated so that peripherals
  14. * on the virtio bus can be discovered by their drivers
  15. */
  16. virtio_init();
  17. return 0;
  18. }
  19. int board_late_init(void)
  20. {
  21. ulong kernel_start;
  22. ofnode chosen_node;
  23. int ret;
  24. chosen_node = ofnode_path("/chosen");
  25. if (!ofnode_valid(chosen_node)) {
  26. debug("No chosen node found, can't get kernel start address\n");
  27. return 0;
  28. }
  29. #ifdef CONFIG_ARCH_RV64I
  30. ret = ofnode_read_u64(chosen_node, "riscv,kernel-start",
  31. (u64 *)&kernel_start);
  32. #else
  33. ret = ofnode_read_u32(chosen_node, "riscv,kernel-start",
  34. (u32 *)&kernel_start);
  35. #endif
  36. if (ret) {
  37. debug("Can't find kernel start address in device tree\n");
  38. return 0;
  39. }
  40. env_set_hex("kernel_start", kernel_start);
  41. return 0;
  42. }
  43. /*
  44. * QEMU specifies the location of Linux (supplied with the -kernel argument)
  45. * in the device tree using the riscv,kernel-start and riscv,kernel-end
  46. * properties. We currently rely on the SBI implementation of BBL to run
  47. * Linux and therefore embed Linux as payload in BBL. This causes an issue,
  48. * because BBL detects the kernel properties in the device tree and ignores
  49. * the Linux payload as a result. To work around this issue, we clear the
  50. * kernel properties before booting Linux.
  51. *
  52. * This workaround can be removed, once we do not require BBL for its SBI
  53. * implementation anymore.
  54. */
  55. int ft_board_setup(void *blob, bd_t *bd)
  56. {
  57. int chosen_offset, ret;
  58. chosen_offset = fdt_path_offset(blob, "/chosen");
  59. if (chosen_offset < 0)
  60. return 0;
  61. #ifdef CONFIG_ARCH_RV64I
  62. ret = fdt_setprop_u64(blob, chosen_offset, "riscv,kernel-start", 0);
  63. #else
  64. ret = fdt_setprop_u32(blob, chosen_offset, "riscv,kernel-start", 0);
  65. #endif
  66. if (ret)
  67. return ret;
  68. #ifdef CONFIG_ARCH_RV64I
  69. ret = fdt_setprop_u64(blob, chosen_offset, "riscv,kernel-end", 0);
  70. #else
  71. ret = fdt_setprop_u32(blob, chosen_offset, "riscv,kernel-end", 0);
  72. #endif
  73. if (ret)
  74. return ret;
  75. return 0;
  76. }