2014-10-15 21:51:47 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2016-05-17 19:56:03 +02:00
|
|
|
"errors"
|
|
|
|
"fmt"
|
2014-10-15 21:51:47 +02:00
|
|
|
"io"
|
|
|
|
"io/ioutil"
|
|
|
|
"log"
|
|
|
|
"os"
|
|
|
|
"os/exec"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
2015-05-29 20:49:09 +02:00
|
|
|
func TryRunAndSave(output string, name string, arg []string) error {
|
2014-10-15 21:51:47 +02:00
|
|
|
cmd := exec.Command(name, arg...)
|
|
|
|
|
|
|
|
f, err := os.Create(output)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
cmd.Stdout = f
|
|
|
|
cmd.Stderr = f
|
|
|
|
|
|
|
|
err = cmd.Start()
|
|
|
|
if err != nil {
|
2015-05-29 20:49:09 +02:00
|
|
|
return err
|
2014-10-15 21:51:47 +02:00
|
|
|
}
|
|
|
|
cmd.Wait()
|
2015-05-29 20:49:09 +02:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func RunAndSave(output string, name string, arg ...string) {
|
|
|
|
err := TryRunAndSave(output, name, arg)
|
|
|
|
if err == nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
idx := strings.LastIndex(name, "/")
|
|
|
|
relname := name
|
|
|
|
if idx >= 0 {
|
|
|
|
relname = name[idx+1:]
|
|
|
|
}
|
|
|
|
relname = "./" + relname
|
|
|
|
err = TryRunAndSave(output, relname, arg)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
2014-10-15 21:51:47 +02:00
|
|
|
}
|
|
|
|
|
2016-05-17 19:56:03 +02:00
|
|
|
const MAXPROMPTRETRY = 3
|
|
|
|
|
|
|
|
func PromptUser(prompt string, opts []string) (match string, err error) {
|
|
|
|
for i := 1; i < MAXPROMPTRETRY; i++ {
|
|
|
|
fmt.Println("%s. (%s) Default:%s", prompt, strings.Join(opts, "/"), opts[0])
|
|
|
|
var usrInput string
|
|
|
|
fmt.Scanln(&usrInput)
|
|
|
|
|
|
|
|
// Check for default entry
|
|
|
|
if usrInput == "" {
|
|
|
|
match = opts[0]
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, opt := range opts {
|
|
|
|
if opt == usrInput {
|
|
|
|
match = opt
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
err = errors.New("max retries exceeded")
|
|
|
|
fmt.Fprintln(os.Stderr, "ERROR: max retries exceeded")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2014-10-15 21:51:47 +02:00
|
|
|
func MakeLogs(outDir string) {
|
|
|
|
os.MkdirAll(outDir, 0700)
|
|
|
|
RunAndSave(outDir+"/lspci.log", "lspci", "-nnvvvxxxx")
|
|
|
|
RunAndSave(outDir+"/dmidecode.log", "dmidecode")
|
|
|
|
RunAndSave(outDir+"/acpidump.log", "acpidump")
|
2016-05-17 19:56:03 +02:00
|
|
|
|
|
|
|
inteltoolArgs := "-a"
|
|
|
|
opt, err := PromptUser("WARNING: The following tool MAY cause your system to hang when it attempts "+
|
|
|
|
"to probe for graphics registers. Having the graphics registers will help create a better port. "+
|
|
|
|
"Should autoport probe these registers?",
|
|
|
|
[]string{"y", "yes", "n", "no"})
|
|
|
|
|
|
|
|
// Continue even if there is an error
|
|
|
|
|
|
|
|
switch opt {
|
|
|
|
case "y", "yes":
|
2017-01-08 03:42:30 +01:00
|
|
|
inteltoolArgs += "f"
|
2016-05-17 19:56:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
RunAndSave(outDir+"/inteltool.log", "../inteltool/inteltool", inteltoolArgs)
|
2017-02-24 08:19:25 +01:00
|
|
|
RunAndSave(outDir+"/ectool.log", "../ectool/ectool", "-d")
|
2014-10-15 21:51:47 +02:00
|
|
|
|
|
|
|
SysDir := "/sys/class/sound/card0/"
|
|
|
|
files, _ := ioutil.ReadDir(SysDir)
|
|
|
|
for _, f := range files {
|
|
|
|
if (strings.HasPrefix(f.Name(), "hw") || strings.HasPrefix(f.Name(), "hdaudio")) && f.IsDir() {
|
|
|
|
in, err := os.Open(SysDir + f.Name() + "/init_pin_configs")
|
|
|
|
defer in.Close()
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
out, err := os.Create(outDir + "/pin_" + strings.Replace(f.Name(), "hdaudio", "hw", -1))
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
defer out.Close()
|
|
|
|
io.Copy(out, in)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ProcDir := "/proc/asound/card0/"
|
|
|
|
files, _ = ioutil.ReadDir(ProcDir)
|
|
|
|
for _, f := range files {
|
|
|
|
if strings.HasPrefix(f.Name(), "codec#") && !f.IsDir() {
|
|
|
|
in, err := os.Open(ProcDir + f.Name())
|
|
|
|
defer in.Close()
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
out, err := os.Create(outDir + "/" + f.Name())
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
defer out.Close()
|
|
|
|
io.Copy(out, in)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, fname := range []string{"cpuinfo", "ioports"} {
|
|
|
|
in, err := os.Open("/proc/" + fname)
|
|
|
|
defer in.Close()
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
out, err := os.Create(outDir + "/" + fname + ".log")
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
defer out.Close()
|
|
|
|
io.Copy(out, in)
|
|
|
|
}
|
2015-05-29 23:53:37 +02:00
|
|
|
|
|
|
|
out, err := os.Create(outDir + "/input_bustypes.log")
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
defer out.Close()
|
|
|
|
|
|
|
|
ClassInputDir := "/sys/class/input/"
|
|
|
|
files, _ = ioutil.ReadDir(ClassInputDir)
|
|
|
|
for _, f := range files {
|
|
|
|
if strings.HasPrefix(f.Name(), "input") && !f.Mode().IsRegular() { /* Allow both dirs and symlinks. */
|
|
|
|
in, err := os.Open(ClassInputDir + f.Name() + "/id/bustype")
|
|
|
|
defer in.Close()
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
io.Copy(out, in)
|
|
|
|
}
|
|
|
|
}
|
2014-10-15 21:51:47 +02:00
|
|
|
}
|