scsi2sd.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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 stored in flash.
  24. The flash is organised as 2 arrays of 256 rows, with each row
  25. having 256 bytes. Total of 128kb.
  26. Linear flash memory map:
  27. -----------------------------------------
  28. Array 1 |Row 255 | Bootloader metadata
  29. ---------------------------------
  30. |Row 254 |
  31. |Row 252 | Blank
  32. ---------------------------------
  33. |Row 251 |
  34. | ... |
  35. |Row 236 | Config target 3
  36. | ... |
  37. |Row 220 | Config target 2
  38. | ... |
  39. |Row 204 | Config target 1
  40. | ... |
  41. |Row 188 | Config target 0
  42. ---------------------------------
  43. |Row 235 |
  44. | ... |
  45. |Row 0 |
  46. --------| |
  47. Array 0 |Row 255 | Blank
  48. ---------------------------------
  49. |Row 121 |
  50. | ... |
  51. |Row 37 | Application
  52. ---------------------------------
  53. |Row 36 |
  54. | ... |
  55. |Row 0 | Bootloader
  56. */
  57. #include "stdint.h"
  58. #define MAX_SCSI_TARGETS 4
  59. #define SCSI_CONFIG_ARRAY 1
  60. #define SCSI_CONFIG_ROWS 16
  61. // 256 bytes data, 32 bytes ECC
  62. #define SCSI_CONFIG_ROW_SIZE 256
  63. #define SCSI_CONFIG_ROW_ECC 288
  64. #define SCSI_CONFIG_0_ROW 188
  65. #define SCSI_CONFIG_1_ROW 204
  66. #define SCSI_CONFIG_2_ROW 220
  67. #define SCSI_CONFIG_3_ROW 236
  68. typedef enum
  69. {
  70. CONFIG_TARGET_ID_BITS = 0x07,
  71. CONFIG_TARGET_ENABLED = 0x80
  72. } CONFIG_TARGET_FLAGS;
  73. typedef enum
  74. {
  75. CONFIG_ENABLE_UNIT_ATTENTION = 1,
  76. CONFIG_ENABLE_PARITY = 2,
  77. } CONFIG_FLAGS;
  78. typedef enum
  79. {
  80. CONFIG_FIXED,
  81. CONFIG_REMOVEABLE,
  82. CONFIG_OPTICAL,
  83. CONFIG_FLOPPY_14MB
  84. } CONFIG_TYPE;
  85. typedef struct __attribute__((packed))
  86. {
  87. uint8_t deviceType;
  88. uint8_t pageCode;
  89. uint8_t reserved;
  90. uint8_t pageLength;
  91. uint8_t data[0]; // pageLength bytes.
  92. } VPD;
  93. typedef struct __attribute__((packed))
  94. {
  95. // bits 7 -> 3 = CONFIG_TARGET_FLAGS
  96. // bits 2 -> 0 = target SCSI ID.
  97. uint8_t scsiId;
  98. uint8_t deviceType; // CONFIG_TYPE
  99. uint8_t flags; // CONFIG_FLAGS
  100. uint8_t pad0;
  101. uint32_t sdSectorStart;
  102. uint32_t scsiSectors;
  103. uint16_t bytesPerSector;
  104. // Max allowed by legacy IBM-PC bios is 6 bits (63)
  105. uint16_t sectorsPerTrack;
  106. // MS-Dos up to 7.10 will crash on >= 256 heads.
  107. uint16_t headsPerCylinder;
  108. char vendor[8];
  109. char prodId[16];
  110. char revision[4];
  111. char serial[16];
  112. uint8_t reserved[962]; // Pad out to 1024 bytes for main section.
  113. uint8_t vpd[3072]; // Total size is 4k.
  114. } TargetConfig;
  115. typedef enum
  116. {
  117. CONFIG_NONE, // Invalid
  118. // Command content:
  119. // uint8_t CONFIG_PING
  120. // Response:
  121. // CONFIG_STATUS
  122. CONFIG_PING,
  123. // Command content:
  124. // uint8_t CONFIG_WRITEFLASH
  125. // uint8_t[256] flashData
  126. // uint8_t flashArray
  127. // uint8_t flashRow
  128. // Response:
  129. // CONFIG_STATUS
  130. CONFIG_WRITEFLASH,
  131. // Command content:
  132. // uint8_t CONFIG_READFLASH
  133. // uint8_t flashArray
  134. // uint8_t flashRow
  135. // Response:
  136. // 256 bytes of flash
  137. CONFIG_READFLASH,
  138. // Command content:
  139. // uint8_t CONFIG_REBOOT
  140. // Response: None.
  141. CONFIG_REBOOT
  142. } CONFIG_COMMAND;
  143. typedef enum
  144. {
  145. CONFIG_STATUS_GOOD,
  146. CONFIG_STATUS_ERR
  147. } CONFIG_STATUS;
  148. #ifdef __cplusplus
  149. } // extern "C"
  150. #include <type_traits>
  151. static_assert(
  152. std::is_pod<TargetConfig>::value, "Misuse of TargetConfig struct"
  153. );
  154. static_assert(
  155. sizeof(TargetConfig) == 4096,
  156. "TargetConfig struct size mismatch"
  157. );
  158. #endif
  159. #endif