Maximilian Brune has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/74361 )
Change subject: [WIP] NO REVIEW util/autoport: Use regex for log reading ......................................................................
[WIP] NO REVIEW util/autoport: Use regex for log reading
The current implementation doesn't work if there are more than one PCIE domain used by the System, since lspci changes it's output depending on whether or not multiple domains are used.
Signed-off-by: Maximilian Brune maximilian.brune@9elements.com Change-Id: I3daaa1b08ab93ae2b1ebdeba9f2da9dae39b3301 --- M util/autoport/log_reader.go 1 file changed, 43 insertions(+), 17 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/61/74361/1
diff --git a/util/autoport/log_reader.go b/util/autoport/log_reader.go index b144804..9d9b768 100644 --- a/util/autoport/log_reader.go +++ b/util/autoport/log_reader.go @@ -135,33 +135,45 @@ scanner := bufio.NewScanner(file)
PCIList = []PCIDevData{} - + // [domain] : bus : dev . func desc vendor : device + pcieLine := regexp.MustCompile(`^([0-9]{4,}:){0,1}([0-9a-z][0-9a-z]):([0-1][0-9a-f]).([0-7]) .+ [([0-9a-z]{4}):([0-9a-z]{4})]`) + hexLine := regexp.MustCompile(`^[0-9a-z]{2,}:( [0-9a-z])+`) for scanner.Scan() { line := scanner.Text() + matches := pcieLine.FindStringSubmatch(line) switch { - case !(len(line) < 7 || !isXDigit(line[0]) || !isXDigit(line[1]) || line[2] != ':' || !isXDigit(line[3]) || !isXDigit(line[4]) || line[5] != '.' || !isXDigit(line[6])): + case len(matches) == 7: cur := PCIDevData{} - fmt.Sscanf(line, "%x:%x.%x", &cur.Bus, &cur.Dev, &cur.Func) - lc := strings.LastIndex(line, ":") - li := strings.LastIndex(line[0:lc], "[") - if li < 0 { - continue + var b, d, f, di, vi uint64 + if b, err = strconv.ParseUint(matches[2], 16, 8); err != nil { + log.Fatal(err) } - ven := 0 - dev := 0 - fmt.Sscanf(line[li+1:], "%x:%x", &ven, &dev) - cur.PCIDevID = uint16(dev) - cur.PCIVenID = uint16(ven) + if d, err = strconv.ParseUint(matches[3], 16, 8); err != nil { + log.Fatal(err) + } + if f, err = strconv.ParseUint(matches[4], 16, 4); err != nil { + log.Fatal(err) + } + if di,err = strconv.ParseUint(matches[5], 16, 16); err != nil { + log.Fatal(err) + } + if vi,err = strconv.ParseUint(matches[6], 16, 16); err != nil { + log.Fatal(err) + } + cur.Bus = int(b) + cur.Dev = int(d) + cur.Func = int(f) + cur.PCIDevID = uint16(di) + cur.PCIVenID = uint16(vi) + fmt.Printf("%2x:%2x.%1x %4x:%4x\n", cur.Bus, cur.Dev, cur.Func, cur.PCIDevID, cur.PCIVenID) cur.ConfigDump = make([]byte, 0x100, 0x1000) PCIList = append(PCIList, cur) - case len(line) > 7 && isXDigit(line[0]) && line[1] == '0' && line[2] == ':': - start := 0 - fmt.Sscanf(line, "%x:", &start) + case hexLine.MatchString(line): cur := &PCIList[len(PCIList)-1] cur.ConfigDump = l.AssignHexLine(line, cur.ConfigDump) } } - + fmt.Println() if err := scanner.Err(); err != nil { log.Fatal(err) } @@ -271,7 +283,7 @@ } defer codec.Close() pin, err := os.Open(l.InputDirectory + "/pin_hwC" + strconv.Itoa(cardno) + - "D" + strconv.Itoa(codecno)) + "D" + strconv.Itoa(codecno)) if err != nil { continue }