14 type LogDevReader
struct {
16 ACPITables
map[string][]byte
20 func isXDigit(x
uint8) bool {
21 if x
>= '0' && x
<= '9' {
24 if x
>= 'a' && x
<= 'f' {
27 if x
>= 'A' && x
<= 'F' {
39 func (l
*LogDevReader
) ReadHexLine(line
string) (hex HexLine
) {
41 line
= strings
.Trim(line
, " ")
42 fmt
.Sscanf(line
, "%x:", &hex
.start
)
43 ll
, _
:= fmt
.Sscanf(line
, "%x: %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x", &hex
.start
,
44 &hex
.values
[0], &hex
.values
[1], &hex
.values
[2],
45 &hex
.values
[3], &hex
.values
[4], &hex
.values
[5],
46 &hex
.values
[6], &hex
.values
[7], &hex
.values
[8],
47 &hex
.values
[9], &hex
.values
[10], &hex
.values
[11],
48 &hex
.values
[12], &hex
.values
[13], &hex
.values
[14],
50 hex
.length
= uint(ll
- 1)
54 func (l
*LogDevReader
) AssignHexLine(inp
string, target
[]byte) []byte {
55 hex
:= l
.ReadHexLine(inp
)
56 if hex
.start
+hex
.length
> uint(len(target
)) {
57 target
= target
[0 : hex
.start
+hex
.length
]
59 copy(target
[hex
.start
:hex
.start
+hex
.length
], hex
.values
[0:hex
.length
])
63 func (l
*LogDevReader
) GetEC() []byte {
67 l
.EC
= make([]byte, 0x100, 0x100)
69 file
, err
:= os
.Open(l
.InputDirectory
+ "/ectool.log")
75 scanner
:= bufio
.NewScanner(file
)
78 line
:= scanner
.Text()
79 if len(line
) > 7 && isXDigit(line
[0]) && isXDigit(line
[1]) && line
[2] == ':' {
80 l
.EC
= l
.AssignHexLine(line
, l
.EC
)
84 if err
:= scanner
.Err(); err
!= nil {
91 func (l
*LogDevReader
) GetACPI() (Tables
map[string][]byte) {
92 if l
.ACPITables
!= nil {
97 file
, err
:= os
.Open(l
.InputDirectory
+ "/acpidump.log")
103 scanner
:= bufio
.NewScanner(file
)
105 Tables
= map[string][]byte{}
109 line
:= scanner
.Text()
110 /* Only supports ACPI tables up to 0x10000 in size, FIXME if needed */
111 is_hexline
, _
:= regexp
.MatchString(" *[0-9A-Fa-f]{4}: ", line
)
113 case len(line
) >= 6 && line
[5] == '@':
115 Tables
[curTable
] = make([]byte, 0, 100000)
117 Tables
[curTable
] = l
.AssignHexLine(line
, Tables
[curTable
])
121 if err
:= scanner
.Err(); err
!= nil {
128 func (l
*LogDevReader
) GetPCIList() (PCIList
[]PCIDevData
) {
129 file
, err
:= os
.Open(l
.InputDirectory
+ "/lspci.log")
135 scanner
:= bufio
.NewScanner(file
)
137 PCIList
= []PCIDevData
{}
140 line
:= scanner
.Text()
142 case !(len(line
) < 7 ||
!isXDigit(line
[0]) ||
!isXDigit(line
[1]) || line
[2] != ':' ||
!isXDigit(line
[3]) ||
!isXDigit(line
[4]) || line
[5] != '.' ||
!isXDigit(line
[6])):
144 fmt
.Sscanf(line
, "%x:%x.%x", &cur
.Bus
, &cur
.Dev
, &cur
.Func
)
145 lc
:= strings
.LastIndex(line
, ":")
146 li
:= strings
.LastIndex(line
[0:lc
], "[")
152 fmt
.Sscanf(line
[li
+1:], "%x:%x", &ven
, &dev
)
153 cur
.PCIDevID
= uint16(dev
)
154 cur
.PCIVenID
= uint16(ven
)
155 cur
.ConfigDump
= make([]byte, 0x100, 0x1000)
156 PCIList
= append(PCIList
, cur
)
157 case len(line
) > 7 && isXDigit(line
[0]) && line
[1] == '0' && line
[2] == ':':
159 fmt
.Sscanf(line
, "%x:", &start
)
160 cur
:= &PCIList
[len(PCIList
)-1]
161 cur
.ConfigDump
= l
.AssignHexLine(line
, cur
.ConfigDump
)
165 if err
:= scanner
.Err(); err
!= nil {
172 func (l
*LogDevReader
) GetInteltool() (ret InteltoolData
) {
173 file
, err
:= os
.Open(l
.InputDirectory
+ "/inteltool.log")
179 scanner
:= bufio
.NewScanner(file
)
181 ret
.GPIO
= map[uint16]uint32{}
182 ret
.RCBA
= map[uint16]uint32{}
183 ret
.IGD
= map[uint32]uint32{}
185 line
:= scanner
.Text()
187 case len(line
) > 7 && line
[0] == '0' && line
[1] == 'x' && line
[6] == ':' && paragraph
== "RCBA":
189 fmt
.Sscanf(line
, "0x%x: 0x%x", &addr
, &value
)
190 ret
.RCBA
[uint16(addr
)] = uint32(value
)
191 case len(line
) > 9 && line
[0] == '0' && line
[1] == 'x' && line
[8] == ':' && paragraph
== "IGD":
193 fmt
.Sscanf(line
, "0x%x: 0x%x", &addr
, &value
)
194 ret
.IGD
[uint32(addr
)] = uint32(value
)
195 case strings
.Contains(line
, "DEFAULT"):
197 case strings
.Contains(line
, "DIFF"):
199 case strings
.HasPrefix(line
, "gpiobase"):
201 fmt
.Sscanf(line
, "gpiobase+0x%x: 0x%x", &addr
, &value
)
202 ret
.GPIO
[uint16(addr
)] = uint32(value
)
203 case strings
.HasPrefix(line
, "============="):
204 paragraph
= strings
.Trim(line
, "= ")
208 if err
:= scanner
.Err(); err
!= nil {
214 func (l
*LogDevReader
) GetDMI() (ret DMIData
) {
215 file
, err
:= os
.Open(l
.InputDirectory
+ "/dmidecode.log")
221 scanner
:= bufio
.NewScanner(file
)
224 line
:= scanner
.Text()
225 if !strings
.HasPrefix(line
, "\t") {
226 paragraph
= strings
.TrimSpace(line
)
229 idx
:= strings
.Index(line
, ":")
233 name
:= strings
.TrimSpace(line
[0:idx
])
234 value
:= strings
.TrimSpace(line
[idx
+1:])
235 switch paragraph
+ ":" + name
{
236 case "System Information:Manufacturer":
238 case "System Information:Product Name":
240 case "System Information:Version":
242 case "Chassis Information:Type":
243 ret
.IsLaptop
= (value
== "Notebook" || value
== "Laptop")
247 if err
:= scanner
.Err(); err
!= nil {
253 func (l
*LogDevReader
) GetAzaliaCodecs() (ret
[]AzaliaCodec
) {
254 for codecno
:= 0; codecno
< 10; codecno
++ {
255 cur
:= AzaliaCodec
{CodecNo
: codecno
, PinConfig
: map[int]uint32{}}
256 codec
, err
:= os
.Open(l
.InputDirectory
+ "/codec#" + strconv
.Itoa(codecno
))
261 pin
, err
:= os
.Open(l
.InputDirectory
+ "/pin_hwC0D" + strconv
.Itoa(codecno
))
267 scanner
:= bufio
.NewScanner(codec
)
269 line
:= scanner
.Text()
270 if strings
.HasPrefix(line
, "Codec:") {
271 fmt
.Sscanf(line
, "Codec: %s", &cur
.Name
)
274 if strings
.HasPrefix(line
, "Vendor Id:") {
275 fmt
.Sscanf(line
, "Vendor Id: 0x%x", &cur
.VendorID
)
278 if strings
.HasPrefix(line
, "Subsystem Id:") {
279 fmt
.Sscanf(line
, "Subsystem Id: 0x%x", &cur
.SubsystemID
)
284 scanner
= bufio
.NewScanner(pin
)
286 line
:= scanner
.Text()
289 fmt
.Sscanf(line
, "0x%x 0x%x", &addr
, &val
)
290 cur
.PinConfig
[addr
] = val
292 ret
= append(ret
, cur
)
297 func (l
*LogDevReader
) GetIOPorts() []IOPorts
{
298 file
, err
:= os
.Open(l
.InputDirectory
+ "/ioports.log")
303 scanner
:= bufio
.NewScanner(file
)
304 ret
:= make([]IOPorts
, 0, 100)
306 line
:= scanner
.Text()
308 fmt
.Sscanf(line
, " %x-%x : %s", &el
.Start
, &el
.End
, &el
.Usage
)
309 ret
= append(ret
, el
)
312 if err
:= scanner
.Err(); err
!= nil {
319 func (l
*LogDevReader
) GetCPUModel() (ret
[]uint32) {
320 file
, err
:= os
.Open(l
.InputDirectory
+ "/cpuinfo.log")
326 scanner
:= bufio
.NewScanner(file
)
327 ret
= make([]uint32, 0, 100)
330 line
:= scanner
.Text()
331 sep
:= strings
.Index(line
, ":")
335 key
:= strings
.TrimSpace(line
[0:sep
])
336 val
:= strings
.TrimSpace(line
[sep
+1:])
338 if key
== "processor" {
339 proc
, _
:= strconv
.Atoi(val
)
340 if len(ret
) <= proc
{
341 ret
= ret
[0 : proc
+1]
345 if key
== "cpu family" {
346 family
, _
:= strconv
.Atoi(val
)
347 ret
[proc
] |
= uint32(((family
& 0xf) << 8) |
((family
& 0xff0) << 16))
350 model
, _
:= strconv
.Atoi(val
)
351 ret
[proc
] |
= uint32(((model
& 0xf) << 4) |
((model
& 0xf0) << 12))
353 if key
== "stepping" {
354 stepping
, _
:= strconv
.Atoi(val
)
355 ret
[proc
] |
= uint32(stepping
& 0xf)
359 if err
:= scanner
.Err(); err
!= nil {
365 func (l
*LogDevReader
) HasPS2() bool {
366 file
, err
:= os
.Open(l
.InputDirectory
+ "/input_bustypes.log")
371 scanner
:= bufio
.NewScanner(file
)
373 line
:= scanner
.Text()
374 if strings
.Index(line
, "0011") >= 0 {
381 var FlagLogInput
= flag
.String("input_log", ".", "Input log directory")
382 var FlagLogMkLogs
= flag
.Bool("make_logs", false, "Dump logs")
384 func MakeLogReader() *LogDevReader
{
386 MakeLogs(*FlagLogInput
)
388 return &LogDevReader
{InputDirectory
: *FlagLogInput
}