[FrontPage] [TitleIndex] [WordIndex

SDCard & Associated Pi Tracking

(usdcardlog and cid_decoder.c)



GNU Autotools configuration files etc.

pi@raspiP3Bplus18:~/usdcard_tools-0.0 $ cat ./configure.ac 
#                                               -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.

AC_PREREQ([2.69])
AC_INIT([usdcard_tools], [0.0], [trevor.gowen@blueyonder.co.uk])
#AC_CONFIG_SRCDIR([common/parsel.c])
AC_CONFIG_SRCDIR([config.h.in])
# Platform & System ...
AC_CANONICAL_BUILD
AC_CANONICAL_HOST
AM_INIT_AUTOMAKE([-Wall foreign]) 
AC_CONFIG_HEADERS([config.h])

# Checks for programs.
AC_PROG_CC

# Checks for libraries.
AC_PROG_RANLIB

# Checks for header files.
AC_CHECK_HEADERS([stdlib.h string.h unistd.h])

# Checks for typedefs, structures, and compiler characteristics.
AC_TYPE_SSIZE_T

# Checks for library functions.

AC_CONFIG_FILES([Makefile
                 common/Makefile
                 src/Makefile])
AC_OUTPUT

### $Log: configure.ac,v $
### Revision 1.3  2019/02/05 23:41:45  pi
### SCM Version 0.01 build working here
###
### Revision 1.2  2019/02/05 23:23:13  pi
### Duplicate line removed
###
### Revision 1.1  2019/02/05 23:18:58  pi
### Initial revision
###
#
#
#

pi@raspiP3Bplus18:~/usdcard_tools-0.0 $ cat ./Makefile.am 
## Process this file with automake to produce Makefile.in
SUBDIRS = common src
EXTRA_DIST = scripts

### $Log: Makefile.am,v $
### Revision 1.1  2019/02/05 22:51:02  pi
### Initial revision
###
#
#

pi@raspiP3Bplus18:~/usdcard_tools-0.0/common $ cat ./Makefile.am 
## Process this file with automake to produce Makefile.in
noinst_LIBRARIES = libparsel.a 
libparsel_a_SOURCES = parsel.h parsel.c

### $Log: Makefile.am,v $
### Revision 1.1  2019/02/05 23:06:29  pi
### Initial revision
###
#
#
#

pi@raspiP3Bplus18:~/usdcard_tools-0.0/src $ cat ./Makefile.am 
## Process this file with automake to produce Makefile.in
bin_PROGRAMS = cid_decoder
cid_decoder_SOURCES = ../common/rcs_scm.h cid_decoder.c
cid_decoder_CPPFLAGS = -I$(top_srcdir)/common
cid_decoder_LDADD = ../common/libparsel.a 

### $Log: Makefile.am,v $
### Revision 1.1  2019/02/05 22:57:46  pi
### Initial revision
###
#
#
#

Simple Script

(usdcardlog)

pi@raspiP3Bplus18:~/usdcard_tools-0.0/scripts $ cat usdcardlog 
#!/bin/bash
date
echo "CID:"
cat /sys/block/mmcblk0/device/cid
df / -H
uname -a
cat /etc/os-release
gpio -v
gpio readall

# $Log: usdcardlog,v $
# Revision 1.1  2019/02/05 22:46:41  pi
# Initial revision
#
#
#

Example Output

pi@raspiP3Bplus18:~/usdcard_tools-0.0 $ ./scripts/usdcardlog 
Wed 13 Feb 16:30:36 UTC 2019
CID:
02544d53413136472225498b4500f7bb
Filesystem      Size  Used Avail Use% Mounted on
/dev/root        16G  7.7G  6.9G  54% /
Linux raspiP3Bplus18 4.14.79-v7+ #1159 SMP Sun Nov 4 17:50:20 GMT 2018 armv7l GNU/Linux
PRETTY_NAME="Raspbian GNU/Linux 9 (stretch)"
NAME="Raspbian GNU/Linux"
VERSION_ID="9"
VERSION="9 (stretch)"
ID=raspbian
ID_LIKE=debian
HOME_URL="http://www.raspbian.org/"
SUPPORT_URL="http://www.raspbian.org/RaspbianForums"
BUG_REPORT_URL="http://www.raspbian.org/RaspbianBugs"
gpio version: 2.46
Copyright (c) 2012-2018 Gordon Henderson
This is free software with ABSOLUTELY NO WARRANTY.
For details type: gpio -warranty

Raspberry Pi Details:
  Type: Pi 3+, Revision: 03, Memory: 1024MB, Maker: Sony 
  * Device tree is enabled.
  *--> Raspberry Pi 3 Model B Plus Rev 1.3
  * This Raspberry Pi supports user-level GPIO access.
 +-----+-----+---------+------+---+---Pi 3+--+---+------+---------+-----+-----+
 | BCM | wPi |   Name  | Mode | V | Physical | V | Mode | Name    | wPi | BCM |
 +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+
 |     |     |    3.3v |      |   |  1 || 2  |   |      | 5v      |     |     |
 |   2 |   8 |   SDA.1 | ALT0 | 1 |  3 || 4  |   |      | 5v      |     |     |
 |   3 |   9 |   SCL.1 | ALT0 | 1 |  5 || 6  |   |      | 0v      |     |     |
 |   4 |   7 | GPIO. 7 |   IN | 1 |  7 || 8  | 1 | ALT5 | TxD     | 15  | 14  |
 |     |     |      0v |      |   |  9 || 10 | 1 | ALT5 | RxD     | 16  | 15  |
 |  17 |   0 | GPIO. 0 |   IN | 0 | 11 || 12 | 0 | IN   | GPIO. 1 | 1   | 18  |
 |  27 |   2 | GPIO. 2 |   IN | 0 | 13 || 14 |   |      | 0v      |     |     |
 |  22 |   3 | GPIO. 3 |   IN | 0 | 15 || 16 | 0 | IN   | GPIO. 4 | 4   | 23  |
 |     |     |    3.3v |      |   | 17 || 18 | 0 | IN   | GPIO. 5 | 5   | 24  |
 |  10 |  12 |    MOSI | ALT0 | 0 | 19 || 20 |   |      | 0v      |     |     |
 |   9 |  13 |    MISO | ALT0 | 0 | 21 || 22 | 0 | IN   | GPIO. 6 | 6   | 25  |
 |  11 |  14 |    SCLK | ALT0 | 0 | 23 || 24 | 1 | OUT  | CE0     | 10  | 8   |
 |     |     |      0v |      |   | 25 || 26 | 1 | OUT  | CE1     | 11  | 7   |
 |   0 |  30 |   SDA.0 |   IN | 1 | 27 || 28 | 1 | IN   | SCL.0   | 31  | 1   |
 |   5 |  21 | GPIO.21 |   IN | 1 | 29 || 30 |   |      | 0v      |     |     |
 |   6 |  22 | GPIO.22 |   IN | 1 | 31 || 32 | 0 | IN   | GPIO.26 | 26  | 12  |
 |  13 |  23 | GPIO.23 |   IN | 0 | 33 || 34 |   |      | 0v      |     |     |
 |  19 |  24 | GPIO.24 |   IN | 0 | 35 || 36 | 0 | IN   | GPIO.27 | 27  | 16  |
 |  26 |  25 | GPIO.25 |   IN | 0 | 37 || 38 | 0 | IN   | GPIO.28 | 28  | 20  |
 |     |     |      0v |      |   | 39 || 40 | 0 | IN   | GPIO.29 | 29  | 21  |
 +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+
 | BCM | wPi |   Name  | Mode | V | Physical | V | Mode | Name    | wPi | BCM |
 +-----+-----+---------+------+---+---Pi 3+--+---+------+---------+-----+-----+

Self-generated, brief Program Help

(cid_decoder.c)

pi@raspiP4B4-32GbI:~/pi_tools_etc/usdcard_tools-0.0 $ ./src/cid_decoder 
cid_decoder.c Version 0.01 {Exp}, [12/06/2019], (c) F_Trevor_Gowen
                <--| Package usdcard_tools_0.0 |-->
Usage cid_decoder  [Options]
Options: -a arg_filename[.arg],
         -E        {Echo command-line arguments},
         -LX       {Log eXtracted cid (implies -X)},
         -oldCID   {decode an old CID in rawcid file},
         -rawCID s {decode the rawCID string s},
         -tag s    {TAG the Log filename with string s},
         -Q        {Quiet - default},
         -V        {Verbose},
         -X        {eXecute decode operation}.

Code Snippits

(Structures etc.)

typedef struct
{
  char rawcid[33];  /* 32-char Hex String */
  char mid;         /* Binary */
  char oid[2];      /* ASCII  */
  char pnm[5];      /* ASCII  */
  char prv;         /* 2xBCD  */
  uint psn;         /* Binary */
  char rsvd;        /* ????   */
  char mdt[2];      /* 3xBCD  */
  char crc;         /* Binary */
} sdcard_cid;

sdcard_cid current_cid;

/* SD Card block/device strings etc. */
static char MMC_CID[] = "/sys/block/mmcblk0/device/cid";
static char RawcidInfile[] = "rawcid";
char cidlogfile[FN_LEN];
FILE *RawcidInfn,*LogcidOutfn;

void init_cid(sdcard_cid *cid)
{
  /* INITialise CID with example (SanDisk 2003) data */
  strncpy((*cid).rawcid, "03534453443030383000000000013201", 32);
  (*cid).mid    = 0x03;
  (*cid).oid[0] = 0x53;
  (*cid).oid[1] = 0x44;
  (*cid).pnm[0] = 0x53;
  (*cid).pnm[1] = 0x44;
  (*cid).pnm[2] = 0x30;
  (*cid).pnm[3] = 0x30;
  (*cid).pnm[4] = 0x38;
  (*cid).prv    = 0x30;
  (*cid).psn    = 0;    /* Dummy value */
  (*cid).rsvd   = 0;    /* Dummy value */
  (*cid).mdt[0] = 19;   /* 2019        */
  (*cid).mdt[1] = 2;    /* February    */
  (*cid).crc    = 1;    /* Dummy value (0) + 1 for the NIU bit */
}

void echo_cid_status(sdcard_cid cid)
{
  char a,b;
  int y;
  printf("sdcard cid status:\n");
  printf("RAWCID %s\n", cid.rawcid);
  printf("MID    0x%02x\n", cid.mid);
  printf("OID    0x%02x%2x (%c%c)\n", cid.oid[0], cid.oid[1], cid.oid[0], cid.oid[1]);
  printf("PNM    0x%02x%2x%2x%2x%2x (%c%c%c%c%c)\n",
         cid.pnm[0], cid.pnm[1], cid.pnm[2], cid.pnm[3], cid.pnm[4],
         cid.pnm[0], cid.pnm[1], cid.pnm[2], cid.pnm[3], cid.pnm[4]);
  a = (cid.prv & 0xf0) / 16;
  b = (cid.prv & 0x0f);
  printf("PRV    0x%02x (%1d.%1d)\n", cid.prv, a, b);
  printf("PSN    0x%08x\n", cid.psn);
  printf("RSVD   0x%01x\n", cid.rsvd);
  y = 2000 + cid.mdt[0];
  printf("MDT    0x%02x%1x (%1d/%4d)\n", cid.mdt[0], cid.mdt[1], cid.mdt[1], y);
  printf("CRC+1  0x%02x\n", cid.crc);
}

Examples

Externally Acquired Raw CID

pi@raspiP3Bplus18:~/pi_tools_etc/usdcard_tools-0.0 $ ./src/cid_decoder -rawCID 035344534331364780c50a158f013101 -X
cid_decoder.c Version 0.01 {Exp}, [23/05/2019], (c) F_Trevor_Gowen
                <--| Package usdcard_tools_0.0 |-->
<cid_decoder.arg>       fopen: No such file or directory
cid_decoder.arg not found
Initialising cid ...
grawcid = 035344534331364780c50a158f013101
raspiP3Bplus18 sdcard cid status:
RAWCID 035344534331364780c50a158f013101
MID    0x03
OID    0x5344 (SD)
PNM    0x5343313647 (SC16G)
PRV    0x80 (8.0)
PSN    0xc50a158f
RSVD   0x0
MDT    0x131 (1/2019)
CRC+1  0x01

raspiP3Bplus18

uSDHC card Boot

pi@raspiP3Bplus18:~/usdcard_tools-0.0 $ ./src/cid_decoder -X
cid_decoder.c Version 0.01 {Exp}, [12/02/2019], (c) F_Trevor_Gowen
                <--| Package usdcard_tools_0.0 |-->
<cid_decoder.arg>       fopen: No such file or directory
cid_decoder.arg not found
Initialising cid ...
Opened rawcid ...
02544d53413136472225498b4500f7bb
raspiP3Bplus18 sdcard cid status:
RAWCID 02544d53413136472225498b4500f7bb
MID    0x02
OID    0x544d (TM)
PNM    0x5341313647 (SA16G)
PRV    0x22 (2.2)
PSN    0x25498b45
RSVD   0x0
MDT    0x0f7 (7/2015)
CRC+1  0xbb

USB Boot

(using -tag s option, s = "x-RISCOS")

pi@raspiP4B4-32GbI:~/pi_tools_etc/usdcard_tools-0.0 $ cat raspiP3BplusUSB_x-RISCOS_cid.log
raspiP3BplusUSB sdcard cid status:
RAWCID 02544d5341303447049c7d74e000995b
MID    0x02
OID    0x544d (TM)
PNM    0x5341303447 (SA04G)
PRV    0x04 (0.4)
PSN    0x9c7d74e0
RSVD   0x0
MDT    0x099 (9/2009)
CRC+1  0x5b

raspi3Aplus2

pi@raspi3Aplus2:~/usdcard_tools-0.0 $ ./src/cid_decoder -X
cid_decoder.c Version 0.01 {Exp}, [12/02/2019], (c) F_Trevor_Gowen
                <--| Package usdcard_tools_0.0 |-->
<cid_decoder.arg>       fopen: No such file or directory
cid_decoder.arg not found
Initialising cid ...
Opened rawcid ...
1b534d303030303010148357890102b5
raspi3Aplus2 sdcard cid status:
RAWCID 1b534d303030303010148357890102b5
MID    0x1b
OID    0x534d (SM)
PNM    0x3030303030 (00000)
PRV    0x10 (1.0)
PSN    0x14835789
RSVD   0x0
MDT    0x102 (2/2016)
CRC+1  0xb5

raspiP2BJamesA

(On which the MoinMoin wiki which exports these pages is run)

pi@raspiP2BJamesA:~/usdcard_tools-0.0 $ ./src/cid_decoder -X
cid_decoder.c Version 0.01 {Exp}, [12/02/2019], (c) F_Trevor_Gowen
                <--| Package usdcard_tools_0.0 |-->
<cid_decoder.arg>       fopen: No such file or directory
cid_decoder.arg not found
Initialising cid ...
Opened rawcid ...
035344534c303847800e66298700e7e5
raspiP2BJamesA sdcard cid status:
RAWCID 035344534c303847800e66298700e7e5
MID    0x03
OID    0x5344 (SD)
PNM    0x534c303847 (SL08G)
PRV    0x80 (8.0)
PSN    0x0e662987
RSVD   0x0
MDT    0x0e7 (7/2014)
CRC+1  0xe5

raspiP4B4-32GbI

pi@raspiP4B4-32GbI:~/pi_tools_etc/usdcard_tools-0.0 $ ./src/cid_decoder -LX
cid_decoder.c Version 0.01 {Exp}, [12/06/2019], (c) F_Trevor_Gowen
                <--| Package usdcard_tools_0.0 |-->
<cid_decoder.arg>       fopen: No such file or directory
cid_decoder.arg not found
Initialising cid ...
Logging to ... raspiP4B4-32GbI_cid.log
Executing 'cat /sys/block/mmcblk0/device/cid > rawcid' ...
Opened rawcid ...
824a544e4361726410218182d900dc00
raspiP4B4-32GbI sdcard cid status:
RAWCID 824a544e4361726410218182d900dc00
MID    0x82
OID    0x4a54 (JT)
PNM    0x4e43617264 (NCard)
PRV    0x10 (1.0)
PSN    0x218182d9
RSVD   0x0
MDT    0x0dc (12/2013)
CRC+1  0x00

Download a "Snapshot" tarball

NB: This may include current "work-in-progress" that is not yet documented here!

Download usdcard_tools-0.0.tar.gz (2019-06-28 18:33:10, 125.3 KB)



2020-07-16 22:10