scsi2sd.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. // Copyright (C) 2014 Michael McMaster <michael@codesrc.com>
  2. //
  3. // This file is part of SCSI2SD.
  4. //
  5. // SCSI2SD is free software: you can redistribute it and/or modify
  6. // it under the terms of the GNU General Public License as published by
  7. // the Free Software Foundation, either version 3 of the License, or
  8. // (at your option) any later version.
  9. //
  10. // SCSI2SD is distributed in the hope that it will be useful,
  11. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. // GNU General Public License for more details.
  14. //
  15. // You should have received a copy of the GNU General Public License
  16. // along with SCSI2SD. If not, see <http://www.gnu.org/licenses/>.
  17. #ifndef scsi2sd_h
  18. #define scsi2sd_h
  19. #ifdef __cplusplus
  20. extern "C" {
  21. #endif
  22. /* Common type definitions shared between the firmware and config tools
  23. The configuration data is now stored on the SD card, occupying the
  24. last 2 sectors.
  25. BoardConfig
  26. TargetConfig (disk 0)
  27. TargetConfig (disk 1)
  28. TargetConfig (disk 2)
  29. TargetConfig (disk 3)
  30. TargetConfig (disk 4)
  31. TargetConfig (disk 5)
  32. TargetConfig (disk 6)
  33. */
  34. #include "stdint.h"
  35. #define S2S_MAX_TARGETS 7
  36. #define S2S_CFG_SIZE (S2S_MAX_TARGETS * sizeof(S2S_TargetCfg) + sizeof(S2S_BoardCfg))
  37. typedef enum
  38. {
  39. S2S_CFG_TARGET_ID_BITS = 0x07,
  40. S2S_CFG_TARGET_ENABLED = 0x80
  41. } S2S_CFG_TARGET_FLAGS;
  42. typedef enum
  43. {
  44. S2S_CFG_ENABLE_UNIT_ATTENTION = 1,
  45. S2S_CFG_ENABLE_PARITY = 2,
  46. S2S_CFG_ENABLE_SCSI2 = 4,
  47. // OBSOLETE S2S_CFG_DISABLE_GLITCH = 8,
  48. S2S_CFG_ENABLE_CACHE = 16,
  49. S2S_CFG_ENABLE_DISCONNECT = 32,
  50. S2S_CFG_ENABLE_SEL_LATCH = 64,
  51. S2S_CFG_MAP_LUNS_TO_IDS = 128
  52. } S2S_CFG_FLAGS;
  53. typedef enum
  54. {
  55. S2S_CFG_ENABLE_TERMINATOR = 1
  56. } S2S_CFG_FLAGS6;
  57. typedef enum
  58. {
  59. S2S_CFG_FIXED,
  60. S2S_CFG_REMOVEABLE,
  61. S2S_CFG_OPTICAL,
  62. S2S_CFG_FLOPPY_14MB,
  63. S2S_CFG_MO,
  64. S2S_CFG_SEQUENTIAL
  65. } S2S_CFG_TYPE;
  66. typedef enum
  67. {
  68. S2S_CFG_QUIRKS_NONE,
  69. S2S_CFG_QUIRKS_APPLE
  70. } S2S_CFG_QUIRKS;
  71. typedef struct __attribute__((packed))
  72. {
  73. // bits 7 -> 3 = S2S_CFG_TARGET_FLAGS
  74. // bits 2 -> 0 = target SCSI ID.
  75. uint8_t scsiId;
  76. uint8_t deviceType; // S2S_CFG_TYPE
  77. uint8_t flagsDEPRECATED; // S2S_CFG_FLAGS, removed in v4.5
  78. uint8_t deviceTypeModifier; // Used in INQUIRY response.
  79. uint32_t sdSectorStart;
  80. uint32_t scsiSectors;
  81. uint16_t bytesPerSector;
  82. // Max allowed by legacy IBM-PC bios is 6 bits (63)
  83. uint16_t sectorsPerTrack;
  84. // MS-Dos up to 7.10 will crash on >= 256 heads.
  85. uint16_t headsPerCylinder;
  86. char vendor[8];
  87. char prodId[16];
  88. char revision[4];
  89. char serial[16];
  90. uint16_t quirks; // S2S_CFG_QUIRKS
  91. uint8_t reserved[64]; // Pad out to 128 bytes for main section.
  92. } S2S_TargetCfg;
  93. typedef struct __attribute__((packed))
  94. {
  95. char magic[4]; // 'BCFG'
  96. uint8_t flags; // S2S_CFG_FLAGS
  97. uint8_t startupDelay; // Seconds.
  98. uint8_t selectionDelay; // milliseconds. 255 = auto
  99. uint8_t flags6; // S2S_CFG_FLAGS6
  100. uint8_t reserved[120]; // Pad out to 128 bytes
  101. } S2S_BoardCfg;
  102. typedef enum
  103. {
  104. S2S_CMD_NONE, // Invalid
  105. // Command content:
  106. // uint8_t S2S_CFG_PING
  107. // Response:
  108. // S2S_CFG_STATUS
  109. S2S_CMD_PING,
  110. // Command content:
  111. // uint8_t S2S_CFG_WRITEFLASH
  112. // uint8_t[256] flashData
  113. // uint8_t flashArray
  114. // uint8_t flashRow
  115. // Response:
  116. // S2S_CFG_STATUS
  117. S2S_CMD_WRITEFLASH,
  118. // Command content:
  119. // uint8_t S2S_CFG_READFLASH
  120. // uint8_t flashArray
  121. // uint8_t flashRow
  122. // Response:
  123. // 256 bytes of flash
  124. S2S_CMD_READFLASH,
  125. // Command content:
  126. // uint8_t S2S_CFG_REBOOT
  127. // Response: None.
  128. S2S_CMD_REBOOT,
  129. // Command content:
  130. // uint8_t S2S_CFG_INFO
  131. // Response:
  132. // uint8_t[16] CSD
  133. // uint8_t[16] CID
  134. S2S_CMD_SDINFO,
  135. // Command content:
  136. // uint8_t S2S_CFG_SCSITEST
  137. // Response:
  138. // S2S_CFG_STATUS
  139. // uint8_t result code (0 = passed)
  140. S2S_CMD_SCSITEST,
  141. // Command content:
  142. // uint8_t S2S_CFG_DEVINFO
  143. // Response:
  144. // uint16_t protocol version (MSB)
  145. // uint16_t firmware version (MSB)
  146. // uint32_t SD capacity(MSB)
  147. S2S_CMD_DEVINFO,
  148. // Command content:
  149. // uint8_t S2S_CFG_SD_WRITE
  150. // uint32_t Sector Number (MSB)
  151. // uint8_t[512] data
  152. // Response:
  153. // S2S_CFG_STATUS
  154. S2S_CMD_SD_WRITE,
  155. // Command content:
  156. // uint8_t S2S_CFG_SD_READ
  157. // uint32_t Sector Number (MSB)
  158. // Response:
  159. // 512 bytes of data
  160. S2S_CMD_SD_READ,
  161. // Command content:
  162. // uint8_t S2S_CFG_DEBUG
  163. // Response:
  164. S2S_CMD_DEBUG,
  165. } S2S_COMMAND;
  166. typedef enum
  167. {
  168. S2S_CFG_STATUS_GOOD,
  169. S2S_CFG_STATUS_ERR
  170. } S2S_CFG_STATUS;
  171. #ifdef __cplusplus
  172. } // extern "C"
  173. #include <type_traits>
  174. static_assert(
  175. std::is_pod<S2S_TargetCfg>::value, "Misuse of TargetConfig struct"
  176. );
  177. static_assert(
  178. sizeof(S2S_TargetCfg) == 128,
  179. "TargetConfig struct size mismatch"
  180. );
  181. static_assert(
  182. std::is_pod<S2S_BoardCfg>::value, "Misuse of BoardConfig struct"
  183. );
  184. static_assert(
  185. sizeof(S2S_BoardCfg) == 128,
  186. "BoardConfig struct size mismatch"
  187. );
  188. #endif
  189. #endif