fork download
  1. #include <stdio.h>
  2.  
  3. /*
  4. NAND Flash Information Dumper
  5. ===============================
  6. Created on July 12, 2020 by Jason Gin (ripitapart.com).
  7. Made to display a specific NAND Flash ID code and corresponding parameter table,
  8. but the data can easily be replaced with other Flash chips' data if desired.
  9. */
  10.  
  11. int main(void) {
  12. printf("NAND Flash Info & Parameter Page Dump:\n");
  13. printf("SanDisk High Endurance 128GB microSDXC Card\n");
  14. printf("Blog post for more info: wp.me/p21X5Z-vp or visit ripitapart.com\n\n");
  15.  
  16. // Raw NAND info and parameter page data from SanDisk High Endurance 128GB microSDXC card
  17. unsigned char nand_flash_id[6] = { 0x45, 0x48, 0x9A, 0xB3, 0x7E, 0x72 };
  18. // NOTE: Real parameter page contains 4128 bytes but is just the same repeating data
  19. unsigned char parameter_page_data[512] =
  20. {
  21. 0x53,0x4E,0x44,0x4B,0x53,0x4E,0x44,0x4B,0x53,0x4E,0x44,0x4B,0x53,0x4E,0x44,0x4B,
  22. 0x53,0x4E,0x44,0x4B,0x53,0x4E,0x44,0x4B,0x53,0x4E,0x44,0x4B,0x53,0x4E,0x44,0x4B,
  23. 0x08,0x08,0x00,0x08,0x06,0x20,0x00,0x02,0x01,0x48,0x9A,0xB3,0x00,0x05,0x08,0x41,
  24. 0x48,0x63,0x6A,0x08,0x08,0x00,0x08,0x06,0x20,0x00,0x02,0x01,0x48,0x9A,0xB3,0x00,
  25. 0x05,0x08,0x41,0x48,0x63,0x6A,0x08,0x08,0x00,0x08,0x06,0x20,0x00,0x02,0x01,0x48,
  26. 0x9A,0xB3,0x00,0x05,0x08,0x41,0x48,0x63,0x6A,0x08,0x08,0x00,0x08,0x06,0x20,0x00,
  27. 0x02,0x01,0x48,0x9A,0xB3,0x00,0x05,0x08,0x41,0x48,0x63,0x6A,0x08,0x08,0x00,0x08,
  28. 0x06,0x20,0x00,0x02,0x01,0x48,0x9A,0xB3,0x00,0x05,0x08,0x41,0x48,0x63,0x6A,0x08,
  29. 0x08,0x00,0x08,0x06,0x20,0x00,0x02,0x01,0x48,0x9A,0xB3,0x00,0x05,0x08,0x41,0x48,
  30. 0x63,0x6A,0x08,0x08,0x00,0x08,0x06,0x20,0x00,0x02,0x01,0x48,0x9A,0xB3,0x00,0x05,
  31. 0x08,0x41,0x48,0x63,0x6A,0x08,0x08,0x00,0x08,0x06,0x20,0x00,0x02,0x01,0x48,0x9A,
  32. 0xB3,0x00,0x05,0x08,0x41,0x48,0x63,0x6A,0x08,0x08,0x00,0x08,0x06,0x20,0x00,0x02,
  33. 0x01,0x48,0x9A,0xB3,0x00,0x05,0x08,0x41,0x48,0x63,0x6A,0x08,0x08,0x00,0x08,0x06,
  34. 0x20,0x00,0x02,0x01,0x48,0x9A,0xB3,0x00,0x05,0x08,0x41,0x48,0x63,0x6A,0x08,0x08,
  35. 0x00,0x08,0x06,0x20,0x00,0x02,0x01,0x48,0x9A,0xB3,0x00,0x05,0x08,0x41,0x48,0x63,
  36. 0x6A,0x08,0x08,0x00,0x08,0x06,0x20,0x00,0x02,0x01,0x48,0x9A,0xB3,0x00,0x05,0x08,
  37. 0x41,0x48,0x63,0x6A,0x08,0x08,0x00,0x08,0x06,0x20,0x00,0x02,0x01,0x48,0x9A,0xB3,
  38. 0x00,0x05,0x08,0x41,0x48,0x63,0x6A,0x08,0x08,0x00,0x08,0x06,0x20,0x00,0x02,0x01,
  39. 0x48,0x9A,0xB3,0x00,0x05,0x08,0x41,0x48,0x63,0x6A,0x08,0x08,0x00,0x08,0x06,0x20,
  40. 0x00,0x02,0x01,0x48,0x9A,0xB3,0x00,0x05,0x08,0x41,0x48,0x63,0x6A,0x08,0x08,0x00,
  41. 0x08,0x06,0x20,0x00,0x02,0x01,0x48,0x9A,0xB3,0x00,0x05,0x08,0x41,0x48,0x63,0x6A,
  42. 0x08,0x08,0x00,0x08,0x06,0x20,0x00,0x02,0x01,0x48,0x9A,0xB3,0x00,0x05,0x08,0x41,
  43. 0x48,0x63,0x6A,0x08,0x08,0x00,0x08,0x06,0x20,0x00,0x02,0x01,0x48,0x9A,0xB3,0x00,
  44. 0x05,0x08,0x41,0x48,0x63,0x6A,0x08,0x08,0x00,0x08,0x06,0x20,0x00,0x02,0x01,0x48,
  45. 0x9A,0xB3,0x00,0x05,0x08,0x41,0x48,0x63,0x6A,0x08,0x08,0x00,0x08,0x06,0x20,0x00,
  46. 0x02,0x01,0x48,0x9A,0xB3,0x00,0x05,0x08,0x41,0x48,0x63,0x6A,0x08,0x08,0x00,0x08,
  47. 0x06,0x20,0x00,0x02,0x01,0x48,0x9A,0xB3,0x00,0x05,0x08,0x41,0x48,0x63,0x6A,0x08,
  48. 0x08,0x00,0x08,0x06,0x20,0x00,0x02,0x01,0x48,0x9A,0xB3,0x00,0x05,0x08,0x41,0x48,
  49. 0x63,0x6A,0x08,0x08,0x00,0x08,0x06,0x20,0x00,0x02,0x01,0x48,0x9A,0xB3,0x00,0x05,
  50. 0x08,0x41,0x48,0x63,0x6A,0x08,0x08,0x00,0x08,0x06,0x20,0x00,0x02,0x01,0x48,0x9A,
  51. 0xB3,0x00,0x05,0x08,0x41,0x48,0x63,0x6A,0x08,0x08,0x00,0x08,0x06,0x20,0x00,0x02,
  52. 0x01,0x48,0x9A,0xB3,0x00,0x05,0x08,0x41,0x48,0x63,0x6A,0x08,0x08,0x00,0x08,0x06
  53. };
  54.  
  55. // Create parameters for hex/ascii printout and print out Flash ID
  56. int bytes_per_row = 16;
  57. int total_rows = sizeof(parameter_page_data) / bytes_per_row;
  58.  
  59. int nand_flash_id_index = 0;
  60. printf("NAND Flash ID: ");
  61. for (nand_flash_id_index = 0; nand_flash_id_index < sizeof(nand_flash_id); nand_flash_id_index++)
  62. {
  63. printf("%.2X ", nand_flash_id[nand_flash_id_index]);
  64. }
  65. printf("\n\n");
  66.  
  67. printf("Parameter page contents:\n");
  68. printf("==========================\n");
  69. printf("Data array size = %d bytes\n",sizeof(parameter_page_data));
  70. printf("Bytes per row = %d\n",bytes_per_row);
  71. printf("Total rows = %d\n\n",total_rows);
  72.  
  73. // Print out parameter page in human-readable form
  74.  
  75. // Desired format:
  76. // Offset 00:01:02:03:04:05:06:07:08:09:0A:0B:0C:0D:0E:0F 0123456789ABCDEF
  77. // ------ --+--+--+--+--+--+--+--+--+--+--+--+--+--+--+-- ----------------
  78. // 0xHHHH HH HH HH HH HH HH HH HH HH HH HH HH HH HH HH HH AAAAAAAAAAAAAAAA
  79.  
  80. int row_index, column_index;
  81. int current_offset = 0;
  82.  
  83. printf("Offset 00:01:02:03:04:05:06:07:08:09:0A:0B:0C:0D:0E:0F 0123456789ABCDEF\n");
  84. printf("------ --+--+--+--+--+--+--+--+--+--+--+--+--+--+--+-- ----------------\n");
  85. for (row_index = 0; row_index < total_rows; row_index++)
  86. {
  87. // Byte offset in hex with padding
  88. printf("0x%.4X ", row_index * bytes_per_row);
  89.  
  90. // Hexadecimal representation
  91. current_offset = (row_index * column_index);
  92. for (column_index = 0; column_index < bytes_per_row; column_index++)
  93. {
  94. printf("%.2X ", parameter_page_data[current_offset]);
  95. current_offset++;
  96. }
  97.  
  98. // ASCII representation
  99. current_offset = (row_index * column_index);
  100. for (column_index = 0; column_index < bytes_per_row; column_index++)
  101. {
  102. if (parameter_page_data[current_offset] < 0x20) // less than 0x20 are ASCII control codes
  103. printf(".");
  104. else if ((parameter_page_data[current_offset] >= 0x20) && (parameter_page_data[current_offset] < 0x80))
  105. printf("%c", parameter_page_data[current_offset]);
  106. else // 0x80 or greater is not valid for UTF-8
  107. printf(".");
  108. current_offset++;
  109. }
  110. printf("\n");
  111. }
  112. return 0;
  113. }
  114.  
Success #stdin #stdout 0s 4252KB
stdin
Standard input is empty
stdout
NAND Flash Info & Parameter Page Dump:
SanDisk High Endurance 128GB microSDXC Card
Blog post for more info: wp.me/p21X5Z-vp or visit ripitapart.com

NAND Flash ID: 45 48 9A B3 7E 72 

Parameter page contents:
==========================
Data array size = 512 bytes
Bytes per row = 16
Total rows = 32

Offset 00:01:02:03:04:05:06:07:08:09:0A:0B:0C:0D:0E:0F 0123456789ABCDEF
------ --+--+--+--+--+--+--+--+--+--+--+--+--+--+--+-- ----------------
0x0000 53 4E 44 4B 53 4E 44 4B 53 4E 44 4B 53 4E 44 4B SNDKSNDKSNDKSNDK
0x0010 53 4E 44 4B 53 4E 44 4B 53 4E 44 4B 53 4E 44 4B SNDKSNDKSNDKSNDK
0x0020 08 08 00 08 06 20 00 02 01 48 9A B3 00 05 08 41 ..... ...H.....A
0x0030 48 63 6A 08 08 00 08 06 20 00 02 01 48 9A B3 00 Hcj..... ...H...
0x0040 05 08 41 48 63 6A 08 08 00 08 06 20 00 02 01 48 ..AHcj..... ...H
0x0050 9A B3 00 05 08 41 48 63 6A 08 08 00 08 06 20 00 .....AHcj..... .
0x0060 02 01 48 9A B3 00 05 08 41 48 63 6A 08 08 00 08 ..H.....AHcj....
0x0070 06 20 00 02 01 48 9A B3 00 05 08 41 48 63 6A 08 . ...H.....AHcj.
0x0080 08 00 08 06 20 00 02 01 48 9A B3 00 05 08 41 48 .... ...H.....AH
0x0090 63 6A 08 08 00 08 06 20 00 02 01 48 9A B3 00 05 cj..... ...H....
0x00A0 08 41 48 63 6A 08 08 00 08 06 20 00 02 01 48 9A .AHcj..... ...H.
0x00B0 B3 00 05 08 41 48 63 6A 08 08 00 08 06 20 00 02 ....AHcj..... ..
0x00C0 01 48 9A B3 00 05 08 41 48 63 6A 08 08 00 08 06 .H.....AHcj.....
0x00D0 20 00 02 01 48 9A B3 00 05 08 41 48 63 6A 08 08  ...H.....AHcj..
0x00E0 00 08 06 20 00 02 01 48 9A B3 00 05 08 41 48 63 ... ...H.....AHc
0x00F0 6A 08 08 00 08 06 20 00 02 01 48 9A B3 00 05 08 j..... ...H.....
0x0100 41 48 63 6A 08 08 00 08 06 20 00 02 01 48 9A B3 AHcj..... ...H..
0x0110 00 05 08 41 48 63 6A 08 08 00 08 06 20 00 02 01 ...AHcj..... ...
0x0120 48 9A B3 00 05 08 41 48 63 6A 08 08 00 08 06 20 H.....AHcj..... 
0x0130 00 02 01 48 9A B3 00 05 08 41 48 63 6A 08 08 00 ...H.....AHcj...
0x0140 08 06 20 00 02 01 48 9A B3 00 05 08 41 48 63 6A .. ...H.....AHcj
0x0150 08 08 00 08 06 20 00 02 01 48 9A B3 00 05 08 41 ..... ...H.....A
0x0160 48 63 6A 08 08 00 08 06 20 00 02 01 48 9A B3 00 Hcj..... ...H...
0x0170 05 08 41 48 63 6A 08 08 00 08 06 20 00 02 01 48 ..AHcj..... ...H
0x0180 9A B3 00 05 08 41 48 63 6A 08 08 00 08 06 20 00 .....AHcj..... .
0x0190 02 01 48 9A B3 00 05 08 41 48 63 6A 08 08 00 08 ..H.....AHcj....
0x01A0 06 20 00 02 01 48 9A B3 00 05 08 41 48 63 6A 08 . ...H.....AHcj.
0x01B0 08 00 08 06 20 00 02 01 48 9A B3 00 05 08 41 48 .... ...H.....AH
0x01C0 63 6A 08 08 00 08 06 20 00 02 01 48 9A B3 00 05 cj..... ...H....
0x01D0 08 41 48 63 6A 08 08 00 08 06 20 00 02 01 48 9A .AHcj..... ...H.
0x01E0 B3 00 05 08 41 48 63 6A 08 08 00 08 06 20 00 02 ....AHcj..... ..
0x01F0 01 48 9A B3 00 05 08 41 48 63 6A 08 08 00 08 06 .H.....AHcj.....