Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ' Gambas module file
- Private Enum UNKNOWN = 0,
- DIRECT_RAMBUS = 1,
- RAMBUS = 2,
- FPM_DRAM = 3,
- EDO = 4,
- PIPELINED_NIBBLE = 5,
- SDR_SDRAM = 6,
- MULTIPLEXED_ROM = 7,
- DDR_SGRAM = 8,
- DDR_SDRAM = 9,
- DDR2_SDRAM = 10,
- DDR3_SDRAM = 11,
- DDR4_SDRAM = 12,
- N_RAM_TYPES = 13
- Private RAM_TYPE As Integer = UNKNOWN
- Private ram_types As String[] = ["Unknown", "Direct Rambus",
- "Rambus", "FPM DRAM", "EDO",
- "Pipelined Nibble", "SDR SDRAM",
- "Multiplexed ROM", "DDR SGRAM",
- "DDR SDRAM", "DDR2 SDRAM",
- "DDR3 SDRAM", "DDR4 SDRAM"]
- Public Struct SPD_DATA
- bytes[512] As Byte
- dev[32] As String
- spd_driver As Integer '/* 0 = eeprom, 1 = ee1004 */
- spd_size As Integer
- ram_type As String
- vendor_bank As Integer
- vendor_index As Integer
- vendor_str As String
- partno As String
- ' const Vendor *vendor;
- ' int dram_vendor_bank;
- ' int dram_vendor_index;
- ' const char *dram_vendor_str;
- ' const Vendor *dram_vendor;
- ' char partno[32];
- form_factor As String
- type_detail As String
- ' dmi_mem_size size_MiB;
- ' int spd_rev_major; // bytes[1] >> 4
- ' int spd_rev_minor; // bytes[1] & 0xf
- ' int week, year;
- manufacturer_date As String
- ' gboolean ddr4_no_ee1004;
- ' struct dmi_mem_socket *dmi_socket;
- ' int match_score
- End Struct
- Public MEMORY_SUPPORTED_VOLTAGE As String
- Public MEMORY_SUPPORTED_CAS_LATENCIES As String
- Public MEMORY_THERMAL_SENSOR As String
- Public Sub main()
- Dim fl As File
- Dim bb As New Byte[256]
- Dim AA As New Byte[256]
- Dim s As String
- Dim i As Integer
- Dim bytes_used, bytes_free As Integer = 0
- Dim spd_data As New SPD_DATA
- Dim spd_size As Integer
- fl = Open "/sys/bus/i2c/drivers/eeprom/0-0052/eeprom" For Read
- bb.Read(fl, 0, Lof(fl))
- 'AA.Read(fl, 128, 140)
- fl.Close
- spd_size = read_spd("/sys/bus/i2c/drivers/eeprom/0-0052/eeprom")
- RAM_TYPE = decode_ram_type(bb)
- Select RAM_TYPE
- Case SDR_SDRAM
- Case DDR_SDRAM
- Case DDR2_SDRAM
- Case DDR3_SDRAM
- With spd_data
- .ram_type = ram_types[RAM_TYPE]
- .partno = decode_ddr3_part_number(bb)
- '.vendor_str = decode_ddr3_manufacturer(bb, SPD_DATA.vendor_str)
- .form_factor = decode_ddr3_module_type(bb)
- .type_detail = decode_ddr3_module_speed(bb)
- .manufacturer_date = decode_ddr3_module_date(bb)
- MEMORY_SUPPORTED_VOLTAGE &= If(bb[6] = 4, "1.25V ", "") & If(bb[6] = 2, "1.35V ", "") & If(bb[6] = 1, "", "1.5V")
- 'MEMORY_THERMAL_SENSOR = If(bytes[32] = )
- MEMORY_SUPPORTED_CAS_LATENCIES &= If(Mid$(Bin(bb[15], 8), 1, 1) = 1, "18T ", "")
- MEMORY_SUPPORTED_CAS_LATENCIES &= If(Mid$(Bin(bb[15], 8), 2, 1) = 1, "17T ", "")
- MEMORY_SUPPORTED_CAS_LATENCIES &= If(Mid$(Bin(bb[15], 8), 3, 1) = 1, "16T ", "")
- MEMORY_SUPPORTED_CAS_LATENCIES &= If(Mid$(Bin(bb[15], 8), 4, 1) = 1, "15T ", "")
- MEMORY_SUPPORTED_CAS_LATENCIES &= If(Mid$(Bin(bb[15], 8), 5, 1) = 1, "14T ", "")
- MEMORY_SUPPORTED_CAS_LATENCIES &= If(Mid$(Bin(bb[15], 8), 6, 1) = 1, "13T ", "")
- MEMORY_SUPPORTED_CAS_LATENCIES &= If(Mid$(Bin(bb[15], 8), 7, 1) = 1, "12T ", "")
- MEMORY_SUPPORTED_CAS_LATENCIES &= If(Mid$(Bin(bb[14], 8), 1, 1) = 1, "11T ", "")
- MEMORY_SUPPORTED_CAS_LATENCIES &= If(Mid$(Bin(bb[14], 8), 2, 1) = 1, "10T ", "")
- MEMORY_SUPPORTED_CAS_LATENCIES &= If(Mid$(Bin(bb[14], 8), 3, 1) = 1, "9T ", "")
- MEMORY_SUPPORTED_CAS_LATENCIES &= If(Mid$(Bin(bb[14], 8), 4, 1) = 1, "8T ", "")
- MEMORY_SUPPORTED_CAS_LATENCIES &= If(Mid$(Bin(bb[14], 8), 5, 1) = 1, "7T ", "")
- MEMORY_SUPPORTED_CAS_LATENCIES &= If(Mid$(Bin(bb[14], 8), 6, 1) = 1, "6T ", "")
- MEMORY_SUPPORTED_CAS_LATENCIES &= If(Mid$(Bin(bb[14], 8), 7, 1) = 1, "5T ", "")
- MEMORY_SUPPORTED_CAS_LATENCIES &= If(Mid$(Bin(bb[14], 8), 8, 1) = 1, "4T ", "")
- End With
- Case DDR4_SDRAM
- End Select
- Print spd_data.ram_type
- Print spd_data.partno
- Print spd_data.form_factor
- Print spd_data.type_detail
- Print spd_data.manufacturer_date
- Print MEMORY_SUPPORTED_VOLTAGE
- Print MEMORY_SUPPORTED_CAS_LATENCIES
- Print spd_size
- For i = 0 To bb.Count - 1
- '
- If bb[i] Then
- bytes_used += 1
- 'Print "RAW:" & bb[i] & "|HEX: " & Hex(bb[i]) & " |Bin: " & Bin(bb[i], 8) & " |Int: " & CInt(bb[i])
- Else
- bytes_free += 1
- 'Print "RAW:" & bb[i] & "|HEX: " & Hex(bb[i]) & " |Bin: " & Bin(bb[i], 8) & " |Int: " & CInt(bb[i])
- Endif
- Next
- Print Subst("Bytes Used: &1 Bytes Free: &2 Bytes Total: &3", bytes_used, bytes_free, bytes_free + bytes_used)
- Print CInt(bb[32] & &H80&)
- 'Print bb[121] & &hF0&
- 's = Hex(bb[0], 2) & Hex(bb[1], 2) & Hex(bb[2], 2)
- Print "RAW:" & bb[6] & "|HEX: " & Hex(bb[6]) & " |Bin: " & Bin(bb[6], 8) & " |Int: " & CInt(bb[6])
- Print "RAW:" & bb[15] & "|HEX: " & Hex(bb[15]) & " |Bin: " & Bin(bb[15], 8) & " |Int: " & CInt(bb[15])
- Print "RAW:" & bb[31] & "|HEX: " & Hex(bb[32]) & " |Bin: " & Bin(bb[32], 8) & " |Int: " & CInt(bb[32])
- 'Print Hex$(15, 3)
- 'Print "HEX: " & Hex(bb[2], 2) & " |Bin: " & Bin(bb[2], 8) & " |Int: " & CInt(bb[2])
- 'Print "HEX: " & Hex(bb[3], 2) & " |Bin: " & Bin(bb[3], 8) & " |Int: " & CInt(bb[3])
- 'Print "HEX: " & Hex(bb[4], 2) & " |Bin: " & Bin(bb[4], 8) & " |Int: " & CInt(bb[4])
- 'Print "HEX: " & Hex(bb[5], 2) & " |Bin: " & Bin(bb[5], 8) & " |Int: " & CInt(bb[5])
- 'Print "HEX: " & Hex(bb[6], 2) & " |Bin: " & Bin(bb[6], 8) & " |Int: " & CInt(bb[6])
- 'Print Hex(bb[128], 2)
- 'Print bb.ToString(128, 20)
- '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])
- 'i = Val("&" & s)
- 'Print i
- 'Print s
- End
- Private Function decode_ram_type(bytes As Byte[]) As Integer
- If bytes[0] < 4 Then
- Select bytes[2]
- Case 1
- Return DIRECT_RAMBUS
- Case 17
- Return RAMBUS
- End Select
- Else
- Select bytes[2]
- Case 1
- Return FPM_DRAM
- Case 2
- Return EDO
- Case 3
- Return PIPELINED_NIBBLE
- Case 4
- Return SDR_SDRAM
- Case 5
- Return MULTIPLEXED_ROM
- Case 6
- Return DDR_SGRAM
- Case 7
- Return DDR_SDRAM
- Case 8
- Return DDR2_SDRAM
- Case 11
- Return DDR3_SDRAM
- Case 12
- Return DDR4_SDRAM
- End Select
- Return UNKNOWN
- Endif
- End
- Private Function decode_ddr3_part_number(bytes As Byte[], Optional partnumber As String) As String
- Dim i As Integer
- For i = 128 To 145
- partnumber &= Chr(bytes[i])
- Next
- Return partnumber
- End
- Private Function decode_ddr34_manufacturer(count As String, code As String, manufacturer As String) As String
- End
- Private Function decode_ddr3_manufacturer(bytes As Byte[], manufacturer As String) As String
- End
- Private Function read_spd(spd_path As String) As Integer
- Dim data_size As Integer = 0
- ' Dim spd As File
- ' Dim bytes As New Byte[512]
- ' spd = Open spd_path For Read
- ' spd.
- ' bytes.Read(spd, 0, )
- ' spd.Close
- ' data_size = bytes.Count
- data_size = Stat(spd_path).Size
- Return data_size
- End
- Private Function decode_ddr3_module_type(bytes As Byte[]) As String
- Dim type As String
- Select bytes[3]
- Case 01
- type = "RDIMM (Registered Long DIMM)"
- Case 02
- type = "UDIMM (Unbuffered Long DIMM)"
- Case 03
- type = "SODIMM (Small Outline DIMM)"
- Default
- type = Null
- End Select
- Return type
- End
- Private Function decode_ddr3_module_speed(bytes As Byte[]) As String
- Dim ctime As Float
- Dim ddrclk As Float
- Dim tbits, pcclk As Integer
- Dim mtb As Float = 0.125
- If (bytes[10] == 1 And bytes[11] == 8) Then mtb = 0.125
- If (bytes[10] == 1 And bytes[11] == 15) Then mtb = 0.0625
- ctime = mtb * bytes[12]
- ddrclk = 2 * (1000 / ctime)
- tbits = 64
- Select bytes[8]
- Case 1
- tbits = 16
- Case 4
- tbits = 32
- Case 3
- Case 0
- tbits = 64
- End Select
- pcclk = ddrclk * (tbits / 8)
- pcclk -= pcclk % 100
- Return Subst("DDR3-&1Mhz PC3-&2", CInt(ddrclk), pcclk)
- End
- Private Function decode_ddr3_module_date(bytes As Byte[]) As String
- Return Subst("&1-W&2", CInt(2000 + bytes[120]), bytes[121])
- End
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement