2
0

digic_boards.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /*
  2. * QEMU model of the Canon DIGIC boards (cameras indeed :).
  3. *
  4. * Copyright (C) 2013 Antony Pavlov <antonynpavlov@gmail.com>
  5. *
  6. * This model is based on reverse engineering efforts
  7. * made by CHDK (http://chdk.wikia.com) and
  8. * Magic Lantern (http://www.magiclantern.fm) projects
  9. * contributors.
  10. *
  11. * See docs here:
  12. * http://magiclantern.wikia.com/wiki/Register_Map
  13. *
  14. * This program is free software; you can redistribute it and/or modify
  15. * it under the terms of the GNU General Public License as published by
  16. * the Free Software Foundation; either version 2 of the License, or
  17. * (at your option) any later version.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU General Public License for more details.
  23. *
  24. */
  25. #include "qemu/osdep.h"
  26. #include "qapi/error.h"
  27. #include "qemu-common.h"
  28. #include "cpu.h"
  29. #include "hw/boards.h"
  30. #include "exec/address-spaces.h"
  31. #include "qemu/error-report.h"
  32. #include "hw/arm/digic.h"
  33. #include "hw/block/flash.h"
  34. #include "hw/loader.h"
  35. #include "sysemu/sysemu.h"
  36. #include "sysemu/qtest.h"
  37. #define DIGIC4_ROM0_BASE 0xf0000000
  38. #define DIGIC4_ROM1_BASE 0xf8000000
  39. #define DIGIC4_ROM_MAX_SIZE 0x08000000
  40. typedef struct DigicBoardState {
  41. DigicState *digic;
  42. MemoryRegion ram;
  43. } DigicBoardState;
  44. typedef struct DigicBoard {
  45. hwaddr ram_size;
  46. void (*add_rom0)(DigicBoardState *, hwaddr, const char *);
  47. const char *rom0_def_filename;
  48. void (*add_rom1)(DigicBoardState *, hwaddr, const char *);
  49. const char *rom1_def_filename;
  50. } DigicBoard;
  51. static void digic4_board_init(DigicBoard *board)
  52. {
  53. Error *err = NULL;
  54. DigicBoardState *s = g_new(DigicBoardState, 1);
  55. s->digic = DIGIC(object_new(TYPE_DIGIC));
  56. object_property_set_bool(OBJECT(s->digic), true, "realized", &err);
  57. if (err != NULL) {
  58. error_reportf_err(err, "Couldn't realize DIGIC SoC: ");
  59. exit(1);
  60. }
  61. memory_region_allocate_system_memory(&s->ram, NULL, "ram", board->ram_size);
  62. memory_region_add_subregion(get_system_memory(), 0, &s->ram);
  63. if (board->add_rom0) {
  64. board->add_rom0(s, DIGIC4_ROM0_BASE, board->rom0_def_filename);
  65. }
  66. if (board->add_rom1) {
  67. board->add_rom1(s, DIGIC4_ROM1_BASE, board->rom1_def_filename);
  68. }
  69. }
  70. static void digic_load_rom(DigicBoardState *s, hwaddr addr,
  71. hwaddr max_size, const char *def_filename)
  72. {
  73. target_long rom_size;
  74. const char *filename;
  75. if (qtest_enabled()) {
  76. /* qtest runs no code so don't attempt a ROM load which
  77. * could fail and result in a spurious test failure.
  78. */
  79. return;
  80. }
  81. if (bios_name) {
  82. filename = bios_name;
  83. } else {
  84. filename = def_filename;
  85. }
  86. if (filename) {
  87. char *fn = qemu_find_file(QEMU_FILE_TYPE_BIOS, filename);
  88. if (!fn) {
  89. error_report("Couldn't find rom image '%s'.", filename);
  90. exit(1);
  91. }
  92. rom_size = load_image_targphys(fn, addr, max_size);
  93. if (rom_size < 0 || rom_size > max_size) {
  94. error_report("Couldn't load rom image '%s'.", filename);
  95. exit(1);
  96. }
  97. g_free(fn);
  98. }
  99. }
  100. /*
  101. * Samsung K8P3215UQB
  102. * 64M Bit (4Mx16) Page Mode / Multi-Bank NOR Flash Memory
  103. */
  104. static void digic4_add_k8p3215uqb_rom(DigicBoardState *s, hwaddr addr,
  105. const char *def_filename)
  106. {
  107. #define FLASH_K8P3215UQB_SIZE (4 * 1024 * 1024)
  108. #define FLASH_K8P3215UQB_SECTOR_SIZE (64 * 1024)
  109. pflash_cfi02_register(addr, "pflash", FLASH_K8P3215UQB_SIZE,
  110. NULL, FLASH_K8P3215UQB_SECTOR_SIZE,
  111. DIGIC4_ROM_MAX_SIZE / FLASH_K8P3215UQB_SIZE,
  112. 4,
  113. 0x00EC, 0x007E, 0x0003, 0x0001,
  114. 0x0555, 0x2aa, 0);
  115. digic_load_rom(s, addr, FLASH_K8P3215UQB_SIZE, def_filename);
  116. }
  117. static DigicBoard digic4_board_canon_a1100 = {
  118. .ram_size = 64 * 1024 * 1024,
  119. .add_rom1 = digic4_add_k8p3215uqb_rom,
  120. .rom1_def_filename = "canon-a1100-rom1.bin",
  121. };
  122. static void canon_a1100_init(MachineState *machine)
  123. {
  124. digic4_board_init(&digic4_board_canon_a1100);
  125. }
  126. static void canon_a1100_machine_init(MachineClass *mc)
  127. {
  128. mc->desc = "Canon PowerShot A1100 IS";
  129. mc->init = &canon_a1100_init;
  130. mc->ignore_memory_transaction_failures = true;
  131. }
  132. DEFINE_MACHINE("canon-a1100", canon_a1100_machine_init)