2
0

mcimx6ul-evk.c 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. * Copyright (c) 2018 Jean-Christophe Dubois <jcd@tribudubois.net>
  3. *
  4. * MCIMX6UL_EVK Board System emulation.
  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 mcimx6ul_evk board, with a Freescale
  10. * i.MX6ul SoC
  11. */
  12. #include "qemu/osdep.h"
  13. #include "qapi/error.h"
  14. #include "hw/arm/fsl-imx6ul.h"
  15. #include "hw/boards.h"
  16. #include "hw/qdev-properties.h"
  17. #include "sysemu/sysemu.h"
  18. #include "qemu/error-report.h"
  19. #include "sysemu/qtest.h"
  20. typedef struct {
  21. FslIMX6ULState soc;
  22. MemoryRegion ram;
  23. } MCIMX6ULEVK;
  24. static void mcimx6ul_evk_init(MachineState *machine)
  25. {
  26. static struct arm_boot_info boot_info;
  27. MCIMX6ULEVK *s = g_new0(MCIMX6ULEVK, 1);
  28. int i;
  29. if (machine->ram_size > FSL_IMX6UL_MMDC_SIZE) {
  30. error_report("RAM size " RAM_ADDR_FMT " above max supported (%08x)",
  31. machine->ram_size, FSL_IMX6UL_MMDC_SIZE);
  32. exit(1);
  33. }
  34. boot_info = (struct arm_boot_info) {
  35. .loader_start = FSL_IMX6UL_MMDC_ADDR,
  36. .board_id = -1,
  37. .ram_size = machine->ram_size,
  38. .nb_cpus = machine->smp.cpus,
  39. };
  40. object_initialize_child(OBJECT(machine), "soc", &s->soc, sizeof(s->soc),
  41. TYPE_FSL_IMX6UL, &error_fatal, NULL);
  42. object_property_set_bool(OBJECT(&s->soc), true, "realized", &error_fatal);
  43. memory_region_allocate_system_memory(&s->ram, NULL, "mcimx6ul-evk.ram",
  44. machine->ram_size);
  45. memory_region_add_subregion(get_system_memory(),
  46. FSL_IMX6UL_MMDC_ADDR, &s->ram);
  47. for (i = 0; i < FSL_IMX6UL_NUM_USDHCS; i++) {
  48. BusState *bus;
  49. DeviceState *carddev;
  50. DriveInfo *di;
  51. BlockBackend *blk;
  52. di = drive_get_next(IF_SD);
  53. blk = di ? blk_by_legacy_dinfo(di) : NULL;
  54. bus = qdev_get_child_bus(DEVICE(&s->soc.usdhc[i]), "sd-bus");
  55. carddev = qdev_create(bus, TYPE_SD_CARD);
  56. qdev_prop_set_drive(carddev, "drive", blk, &error_fatal);
  57. object_property_set_bool(OBJECT(carddev), true,
  58. "realized", &error_fatal);
  59. }
  60. if (!qtest_enabled()) {
  61. arm_load_kernel(&s->soc.cpu, machine, &boot_info);
  62. }
  63. }
  64. static void mcimx6ul_evk_machine_init(MachineClass *mc)
  65. {
  66. mc->desc = "Freescale i.MX6UL Evaluation Kit (Cortex A7)";
  67. mc->init = mcimx6ul_evk_init;
  68. mc->max_cpus = FSL_IMX6UL_NUM_CPUS;
  69. }
  70. DEFINE_MACHINE("mcimx6ul-evk", mcimx6ul_evk_machine_init)