-
Notifications
You must be signed in to change notification settings - Fork 1
/
lsmmc.c
2407 lines (2198 loc) · 49.6 KB
/
lsmmc.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (C) ST-Ericsson SA 2010-2011
* Author: Sebastian Rasmussen <[email protected]>
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials
* provided with the distribution.
* 3. Neither the name of the ST-Ericsson SA nor the names of its
* contributors may be used to endorse or promote products
* derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <assert.h>
#include <ctype.h>
#include <dirent.h>
#include <errno.h>
#include <limits.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "mmc.h"
#define MASKTOBIT0(high) \
((high >= 0) ? ((1ull << ((high) + 1ull)) - 1ull) : 0ull)
#define MASK(high, low) (MASKTOBIT0(high) & ~MASKTOBIT0(low - 1))
#define BITS(value, high, low) (((value) & MASK((high), (low))) >> (low))
#define IDS_MAX 256
struct config {
char *idsfile;
char *dir;
bool verbose;
int interfaces;
char **interface;
char **mmc_ids;
char **sd_ids;
char *type;
char *cid;
char *csd;
char *scr;
char *ext_csd;
};
enum REG_TYPE {
CID = 0,
CSD,
SCR,
EXT_CSD,
};
struct ids_database {
char *type;
int id;
char *manufacturer;
};
struct ids_database database[] = {
{
.type = "sd",
.id = 0x01,
.manufacturer = "Panasonic",
},
{
.type = "sd",
.id = 0x02,
.manufacturer = "Toshiba/Kingston/Viking",
},
{
.type = "sd",
.id = 0x03,
.manufacturer = "SanDisk",
},
{
.type = "sd",
.id = 0x08,
.manufacturer = "Silicon Power",
},
{
.type = "sd",
.id = 0x18,
.manufacturer = "Infineon",
},
{
.type = "sd",
.id = 0x1b,
.manufacturer = "Transcend",
},
{
.type = "sd",
.id = 0x1c,
.manufacturer = "Transcend",
},
{
.type = "sd",
.id = 0x1d,
.manufacturer = "Corsair",
},
{
.type = "sd",
.id = 0x1e,
.manufacturer = "Transcend",
},
{
.type = "sd",
.id = 0x1f,
.manufacturer = "Kingston",
},
{
.type = "sd",
.id = 0x28,
.manufacturer = "Lexar",
},
{
.type = "sd",
.id = 0x30,
.manufacturer = "SanDisk",
},
{
.type = "sd",
.id = 0x33,
.manufacturer = "STMicroelectronics",
},
{
.type = "sd",
.id = 0x41,
.manufacturer = "Kingston",
},
{
.type = "sd",
.id = 0x6f,
.manufacturer = "STMicroelectronics",
},
{
.type = "sd",
.id = 0x89,
.manufacturer = "Unknown",
},
{
.type = "mmc",
.id = 0x00,
.manufacturer = "SanDisk",
},
{
.type = "mmc",
.id = 0x02,
.manufacturer = "Kingston/SanDisk",
},
{
.type = "mmc",
.id = 0x03,
.manufacturer = "Toshiba",
},
{
.type = "mmc",
.id = 0x05,
.manufacturer = "Unknown",
},
{
.type = "mmc",
.id = 0x06,
.manufacturer = "Unknown",
},
{
.type = "mmc",
.id = 0x11,
.manufacturer = "Toshiba",
},
{
.type = "mmc",
.id = 0x15,
.manufacturer = "Samsung/SanDisk/LG",
},
{
.type = "mmc",
.id = 0x37,
.manufacturer = "KingMax",
},
{
.type = "mmc",
.id = 0x44,
.manufacturer = "SanDisk",
},
{
.type = "mmc",
.id = 0x2c,
.manufacturer = "Kingston",
},
{
.type = "mmc",
.id = 0x70,
.manufacturer = "Kingston",
},
};
/* Command line parsing functions */
void usage(void)
{
printf("Usage: print mmc [-h] [-v] <device path ...>\n");
printf("\n");
printf("Options:\n");
printf("\t-h\tShow this help.\n");
printf("\t-v\tEnable verbose mode.\n");
}
int parse_opts(int argc, char **argv, struct config *config)
{
int c;
while ((c = getopt(argc, argv, "hv")) != -1) {
switch (c) {
case 'h':
usage();
return -1;
case 'v':
config->verbose = true;
break;
case '?':
fprintf(stderr,
"Unknown option '%c' encountered.\n\n", c);
usage();
return -1;
case ':':
fprintf(stderr,
"Argument for option '%c' missing.\n\n", c);
usage();
return -1;
default:
fprintf(stderr,
"Unimplemented option '%c' encountered.\n", c);
break;
}
}
if (optind >= argc) {
fprintf(stderr, "Expected mmc directory arguments.\n\n");
usage();
return -1;
}
config->dir = strdup(argv[optind]);
return 0;
}
int parse_ids(struct config *config)
{
unsigned int ids_cnt = sizeof(database) / sizeof(struct ids_database);
unsigned int value;
char **ids;
char *type;
int i;
for (i = 0; i < ids_cnt; i++) {
type = database[i].type;
if (!strcmp(type, "mmc")) {
ids = config->mmc_ids;
} else if (!strcmp(type, "sd")) {
ids = config->sd_ids;
} else {
fprintf(stderr,
"MMC/SD id parse error, unknown type: '%s'.\n",
type);
return -1;
}
value = database[i].id;
if (value >= IDS_MAX) {
fprintf(stderr,
"MMC/SD id parse error, id out of range.\n");
return -1;
}
if (ids[value]) {
fprintf(stderr,
"Duplicate entries: type='%s', id='0x%1x'.\n",
type, value);
return -1;
}
ids[value] = database[i].manufacturer;
}
return 0;
}
/* MMC/SD file parsing functions */
char *read_file(char *name)
{
char *preparsed;
char line[4096];
FILE *f;
f = fopen(name, "r");
if (!f) {
fprintf(stderr, "Could not open MMC/SD file '%s'.\n", name);
return NULL;
}
preparsed = fgets(line, sizeof(line), f);
if (!preparsed) {
if (ferror(f))
fprintf(stderr, "Could not read MMC/SD file '%s'.\n",
name);
else
fprintf(stderr,
"Could not read data from MMC/SD file '%s'.\n",
name);
if (fclose(f))
fprintf(stderr, "Could not close MMC/SD file '%s'.\n",
name);
return NULL;
}
if (fclose(f)) {
fprintf(stderr, "Could not close MMC/SD file '%s'.\n", name);
return NULL;
}
line[sizeof(line) - 1] = '\0';
while (isspace(line[strlen(line) - 1]))
line[strlen(line) - 1] = '\0';
while (isspace(line[0]))
memmove(&line[0], &line[1], sizeof(line)-1);
return strdup(line);
}
/* Hexadecimal string parsing functions */
char *to_binstr(char *hexstr)
{
char *bindigits[] = {
"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111",
"1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111",
};
char *binstr;
binstr = calloc(strlen(hexstr) * 4 + 1, sizeof(char));
while (hexstr && *hexstr != '\0') {
if (!isxdigit(*hexstr))
return NULL;
if (isdigit(*hexstr))
strcat(binstr, bindigits[*hexstr - '0']);
else if (islower(*hexstr))
strcat(binstr, bindigits[*hexstr - 'a']);
else
strcat(binstr, bindigits[*hexstr - 'A']);
hexstr++;
}
return binstr;
}
void bin_to_unsigned(unsigned int *u, char *binstr, int width)
{
*u = 0;
assert(width <= 32);
while (binstr && *binstr != '\0' && width > 0) {
*u <<= 1;
*u |= *binstr == '0' ? 0 : 1;
binstr++;
width--;
}
}
void bin_to_ascii(char *a, char *binstr, int width)
{
assert(width % 8 == 0);
*a = '\0';
while (binstr && *binstr != '\0' && width > 0) {
unsigned int u;
char c[2] = { '\0', '\0' };
char *s = &c[0];
bin_to_unsigned(&u, binstr, 8);
c[0] = u;
strcat(a, s);
binstr += 8;
width -= 8;
}
}
void parse_bin(char *hexstr, char *fmt, ...)
{
va_list args;
char *origstr;
char *binstr;
unsigned long width = 0;
binstr = to_binstr(hexstr);
origstr = binstr;
va_start(args, fmt);
while (binstr && fmt && *fmt != '\0') {
if (isdigit(*fmt)) {
char *rest;
errno = 0;
width = strtoul(fmt, &rest, 10);
if (width == ULONG_MAX && errno != 0)
fprintf(stderr, "strtoul()");
fmt = rest;
} else if (*fmt == 'u') {
unsigned int *u = va_arg(args, unsigned int *);
if (u)
bin_to_unsigned(u, binstr, width);
binstr += width;
width = 0;
fmt++;
} else if (*fmt == 'r') {
binstr += width;
width = 0;
fmt++;
} else if (*fmt == 'a') {
char *c = va_arg(args, char *);
if (c)
bin_to_ascii(c, binstr, width);
binstr += width;
width = 0;
fmt++;
} else {
fmt++;
}
}
va_end(args);
free(origstr);
}
/* MMC/SD information parsing functions */
void print_sd_cid(struct config *config, char *cid)
{
static const char *months[] = {
"jan", "feb", "mar", "apr", "may", "jun",
"jul", "aug", "sep", "oct", "nov", "dec",
"invalid0", "invalid1", "invalid2", "invalid3",
};
unsigned int mid;
char oid[3];
char pnm[6];
unsigned int prv_major;
unsigned int prv_minor;
unsigned int psn;
unsigned int mdt_month;
unsigned int mdt_year;
unsigned int crc;
parse_bin(cid, "8u16a40a4u4u32u4r8u4u7u1r",
&mid, &oid[0], &pnm[0], &prv_major, &prv_minor, &psn,
&mdt_year, &mdt_month, &crc);
oid[2] = '\0';
pnm[5] = '\0';
if (config->verbose) {
printf("======SD/CID======\n");
printf("\tMID: 0x%02x (", mid);
if (config->sd_ids[mid])
printf("%s)\n", config->sd_ids[mid]);
else
printf("Unlisted)\n");
printf("\tOID: %s\n", oid);
printf("\tPNM: %s\n", pnm);
printf("\tPRV: 0x%01x%01x ", prv_major, prv_minor);
printf("(%d.%d)\n", prv_major, prv_minor);
printf("\tPSN: 0x%08x\n", psn);
printf("\tMDT: 0x%02x%01x %d %s\n", mdt_year, mdt_month,
2000 + mdt_year, months[mdt_month]);
printf("\tCRC: 0x%02x\n", crc);
} else {
if (config->sd_ids[mid])
printf("manufacturer: '%s' '%s'\n",
config->sd_ids[mid], oid);
else
printf("manufacturer: 'Unlisted' '%s'\n", oid);
printf("product: '%s' %d.%d\n", pnm, prv_major, prv_minor);
printf("serial: 0x%08x\n", psn);
printf("manfacturing date: %d %s\n", 2000 + mdt_year,
months[mdt_month]);
}
}
void print_mmc_cid(struct config *config, char *cid)
{
static const char *months[] = {
"jan", "feb", "mar", "apr", "may", "jun",
"jul", "aug", "sep", "oct", "nov", "dec",
"invalid0", "invalid1", "invalid2", "invalid3",
};
unsigned int mid;
unsigned int cbx;
unsigned int oid;
char pnm[7];
unsigned int prv_major;
unsigned int prv_minor;
unsigned int psn;
unsigned int mdt_month;
unsigned int mdt_year;
unsigned int crc;
parse_bin(cid, "8u6r2u8u48a4u4u32u4u4u7u1r",
&mid, &cbx, &oid, &pnm[0], &psn, &prv_major, &prv_minor,
&mdt_year, &mdt_month, &crc);
pnm[6] = '\0';
if (config->verbose) {
printf("======MMC/CID======\n");
printf("\tMID: 0x%02x (", mid);
if (config->mmc_ids[mid])
printf("%s)\n", config->mmc_ids[mid]);
else
printf("Unlisted)\n");
printf("\tCBX: 0x%01x (", cbx);
switch (cbx) {
case 0:
printf("card)\n");
break;
case 1:
printf("BGA)\n");
break;
case 2:
printf("PoP)\n");
break;
case 3:
printf("reserved)\n");
break;
}
printf("\tOID: 0x%01x\n", oid);
printf("\tPNM: %s\n", pnm);
printf("\tPRV: 0x%01x%01x ", prv_major, prv_minor);
printf("(%d.%d)\n", prv_major, prv_minor);
printf("\tPSN: 0x%08x\n", psn);
printf("\tMDT: 0x%01x%01x %d %s\n", mdt_month, mdt_year,
1997 + mdt_year, months[mdt_month]);
printf("\tCRC: 0x%02x\n", crc);
} else {
if (config->mmc_ids[mid])
printf("manufacturer: '%s' '%c'\n",
config->mmc_ids[mid], oid);
else
printf("manufacturer: 'Unlisted' '%c'\n", oid);
printf("product: '%s' %d.%d\n", pnm, prv_major, prv_minor);
printf("serial: 0x%08x\n", psn);
printf("manfacturing date: %d %s\n", 1997 + mdt_year,
months[mdt_month]);
}
}
void print_sd_csd(struct config *config, char *csd)
{
unsigned int csd_structure;
unsigned int taac_timevalue;
unsigned int taac_timeunit;
unsigned int nsac;
unsigned int tran_speed_timevalue;
unsigned int tran_speed_transferrateunit;
unsigned int ccc;
unsigned int read_bl_len;
unsigned int read_bl_partial;
unsigned int write_blk_misalign;
unsigned int read_blk_misalign;
unsigned int dsr_imp;
unsigned int c_size;
unsigned int vdd_r_curr_min;
unsigned int vdd_r_curr_max;
unsigned int vdd_w_curr_min;
unsigned int vdd_w_curr_max;
unsigned int c_size_mult;
unsigned int erase_blk_en;
unsigned int sector_size;
unsigned int wp_grp_size;
unsigned int wp_grp_enable;
unsigned int r2w_factor;
unsigned int write_bl_len;
unsigned int write_bl_partial;
unsigned int file_format_grp;
unsigned int copy;
unsigned int perm_write_protect;
unsigned int tmp_write_protect;
unsigned int file_format;
unsigned int crc;
unsigned int taac;
unsigned int tran_speed;
parse_bin(csd, "2u", &csd_structure);
if (csd_structure == 0) {
parse_bin(csd, "2u6r1r4u3u8u1r4u3u12u4u1u1u1u1u2r12u3u3u3u3u3u"
"1u7u7u1u2r3u4u1u5r1u1u1u1u2u2r7u1r",
NULL, &taac_timevalue, &taac_timeunit, &nsac,
&tran_speed_timevalue,
&tran_speed_transferrateunit, &ccc,
&read_bl_len, &read_bl_partial,
&write_blk_misalign, &read_blk_misalign,
&dsr_imp, &c_size, &vdd_r_curr_min,
&vdd_r_curr_max, &vdd_w_curr_min,
&vdd_w_curr_max, &c_size_mult, &erase_blk_en,
§or_size, &wp_grp_size, &wp_grp_enable,
&r2w_factor, &write_bl_len, &write_bl_partial,
&file_format_grp, ©, &perm_write_protect,
&tmp_write_protect, &file_format, &crc);
} else if (csd_structure == 1) {
parse_bin(csd, "2u6r1r4u3u8u1r4u3u12u4u1u1u1u1u6r22u1r1u7u7u1u"
"2r3u4u1u5r1u1u1u1u2u2r7u1r",
NULL, &taac_timevalue, &taac_timeunit, &nsac,
&tran_speed_timevalue,
&tran_speed_transferrateunit, &ccc,
&read_bl_len, &read_bl_partial,
&write_blk_misalign, &read_blk_misalign,
&dsr_imp, &c_size, &erase_blk_en, §or_size,
&wp_grp_size, &wp_grp_enable, &r2w_factor,
&write_bl_len, &write_bl_partial,
&file_format_grp, ©, &perm_write_protect,
&tmp_write_protect, &file_format, &crc);
vdd_r_curr_min = 0;
c_size_mult = 0;
} else {
printf("Unknown CSD structure: 0x%1x\n", csd_structure);
return;
}
taac = taac_timevalue << 3 | taac_timeunit;
tran_speed = tran_speed_timevalue << 3 | tran_speed_transferrateunit;
if (config->verbose) {
float value;
unsigned long long blocks = 0;
int block_size = 0;
unsigned long long memory_capacity;
printf("======SD/CSD======\n");
printf("\tCSD_STRUCTURE: %d\n", csd_structure);
printf("\tTAAC: 0x%02x (", taac);
switch (taac_timevalue) {
case 0x0:
value = 0.0f;
break;
case 0x1:
value = 1.0f;
break;
case 0x2:
value = 1.2f;
break;
case 0x3:
value = 1.3f;
break;
case 0x4:
value = 1.5f;
break;
case 0x5:
value = 2.0f;
break;
case 0x6:
value = 2.5f;
break;
case 0x7:
value = 3.0f;
break;
case 0x8:
value = 3.5f;
break;
case 0x9:
value = 4.0f;
break;
case 0xa:
value = 4.5f;
break;
case 0xb:
value = 5.0f;
break;
case 0xc:
value = 5.5f;
break;
case 0xd:
value = 6.0f;
break;
case 0xe:
value = 7.0f;
break;
case 0xf:
value = 8.0f;
break;
default:
value = 0.0f;
break;
}
switch (taac_timeunit) {
case 0x0:
printf("%.2fns)\n", value * 1.0f);
break;
case 0x1:
printf("%.2fns)\n", value * 10.0f);
break;
case 0x2:
printf("%.2fns)\n", value * 100.0f);
break;
case 0x3:
printf("%.2fus)\n", value * 1.0f);
break;
case 0x4:
printf("%.2fus)\n", value * 10.0f);
break;
case 0x5:
printf("%.2fus)\n", value * 100.0f);
break;
case 0x6:
printf("%.2fms)\n", value * 1.0f);
break;
case 0x7:
printf("%.2fms)\n", value * 10.0f);
break;
}
if (csd_structure == 1 && taac != 0x0e)
printf("Warn: Invalid TAAC (should be 0x0e)\n");
printf("\tNSAC: %d clocks\n", nsac);
if (csd_structure == 1 && nsac != 0x00)
printf("Warn: Invalid NSAC (should be 0x00)\n");
printf("\tTRAN_SPEED: 0x%02x (", tran_speed);
switch (tran_speed_timevalue) {
case 0x0:
value = 0.0f;
break;
case 0x1:
value = 1.0f;
break;
case 0x2:
value = 1.2f;
break;
case 0x3:
value = 1.3f;
break;
case 0x4:
value = 1.5f;
break;
case 0x5:
value = 2.0f;
break;
case 0x6:
value = 2.5f;
break;
case 0x7:
value = 3.0f;
break;
case 0x8:
value = 3.5f;
break;
case 0x9:
value = 4.0f;
break;
case 0xa:
value = 4.5f;
break;
case 0xb:
value = 5.0f;
break;
case 0xc:
value = 5.5f;
break;
case 0xd:
value = 6.0f;
break;
case 0xe:
value = 7.0f;
break;
case 0xf:
value = 8.0f;
break;
default:
value = 0.0f;
break;
}
switch (tran_speed_transferrateunit) {
case 0x0:
printf("%.2fkbit/s)\n", value * 100.0f);
break;
case 0x1:
printf("%.2fMbit/s)\n", value * 1.0f);
break;
case 0x2:
printf("%.2fMbit/s)\n", value * 10.0f);
break;
case 0x3:
printf("%.2fMbit/s)\n", value * 100.0f);
break;
default:
printf("reserved)\n");
break;
}
if (csd_structure == 0 &&
(tran_speed != 0x32 && tran_speed != 0x5a))
printf("Warn: Invalid TRAN_SPEED "
"(should be 0x32 or 0x5a)\n");
if (csd_structure == 1 && tran_speed != 0x32 &&
tran_speed != 0x5a && tran_speed != 0x0b &&
tran_speed != 0x2b)
printf("Warn: Invalid TRAN_SPEED "
"(should be 0x32, 0x5a, 0x0b or 0x2b\n");
printf("\tCCC: 0x%03x (class: ", ccc);
if (ccc & 0x800)
printf("11, ");
if (ccc & 0x400)
printf("10, ");
if (ccc & 0x200)
printf("9, ");
if (ccc & 0x100)
printf("8, ");
if (ccc & 0x080)
printf("7, ");
if (ccc & 0x040)
printf("6, ");
if (ccc & 0x020)
printf("5, ");
if (ccc & 0x010)
printf("4, ");
if (ccc & 0x008)
printf("3, ");
if (ccc & 0x004)
printf("2, ");
if (ccc & 0x002)
printf("1, ");
if (ccc & 0x001)
printf("0, ");
printf(" )\n");
if (csd_structure == 0 &&
(ccc != 0x5b5 && ccc != 0x7b5 && ccc != 0x5f5))
printf("Warn: Invalid CCC (should be 0x5b5, "
"0x7b5 or 0x5f5)\n");
else if (csd_structure == 1 && ccc != 0x5b5 && ccc != 0x7b5)
printf("Warn: Invalid CCC (should be 0x5b5 or 0x7b5)\n");
printf("\tREAD_BL_LEN: 0x%01x (", read_bl_len);
switch (read_bl_len) {
case 0x9:
printf("512 bytes)\n");
break;
case 0xa:
printf("1024 bytes)\n");
break;
case 0xb:
printf("2048 bytes)\n");
break;
default:
printf("reserved bytes)\n");
break;
}
if (csd_structure == 1 && read_bl_len != 0x9)
printf("Warn: Invalid READ_BL_LEN (should be 0x9)\n");
printf("\tREAD_BL_PARTIAL: 0x%01x\n", read_bl_partial);
if (csd_structure == 0 && read_bl_partial != 0x01)
printf("Warn: Invalid READ_BL_PARTIAL (should be 0x01)\n");
else if (csd_structure == 1 && read_bl_partial != 0x00)
printf("Warn: Invalid READ_BL_PARTIAL (should be 0x00)\n");
printf("\tWRITE_BLK_MISALIGN: 0x%01x\n", write_blk_misalign);
if (csd_structure == 1 && write_blk_misalign != 0x00)
printf("Warn: Invalid WRITE_BLK_MISALIGN (should be 0x00)\n");
printf("\tREAD_BLK_MISALIGN: 0x%01x\n", read_blk_misalign);
if (csd_structure == 1 && read_blk_misalign != 0x00)
printf("Warn: Invalid READ_BLK_MISALIGN (should be 0x00)\n");
printf("\tDSR_IMP: 0x%01x\n", dsr_imp);
if (csd_structure == 0) {
int mult;
int blocknr;
int block_len;
printf("\tC_SIZE: 0x%03x\n", c_size);
printf("\tVDD_R_CURR_MIN: 0x%01x (", vdd_r_curr_min);
switch (vdd_r_curr_min) {
case 0x0:
printf("0.5mA)\n");
break;
case 0x1:
printf("1mA)\n");
break;
case 0x2:
printf("5mA)\n");
break;
case 0x3:
printf("10mA)\n");
break;
case 0x4:
printf("25mA)\n");
break;
case 0x5:
printf("35mA)\n");
break;
case 0x6:
printf("60mA)\n");
break;
case 0x7:
printf("100mA)\n");
break;
}
printf("\tVDD_R_CURR_MAX: 0x%01x (", vdd_r_curr_max);
switch (vdd_r_curr_max) {
case 0x0:
printf("1mA)\n");
break;
case 0x1:
printf("5mA)\n");
break;
case 0x2:
printf("10mA)\n");
break;
case 0x3:
printf("25mA)\n");
break;
case 0x4:
printf("35mA)\n");
break;
case 0x5:
printf("45mA)\n");
break;
case 0x6:
printf("80mA)\n");
break;
case 0x7:
printf("200mA)\n");
break;
}
printf("\tVDD_W_CURR_MIN: 0x%01x (", vdd_w_curr_min);
switch (vdd_w_curr_min) {
case 0x0:
printf("0.5mA)\n");
break;
case 0x1:
printf("1mA)\n");
break;
case 0x2:
printf("5mA)\n");
break;
case 0x3:
printf("10mA)\n");