1 // Copyright (C) 2014 Michael McMaster <michael@codesrc.com>
3 // This file is part of SCSI2SD.
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.
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.
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/>.
24 /* Common type definitions shared between the firmware and config tools
26 The configuration data is stored in flash.
28 The flash is organised as 2 arrays of 256 rows, with each row
29 having 256 bytes. Total of 128kb.
31 Linear flash memory map:
32 -----------------------------------------
33 Array 1 |Row 255 | Bootloader metadata
34 ---------------------------------
37 ---------------------------------
40 |Row 236 | Config target 3
42 |Row 220 | Config target 2
44 |Row 204 | Config target 1
46 |Row 188 | Config target 0
47 ---------------------------------
52 Array 0 |Row 255 | Blank
53 ---------------------------------
57 ---------------------------------
66 #define MAX_SCSI_TARGETS 4
67 #define SCSI_CONFIG_ARRAY 1
68 #define SCSI_CONFIG_ROWS 16
70 // 256 bytes data, 32 bytes ECC
71 #define SCSI_CONFIG_ROW_SIZE 256
72 #define SCSI_CONFIG_ROW_ECC 288
73 #define SCSI_CONFIG_0_ROW 188
74 #define SCSI_CONFIG_1_ROW 204
75 #define SCSI_CONFIG_2_ROW 220
76 #define SCSI_CONFIG_3_ROW 236
80 CONFIG_TARGET_ID_BITS
= 0x07,
81 CONFIG_TARGET_ENABLED
= 0x80
82 } CONFIG_TARGET_FLAGS
;
86 CONFIG_ENABLE_UNIT_ATTENTION
= 1,
87 CONFIG_ENABLE_PARITY
= 2,
88 CONFIG_ENABLE_SCSI2
= 4
105 typedef struct __attribute__((packed
))
111 uint8_t data
[0]; // pageLength bytes.
114 typedef struct __attribute__((packed
))
116 // bits 7 -> 3 = CONFIG_TARGET_FLAGS
117 // bits 2 -> 0 = target SCSI ID.
120 uint8_t deviceType
; // CONFIG_TYPE
121 uint8_t flags
; // CONFIG_FLAGS
122 uint8_t deviceTypeModifier
; // Used in INQUIRY response.
124 uint32_t sdSectorStart
;
125 uint32_t scsiSectors
;
127 uint16_t bytesPerSector
;
129 // Max allowed by legacy IBM-PC bios is 6 bits (63)
130 uint16_t sectorsPerTrack
;
132 // MS-Dos up to 7.10 will crash on >= 256 heads.
133 uint16_t headsPerCylinder
;
141 uint16_t quirks
; // CONFIG_QUIRKS
143 uint8_t reserved
[960]; // Pad out to 1024 bytes for main section.
145 uint8_t vpd
[3072]; // Total size is 4k.
150 CONFIG_NONE
, // Invalid
153 // uint8_t CONFIG_PING
159 // uint8_t CONFIG_WRITEFLASH
160 // uint8_t[256] flashData
161 // uint8_t flashArray
168 // uint8_t CONFIG_READFLASH
169 // uint8_t flashArray
172 // 256 bytes of flash
176 // uint8_t CONFIG_REBOOT
181 // uint8_t CONFIG_INFO
188 // uint8_t CONFIG_SCSITEST
191 // uint8_t result code (0 = passed)
207 #include <type_traits>
209 std::is_pod
<TargetConfig
>::value
, "Misuse of TargetConfig struct"
212 sizeof(TargetConfig
) == 4096,
213 "TargetConfig struct size mismatch"