From c992afc0afcbd064e44dc3e6e00ddf2adea335b0 Mon Sep 17 00:00:00 2001 From: Jan Luebbe Date: Mon, 18 Dec 2023 20:21:17 +0100 Subject: [PATCH 1/4] tests: add tests for sd_regs decoding Signed-off-by: Jan Luebbe --- .../02544d53413034471027b7748500bc00.json | 445 ++++++++++++++++ .../1b534d474638533530d8466363a16700.json | 450 ++++++++++++++++ .../744a605553442020104182bbc7010600.json | 498 ++++++++++++++++++ .../9f5449303030303000a1114bb5011400.json | 447 ++++++++++++++++ tests/test_sd_regs.py | 29 + 5 files changed, 1869 insertions(+) create mode 100644 tests/reference/02544d53413034471027b7748500bc00.json create mode 100644 tests/reference/1b534d474638533530d8466363a16700.json create mode 100644 tests/reference/744a605553442020104182bbc7010600.json create mode 100644 tests/reference/9f5449303030303000a1114bb5011400.json create mode 100644 tests/test_sd_regs.py diff --git a/tests/reference/02544d53413034471027b7748500bc00.json b/tests/reference/02544d53413034471027b7748500bc00.json new file mode 100644 index 0000000..4066053 --- /dev/null +++ b/tests/reference/02544d53413034471027b7748500bc00.json @@ -0,0 +1,445 @@ +{ + "scr": { + "reg": "SCR", + "raw": "0235800001000000", + "fields": [ + { + "field": "SCR_STRUCTURE", + "name": "SCR Structure", + "raw": [ + 0, + 4 + ], + "enum": "1.0" + }, + { + "field": "SD_SPEC", + "name": "SD Memory Card - Spec. Version", + "raw": [ + 2, + 4 + ], + "enum": "2.00 or 3.0X" + }, + { + "field": "DATA_STAT_AFTER_ERASE", + "name": "data status after erase", + "raw": [ + 0, + 1 + ], + "value": "False" + }, + { + "field": "SD_SECURITY", + "name": "CPRM Security Support", + "raw": [ + 3, + 3 + ], + "enum": "SDHC Card (Security Version 2.00)" + }, + { + "field": "SD_BUS_WIDTHS", + "name": "DAT Bus widths supported", + "raw": [ + 5, + 4 + ], + "bits": [ + "1 bit", + "4 bit" + ] + }, + { + "field": "SD_SPEC3", + "name": "Spec. Version 3.00 or higher", + "raw": [ + 1, + 1 + ] + }, + { + "field": "EX_SECURITY", + "name": "Extended Security Support", + "raw": [ + 0, + 4 + ] + }, + { + "field": "RESERVED", + "raw": [ + 0, + 9 + ] + }, + { + "field": "CMD_SUPPORT", + "name": "Command Support bits", + "raw": [ + 0, + 2 + ], + "bits": [] + }, + { + "field": "RESERVED_MFG", + "raw": [ + 16777216, + 32 + ] + } + ], + "computed": {} + }, + "cid": { + "reg": "CID", + "raw": "02544d53413034471027b7748500bc00", + "fields": [ + { + "field": "MID", + "name": "Manufacturer ID", + "raw": [ + 2, + 8 + ], + "enum": "SanDisk" + }, + { + "field": "OID", + "name": "OEM/Application ID", + "raw": [ + 21581, + 16 + ], + "value": "TM" + }, + { + "field": "PNM", + "name": "Product name", + "raw": [ + 357575963719, + 40 + ], + "value": "SA04G" + }, + { + "field": "PRV", + "name": "Product revision", + "raw": [ + 16, + 8 + ], + "value": "1.0" + }, + { + "field": "PSN", + "name": "Product serial number", + "raw": [ + 666334341, + 32 + ], + "value": "666334341" + }, + { + "field": "RESERVED", + "raw": [ + 0, + 4 + ] + }, + { + "field": "MDT_Y", + "name": "Manufacturing date (year)", + "raw": [ + 11, + 8 + ], + "value": "2011" + }, + { + "field": "MDT_M", + "name": "Manufacturing date (month)", + "raw": [ + 12, + 4 + ], + "value": "13" + }, + { + "field": "CRC", + "name": "CRC7 checksum", + "raw": [ + 0, + 7 + ] + }, + { + "field": "NU1", + "name": "not used, always 1", + "raw": [ + 0, + 1 + ] + } + ], + "computed": {} + }, + "csd": { + "reg": "CSD_20", + "raw": "400e00325b5900001d177f800a400000", + "fields": [ + { + "field": "CSD_STRUCTURE", + "name": "CSD structure", + "raw": [ + 1, + 2 + ], + "enum": "2.0" + }, + { + "field": "TAAC", + "name": "data read access-time-1", + "raw": [ + 14, + 8 + ], + "decoded": [ + 1.0, + "1ms" + ], + "value": 1000000.0, + "unit": "ns" + }, + { + "field": "NSAC", + "name": "data read access-time-2", + "raw": [ + 0, + 8 + ], + "value": "0", + "unit": "CLK cycles" + }, + { + "field": "TRAN_SPEED", + "name": "max. data transfer rate", + "raw": [ + 50, + 8 + ], + "decoded": [ + 2.5, + "10Mbit/s" + ], + "value": 25000000.0, + "unit": "bit/s" + }, + { + "field": "CCC", + "name": "card command classes", + "raw": [ + 1461, + 12 + ], + "bits": [ + "0", + "2", + "4", + "5", + "7", + "8", + "10" + ] + }, + { + "field": "READ_BL_LEN", + "name": "max. read data block length", + "raw": [ + 9, + 4 + ], + "value": "512", + "unit": "bytes" + }, + { + "field": "READ_BL_PARTIAL", + "name": "partial blocks for read allowed", + "raw": [ + 0, + 1 + ], + "value": "False" + }, + { + "field": "WRITE_BLK_MISALIGN", + "name": "write block misalignment allowed", + "raw": [ + 0, + 1 + ], + "value": "False" + }, + { + "field": "READ_BLK_MISALIGN", + "name": "read block misalignment allowed", + "raw": [ + 0, + 1 + ], + "value": "False" + }, + { + "field": "DSR_IMP", + "name": "driver stage register implemented", + "raw": [ + 0, + 1 + ], + "value": "False" + }, + { + "field": "C_SIZE", + "name": "device size", + "raw": [ + 7447, + 22 + ], + "value": "3904897024", + "unit": "bytes" + }, + { + "field": "ERASE_BLK_EN", + "name": "erase single block enable", + "raw": [ + 1, + 1 + ], + "value": "True" + }, + { + "field": "SECTOR_SIZE", + "name": "erase sector size", + "raw": [ + 127, + 7 + ], + "value": "128", + "unit": "write blocks" + }, + { + "field": "WP_GRP_SIZE", + "name": "write protect group size", + "raw": [ + 0, + 7 + ], + "value": "1", + "unit": "erase sectors" + }, + { + "field": "WP_GRP_ENABLE", + "name": "write protect group enable", + "raw": [ + 0, + 1 + ], + "value": "False" + }, + { + "field": "R2W_FACTOR", + "name": "write speed factor", + "raw": [ + 2, + 3 + ], + "value": "4", + "unit": "multiples of read access time" + }, + { + "field": "WRITE_BL_LEN", + "name": "max. write data block length", + "raw": [ + 9, + 4 + ], + "value": "512", + "unit": "bytes" + }, + { + "field": "WRITE_BL_PARTIAL", + "name": "partial blocks for write allowed", + "raw": [ + 0, + 1 + ], + "value": "False" + }, + { + "field": "FILE_FORMAT_GRP", + "name": "file format group", + "raw": [ + 0, + 1 + ] + }, + { + "field": "COPY", + "name": "copy flag", + "raw": [ + 0, + 1 + ], + "value": "False" + }, + { + "field": "PERM_WRITE_PROTECT", + "name": "permanent write protection", + "raw": [ + 0, + 1 + ], + "value": "False" + }, + { + "field": "TMP_WRITE_PROTECT", + "name": "temporary write protection", + "raw": [ + 0, + 1 + ], + "value": "False" + }, + { + "field": "FILE_FORMAT", + "name": "file format", + "raw": [ + 0, + 3 + ], + "enum": "Hard disk-like file system with partition table" + }, + { + "field": "CRC", + "raw": [ + 0, + 7 + ] + } + ], + "computed": { + "sector_size_bytes": { + "value": 65536, + "unit": "bytes", + "name": "sector size" + }, + "wp_grp_size_bytes": { + "value": 65536, + "unit": "bytes", + "name": "write protect group size" + } + } + } +} diff --git a/tests/reference/1b534d474638533530d8466363a16700.json b/tests/reference/1b534d474638533530d8466363a16700.json new file mode 100644 index 0000000..e1db5b1 --- /dev/null +++ b/tests/reference/1b534d474638533530d8466363a16700.json @@ -0,0 +1,450 @@ +{ + "scr": { + "reg": "SCR", + "raw": "0205848700000000", + "fields": [ + { + "field": "SCR_STRUCTURE", + "name": "SCR Structure", + "raw": [ + 0, + 4 + ], + "enum": "1.0" + }, + { + "field": "SD_SPEC", + "name": "SD Memory Card - Spec. Version", + "raw": [ + 2, + 4 + ], + "enum": "2.00 or 3.0X" + }, + { + "field": "DATA_STAT_AFTER_ERASE", + "name": "data status after erase", + "raw": [ + 0, + 1 + ], + "value": "False" + }, + { + "field": "SD_SECURITY", + "name": "CPRM Security Support", + "raw": [ + 0, + 3 + ], + "enum": "No Security" + }, + { + "field": "SD_BUS_WIDTHS", + "name": "DAT Bus widths supported", + "raw": [ + 5, + 4 + ], + "bits": [ + "1 bit", + "4 bit" + ] + }, + { + "field": "SD_SPEC3", + "name": "Spec. Version 3.00 or higher", + "raw": [ + 1, + 1 + ] + }, + { + "field": "EX_SECURITY", + "name": "Extended Security Support", + "raw": [ + 0, + 4 + ] + }, + { + "field": "RESERVED", + "raw": [ + 289, + 9 + ] + }, + { + "field": "CMD_SUPPORT", + "name": "Command Support bits", + "raw": [ + 3, + 2 + ], + "bits": [ + "Speed Class Control (CMD20)", + "Set Block Count (CMD23)" + ] + }, + { + "field": "RESERVED_MFG", + "raw": [ + 0, + 32 + ] + } + ], + "computed": {} + }, + "cid": { + "reg": "CID", + "raw": "1b534d474638533530d8466363a16700", + "fields": [ + { + "field": "MID", + "name": "Manufacturer ID", + "raw": [ + 27, + 8 + ], + "enum": "Samsung" + }, + { + "field": "OID", + "name": "OEM/Application ID", + "raw": [ + 21325, + 16 + ], + "value": "SM" + }, + { + "field": "PNM", + "name": "Product name", + "raw": [ + 306120774453, + 40 + ], + "value": "GF8S5" + }, + { + "field": "PRV", + "name": "Product revision", + "raw": [ + 48, + 8 + ], + "value": "3.0" + }, + { + "field": "PSN", + "name": "Product serial number", + "raw": [ + 3628491619, + 32 + ], + "value": "3628491619" + }, + { + "field": "RESERVED", + "raw": [ + 10, + 4 + ] + }, + { + "field": "MDT_Y", + "name": "Manufacturing date (year)", + "raw": [ + 22, + 8 + ], + "value": "2022" + }, + { + "field": "MDT_M", + "name": "Manufacturing date (month)", + "raw": [ + 7, + 4 + ], + "value": "8" + }, + { + "field": "CRC", + "name": "CRC7 checksum", + "raw": [ + 0, + 7 + ] + }, + { + "field": "NU1", + "name": "not used, always 1", + "raw": [ + 0, + 1 + ] + } + ], + "computed": {} + }, + "csd": { + "reg": "CSD_20", + "raw": "400e0032db79000eebff7f800a400000", + "fields": [ + { + "field": "CSD_STRUCTURE", + "name": "CSD structure", + "raw": [ + 1, + 2 + ], + "enum": "2.0" + }, + { + "field": "TAAC", + "name": "data read access-time-1", + "raw": [ + 14, + 8 + ], + "decoded": [ + 1.0, + "1ms" + ], + "value": 1000000.0, + "unit": "ns" + }, + { + "field": "NSAC", + "name": "data read access-time-2", + "raw": [ + 0, + 8 + ], + "value": "0", + "unit": "CLK cycles" + }, + { + "field": "TRAN_SPEED", + "name": "max. data transfer rate", + "raw": [ + 50, + 8 + ], + "decoded": [ + 2.5, + "10Mbit/s" + ], + "value": 25000000.0, + "unit": "bit/s" + }, + { + "field": "CCC", + "name": "card command classes", + "raw": [ + 3511, + 12 + ], + "bits": [ + "0", + "1", + "2", + "4", + "5", + "7", + "8", + "10", + "11" + ] + }, + { + "field": "READ_BL_LEN", + "name": "max. read data block length", + "raw": [ + 9, + 4 + ], + "value": "512", + "unit": "bytes" + }, + { + "field": "READ_BL_PARTIAL", + "name": "partial blocks for read allowed", + "raw": [ + 0, + 1 + ], + "value": "False" + }, + { + "field": "WRITE_BLK_MISALIGN", + "name": "write block misalignment allowed", + "raw": [ + 0, + 1 + ], + "value": "False" + }, + { + "field": "READ_BLK_MISALIGN", + "name": "read block misalignment allowed", + "raw": [ + 0, + 1 + ], + "value": "False" + }, + { + "field": "DSR_IMP", + "name": "driver stage register implemented", + "raw": [ + 0, + 1 + ], + "value": "False" + }, + { + "field": "C_SIZE", + "name": "device size", + "raw": [ + 977919, + 22 + ], + "value": "512711720960", + "unit": "bytes" + }, + { + "field": "ERASE_BLK_EN", + "name": "erase single block enable", + "raw": [ + 1, + 1 + ], + "value": "True" + }, + { + "field": "SECTOR_SIZE", + "name": "erase sector size", + "raw": [ + 127, + 7 + ], + "value": "128", + "unit": "write blocks" + }, + { + "field": "WP_GRP_SIZE", + "name": "write protect group size", + "raw": [ + 0, + 7 + ], + "value": "1", + "unit": "erase sectors" + }, + { + "field": "WP_GRP_ENABLE", + "name": "write protect group enable", + "raw": [ + 0, + 1 + ], + "value": "False" + }, + { + "field": "R2W_FACTOR", + "name": "write speed factor", + "raw": [ + 2, + 3 + ], + "value": "4", + "unit": "multiples of read access time" + }, + { + "field": "WRITE_BL_LEN", + "name": "max. write data block length", + "raw": [ + 9, + 4 + ], + "value": "512", + "unit": "bytes" + }, + { + "field": "WRITE_BL_PARTIAL", + "name": "partial blocks for write allowed", + "raw": [ + 0, + 1 + ], + "value": "False" + }, + { + "field": "FILE_FORMAT_GRP", + "name": "file format group", + "raw": [ + 0, + 1 + ] + }, + { + "field": "COPY", + "name": "copy flag", + "raw": [ + 0, + 1 + ], + "value": "False" + }, + { + "field": "PERM_WRITE_PROTECT", + "name": "permanent write protection", + "raw": [ + 0, + 1 + ], + "value": "False" + }, + { + "field": "TMP_WRITE_PROTECT", + "name": "temporary write protection", + "raw": [ + 0, + 1 + ], + "value": "False" + }, + { + "field": "FILE_FORMAT", + "name": "file format", + "raw": [ + 0, + 3 + ], + "enum": "Hard disk-like file system with partition table" + }, + { + "field": "CRC", + "raw": [ + 0, + 7 + ] + } + ], + "computed": { + "sector_size_bytes": { + "value": 65536, + "unit": "bytes", + "name": "sector size" + }, + "wp_grp_size_bytes": { + "value": 65536, + "unit": "bytes", + "name": "write protect group size" + } + } + } +} diff --git a/tests/reference/744a605553442020104182bbc7010600.json b/tests/reference/744a605553442020104182bbc7010600.json new file mode 100644 index 0000000..021d8bc --- /dev/null +++ b/tests/reference/744a605553442020104182bbc7010600.json @@ -0,0 +1,498 @@ +{ + "scr": { + "reg": "SCR", + "raw": "0225800000000000", + "fields": [ + { + "field": "SCR_STRUCTURE", + "name": "SCR Structure", + "raw": [ + 0, + 4 + ], + "enum": "1.0" + }, + { + "field": "SD_SPEC", + "name": "SD Memory Card - Spec. Version", + "raw": [ + 2, + 4 + ], + "enum": "2.00 or 3.0X" + }, + { + "field": "DATA_STAT_AFTER_ERASE", + "name": "data status after erase", + "raw": [ + 0, + 1 + ], + "value": "False" + }, + { + "field": "SD_SECURITY", + "name": "CPRM Security Support", + "raw": [ + 2, + 3 + ], + "enum": "SDSC Card (Security Version 1.01)" + }, + { + "field": "SD_BUS_WIDTHS", + "name": "DAT Bus widths supported", + "raw": [ + 5, + 4 + ], + "bits": [ + "1 bit", + "4 bit" + ] + }, + { + "field": "SD_SPEC3", + "name": "Spec. Version 3.00 or higher", + "raw": [ + 1, + 1 + ] + }, + { + "field": "EX_SECURITY", + "name": "Extended Security Support", + "raw": [ + 0, + 4 + ] + }, + { + "field": "RESERVED", + "raw": [ + 0, + 9 + ] + }, + { + "field": "CMD_SUPPORT", + "name": "Command Support bits", + "raw": [ + 0, + 2 + ], + "bits": [] + }, + { + "field": "RESERVED_MFG", + "raw": [ + 0, + 32 + ] + } + ], + "computed": {} + }, + "cid": { + "reg": "CID", + "raw": "744a605553442020104182bbc7010600", + "fields": [ + { + "field": "MID", + "name": "Manufacturer ID", + "raw": [ + 116, + 8 + ], + "enum": "Transcend" + }, + { + "field": "OID", + "name": "OEM/Application ID", + "raw": [ + 19040, + 16 + ], + "value": "J`" + }, + { + "field": "PNM", + "name": "Product name", + "raw": [ + 366469193760, + 40 + ], + "value": "USD " + }, + { + "field": "PRV", + "name": "Product revision", + "raw": [ + 16, + 8 + ], + "value": "1.0" + }, + { + "field": "PSN", + "name": "Product serial number", + "raw": [ + 1099086791, + 32 + ], + "value": "1099086791" + }, + { + "field": "RESERVED", + "raw": [ + 0, + 4 + ] + }, + { + "field": "MDT_Y", + "name": "Manufacturing date (year)", + "raw": [ + 16, + 8 + ], + "value": "2016" + }, + { + "field": "MDT_M", + "name": "Manufacturing date (month)", + "raw": [ + 6, + 4 + ], + "value": "7" + }, + { + "field": "CRC", + "name": "CRC7 checksum", + "raw": [ + 0, + 7 + ] + }, + { + "field": "NU1", + "name": "not used, always 1", + "raw": [ + 0, + 1 + ] + } + ], + "computed": {} + }, + "csd": { + "reg": "CSD_10", + "raw": "007f00325b5a83bd6db7ff800a800000", + "fields": [ + { + "field": "CSD_STRUCTURE", + "name": "CSD structure", + "raw": [ + 0, + 2 + ], + "enum": "1.0" + }, + { + "field": "TAAC", + "name": "data read access-time-1", + "raw": [ + 127, + 8 + ], + "decoded": [ + 8.0, + "10ms" + ], + "value": 80000000.0, + "unit": "ns" + }, + { + "field": "NSAC", + "name": "data read access-time-2", + "raw": [ + 0, + 8 + ], + "value": "0", + "unit": "CLK cycles" + }, + { + "field": "TRAN_SPEED", + "name": "max. data transfer rate", + "raw": [ + 50, + 8 + ], + "decoded": [ + 2.5, + "10Mbit/s" + ], + "value": 25000000.0, + "unit": "bit/s" + }, + { + "field": "CCC", + "name": "card command classes", + "raw": [ + 1461, + 12 + ], + "bits": [ + "0", + "2", + "4", + "5", + "7", + "8", + "10" + ] + }, + { + "field": "READ_BL_LEN", + "name": "max. read data block length", + "raw": [ + 10, + 4 + ], + "value": "1024", + "unit": "bytes" + }, + { + "field": "READ_BL_PARTIAL", + "name": "partial blocks for read allowed", + "raw": [ + 1, + 1 + ], + "value": "True" + }, + { + "field": "WRITE_BLK_MISALIGN", + "name": "write block misalignment allowed", + "raw": [ + 0, + 1 + ], + "value": "False" + }, + { + "field": "READ_BLK_MISALIGN", + "name": "read block misalignment allowed", + "raw": [ + 0, + 1 + ], + "value": "False" + }, + { + "field": "DSR_IMP", + "name": "driver stage register implemented", + "raw": [ + 0, + 1 + ], + "value": "False" + }, + { + "field": "C_SIZE", + "name": "device size", + "raw": [ + 3829, + 12 + ], + "value": "3830" + }, + { + "field": "VDD_R_CURR_MIN", + "name": "max. read current @VDD min", + "raw": [ + 5, + 3 + ], + "enum": 35, + "unit": "mA" + }, + { + "field": "VDD_R_CURR_MAX", + "name": "max. read current @VDD max", + "raw": [ + 5, + 3 + ], + "enum": 45, + "unit": "mA" + }, + { + "field": "VDD_W_CURR_MIN", + "name": "max. write current @VDD min", + "raw": [ + 5, + 3 + ], + "enum": 35, + "unit": "mA" + }, + { + "field": "VDD_W_CURR_MAX", + "name": "max. write current @VDD max", + "raw": [ + 5, + 3 + ], + "enum": 45, + "unit": "mA" + }, + { + "field": "C_SIZE_MULT", + "name": "device size multiplier", + "raw": [ + 7, + 3 + ], + "value": "512" + }, + { + "field": "ERASE_BLK_EN", + "name": "erase single block enable", + "raw": [ + 1, + 1 + ], + "value": "True" + }, + { + "field": "SECTOR_SIZE", + "name": "erase sector size", + "raw": [ + 127, + 7 + ], + "value": "128", + "unit": "write blocks" + }, + { + "field": "WP_GRP_SIZE", + "name": "write protect group size", + "raw": [ + 0, + 7 + ], + "value": "1", + "unit": "erase sectors" + }, + { + "field": "WP_GRP_ENABLE", + "name": "write protect group enable", + "raw": [ + 0, + 1 + ], + "value": "False" + }, + { + "field": "R2W_FACTOR", + "name": "write speed factor", + "raw": [ + 2, + 3 + ], + "value": "4", + "unit": "multiples of read access time" + }, + { + "field": "WRITE_BL_LEN", + "name": "max. write data block length", + "raw": [ + 10, + 4 + ], + "value": "1024", + "unit": "bytes" + }, + { + "field": "WRITE_BL_PARTIAL", + "name": "partial blocks for write allowed", + "raw": [ + 0, + 1 + ], + "value": "False" + }, + { + "field": "FILE_FORMAT_GRP", + "name": "file format group", + "raw": [ + 0, + 1 + ] + }, + { + "field": "COPY", + "name": "copy flag", + "raw": [ + 0, + 1 + ], + "value": "False" + }, + { + "field": "PERM_WRITE_PROTECT", + "name": "permanent write protection", + "raw": [ + 0, + 1 + ], + "value": "False" + }, + { + "field": "TMP_WRITE_PROTECT", + "name": "temporary write protection", + "raw": [ + 0, + 1 + ], + "value": "False" + }, + { + "field": "FILE_FORMAT", + "name": "file format", + "raw": [ + 0, + 3 + ], + "enum": "Hard disk-like file system with partition table" + }, + { + "field": "CRC", + "raw": [ + 0, + 7 + ] + } + ], + "computed": { + "sector_size_bytes": { + "value": 131072, + "unit": "bytes", + "name": "sector size" + }, + "wp_grp_size_bytes": { + "value": 131072, + "unit": "bytes", + "name": "write protect group size" + }, + "device_size_bytes": { + "value": 2008023040, + "unit": "bytes", + "name": "device size" + } + } + } +} diff --git a/tests/reference/9f5449303030303000a1114bb5011400.json b/tests/reference/9f5449303030303000a1114bb5011400.json new file mode 100644 index 0000000..5bd0bb8 --- /dev/null +++ b/tests/reference/9f5449303030303000a1114bb5011400.json @@ -0,0 +1,447 @@ +{ + "scr": { + "reg": "SCR", + "raw": "02b5800200000000", + "fields": [ + { + "field": "SCR_STRUCTURE", + "name": "SCR Structure", + "raw": [ + 0, + 4 + ], + "enum": "1.0" + }, + { + "field": "SD_SPEC", + "name": "SD Memory Card - Spec. Version", + "raw": [ + 2, + 4 + ], + "enum": "2.00 or 3.0X" + }, + { + "field": "DATA_STAT_AFTER_ERASE", + "name": "data status after erase", + "raw": [ + 1, + 1 + ], + "value": "True" + }, + { + "field": "SD_SECURITY", + "name": "CPRM Security Support", + "raw": [ + 3, + 3 + ], + "enum": "SDHC Card (Security Version 2.00)" + }, + { + "field": "SD_BUS_WIDTHS", + "name": "DAT Bus widths supported", + "raw": [ + 5, + 4 + ], + "bits": [ + "1 bit", + "4 bit" + ] + }, + { + "field": "SD_SPEC3", + "name": "Spec. Version 3.00 or higher", + "raw": [ + 1, + 1 + ] + }, + { + "field": "EX_SECURITY", + "name": "Extended Security Support", + "raw": [ + 0, + 4 + ] + }, + { + "field": "RESERVED", + "raw": [ + 0, + 9 + ] + }, + { + "field": "CMD_SUPPORT", + "name": "Command Support bits", + "raw": [ + 2, + 2 + ], + "bits": [ + "Set Block Count (CMD23)" + ] + }, + { + "field": "RESERVED_MFG", + "raw": [ + 0, + 32 + ] + } + ], + "computed": {} + }, + "cid": { + "reg": "CID", + "raw": "9f5449303030303000a1114bb5011400", + "fields": [ + { + "field": "MID", + "name": "Manufacturer ID", + "raw": [ + 159, + 8 + ], + "enum": "Kingston SD" + }, + { + "field": "OID", + "name": "OEM/Application ID", + "raw": [ + 21577, + 16 + ], + "value": "TI" + }, + { + "field": "PNM", + "name": "Product name", + "raw": [ + 206966894640, + 40 + ], + "value": "00000" + }, + { + "field": "PRV", + "name": "Product revision", + "raw": [ + 0, + 8 + ], + "value": "0.0" + }, + { + "field": "PSN", + "name": "Product serial number", + "raw": [ + 2702265269, + 32 + ], + "value": "2702265269" + }, + { + "field": "RESERVED", + "raw": [ + 0, + 4 + ] + }, + { + "field": "MDT_Y", + "name": "Manufacturing date (year)", + "raw": [ + 17, + 8 + ], + "value": "2017" + }, + { + "field": "MDT_M", + "name": "Manufacturing date (month)", + "raw": [ + 4, + 4 + ], + "value": "5" + }, + { + "field": "CRC", + "name": "CRC7 checksum", + "raw": [ + 0, + 7 + ] + }, + { + "field": "NU1", + "name": "not used, always 1", + "raw": [ + 0, + 1 + ] + } + ], + "computed": {} + }, + "csd": { + "reg": "CSD_20", + "raw": "400e00325b5900003b877f800a400000", + "fields": [ + { + "field": "CSD_STRUCTURE", + "name": "CSD structure", + "raw": [ + 1, + 2 + ], + "enum": "2.0" + }, + { + "field": "TAAC", + "name": "data read access-time-1", + "raw": [ + 14, + 8 + ], + "decoded": [ + 1.0, + "1ms" + ], + "value": 1000000.0, + "unit": "ns" + }, + { + "field": "NSAC", + "name": "data read access-time-2", + "raw": [ + 0, + 8 + ], + "value": "0", + "unit": "CLK cycles" + }, + { + "field": "TRAN_SPEED", + "name": "max. data transfer rate", + "raw": [ + 50, + 8 + ], + "decoded": [ + 2.5, + "10Mbit/s" + ], + "value": 25000000.0, + "unit": "bit/s" + }, + { + "field": "CCC", + "name": "card command classes", + "raw": [ + 1461, + 12 + ], + "bits": [ + "0", + "2", + "4", + "5", + "7", + "8", + "10" + ] + }, + { + "field": "READ_BL_LEN", + "name": "max. read data block length", + "raw": [ + 9, + 4 + ], + "value": "512", + "unit": "bytes" + }, + { + "field": "READ_BL_PARTIAL", + "name": "partial blocks for read allowed", + "raw": [ + 0, + 1 + ], + "value": "False" + }, + { + "field": "WRITE_BLK_MISALIGN", + "name": "write block misalignment allowed", + "raw": [ + 0, + 1 + ], + "value": "False" + }, + { + "field": "READ_BLK_MISALIGN", + "name": "read block misalignment allowed", + "raw": [ + 0, + 1 + ], + "value": "False" + }, + { + "field": "DSR_IMP", + "name": "driver stage register implemented", + "raw": [ + 0, + 1 + ], + "value": "False" + }, + { + "field": "C_SIZE", + "name": "device size", + "raw": [ + 15239, + 22 + ], + "value": "7990149120", + "unit": "bytes" + }, + { + "field": "ERASE_BLK_EN", + "name": "erase single block enable", + "raw": [ + 1, + 1 + ], + "value": "True" + }, + { + "field": "SECTOR_SIZE", + "name": "erase sector size", + "raw": [ + 127, + 7 + ], + "value": "128", + "unit": "write blocks" + }, + { + "field": "WP_GRP_SIZE", + "name": "write protect group size", + "raw": [ + 0, + 7 + ], + "value": "1", + "unit": "erase sectors" + }, + { + "field": "WP_GRP_ENABLE", + "name": "write protect group enable", + "raw": [ + 0, + 1 + ], + "value": "False" + }, + { + "field": "R2W_FACTOR", + "name": "write speed factor", + "raw": [ + 2, + 3 + ], + "value": "4", + "unit": "multiples of read access time" + }, + { + "field": "WRITE_BL_LEN", + "name": "max. write data block length", + "raw": [ + 9, + 4 + ], + "value": "512", + "unit": "bytes" + }, + { + "field": "WRITE_BL_PARTIAL", + "name": "partial blocks for write allowed", + "raw": [ + 0, + 1 + ], + "value": "False" + }, + { + "field": "FILE_FORMAT_GRP", + "name": "file format group", + "raw": [ + 0, + 1 + ] + }, + { + "field": "COPY", + "name": "copy flag", + "raw": [ + 0, + 1 + ], + "value": "False" + }, + { + "field": "PERM_WRITE_PROTECT", + "name": "permanent write protection", + "raw": [ + 0, + 1 + ], + "value": "False" + }, + { + "field": "TMP_WRITE_PROTECT", + "name": "temporary write protection", + "raw": [ + 0, + 1 + ], + "value": "False" + }, + { + "field": "FILE_FORMAT", + "name": "file format", + "raw": [ + 0, + 3 + ], + "enum": "Hard disk-like file system with partition table" + }, + { + "field": "CRC", + "raw": [ + 0, + 7 + ] + } + ], + "computed": { + "sector_size_bytes": { + "value": 65536, + "unit": "bytes", + "name": "sector size" + }, + "wp_grp_size_bytes": { + "value": 65536, + "unit": "bytes", + "name": "write protect group size" + } + } + } +} diff --git a/tests/test_sd_regs.py b/tests/test_sd_regs.py new file mode 100644 index 0000000..44b68dd --- /dev/null +++ b/tests/test_sd_regs.py @@ -0,0 +1,29 @@ +import os.path +import json + +import pytest + +from usbsdmux.sd_regs import SCR, CID, decode_csd + +REFS = [ + "02544d53413034471027b7748500bc00", + "1b534d474638533530d8466363a16700", + "744a605553442020104182bbc7010600", + "9f5449303030303000a1114bb5011400", +] + + +@pytest.mark.parametrize("cid", REFS) +def test_decode(cid): + ref_name = os.path.join(os.path.dirname(__file__), "reference", f"{cid}.json") + ref = json.load(open(ref_name)) + + res = {} + res["scr"] = SCR(ref["scr"]["raw"]).decode() + res["cid"] = CID(ref["cid"]["raw"]).decode() + res["csd"] = decode_csd(ref["csd"]["raw"]).decode() + + # get rid of json differences, like [] -> () + res = json.loads(json.dumps(res)) + + assert res == ref From 1c78334a98ec9602755b0984fb6180d8e15d5461 Mon Sep 17 00:00:00 2001 From: Jan Luebbe Date: Mon, 18 Dec 2023 20:28:44 +0100 Subject: [PATCH 2/4] tests: add tests for sd_regs text output Signed-off-by: Jan Luebbe --- .../02544d53413034471027b7748500bc00.text | 128 ++++++++++++++++ .../1b534d474638533530d8466363a16700.text | 128 ++++++++++++++++ .../744a605553442020104182bbc7010600.text | 143 ++++++++++++++++++ .../9f5449303030303000a1114bb5011400.text | 128 ++++++++++++++++ tests/test_sd_regs.py | 16 ++ 5 files changed, 543 insertions(+) create mode 100644 tests/reference/02544d53413034471027b7748500bc00.text create mode 100644 tests/reference/1b534d474638533530d8466363a16700.text create mode 100644 tests/reference/744a605553442020104182bbc7010600.text create mode 100644 tests/reference/9f5449303030303000a1114bb5011400.text diff --git a/tests/reference/02544d53413034471027b7748500bc00.text b/tests/reference/02544d53413034471027b7748500bc00.text new file mode 100644 index 0000000..12e9c63 --- /dev/null +++ b/tests/reference/02544d53413034471027b7748500bc00.text @@ -0,0 +1,128 @@ +CSD_20 Register Value: 400e00325b5900001d177f800a400000 + CSD_STRUCTURE: CSD structure + raw: 0b01 == 0x1 == 1 + enum: 2.0 + TAAC: data read access-time-1 + raw: 0b00001110 == 0xe == 14 + decoded: (1.0, '1ms') + value: 1000000.0 ns + NSAC: data read access-time-2 + raw: 0b00000000 == 0x0 == 0 + value: 0 CLK cycles + TRAN_SPEED: max. data transfer rate + raw: 0b00110010 == 0x32 == 50 + decoded: (2.5, '10Mbit/s') + value: 25000000.0 bit/s + CCC: card command classes + raw: 0b010110110101 == 0x5b5 == 1461 + bits: 0, 2, 4, 5, 7, 8, 10 + READ_BL_LEN: max. read data block length + raw: 0b1001 == 0x9 == 9 + value: 512 bytes + READ_BL_PARTIAL: partial blocks for read allowed + raw: 0b0 == 0x0 == 0 + value: False + WRITE_BLK_MISALIGN: write block misalignment allowed + raw: 0b0 == 0x0 == 0 + value: False + READ_BLK_MISALIGN: read block misalignment allowed + raw: 0b0 == 0x0 == 0 + value: False + DSR_IMP: driver stage register implemented + raw: 0b0 == 0x0 == 0 + value: False + C_SIZE: device size + raw: 0b0000000001110100010111 == 0x1d17 == 7447 + value: 3904897024 bytes + ERASE_BLK_EN: erase single block enable + raw: 0b1 == 0x1 == 1 + value: True + SECTOR_SIZE: erase sector size + raw: 0b1111111 == 0x7f == 127 + value: 128 write blocks + WP_GRP_SIZE: write protect group size + raw: 0b0000000 == 0x0 == 0 + value: 1 erase sectors + WP_GRP_ENABLE: write protect group enable + raw: 0b0 == 0x0 == 0 + value: False + R2W_FACTOR: write speed factor + raw: 0b010 == 0x2 == 2 + value: 4 multiples of read access time + WRITE_BL_LEN: max. write data block length + raw: 0b1001 == 0x9 == 9 + value: 512 bytes + WRITE_BL_PARTIAL: partial blocks for write allowed + raw: 0b0 == 0x0 == 0 + value: False + FILE_FORMAT_GRP: file format group + raw: 0b0 == 0x0 == 0 + COPY: copy flag + raw: 0b0 == 0x0 == 0 + value: False + PERM_WRITE_PROTECT: permanent write protection + raw: 0b0 == 0x0 == 0 + value: False + TMP_WRITE_PROTECT: temporary write protection + raw: 0b0 == 0x0 == 0 + value: False + FILE_FORMAT: file format + raw: 0b000 == 0x0 == 0 + enum: Hard disk-like file system with partition table + CRC + raw: 0b0000000 == 0x0 == 0 +SCR Register Value: 0235800001000000 + SCR_STRUCTURE: SCR Structure + raw: 0b0000 == 0x0 == 0 + enum: 1.0 + SD_SPEC: SD Memory Card - Spec. Version + raw: 0b0010 == 0x2 == 2 + enum: 2.00 or 3.0X + DATA_STAT_AFTER_ERASE: data status after erase + raw: 0b0 == 0x0 == 0 + value: False + SD_SECURITY: CPRM Security Support + raw: 0b011 == 0x3 == 3 + enum: SDHC Card (Security Version 2.00) + SD_BUS_WIDTHS: DAT Bus widths supported + raw: 0b0101 == 0x5 == 5 + bits: 1 bit, 4 bit + SD_SPEC3: Spec. Version 3.00 or higher + raw: 0b1 == 0x1 == 1 + EX_SECURITY: Extended Security Support + raw: 0b0000 == 0x0 == 0 + RESERVED + raw: 0b000000000 == 0x0 == 0 + CMD_SUPPORT: Command Support bits + raw: 0b00 == 0x0 == 0 + bits: + RESERVED_MFG + raw: 0b00000001000000000000000000000000 == 0x1000000 == 16777216 +CID Register Value: 02544d53413034471027b7748500bc00 + MID: Manufacturer ID + raw: 0b00000010 == 0x2 == 2 + enum: SanDisk + OID: OEM/Application ID + raw: 0b0101010001001101 == 0x544d == 21581 + value: TM + PNM: Product name + raw: 0b0101001101000001001100000011010001000111 == 0x5341303447 == 357575963719 + value: SA04G + PRV: Product revision + raw: 0b00010000 == 0x10 == 16 + value: 1.0 + PSN: Product serial number + raw: 0b00100111101101110111010010000101 == 0x27b77485 == 666334341 + value: 666334341 + RESERVED + raw: 0b0000 == 0x0 == 0 + MDT_Y: Manufacturing date (year) + raw: 0b00001011 == 0xb == 11 + value: 2011 + MDT_M: Manufacturing date (month) + raw: 0b1100 == 0xc == 12 + value: 13 + CRC: CRC7 checksum + raw: 0b0000000 == 0x0 == 0 + NU1: not used, always 1 + raw: 0b0 == 0x0 == 0 diff --git a/tests/reference/1b534d474638533530d8466363a16700.text b/tests/reference/1b534d474638533530d8466363a16700.text new file mode 100644 index 0000000..a0cba54 --- /dev/null +++ b/tests/reference/1b534d474638533530d8466363a16700.text @@ -0,0 +1,128 @@ +CSD_20 Register Value: 400e0032db79000eebff7f800a400000 + CSD_STRUCTURE: CSD structure + raw: 0b01 == 0x1 == 1 + enum: 2.0 + TAAC: data read access-time-1 + raw: 0b00001110 == 0xe == 14 + decoded: (1.0, '1ms') + value: 1000000.0 ns + NSAC: data read access-time-2 + raw: 0b00000000 == 0x0 == 0 + value: 0 CLK cycles + TRAN_SPEED: max. data transfer rate + raw: 0b00110010 == 0x32 == 50 + decoded: (2.5, '10Mbit/s') + value: 25000000.0 bit/s + CCC: card command classes + raw: 0b110110110111 == 0xdb7 == 3511 + bits: 0, 1, 2, 4, 5, 7, 8, 10, 11 + READ_BL_LEN: max. read data block length + raw: 0b1001 == 0x9 == 9 + value: 512 bytes + READ_BL_PARTIAL: partial blocks for read allowed + raw: 0b0 == 0x0 == 0 + value: False + WRITE_BLK_MISALIGN: write block misalignment allowed + raw: 0b0 == 0x0 == 0 + value: False + READ_BLK_MISALIGN: read block misalignment allowed + raw: 0b0 == 0x0 == 0 + value: False + DSR_IMP: driver stage register implemented + raw: 0b0 == 0x0 == 0 + value: False + C_SIZE: device size + raw: 0b0011101110101111111111 == 0xeebff == 977919 + value: 512711720960 bytes + ERASE_BLK_EN: erase single block enable + raw: 0b1 == 0x1 == 1 + value: True + SECTOR_SIZE: erase sector size + raw: 0b1111111 == 0x7f == 127 + value: 128 write blocks + WP_GRP_SIZE: write protect group size + raw: 0b0000000 == 0x0 == 0 + value: 1 erase sectors + WP_GRP_ENABLE: write protect group enable + raw: 0b0 == 0x0 == 0 + value: False + R2W_FACTOR: write speed factor + raw: 0b010 == 0x2 == 2 + value: 4 multiples of read access time + WRITE_BL_LEN: max. write data block length + raw: 0b1001 == 0x9 == 9 + value: 512 bytes + WRITE_BL_PARTIAL: partial blocks for write allowed + raw: 0b0 == 0x0 == 0 + value: False + FILE_FORMAT_GRP: file format group + raw: 0b0 == 0x0 == 0 + COPY: copy flag + raw: 0b0 == 0x0 == 0 + value: False + PERM_WRITE_PROTECT: permanent write protection + raw: 0b0 == 0x0 == 0 + value: False + TMP_WRITE_PROTECT: temporary write protection + raw: 0b0 == 0x0 == 0 + value: False + FILE_FORMAT: file format + raw: 0b000 == 0x0 == 0 + enum: Hard disk-like file system with partition table + CRC + raw: 0b0000000 == 0x0 == 0 +SCR Register Value: 0205848700000000 + SCR_STRUCTURE: SCR Structure + raw: 0b0000 == 0x0 == 0 + enum: 1.0 + SD_SPEC: SD Memory Card - Spec. Version + raw: 0b0010 == 0x2 == 2 + enum: 2.00 or 3.0X + DATA_STAT_AFTER_ERASE: data status after erase + raw: 0b0 == 0x0 == 0 + value: False + SD_SECURITY: CPRM Security Support + raw: 0b000 == 0x0 == 0 + enum: No Security + SD_BUS_WIDTHS: DAT Bus widths supported + raw: 0b0101 == 0x5 == 5 + bits: 1 bit, 4 bit + SD_SPEC3: Spec. Version 3.00 or higher + raw: 0b1 == 0x1 == 1 + EX_SECURITY: Extended Security Support + raw: 0b0000 == 0x0 == 0 + RESERVED + raw: 0b100100001 == 0x121 == 289 + CMD_SUPPORT: Command Support bits + raw: 0b11 == 0x3 == 3 + bits: Speed Class Control (CMD20), Set Block Count (CMD23) + RESERVED_MFG + raw: 0b00000000000000000000000000000000 == 0x0 == 0 +CID Register Value: 1b534d474638533530d8466363a16700 + MID: Manufacturer ID + raw: 0b00011011 == 0x1b == 27 + enum: Samsung + OID: OEM/Application ID + raw: 0b0101001101001101 == 0x534d == 21325 + value: SM + PNM: Product name + raw: 0b0100011101000110001110000101001100110101 == 0x4746385335 == 306120774453 + value: GF8S5 + PRV: Product revision + raw: 0b00110000 == 0x30 == 48 + value: 3.0 + PSN: Product serial number + raw: 0b11011000010001100110001101100011 == 0xd8466363 == 3628491619 + value: 3628491619 + RESERVED + raw: 0b1010 == 0xa == 10 + MDT_Y: Manufacturing date (year) + raw: 0b00010110 == 0x16 == 22 + value: 2022 + MDT_M: Manufacturing date (month) + raw: 0b0111 == 0x7 == 7 + value: 8 + CRC: CRC7 checksum + raw: 0b0000000 == 0x0 == 0 + NU1: not used, always 1 + raw: 0b0 == 0x0 == 0 diff --git a/tests/reference/744a605553442020104182bbc7010600.text b/tests/reference/744a605553442020104182bbc7010600.text new file mode 100644 index 0000000..e4be0d3 --- /dev/null +++ b/tests/reference/744a605553442020104182bbc7010600.text @@ -0,0 +1,143 @@ +CSD_10 Register Value: 007f00325b5a83bd6db7ff800a800000 + CSD_STRUCTURE: CSD structure + raw: 0b00 == 0x0 == 0 + enum: 1.0 + TAAC: data read access-time-1 + raw: 0b01111111 == 0x7f == 127 + decoded: (8.0, '10ms') + value: 80000000.0 ns + NSAC: data read access-time-2 + raw: 0b00000000 == 0x0 == 0 + value: 0 CLK cycles + TRAN_SPEED: max. data transfer rate + raw: 0b00110010 == 0x32 == 50 + decoded: (2.5, '10Mbit/s') + value: 25000000.0 bit/s + CCC: card command classes + raw: 0b010110110101 == 0x5b5 == 1461 + bits: 0, 2, 4, 5, 7, 8, 10 + READ_BL_LEN: max. read data block length + raw: 0b1010 == 0xa == 10 + value: 1024 bytes + READ_BL_PARTIAL: partial blocks for read allowed + raw: 0b1 == 0x1 == 1 + value: True + WRITE_BLK_MISALIGN: write block misalignment allowed + raw: 0b0 == 0x0 == 0 + value: False + READ_BLK_MISALIGN: read block misalignment allowed + raw: 0b0 == 0x0 == 0 + value: False + DSR_IMP: driver stage register implemented + raw: 0b0 == 0x0 == 0 + value: False + C_SIZE: device size + raw: 0b111011110101 == 0xef5 == 3829 + value: 3830 + VDD_R_CURR_MIN: max. read current @VDD min + raw: 0b101 == 0x5 == 5 + enum: 35 mA + VDD_R_CURR_MAX: max. read current @VDD max + raw: 0b101 == 0x5 == 5 + enum: 45 mA + VDD_W_CURR_MIN: max. write current @VDD min + raw: 0b101 == 0x5 == 5 + enum: 35 mA + VDD_W_CURR_MAX: max. write current @VDD max + raw: 0b101 == 0x5 == 5 + enum: 45 mA + C_SIZE_MULT: device size multiplier + raw: 0b111 == 0x7 == 7 + value: 512 + ERASE_BLK_EN: erase single block enable + raw: 0b1 == 0x1 == 1 + value: True + SECTOR_SIZE: erase sector size + raw: 0b1111111 == 0x7f == 127 + value: 128 write blocks + WP_GRP_SIZE: write protect group size + raw: 0b0000000 == 0x0 == 0 + value: 1 erase sectors + WP_GRP_ENABLE: write protect group enable + raw: 0b0 == 0x0 == 0 + value: False + R2W_FACTOR: write speed factor + raw: 0b010 == 0x2 == 2 + value: 4 multiples of read access time + WRITE_BL_LEN: max. write data block length + raw: 0b1010 == 0xa == 10 + value: 1024 bytes + WRITE_BL_PARTIAL: partial blocks for write allowed + raw: 0b0 == 0x0 == 0 + value: False + FILE_FORMAT_GRP: file format group + raw: 0b0 == 0x0 == 0 + COPY: copy flag + raw: 0b0 == 0x0 == 0 + value: False + PERM_WRITE_PROTECT: permanent write protection + raw: 0b0 == 0x0 == 0 + value: False + TMP_WRITE_PROTECT: temporary write protection + raw: 0b0 == 0x0 == 0 + value: False + FILE_FORMAT: file format + raw: 0b000 == 0x0 == 0 + enum: Hard disk-like file system with partition table + CRC + raw: 0b0000000 == 0x0 == 0 +SCR Register Value: 0225800000000000 + SCR_STRUCTURE: SCR Structure + raw: 0b0000 == 0x0 == 0 + enum: 1.0 + SD_SPEC: SD Memory Card - Spec. Version + raw: 0b0010 == 0x2 == 2 + enum: 2.00 or 3.0X + DATA_STAT_AFTER_ERASE: data status after erase + raw: 0b0 == 0x0 == 0 + value: False + SD_SECURITY: CPRM Security Support + raw: 0b010 == 0x2 == 2 + enum: SDSC Card (Security Version 1.01) + SD_BUS_WIDTHS: DAT Bus widths supported + raw: 0b0101 == 0x5 == 5 + bits: 1 bit, 4 bit + SD_SPEC3: Spec. Version 3.00 or higher + raw: 0b1 == 0x1 == 1 + EX_SECURITY: Extended Security Support + raw: 0b0000 == 0x0 == 0 + RESERVED + raw: 0b000000000 == 0x0 == 0 + CMD_SUPPORT: Command Support bits + raw: 0b00 == 0x0 == 0 + bits: + RESERVED_MFG + raw: 0b00000000000000000000000000000000 == 0x0 == 0 +CID Register Value: 744a605553442020104182bbc7010600 + MID: Manufacturer ID + raw: 0b01110100 == 0x74 == 116 + enum: Transcend + OID: OEM/Application ID + raw: 0b0100101001100000 == 0x4a60 == 19040 + value: J` + PNM: Product name + raw: 0b0101010101010011010001000010000000100000 == 0x5553442020 == 366469193760 + value: USD + PRV: Product revision + raw: 0b00010000 == 0x10 == 16 + value: 1.0 + PSN: Product serial number + raw: 0b01000001100000101011101111000111 == 0x4182bbc7 == 1099086791 + value: 1099086791 + RESERVED + raw: 0b0000 == 0x0 == 0 + MDT_Y: Manufacturing date (year) + raw: 0b00010000 == 0x10 == 16 + value: 2016 + MDT_M: Manufacturing date (month) + raw: 0b0110 == 0x6 == 6 + value: 7 + CRC: CRC7 checksum + raw: 0b0000000 == 0x0 == 0 + NU1: not used, always 1 + raw: 0b0 == 0x0 == 0 diff --git a/tests/reference/9f5449303030303000a1114bb5011400.text b/tests/reference/9f5449303030303000a1114bb5011400.text new file mode 100644 index 0000000..1014c24 --- /dev/null +++ b/tests/reference/9f5449303030303000a1114bb5011400.text @@ -0,0 +1,128 @@ +CSD_20 Register Value: 400e00325b5900003b877f800a400000 + CSD_STRUCTURE: CSD structure + raw: 0b01 == 0x1 == 1 + enum: 2.0 + TAAC: data read access-time-1 + raw: 0b00001110 == 0xe == 14 + decoded: (1.0, '1ms') + value: 1000000.0 ns + NSAC: data read access-time-2 + raw: 0b00000000 == 0x0 == 0 + value: 0 CLK cycles + TRAN_SPEED: max. data transfer rate + raw: 0b00110010 == 0x32 == 50 + decoded: (2.5, '10Mbit/s') + value: 25000000.0 bit/s + CCC: card command classes + raw: 0b010110110101 == 0x5b5 == 1461 + bits: 0, 2, 4, 5, 7, 8, 10 + READ_BL_LEN: max. read data block length + raw: 0b1001 == 0x9 == 9 + value: 512 bytes + READ_BL_PARTIAL: partial blocks for read allowed + raw: 0b0 == 0x0 == 0 + value: False + WRITE_BLK_MISALIGN: write block misalignment allowed + raw: 0b0 == 0x0 == 0 + value: False + READ_BLK_MISALIGN: read block misalignment allowed + raw: 0b0 == 0x0 == 0 + value: False + DSR_IMP: driver stage register implemented + raw: 0b0 == 0x0 == 0 + value: False + C_SIZE: device size + raw: 0b0000000011101110000111 == 0x3b87 == 15239 + value: 7990149120 bytes + ERASE_BLK_EN: erase single block enable + raw: 0b1 == 0x1 == 1 + value: True + SECTOR_SIZE: erase sector size + raw: 0b1111111 == 0x7f == 127 + value: 128 write blocks + WP_GRP_SIZE: write protect group size + raw: 0b0000000 == 0x0 == 0 + value: 1 erase sectors + WP_GRP_ENABLE: write protect group enable + raw: 0b0 == 0x0 == 0 + value: False + R2W_FACTOR: write speed factor + raw: 0b010 == 0x2 == 2 + value: 4 multiples of read access time + WRITE_BL_LEN: max. write data block length + raw: 0b1001 == 0x9 == 9 + value: 512 bytes + WRITE_BL_PARTIAL: partial blocks for write allowed + raw: 0b0 == 0x0 == 0 + value: False + FILE_FORMAT_GRP: file format group + raw: 0b0 == 0x0 == 0 + COPY: copy flag + raw: 0b0 == 0x0 == 0 + value: False + PERM_WRITE_PROTECT: permanent write protection + raw: 0b0 == 0x0 == 0 + value: False + TMP_WRITE_PROTECT: temporary write protection + raw: 0b0 == 0x0 == 0 + value: False + FILE_FORMAT: file format + raw: 0b000 == 0x0 == 0 + enum: Hard disk-like file system with partition table + CRC + raw: 0b0000000 == 0x0 == 0 +SCR Register Value: 02b5800200000000 + SCR_STRUCTURE: SCR Structure + raw: 0b0000 == 0x0 == 0 + enum: 1.0 + SD_SPEC: SD Memory Card - Spec. Version + raw: 0b0010 == 0x2 == 2 + enum: 2.00 or 3.0X + DATA_STAT_AFTER_ERASE: data status after erase + raw: 0b1 == 0x1 == 1 + value: True + SD_SECURITY: CPRM Security Support + raw: 0b011 == 0x3 == 3 + enum: SDHC Card (Security Version 2.00) + SD_BUS_WIDTHS: DAT Bus widths supported + raw: 0b0101 == 0x5 == 5 + bits: 1 bit, 4 bit + SD_SPEC3: Spec. Version 3.00 or higher + raw: 0b1 == 0x1 == 1 + EX_SECURITY: Extended Security Support + raw: 0b0000 == 0x0 == 0 + RESERVED + raw: 0b000000000 == 0x0 == 0 + CMD_SUPPORT: Command Support bits + raw: 0b10 == 0x2 == 2 + bits: Set Block Count (CMD23) + RESERVED_MFG + raw: 0b00000000000000000000000000000000 == 0x0 == 0 +CID Register Value: 9f5449303030303000a1114bb5011400 + MID: Manufacturer ID + raw: 0b10011111 == 0x9f == 159 + enum: Kingston SD + OID: OEM/Application ID + raw: 0b0101010001001001 == 0x5449 == 21577 + value: TI + PNM: Product name + raw: 0b0011000000110000001100000011000000110000 == 0x3030303030 == 206966894640 + value: 00000 + PRV: Product revision + raw: 0b00000000 == 0x0 == 0 + value: 0.0 + PSN: Product serial number + raw: 0b10100001000100010100101110110101 == 0xa1114bb5 == 2702265269 + value: 2702265269 + RESERVED + raw: 0b0000 == 0x0 == 0 + MDT_Y: Manufacturing date (year) + raw: 0b00010001 == 0x11 == 17 + value: 2017 + MDT_M: Manufacturing date (month) + raw: 0b0100 == 0x4 == 4 + value: 5 + CRC: CRC7 checksum + raw: 0b0000000 == 0x0 == 0 + NU1: not used, always 1 + raw: 0b0 == 0x0 == 0 diff --git a/tests/test_sd_regs.py b/tests/test_sd_regs.py index 44b68dd..b11f9c7 100644 --- a/tests/test_sd_regs.py +++ b/tests/test_sd_regs.py @@ -27,3 +27,19 @@ def test_decode(cid): res = json.loads(json.dumps(res)) assert res == ref + + +@pytest.mark.parametrize("cid", REFS) +def test_to_text(cid): + ref_name_json = os.path.join(os.path.dirname(__file__), "reference", f"{cid}.json") + ref_name_text = os.path.join(os.path.dirname(__file__), "reference", f"{cid}.text") + ref_json = json.load(open(ref_name_json)) + ref_text = open(ref_name_text).read().split("\n")[:-1] + + res = [] + + res += decode_csd(ref_json["csd"]["raw"]).get_text_report() + res += SCR(ref_json["scr"]["raw"]).get_text_report() + res += CID(ref_json["cid"]["raw"]).get_text_report() + + assert res == ref_text From f7726832839186331e447e4adb38386fba298d6a Mon Sep 17 00:00:00 2001 From: Jan Luebbe Date: Mon, 18 Dec 2023 20:33:19 +0100 Subject: [PATCH 3/4] Add pytest workflow for GitHub Actions Signed-off-by: Jan Luebbe --- .github/workflows/pytest.yml | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 .github/workflows/pytest.yml diff --git a/.github/workflows/pytest.yml b/.github/workflows/pytest.yml new file mode 100644 index 0000000..ae3ed0a --- /dev/null +++ b/.github/workflows/pytest.yml @@ -0,0 +1,17 @@ +name: pytest + +on: [push, pull_request] + +jobs: + python-pytest: + name: Python pytest + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Install python dependencies + run: | + python -m pip install --upgrade pip + python -m pip install --upgrade pytest + - name: Run pytest + run: | + python -m pytest -vv From c962e73c3ee04c26d2f4ad0c2eabcb70ec627881 Mon Sep 17 00:00:00 2001 From: Jan Luebbe Date: Tue, 19 Dec 2023 16:52:16 +0100 Subject: [PATCH 4/4] tests: add script to regenerate the reference output Signed-off-by: Jan Luebbe --- tests/reference/regenerate.sh | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100755 tests/reference/regenerate.sh diff --git a/tests/reference/regenerate.sh b/tests/reference/regenerate.sh new file mode 100755 index 0000000..b9458e3 --- /dev/null +++ b/tests/reference/regenerate.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +set -ex + +self="$(realpath "${0}")" && selfdir="$(dirname "${self}")" + +cd "${selfdir}" + +for json in *.json; do + text="$(basename -s .json "${json}").text" + ../../usbsdmux/sd_regs.py --json "${json}" > "${json}.tmp" + ../../usbsdmux/sd_regs.py "${json}.tmp" > "${text}.tmp" + mv "${json}.tmp" "${json}" + mv "${text}.tmp" "${text}" +done