15 func TryRunAndSave(output
string, name
string, arg
[]string) error
{
16 cmd
:= exec
.Command(name
, arg
...)
18 f
, err
:= os
.Create(output
)
34 func RunAndSave(output
string, name
string, arg
...string) {
35 err
:= TryRunAndSave(output
, name
, arg
)
39 idx
:= strings
.LastIndex(name
, "/")
42 relname
= name
[idx
+1:]
44 relname
= "./" + relname
45 err
= TryRunAndSave(output
, relname
, arg
)
51 const MAXPROMPTRETRY
= 3
53 func PromptUser(prompt
string, opts
[]string) (match
string, err error
) {
54 for i
:= 1; i
< MAXPROMPTRETRY
; i
++ {
55 fmt
.Printf("%s. (%s) Default:%s\n", prompt
,
56 strings
.Join(opts
, "/"), opts
[0])
60 // Check for default entry
66 for _
, opt
:= range opts
{
73 err
= errors
.New("max retries exceeded")
74 fmt
.Fprintln(os
.Stderr
, "ERROR: max retries exceeded")
78 func MakeHDALogs(outDir
string, cardName
string) {
79 SysDir
:= "/sys/class/sound/" + cardName
+ "/"
80 files
, _
:= ioutil
.ReadDir(SysDir
)
81 for _
, f
:= range files
{
82 if (strings
.HasPrefix(f
.Name(), "hw") || strings
.HasPrefix(f
.Name(), "hdaudio")) && f
.IsDir() {
83 in
, err
:= os
.Open(SysDir
+ f
.Name() + "/init_pin_configs")
88 out
, err
:= os
.Create(outDir
+ "/pin_" + strings
.Replace(f
.Name(), "hdaudio", "hw", -1))
97 ProcDir
:= "/proc/asound/" + cardName
+ "/"
98 files
, _
= ioutil
.ReadDir(ProcDir
)
99 for _
, f
:= range files
{
100 if strings
.HasPrefix(f
.Name(), "codec#") && !f
.IsDir() {
101 in
, err
:= os
.Open(ProcDir
+ f
.Name())
106 out
, err
:= os
.Create(outDir
+ "/" + f
.Name())
116 func MakeLogs(outDir
string) {
117 os
.MkdirAll(outDir
, 0700)
118 RunAndSave(outDir
+"/lspci.log", "lspci", "-nnvvvxxxx")
119 RunAndSave(outDir
+"/dmidecode.log", "dmidecode")
120 RunAndSave(outDir
+"/acpidump.log", "acpidump")
122 inteltoolArgs
:= "-a"
123 opt
, err
:= PromptUser("WARNING: The following tool MAY cause your system to hang when it attempts "+
124 "to probe for graphics registers. Having the graphics registers will help create a better port. "+
125 "Should autoport probe these registers?",
126 []string{"y", "yes", "n", "no"})
128 // Continue even if there is an error
135 RunAndSave(outDir
+"/inteltool.log", "../inteltool/inteltool", inteltoolArgs
)
136 RunAndSave(outDir
+"/ectool.log", "../ectool/ectool", "-pd")
137 RunAndSave(outDir
+"/superiotool.log", "../superiotool/superiotool", "-ade")
139 SysSound
:= "/sys/class/sound/"
141 cards
, _
:= ioutil
.ReadDir(SysSound
)
142 for _
, f
:= range cards
{
143 if strings
.HasPrefix(f
.Name(), "card") {
144 cid
, err
:= ioutil
.ReadFile(SysSound
+ f
.Name() + "/id")
145 if err
== nil && bytes
.Equal(cid
, []byte("PCH\n")) {
146 fmt
.Fprintln(os
.Stderr
, "PCH sound card is", f
.Name())
153 MakeHDALogs(outDir
, card
)
155 fmt
.Fprintln(os
.Stderr
, "HDAudio not found on PCH.")
158 for _
, fname
:= range []string{"cpuinfo", "ioports"} {
159 in
, err
:= os
.Open("/proc/" + fname
)
164 out
, err
:= os
.Create(outDir
+ "/" + fname
+ ".log")
172 out
, err
:= os
.Create(outDir
+ "/input_bustypes.log")
178 ClassInputDir
:= "/sys/class/input/"
179 files
, _
:= ioutil
.ReadDir(ClassInputDir
)
180 for _
, f
:= range files
{
181 if strings
.HasPrefix(f
.Name(), "input") && !f
.Mode().IsRegular() { /* Allow both dirs and symlinks. */
182 in
, err
:= os
.Open(ClassInputDir
+ f
.Name() + "/id/bustype")