Advertisement
Guest User

Untitled

a guest
Nov 19th, 2019
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
GAMBAS 8.54 KB | None | 0 0
  1. ' Gambas module file
  2.  
  3. Private Enum UNKNOWN = 0,
  4.   DIRECT_RAMBUS = 1,
  5.   RAMBUS = 2,
  6.   FPM_DRAM = 3,
  7.   EDO = 4,
  8.   PIPELINED_NIBBLE = 5,
  9.   SDR_SDRAM = 6,
  10.   MULTIPLEXED_ROM = 7,
  11.   DDR_SGRAM = 8,
  12.   DDR_SDRAM = 9,
  13.   DDR2_SDRAM = 10,
  14.   DDR3_SDRAM = 11,
  15.   DDR4_SDRAM = 12,
  16.   N_RAM_TYPES = 13
  17.  
  18. Private RAM_TYPE As Integer = UNKNOWN
  19. Private ram_types As String[] = ["Unknown", "Direct Rambus",
  20.                                  "Rambus", "FPM DRAM", "EDO",
  21.                                  "Pipelined Nibble", "SDR SDRAM",
  22.                                  "Multiplexed ROM", "DDR SGRAM",
  23.                                  "DDR SDRAM", "DDR2 SDRAM",
  24.                                  "DDR3 SDRAM", "DDR4 SDRAM"]
  25.  
  26. Public Struct SPD_DATA
  27.   bytes[512] As Byte
  28.   dev[32] As String
  29.   spd_driver As Integer '/* 0 = eeprom, 1 = ee1004 */
  30.   spd_size As Integer
  31.   ram_type As String
  32.   vendor_bank As Integer
  33.   vendor_index As Integer
  34.   vendor_str As String
  35.   partno As String
  36.   '     const Vendor *vendor;
  37.   '     int dram_vendor_bank;
  38.   '     int dram_vendor_index;
  39.   '     const char *dram_vendor_str;
  40.   '     const Vendor *dram_vendor;
  41.   '     char partno[32];
  42.   form_factor As String
  43.   type_detail As String
  44.   '     dmi_mem_size size_MiB;
  45.   '     int spd_rev_major; // bytes[1] >> 4
  46.   '     int spd_rev_minor; // bytes[1] & 0xf
  47.   '     int week, year;
  48.   manufacturer_date As String
  49.   '     gboolean ddr4_no_ee1004;
  50.   '     struct dmi_mem_socket *dmi_socket;
  51.   '     int match_score
  52. End Struct
  53.  
  54. Public MEMORY_SUPPORTED_VOLTAGE As String
  55. Public MEMORY_SUPPORTED_CAS_LATENCIES As String
  56. Public MEMORY_THERMAL_SENSOR As String
  57.  
  58. Public Sub main()
  59.  
  60.   Dim fl As File
  61.   Dim bb As New Byte[256]
  62.   Dim AA As New Byte[256]
  63.   Dim s As String
  64.   Dim i As Integer
  65.   Dim bytes_used, bytes_free As Integer = 0
  66.   Dim spd_data As New SPD_DATA
  67.   Dim spd_size As Integer
  68.  
  69.   fl = Open "/sys/bus/i2c/drivers/eeprom/0-0052/eeprom" For Read
  70.  
  71.   bb.Read(fl, 0, Lof(fl))
  72.   'AA.Read(fl, 128, 140)
  73.   fl.Close
  74.  
  75.   spd_size = read_spd("/sys/bus/i2c/drivers/eeprom/0-0052/eeprom")
  76.   RAM_TYPE = decode_ram_type(bb)
  77.  
  78.   Select RAM_TYPE
  79.     Case SDR_SDRAM
  80.      
  81.     Case DDR_SDRAM
  82.      
  83.     Case DDR2_SDRAM
  84.      
  85.     Case DDR3_SDRAM
  86.       With spd_data
  87.         .ram_type = ram_types[RAM_TYPE]
  88.         .partno = decode_ddr3_part_number(bb)
  89.         '.vendor_str = decode_ddr3_manufacturer(bb, SPD_DATA.vendor_str)
  90.         .form_factor = decode_ddr3_module_type(bb)
  91.         .type_detail = decode_ddr3_module_speed(bb)
  92.         .manufacturer_date = decode_ddr3_module_date(bb)
  93.         MEMORY_SUPPORTED_VOLTAGE &= If(bb[6] = 4, "1.25V ", "") & If(bb[6] = 2, "1.35V ", "") & If(bb[6] = 1, "", "1.5V")
  94.        
  95.         'MEMORY_THERMAL_SENSOR = If(bytes[32] = )
  96.        
  97.         MEMORY_SUPPORTED_CAS_LATENCIES &= If(Mid$(Bin(bb[15], 8), 1, 1) = 1, "18T ", "")
  98.         MEMORY_SUPPORTED_CAS_LATENCIES &= If(Mid$(Bin(bb[15], 8), 2, 1) = 1, "17T ", "")
  99.         MEMORY_SUPPORTED_CAS_LATENCIES &= If(Mid$(Bin(bb[15], 8), 3, 1) = 1, "16T ", "")
  100.         MEMORY_SUPPORTED_CAS_LATENCIES &= If(Mid$(Bin(bb[15], 8), 4, 1) = 1, "15T ", "")
  101.         MEMORY_SUPPORTED_CAS_LATENCIES &= If(Mid$(Bin(bb[15], 8), 5, 1) = 1, "14T ", "")
  102.         MEMORY_SUPPORTED_CAS_LATENCIES &= If(Mid$(Bin(bb[15], 8), 6, 1) = 1, "13T ", "")
  103.         MEMORY_SUPPORTED_CAS_LATENCIES &= If(Mid$(Bin(bb[15], 8), 7, 1) = 1, "12T ", "")
  104.  
  105.         MEMORY_SUPPORTED_CAS_LATENCIES &= If(Mid$(Bin(bb[14], 8), 1, 1) = 1, "11T ", "")
  106.         MEMORY_SUPPORTED_CAS_LATENCIES &= If(Mid$(Bin(bb[14], 8), 2, 1) = 1, "10T ", "")
  107.         MEMORY_SUPPORTED_CAS_LATENCIES &= If(Mid$(Bin(bb[14], 8), 3, 1) = 1, "9T ", "")
  108.         MEMORY_SUPPORTED_CAS_LATENCIES &= If(Mid$(Bin(bb[14], 8), 4, 1) = 1, "8T ", "")
  109.         MEMORY_SUPPORTED_CAS_LATENCIES &= If(Mid$(Bin(bb[14], 8), 5, 1) = 1, "7T ", "")
  110.         MEMORY_SUPPORTED_CAS_LATENCIES &= If(Mid$(Bin(bb[14], 8), 6, 1) = 1, "6T ", "")
  111.         MEMORY_SUPPORTED_CAS_LATENCIES &= If(Mid$(Bin(bb[14], 8), 7, 1) = 1, "5T ", "")
  112.         MEMORY_SUPPORTED_CAS_LATENCIES &= If(Mid$(Bin(bb[14], 8), 8, 1) = 1, "4T ", "")
  113.  
  114.       End With
  115.      
  116.     Case DDR4_SDRAM
  117.      
  118.   End Select
  119.  
  120.   Print spd_data.ram_type
  121.   Print spd_data.partno
  122.   Print spd_data.form_factor
  123.   Print spd_data.type_detail
  124.   Print spd_data.manufacturer_date
  125.   Print MEMORY_SUPPORTED_VOLTAGE
  126.   Print MEMORY_SUPPORTED_CAS_LATENCIES
  127.   Print spd_size
  128.  
  129.  
  130.   For i = 0 To bb.Count - 1
  131.     '
  132.     If bb[i] Then
  133.       bytes_used += 1
  134.       'Print "RAW:" & bb[i] & "|HEX: " & Hex(bb[i]) & " |Bin: " & Bin(bb[i], 8) & " |Int: " & CInt(bb[i])
  135.     Else
  136.       bytes_free += 1
  137.       'Print "RAW:" & bb[i] & "|HEX: " & Hex(bb[i]) & " |Bin: " & Bin(bb[i], 8) & " |Int: " & CInt(bb[i])
  138.     Endif
  139.   Next
  140.  
  141.   Print Subst("Bytes Used: &1 Bytes Free: &2 Bytes Total: &3", bytes_used, bytes_free, bytes_free + bytes_used)
  142.   Print CInt(bb[32] & &H80&)
  143.   'Print bb[121] & &hF0&
  144.   's = Hex(bb[0], 2) & Hex(bb[1], 2) & Hex(bb[2], 2)
  145.   Print "RAW:" & bb[6] & "|HEX: " & Hex(bb[6]) & " |Bin: " & Bin(bb[6], 8) & " |Int: " & CInt(bb[6])
  146.   Print "RAW:" & bb[15] & "|HEX: " & Hex(bb[15]) & " |Bin: " & Bin(bb[15], 8) & " |Int: " & CInt(bb[15])
  147.   Print "RAW:" & bb[31] & "|HEX: " & Hex(bb[32]) & " |Bin: " & Bin(bb[32], 8) & " |Int: " & CInt(bb[32])
  148.   'Print Hex$(15, 3)
  149.   'Print "HEX: " & Hex(bb[2], 2) & " |Bin: " & Bin(bb[2], 8) & " |Int: " & CInt(bb[2])
  150.   'Print "HEX: " & Hex(bb[3], 2) & " |Bin: " & Bin(bb[3], 8) & " |Int: " & CInt(bb[3])
  151.   'Print "HEX: " & Hex(bb[4], 2) & " |Bin: " & Bin(bb[4], 8) & " |Int: " & CInt(bb[4])
  152.   'Print "HEX: " & Hex(bb[5], 2) & " |Bin: " & Bin(bb[5], 8) & " |Int: " & CInt(bb[5])
  153.   'Print "HEX: " & Hex(bb[6], 2) & " |Bin: " & Bin(bb[6], 8) & " |Int: " & CInt(bb[6])
  154.   'Print Hex(bb[128], 2)
  155.   'Print bb.ToString(128, 20)
  156.   'Print Chr(bb[128]) & Chr(bb[129]) & Chr(bb[130]) & Chr(bb[131]) & Chr(bb[132]) & Chr(bb[133]) & Chr(bb[134]) & Chr(bb[135]) & Chr(bb[136]) & Chr(bb[137]) & Chr(bb[138]) & Chr(bb[139]) & Chr(bb[140])
  157.   'i = Val("&" & s)
  158.    
  159.   'Print i
  160.   'Print s
  161.  
  162. End
  163.  
  164. Private Function decode_ram_type(bytes As Byte[]) As Integer
  165.   If bytes[0] < 4 Then
  166.     Select bytes[2]
  167.       Case 1
  168.         Return DIRECT_RAMBUS
  169.       Case 17
  170.         Return RAMBUS
  171.     End Select
  172.   Else
  173.     Select bytes[2]
  174.       Case 1
  175.         Return FPM_DRAM
  176.       Case 2
  177.         Return EDO
  178.       Case 3
  179.         Return PIPELINED_NIBBLE
  180.       Case 4
  181.         Return SDR_SDRAM
  182.       Case 5
  183.         Return MULTIPLEXED_ROM
  184.       Case 6
  185.         Return DDR_SGRAM
  186.       Case 7
  187.         Return DDR_SDRAM
  188.       Case 8
  189.         Return DDR2_SDRAM
  190.       Case 11
  191.         Return DDR3_SDRAM
  192.       Case 12
  193.         Return DDR4_SDRAM
  194.     End Select
  195.     Return UNKNOWN
  196.   Endif
  197. End
  198.  
  199. Private Function decode_ddr3_part_number(bytes As Byte[], Optional partnumber As String) As String
  200.   Dim i As Integer
  201.   For i = 128 To 145
  202.     partnumber &= Chr(bytes[i])
  203.   Next
  204.   Return partnumber
  205. End
  206.  
  207. Private Function decode_ddr34_manufacturer(count As String, code As String, manufacturer As String) As String
  208.  
  209.  
  210.  
  211. End
  212.  
  213. Private Function decode_ddr3_manufacturer(bytes As Byte[], manufacturer As String) As String
  214.  
  215.  
  216.  
  217. End
  218.  
  219. Private Function read_spd(spd_path As String) As Integer
  220.   Dim data_size As Integer = 0
  221.   ' Dim spd As File
  222.   ' Dim bytes As New Byte[512]
  223.   ' spd = Open spd_path For Read
  224.   ' spd.
  225.   ' bytes.Read(spd, 0, )
  226.   ' spd.Close
  227.   ' data_size = bytes.Count
  228.   data_size = Stat(spd_path).Size
  229.   Return data_size
  230. End
  231.  
  232. Private Function decode_ddr3_module_type(bytes As Byte[]) As String
  233.   Dim type As String
  234.   Select bytes[3]
  235.     Case 01
  236.       type = "RDIMM (Registered Long DIMM)"
  237.     Case 02
  238.       type = "UDIMM (Unbuffered Long DIMM)"
  239.     Case 03
  240.       type = "SODIMM (Small Outline DIMM)"
  241.     Default
  242.       type = Null
  243.   End Select
  244.   Return type
  245. End
  246.  
  247. Private Function decode_ddr3_module_speed(bytes As Byte[]) As String
  248.   Dim ctime As Float
  249.   Dim ddrclk As Float
  250.   Dim tbits, pcclk As Integer
  251.   Dim mtb As Float = 0.125
  252.  
  253.   If (bytes[10] == 1 And bytes[11] == 8) Then mtb = 0.125
  254.   If (bytes[10] == 1 And bytes[11] == 15) Then mtb = 0.0625
  255.   ctime = mtb * bytes[12]
  256.   ddrclk = 2 * (1000 / ctime)
  257.  
  258.   tbits = 64
  259.   Select bytes[8]
  260.     Case 1
  261.       tbits = 16
  262.     Case 4
  263.       tbits = 32
  264.     Case 3
  265.     Case 0
  266.       tbits = 64
  267.   End Select
  268.  
  269.   pcclk = ddrclk * (tbits / 8)
  270.   pcclk -= pcclk % 100
  271.  
  272.   Return Subst("DDR3-&1Mhz PC3-&2", CInt(ddrclk), pcclk)
  273. End
  274.  
  275. Private Function decode_ddr3_module_date(bytes As Byte[]) As String
  276.   Return Subst("&1-W&2", CInt(2000 + bytes[120]), bytes[121])
  277. End
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement