sabrelite.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /*
  2. * SABRELITE Board System emulation.
  3. *
  4. * Copyright (c) 2015 Jean-Christophe Dubois <jcd@tribudubois.net>
  5. *
  6. * This code is licensed under the GPL, version 2 or later.
  7. * See the file `COPYING' in the top level directory.
  8. *
  9. * It (partially) emulates a sabrelite board, with a Freescale
  10. * i.MX6 SoC
  11. */
  12. #include "qemu/osdep.h"
  13. #include "qapi/error.h"
  14. #include "hw/arm/fsl-imx6.h"
  15. #include "hw/arm/boot.h"
  16. #include "hw/boards.h"
  17. #include "hw/qdev-properties.h"
  18. #include "qemu/error-report.h"
  19. #include "system/qtest.h"
  20. static struct arm_boot_info sabrelite_binfo = {
  21. /* DDR memory start */
  22. .loader_start = FSL_IMX6_MMDC_ADDR,
  23. /* No board ID, we boot from DT tree */
  24. .board_id = -1,
  25. };
  26. /* No need to do any particular setup for secondary boot */
  27. static void sabrelite_write_secondary(ARMCPU *cpu,
  28. const struct arm_boot_info *info)
  29. {
  30. }
  31. /* Secondary cores are reset through SRC device */
  32. static void sabrelite_reset_secondary(ARMCPU *cpu,
  33. const struct arm_boot_info *info)
  34. {
  35. }
  36. static void sabrelite_init(MachineState *machine)
  37. {
  38. FslIMX6State *s;
  39. /* Check the amount of memory is compatible with the SOC */
  40. if (machine->ram_size > FSL_IMX6_MMDC_SIZE) {
  41. error_report("RAM size " RAM_ADDR_FMT " above max supported (%08x)",
  42. machine->ram_size, FSL_IMX6_MMDC_SIZE);
  43. exit(1);
  44. }
  45. s = FSL_IMX6(object_new(TYPE_FSL_IMX6));
  46. object_property_add_child(OBJECT(machine), "soc", OBJECT(s));
  47. /* Ethernet PHY address is 6 */
  48. object_property_set_int(OBJECT(s), "fec-phy-num", 6, &error_fatal);
  49. qdev_realize(DEVICE(s), NULL, &error_fatal);
  50. memory_region_add_subregion(get_system_memory(), FSL_IMX6_MMDC_ADDR,
  51. machine->ram);
  52. {
  53. /*
  54. * TODO: Ideally we would expose the chip select and spi bus on the
  55. * SoC object using alias properties; then we would not need to
  56. * directly access the underlying spi device object.
  57. */
  58. /* Add the sst25vf016b NOR FLASH memory to first SPI */
  59. Object *spi_dev;
  60. spi_dev = object_resolve_path_component(OBJECT(s), "spi1");
  61. if (spi_dev) {
  62. SSIBus *spi_bus;
  63. spi_bus = (SSIBus *)qdev_get_child_bus(DEVICE(spi_dev), "spi");
  64. if (spi_bus) {
  65. DeviceState *flash_dev;
  66. qemu_irq cs_line;
  67. DriveInfo *dinfo = drive_get(IF_MTD, 0, 0);
  68. flash_dev = qdev_new("sst25vf016b");
  69. if (dinfo) {
  70. qdev_prop_set_drive_err(flash_dev, "drive",
  71. blk_by_legacy_dinfo(dinfo),
  72. &error_fatal);
  73. }
  74. qdev_realize_and_unref(flash_dev, BUS(spi_bus), &error_fatal);
  75. cs_line = qdev_get_gpio_in_named(flash_dev, SSI_GPIO_CS, 0);
  76. qdev_connect_gpio_out(DEVICE(&s->gpio[2]), 19, cs_line);
  77. }
  78. }
  79. }
  80. sabrelite_binfo.ram_size = machine->ram_size;
  81. sabrelite_binfo.secure_boot = true;
  82. sabrelite_binfo.write_secondary_boot = sabrelite_write_secondary;
  83. sabrelite_binfo.secondary_cpu_reset_hook = sabrelite_reset_secondary;
  84. if (!qtest_enabled()) {
  85. arm_load_kernel(&s->cpu[0], machine, &sabrelite_binfo);
  86. }
  87. }
  88. static void sabrelite_machine_init(MachineClass *mc)
  89. {
  90. mc->desc = "Freescale i.MX6 Quad SABRE Lite Board (Cortex-A9)";
  91. mc->init = sabrelite_init;
  92. mc->max_cpus = FSL_IMX6_NUM_CPUS;
  93. mc->ignore_memory_transaction_failures = true;
  94. mc->default_ram_id = "sabrelite.ram";
  95. }
  96. DEFINE_MACHINE("sabrelite", sabrelite_machine_init)