diff options
Diffstat (limited to 'utils/imxtools/scsitools/stmp_scsi.h')
-rw-r--r-- | utils/imxtools/scsitools/stmp_scsi.h | 169 |
1 files changed, 167 insertions, 2 deletions
diff --git a/utils/imxtools/scsitools/stmp_scsi.h b/utils/imxtools/scsitools/stmp_scsi.h index 1a035cc649..68d77daeec 100644 --- a/utils/imxtools/scsitools/stmp_scsi.h +++ b/utils/imxtools/scsitools/stmp_scsi.h | |||
@@ -84,7 +84,7 @@ struct scsi_stmp_logical_table_entry_t | |||
84 | #define SCSI_STMP_DRIVE_TAG_USER_STORAGE 0xa | 84 | #define SCSI_STMP_DRIVE_TAG_USER_STORAGE 0xa |
85 | #define SCSI_STMP_DRIVE_TAG_SYSTEM_BOOT 0x50 | 85 | #define SCSI_STMP_DRIVE_TAG_SYSTEM_BOOT 0x50 |
86 | 86 | ||
87 | struct scsi_stmp_logical_table_t | 87 | struct scsi_stmp_logical_table_header_t |
88 | { | 88 | { |
89 | uint16_t count; /* big-endian */ | 89 | uint16_t count; /* big-endian */ |
90 | } __attribute__((packed)); | 90 | } __attribute__((packed)); |
@@ -135,7 +135,7 @@ struct scsi_stmp_logical_media_info_manufacturer_t | |||
135 | } __attribute__((packed)); | 135 | } __attribute__((packed)); |
136 | 136 | ||
137 | #define SCSI_STMP_DRIVE_INFO_SECTOR_SIZE 0 /** Sector Size (bytes) */ | 137 | #define SCSI_STMP_DRIVE_INFO_SECTOR_SIZE 0 /** Sector Size (bytes) */ |
138 | #define SCSI_STMP_DRIVe_INFO_ERASE_SIZE 1 /** Erase Size (bytes) */ | 138 | #define SCSI_STMP_DRIVE_INFO_ERASE_SIZE 1 /** Erase Size (bytes) */ |
139 | #define SCSI_STMP_DRIVE_INFO_SIZE 2 /** Total Size (bytes) */ | 139 | #define SCSI_STMP_DRIVE_INFO_SIZE 2 /** Total Size (bytes) */ |
140 | #define SCSI_STMP_DRIVE_INFO_SIZE_MEGA 3 /** Total Size (mega-bytes) */ | 140 | #define SCSI_STMP_DRIVE_INFO_SIZE_MEGA 3 /** Total Size (mega-bytes) */ |
141 | #define SCSI_STMP_DRIVE_INFO_SECTOR_COUNT 4 /** Sector Count */ | 141 | #define SCSI_STMP_DRIVE_INFO_SECTOR_COUNT 4 /** Sector Count */ |
@@ -187,6 +187,14 @@ struct scsi_stmp_logical_drive_info_type_t | |||
187 | uint8_t type; | 187 | uint8_t type; |
188 | } __attribute__((packed)); | 188 | } __attribute__((packed)); |
189 | 189 | ||
190 | struct scsi_stmp_logical_drive_info_version_t | ||
191 | { | ||
192 | uint16_t major; | ||
193 | uint16_t minor; | ||
194 | uint16_t revision; | ||
195 | } __attribute__((packed)); | ||
196 | |||
197 | struct stmp_device_t; | ||
190 | typedef struct stmp_device_t *stmp_device_t; | 198 | typedef struct stmp_device_t *stmp_device_t; |
191 | 199 | ||
192 | typedef void (*stmp_printf_t)(void *user, const char *fmt, ...); | 200 | typedef void (*stmp_printf_t)(void *user, const char *fmt, ...); |
@@ -197,4 +205,161 @@ typedef void (*stmp_printf_t)(void *user, const char *fmt, ...); | |||
197 | #define STMP_READ (1 << 1) | 205 | #define STMP_READ (1 << 1) |
198 | #define STMP_WRITE (1 << 2) | 206 | #define STMP_WRITE (1 << 2) |
199 | 207 | ||
208 | uint16_t stmp_fix_endian16be(uint16_t w); | ||
209 | uint32_t stmp_fix_endian32be(uint32_t w); | ||
210 | uint64_t stmp_fix_endian64be(uint64_t w); | ||
211 | /* returns NULL on error */ | ||
212 | stmp_device_t stmp_open(rb_scsi_device_t dev, unsigned flags, void *user, stmp_printf_t printf); | ||
213 | void stmp_close(stmp_device_t dev); | ||
214 | /* returns <0 on error and status otherwise */ | ||
215 | int stmp_scsi(stmp_device_t dev, uint8_t *cdb, int cdb_size, unsigned flags, | ||
216 | void *sense, int *sense_size, void *buffer, int *buf_size); | ||
217 | /* returns != 0 on error */ | ||
218 | int stmp_sense_analysis(stmp_device_t dev, int status, uint8_t *sense, int sense_size); | ||
219 | void stmp_printf(rb_scsi_device_t dev, const char *fmt, ...); | ||
220 | void stmp_debugf(rb_scsi_device_t dev, const char *fmt, ...); | ||
221 | |||
222 | /** | ||
223 | * Mid-level API | ||
224 | */ | ||
225 | |||
226 | /* returns !=0 on error */ | ||
227 | int stmp_scsi_inquiry(stmp_device_t dev, uint8_t *dev_type, char vendor[9], char product[17]); | ||
228 | |||
229 | int stmp_scsi_get_protocol_version(stmp_device_t dev, void *buf, int *len); | ||
230 | int stmp_scsi_get_chip_major_rev_id(stmp_device_t dev, void *buf, int *len); | ||
231 | int stmp_scsi_get_rom_rev_id(stmp_device_t dev, void *buf, int *len); | ||
232 | int stmp_scsi_read_logical_drive_sectors(stmp_device_t dev, uint8_t drive, uint64_t address, | ||
233 | uint32_t count, void *buffer, int *buffer_size); | ||
234 | int stmp_scsi_write_logical_drive_sectors(stmp_device_t dev, uint8_t drive, uint64_t address, | ||
235 | uint32_t count, void *buffer, int *buffer_size); | ||
236 | /* the following functions *DO NOT* fix the endianness of the structures */ | ||
237 | int stmp_scsi_get_logical_table(stmp_device_t dev, int entry_count, void *buf, int *len); | ||
238 | int stmp_scsi_get_serial_number(stmp_device_t dev, uint8_t info, void *data, int *len); | ||
239 | int stmp_scsi_get_logical_media_info(stmp_device_t dev, uint8_t info, void *data, int *len); | ||
240 | int stmp_scsi_get_logical_drive_info(stmp_device_t dev, uint8_t drive, uint8_t info, void *data, int *len); | ||
241 | int stmp_scsi_get_device_info(stmp_device_t dev, uint8_t info, void *data, int *len); | ||
242 | /* these helper functions fix the endianness for the previous calls, or returns != 0 | ||
243 | * if they don't know about this info or the size doesn't match */ | ||
244 | int stmp_fix_logical_media_info(uint8_t info, void *data, int len); | ||
245 | int stmp_fix_logical_drive_info(uint8_t info, void *data, int len); | ||
246 | int stmp_fix_device_info(uint8_t info, void *data, int len); | ||
247 | |||
248 | /** | ||
249 | * High-Level API | ||
250 | */ | ||
251 | |||
252 | struct stmp_logical_media_table_t | ||
253 | { | ||
254 | struct scsi_stmp_logical_table_header_t header; | ||
255 | struct scsi_stmp_logical_table_entry_t entry[]; | ||
256 | }__attribute__((packed)) table; | ||
257 | |||
258 | struct stmp_logical_media_info_t | ||
259 | { | ||
260 | struct | ||
261 | { | ||
262 | bool nr_drives; | ||
263 | bool size; | ||
264 | bool alloc_size; | ||
265 | bool initialised; | ||
266 | bool state; | ||
267 | bool write_protected; | ||
268 | bool type; | ||
269 | bool serial_len; | ||
270 | bool serial; | ||
271 | bool system; | ||
272 | bool present; | ||
273 | bool page_size; | ||
274 | bool vendor; | ||
275 | bool nand_id; | ||
276 | bool nr_devices; | ||
277 | }has; | ||
278 | uint16_t nr_drives; | ||
279 | uint64_t size; | ||
280 | uint32_t alloc_size; | ||
281 | uint8_t initialised; | ||
282 | uint8_t state; | ||
283 | uint8_t write_protected; | ||
284 | uint8_t type; | ||
285 | uint32_t serial_len; | ||
286 | uint8_t *serial; /* must be released with free() */ | ||
287 | uint8_t system; | ||
288 | uint8_t present; | ||
289 | uint32_t page_size; | ||
290 | uint32_t vendor; | ||
291 | uint8_t nand_id[6]; | ||
292 | uint32_t nr_devices; | ||
293 | }; | ||
294 | |||
295 | #define SCSI_STMP_DRIVE_INFO_SECTOR_SIZE 0 /** Sector Size (bytes) */ | ||
296 | #define SCSI_STMP_DRIVE_INFO_ERASE_SIZE 1 /** Erase Size (bytes) */ | ||
297 | #define SCSI_STMP_DRIVE_INFO_SIZE 2 /** Total Size (bytes) */ | ||
298 | #define SCSI_STMP_DRIVE_INFO_SIZE_MEGA 3 /** Total Size (mega-bytes) */ | ||
299 | #define SCSI_STMP_DRIVE_INFO_SECTOR_COUNT 4 /** Sector Count */ | ||
300 | #define SCSI_STMP_DRIVE_INFO_TYPE 5 /** Drive Type */ | ||
301 | #define SCSI_STMP_DRIVE_INFO_TAG 6 /** Drive Tag */ | ||
302 | #define SCSI_STMP_DRIVE_INFO_COMPONENT_VERSION 7 /** Component Version */ | ||
303 | #define SCSI_STMP_DRIVE_INFO_PROJECT_VERSION 8 /** Project Version */ | ||
304 | #define SCSI_STMP_DRIVE_INFO_IS_WRITE_PROTECTED 9 /** Is Write Protected */ | ||
305 | #define SCSI_STMP_DRIVE_INFO_SERIAL_NUMBER_SIZE 10 /** Serial Number Size */ | ||
306 | #define SCSI_STMP_DRIVE_INFO_SERIAL_NUMBER 11 /** Serial Number */ | ||
307 | #define SCSI_STMP_DRIVE_INFO_MEDIA_PRESENT 12 /** Is Media Present */ | ||
308 | #define SCSI_STMP_DRIVE_INFO_MEDIA_CHANGE 13 /** Media Change */ | ||
309 | #define SCSI_STMP_DRIVE_INFO_SECTOR_ALLOCATION 14 /** Sector Allocation */ | ||
310 | |||
311 | struct stmp_logical_drive_info_t | ||
312 | { | ||
313 | struct | ||
314 | { | ||
315 | bool sector_size; | ||
316 | bool erase_size; | ||
317 | bool size; | ||
318 | bool sector_count; | ||
319 | bool type; | ||
320 | bool tag; | ||
321 | bool component_version; | ||
322 | bool project_version; | ||
323 | bool write_protected; | ||
324 | bool serial_len; | ||
325 | bool serial; | ||
326 | bool present; | ||
327 | bool change; | ||
328 | bool sector_alloc; | ||
329 | }has; | ||
330 | uint32_t sector_size; | ||
331 | uint32_t erase_size; | ||
332 | uint64_t size; | ||
333 | uint64_t sector_count; | ||
334 | uint32_t type; | ||
335 | uint8_t tag; | ||
336 | struct scsi_stmp_logical_drive_info_version_t component_version; | ||
337 | struct scsi_stmp_logical_drive_info_version_t project_version; | ||
338 | uint8_t write_protected; | ||
339 | uint32_t serial_len; | ||
340 | uint8_t *serial; | ||
341 | uint8_t present; | ||
342 | uint8_t change; | ||
343 | uint32_t sector_alloc; | ||
344 | }; | ||
345 | |||
346 | int stmp_get_protocol_version(stmp_device_t dev, struct scsi_stmp_protocol_version_t *ver); | ||
347 | int stmp_get_chip_major_rev_id(stmp_device_t dev, uint16_t *ver); | ||
348 | int stmp_get_rom_rev_id(stmp_device_t dev, uint16_t *ver); | ||
349 | /* return 0 on success, buffers must be released with free() */ | ||
350 | int stmp_get_device_serial(stmp_device_t dev, uint8_t **buffer, int *len); | ||
351 | int stmp_get_logical_media_info(stmp_device_t dev, struct stmp_logical_media_info_t *info); | ||
352 | int stmp_get_logical_media_table(stmp_device_t dev, struct stmp_logical_media_table_t **table); | ||
353 | int stmp_get_logical_drive_info(stmp_device_t dev, uint8_t drive, struct stmp_logical_drive_info_t *info); | ||
354 | int stmp_read_logical_drive_sectors(stmp_device_t dev, uint8_t drive, uint64_t address, | ||
355 | uint32_t count, void *buffer, int buffer_size); | ||
356 | int stmp_write_logical_drive_sectors(stmp_device_t dev, uint8_t drive, uint64_t address, | ||
357 | uint32_t count, void *buffer, int buffer_size); | ||
358 | /* string helpers */ | ||
359 | const char *stmp_get_logical_media_type_string(uint32_t type); | ||
360 | const char *stmp_get_logical_media_vendor_string(uint32_t type); | ||
361 | const char *stmp_get_logical_drive_type_string(uint32_t type); | ||
362 | const char *stmp_get_logical_drive_tag_string(uint32_t type); | ||
363 | const char *stmp_get_logical_media_state_string(uint8_t state); | ||
364 | |||
200 | #endif /* __STMP_SCSI__ */ | 365 | #endif /* __STMP_SCSI__ */ |