diff options
Diffstat (limited to 'utils/imxtools/scsitools')
-rw-r--r-- | utils/imxtools/scsitools/misc.c | 5 | ||||
-rw-r--r-- | utils/imxtools/scsitools/stmp_scsi.c | 8 | ||||
-rw-r--r-- | utils/imxtools/scsitools/stmp_scsi.h | 41 |
3 files changed, 41 insertions, 13 deletions
diff --git a/utils/imxtools/scsitools/misc.c b/utils/imxtools/scsitools/misc.c index 108235e7fd..36eae198e5 100644 --- a/utils/imxtools/scsitools/misc.c +++ b/utils/imxtools/scsitools/misc.c | |||
@@ -32,7 +32,12 @@ char GREEN[] = { 0x1b, 0x5b, 0x31, 0x3b, '3', '2', 0x6d, '\0' }; | |||
32 | char YELLOW[] = { 0x1b, 0x5b, 0x31, 0x3b, '3', '3', 0x6d, '\0' }; | 32 | char YELLOW[] = { 0x1b, 0x5b, 0x31, 0x3b, '3', '3', 0x6d, '\0' }; |
33 | char BLUE[] = { 0x1b, 0x5b, 0x31, 0x3b, '3', '4', 0x6d, '\0' }; | 33 | char BLUE[] = { 0x1b, 0x5b, 0x31, 0x3b, '3', '4', 0x6d, '\0' }; |
34 | 34 | ||
35 | #if defined(_WIN32) || defined(__WIN32__) | ||
36 | /* disable colors on Windows */ | ||
37 | static bool g_color_enable = false; | ||
38 | #else | ||
35 | static bool g_color_enable = true; | 39 | static bool g_color_enable = true; |
40 | #endif | ||
36 | 41 | ||
37 | void *xmalloc(size_t s) | 42 | void *xmalloc(size_t s) |
38 | { | 43 | { |
diff --git a/utils/imxtools/scsitools/stmp_scsi.c b/utils/imxtools/scsitools/stmp_scsi.c index e1d0dc4c77..8daeb8a532 100644 --- a/utils/imxtools/scsitools/stmp_scsi.c +++ b/utils/imxtools/scsitools/stmp_scsi.c | |||
@@ -245,14 +245,22 @@ int stmp_get_logical_media_table(stmp_device_t dev, struct stmp_logical_media_ta | |||
245 | int len = sizeof(header); | 245 | int len = sizeof(header); |
246 | int ret = stmp_scsi_get_logical_table(dev, 0, &header, &len); | 246 | int ret = stmp_scsi_get_logical_table(dev, 0, &header, &len); |
247 | if(ret || len != sizeof(header)) | 247 | if(ret || len != sizeof(header)) |
248 | { | ||
249 | stmp_debugf(dev, "Device returned the wrong size for logical media header: " | ||
250 | "%d bytes but expected %d\n", len, sizeof(header)); | ||
248 | return -1; | 251 | return -1; |
252 | } | ||
249 | header.count = stmp_fix_endian16be(header.count); | 253 | header.count = stmp_fix_endian16be(header.count); |
250 | int sz = sizeof(header) + header.count * sizeof(struct scsi_stmp_logical_table_entry_t); | 254 | int sz = sizeof(header) + header.count * sizeof(struct scsi_stmp_logical_table_entry_t); |
251 | len = sz; | 255 | len = sz; |
252 | *table = malloc(sz); | 256 | *table = malloc(sz); |
253 | ret = stmp_scsi_get_logical_table(dev, header.count, &(*table)->header, &len); | 257 | ret = stmp_scsi_get_logical_table(dev, header.count, &(*table)->header, &len); |
254 | if(ret || len != sz) | 258 | if(ret || len != sz) |
259 | { | ||
260 | stmp_debugf(dev, "Device returned the wrong size for logical media table: " | ||
261 | "%d bytes but expected %d (%d entries)\n", len, sz, header.count); | ||
255 | return -1; | 262 | return -1; |
263 | } | ||
256 | (*table)->header.count = stmp_fix_endian16be((*table)->header.count); | 264 | (*table)->header.count = stmp_fix_endian16be((*table)->header.count); |
257 | for(unsigned i = 0; i < (*table)->header.count; i++) | 265 | for(unsigned i = 0; i < (*table)->header.count; i++) |
258 | (*table)->entry[i].size = stmp_fix_endian64be((*table)->entry[i].size); | 266 | (*table)->entry[i].size = stmp_fix_endian64be((*table)->entry[i].size); |
diff --git a/utils/imxtools/scsitools/stmp_scsi.h b/utils/imxtools/scsitools/stmp_scsi.h index 56068b5d4c..e85122041f 100644 --- a/utils/imxtools/scsitools/stmp_scsi.h +++ b/utils/imxtools/scsitools/stmp_scsi.h | |||
@@ -25,6 +25,17 @@ | |||
25 | #include <stdbool.h> | 25 | #include <stdbool.h> |
26 | #include "rbscsi.h" | 26 | #include "rbscsi.h" |
27 | 27 | ||
28 | #if defined(_WIN32) || defined(__WIN32__) | ||
29 | /* Mingw has a curious behaviour: it packs only the last field, see | ||
30 | * https://gcc.gnu.org/bugzilla/show_bug.cgi?id=52991 */ | ||
31 | #pragma pack(push) | ||
32 | #pragma pack(1) | ||
33 | #define RB_POP_PACK | ||
34 | #define RB_PACKED | ||
35 | #else | ||
36 | #define RB_PACKED __attribute__((packed)) | ||
37 | #endif | ||
38 | |||
28 | /** | 39 | /** |
29 | * Low-Level SCSI stuff | 40 | * Low-Level SCSI stuff |
30 | */ | 41 | */ |
@@ -57,17 +68,17 @@ struct scsi_stmp_protocol_version_t | |||
57 | { | 68 | { |
58 | uint8_t major; | 69 | uint8_t major; |
59 | uint8_t minor; | 70 | uint8_t minor; |
60 | } __attribute__((packed)); | 71 | } RB_PACKED; |
61 | 72 | ||
62 | struct scsi_stmp_rom_rev_id_t | 73 | struct scsi_stmp_rom_rev_id_t |
63 | { | 74 | { |
64 | uint16_t rev; /* big-endian */ | 75 | uint16_t rev; /* big-endian */ |
65 | } __attribute__((packed)); | 76 | } RB_PACKED; |
66 | 77 | ||
67 | struct scsi_stmp_chip_major_rev_id_t | 78 | struct scsi_stmp_chip_major_rev_id_t |
68 | { | 79 | { |
69 | uint16_t rev; /* big-endian */ | 80 | uint16_t rev; /* big-endian */ |
70 | } __attribute__((packed)); | 81 | } RB_PACKED; |
71 | 82 | ||
72 | struct scsi_stmp_logical_table_entry_t | 83 | struct scsi_stmp_logical_table_entry_t |
73 | { | 84 | { |
@@ -75,7 +86,7 @@ struct scsi_stmp_logical_table_entry_t | |||
75 | uint8_t type; | 86 | uint8_t type; |
76 | uint8_t tag; | 87 | uint8_t tag; |
77 | uint64_t size; /* big-endian */ | 88 | uint64_t size; /* big-endian */ |
78 | } __attribute__((packed)); | 89 | } RB_PACKED; |
79 | 90 | ||
80 | #define SCSI_STMP_DRIVE_TYPE_USER 0 | 91 | #define SCSI_STMP_DRIVE_TYPE_USER 0 |
81 | #define SCSI_STMP_DRIVE_TYPE_SYSTEM 1 | 92 | #define SCSI_STMP_DRIVE_TYPE_SYSTEM 1 |
@@ -87,7 +98,7 @@ struct scsi_stmp_logical_table_entry_t | |||
87 | struct scsi_stmp_logical_table_header_t | 98 | struct scsi_stmp_logical_table_header_t |
88 | { | 99 | { |
89 | uint16_t count; /* big-endian */ | 100 | uint16_t count; /* big-endian */ |
90 | } __attribute__((packed)); | 101 | } RB_PACKED; |
91 | 102 | ||
92 | #define SCSI_STMP_MEDIA_INFO_NR_DRIVES 0 /** Number of drives (obsolete) */ | 103 | #define SCSI_STMP_MEDIA_INFO_NR_DRIVES 0 /** Number of drives (obsolete) */ |
93 | #define SCSI_STMP_MEDIA_INFO_SIZE 1 /** Total size (bytes) */ | 104 | #define SCSI_STMP_MEDIA_INFO_SIZE 1 /** Total size (bytes) */ |
@@ -127,12 +138,12 @@ struct scsi_stmp_logical_table_header_t | |||
127 | struct scsi_stmp_logical_media_info_type_t | 138 | struct scsi_stmp_logical_media_info_type_t |
128 | { | 139 | { |
129 | uint8_t type; | 140 | uint8_t type; |
130 | } __attribute__((packed)); | 141 | } RB_PACKED; |
131 | 142 | ||
132 | struct scsi_stmp_logical_media_info_manufacturer_t | 143 | struct scsi_stmp_logical_media_info_manufacturer_t |
133 | { | 144 | { |
134 | uint32_t type; /* big-endian */ | 145 | uint32_t type; /* big-endian */ |
135 | } __attribute__((packed)); | 146 | } RB_PACKED; |
136 | 147 | ||
137 | #define SCSI_STMP_DRIVE_INFO_SECTOR_SIZE 0 /** Sector Size (bytes) */ | 148 | #define SCSI_STMP_DRIVE_INFO_SECTOR_SIZE 0 /** Sector Size (bytes) */ |
138 | #define SCSI_STMP_DRIVE_INFO_ERASE_SIZE 1 /** Erase Size (bytes) */ | 149 | #define SCSI_STMP_DRIVE_INFO_ERASE_SIZE 1 /** Erase Size (bytes) */ |
@@ -170,29 +181,29 @@ struct scsi_stmp_logical_media_info_manufacturer_t | |||
170 | struct scsi_stmp_logical_drive_info_sector_t | 181 | struct scsi_stmp_logical_drive_info_sector_t |
171 | { | 182 | { |
172 | uint32_t size; /* big-endian */ | 183 | uint32_t size; /* big-endian */ |
173 | } __attribute__((packed)); | 184 | } RB_PACKED; |
174 | 185 | ||
175 | struct scsi_stmp_logical_drive_info_count_t | 186 | struct scsi_stmp_logical_drive_info_count_t |
176 | { | 187 | { |
177 | uint64_t count; /* big-endian */ | 188 | uint64_t count; /* big-endian */ |
178 | } __attribute__((packed)); | 189 | } RB_PACKED; |
179 | 190 | ||
180 | struct scsi_stmp_logical_drive_info_size_t | 191 | struct scsi_stmp_logical_drive_info_size_t |
181 | { | 192 | { |
182 | uint64_t size; /* big-endian */ | 193 | uint64_t size; /* big-endian */ |
183 | } __attribute__((packed)); | 194 | } RB_PACKED; |
184 | 195 | ||
185 | struct scsi_stmp_logical_drive_info_type_t | 196 | struct scsi_stmp_logical_drive_info_type_t |
186 | { | 197 | { |
187 | uint8_t type; | 198 | uint8_t type; |
188 | } __attribute__((packed)); | 199 | } RB_PACKED; |
189 | 200 | ||
190 | struct scsi_stmp_logical_drive_info_version_t | 201 | struct scsi_stmp_logical_drive_info_version_t |
191 | { | 202 | { |
192 | uint16_t major; | 203 | uint16_t major; |
193 | uint16_t minor; | 204 | uint16_t minor; |
194 | uint16_t revision; | 205 | uint16_t revision; |
195 | } __attribute__((packed)); | 206 | } RB_PACKED; |
196 | 207 | ||
197 | struct stmp_device_t; | 208 | struct stmp_device_t; |
198 | typedef struct stmp_device_t *stmp_device_t; | 209 | typedef struct stmp_device_t *stmp_device_t; |
@@ -253,7 +264,11 @@ struct stmp_logical_media_table_t | |||
253 | { | 264 | { |
254 | struct scsi_stmp_logical_table_header_t header; | 265 | struct scsi_stmp_logical_table_header_t header; |
255 | struct scsi_stmp_logical_table_entry_t entry[]; | 266 | struct scsi_stmp_logical_table_entry_t entry[]; |
256 | }__attribute__((packed)) table; | 267 | }RB_PACKED table; |
268 | |||
269 | #ifdef RB_POP_PACK | ||
270 | #pragma pack(pop) | ||
271 | #endif | ||
257 | 272 | ||
258 | struct stmp_logical_media_info_t | 273 | struct stmp_logical_media_info_t |
259 | { | 274 | { |