#!/usr/bin/env python3 # -*- coding: utf-8 -*- import os APPLICATION_NAME = 'SD and MMC Block Device Attributes Reader' APPLICATION_VERSION = 0.02 SEPARATOR_LENGTH = 40 SYS_DEVICE = '/sys/block/mmcblk0/device' # https://mjmwired.net/kernel/Documentation/mmc/mmc-dev-attrs.txt SD_MMC_ATTRS = [ 'cid', # Card Identification Register 'csd', # Card Specific Data Register 'scr', # SD Card Configuration Register (SD only) 'date', # Manufacturing Date (from CID Register) 'fwrev', # Firmware/Product Revision (from CID Register) (SD and MMCv1 only) 'hwrev', # Hardware/Product Revision (from CID Register) (SD and MMCv1 only) 'manfid', # Manufacturer ID (from CID Register) 'name', # Product Name (from CID Register) 'oemid', # OEM/Application ID (from CID Register) 'prv', # Product Revision (from CID Register) (SD and MMCv4 only) 'serial', # Product Serial Number (from CID Register) 'erase_size', # Erase group size 'preferred_erase_size', # Preferred erase size 'raw_rpmb_size_mult', # RPMB partition size 'rel_sectors', # Reliable write sector count 'ocr', # Operation Conditions Register 'dsr', # Driver Stage Register 'cmdq_en', # Command Queue enabled: 1 => enabled, 0 => not enabled ] def cat(filename): with open(filename) as fp: result = fp.read() return result.replace('\n', '\\n') def main(): print('\n' + '=' * 5 + f' {APPLICATION_NAME} Ver {APPLICATION_VERSION} ' + '=' * 5) print(f'device: {SYS_DEVICE}') print('-' * SEPARATOR_LENGTH) for index, attr in enumerate(SD_MMC_ATTRS): path = os.path.join(SYS_DEVICE, attr) if os.path.isfile(path): if attr == 'oemid': hex_string = cat(path) ascii_string = bytes.fromhex(hex_string.replace('\\n', '')[2:]).decode('ASCII') print(f'{attr}: {hex_string} (\'{ascii_string}\')') else: print(f'{attr}: {cat(path)}') else: print(f'{attr}: None') print('-' * SEPARATOR_LENGTH) if __name__ == '__main__': main()