summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew McRae <amcrae@google.com>2022-03-15 14:37:23 +1100
committerCommit Bot <commit-bot@chromium.org>2022-03-16 09:32:28 +0000
commitfe1acaff0f830a1e8ee50b94a57815f15d931e80 (patch)
treea190afd5291ccfcbddb1b029dfdf31851bc29b75
parent74c77c7a67b3f3ebdbc0b68e7a6a6fe4b8c238b1 (diff)
downloadchrome-ec-fe1acaff0f830a1e8ee50b94a57815f15d931e80.tar.gz
pinmap: Optionally use column to select pins
Instead of using the chip name, optionally use a column designator to select the pins to process. BUG=b:221764513 TEST=go test ./...; regenerate DTS BRANCH=none Signed-off-by: Andrew McRae <amcrae@google.com> Change-Id: I4d056826f3768b34abb6ac3efcf916e48a76b2ab Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3522250 Reviewed-by: Eizan Miyamoto <eizan@chromium.org>
-rw-r--r--util/pinmap/README.md4
-rw-r--r--util/pinmap/pinmap/main.go3
-rw-r--r--util/pinmap/pm/reader.go8
-rw-r--r--util/pinmap/pm/reader_test.go10
-rw-r--r--util/pinmap/readers/csv/csv.go27
-rw-r--r--util/pinmap/readers/csv/csv_test.go4
6 files changed, 36 insertions, 20 deletions
diff --git a/util/pinmap/README.md b/util/pinmap/README.md
index a0b4823b2b..0246ed47cd 100644
--- a/util/pinmap/README.md
+++ b/util/pinmap/README.md
@@ -37,6 +37,8 @@ Running `pinmap --help` prints a usage page.
The `--reader` flag allows selecting different forms of input.
The default is `csv`, which is expected to be the downloaded CSV from a spreadsheet.
+The `--column` flag selects the spreadsheet column index to use for the pin allocations.
+
The `--chip` flag selects the EC part to be used.
## Spreadsheet format
@@ -89,7 +91,7 @@ Assume that the spreadsheet is downloaded as CSV format to the file `signals.csv
a NPCX993 EC chip is selected, the following command can be run:
```
-pinmap --chip=NPCX993 --output=generated.dts signals.csv
+pinmap --chip=NPCX993 --output=generated.dts --column=J signals.csv
```
The file `generated.dts` contains the DTS configuration as processed and generated by the utility.
diff --git a/util/pinmap/pinmap/main.go b/util/pinmap/pinmap/main.go
index ba47e8595f..8b1f1f38f6 100644
--- a/util/pinmap/pinmap/main.go
+++ b/util/pinmap/pinmap/main.go
@@ -19,6 +19,7 @@ var output = flag.String("output", "gpio.dts", "Output file")
var reader = flag.String("reader", "csv", "Input source type")
var names = flag.Bool("names", false, "Generate gpio-line-names")
var force = flag.Bool("force", false, "Overwrite output file")
+var column = flag.String("column", "", "Spreadsheet column index (A-Z) to use for chip pins")
func main() {
flag.Usage = Usage
@@ -30,7 +31,7 @@ func main() {
if chip == nil {
Error(fmt.Sprintf("No matching chip for '%s'", *chipFlag))
}
- pins, err := pm.ReadPins(*reader, *chipFlag, flag.Arg(0))
+ pins, err := pm.ReadPins(*reader, *column, flag.Arg(0))
if err != nil {
Error(fmt.Sprintf("%s - %s: %v", *reader, flag.Arg(0), err))
}
diff --git a/util/pinmap/pm/reader.go b/util/pinmap/pm/reader.go
index d518b7fc3a..08dbb9e3af 100644
--- a/util/pinmap/pm/reader.go
+++ b/util/pinmap/pm/reader.go
@@ -11,18 +11,18 @@ import (
// Reader reads the pin configuration from a source.
type Reader interface {
Name() string
- Read(arg string, chip string) (*Pins, error)
+ Read(key string, arg string) (*Pins, error)
}
// readerlist is registered list of readers.
var readerList []Reader
-// ReadPins will use the selected reader and the chip to
+// ReadPins will use the selected reader and the key to
// read the EC pin data.
-func ReadPins(reader, chip, arg string) (*Pins, error) {
+func ReadPins(reader, key, arg string) (*Pins, error) {
for _, r := range readerList {
if r.Name() == reader {
- return r.Read(chip, arg)
+ return r.Read(key, arg)
}
}
return nil, fmt.Errorf("%s: unknown reader", reader)
diff --git a/util/pinmap/pm/reader_test.go b/util/pinmap/pm/reader_test.go
index 3f3929e103..5eabf67490 100644
--- a/util/pinmap/pm/reader_test.go
+++ b/util/pinmap/pm/reader_test.go
@@ -14,8 +14,8 @@ import (
type testReader struct {
name string
+ key string
arg string
- chip string
pins pm.Pins
}
@@ -23,9 +23,9 @@ func (r *testReader) Name() string {
return r.name
}
-func (r *testReader) Read(arg, chip string) (*pm.Pins, error) {
+func (r *testReader) Read(key, arg string) (*pm.Pins, error) {
+ r.key = key
r.arg = arg
- r.chip = chip
return &r.pins, nil
}
@@ -33,14 +33,14 @@ func TestReader(t *testing.T) {
n := "Test1"
tr1 := &testReader{name: n}
pm.RegisterReader(tr1)
- p, err := pm.ReadPins(n, "arg1", "chiptest")
+ p, err := pm.ReadPins(n, "key", "arg1")
if err != nil {
t.Errorf("Error %v on reading pins", err)
}
if p != &tr1.pins {
t.Errorf("Did not match Pins")
}
- p, err = pm.ReadPins("notMine", "arg1", "chiptest")
+ p, err = pm.ReadPins("notMine", "key", "arg1")
if err == nil {
t.Errorf("Should heve returned error")
}
diff --git a/util/pinmap/readers/csv/csv.go b/util/pinmap/readers/csv/csv.go
index 8e1691268d..3f541f5da6 100644
--- a/util/pinmap/readers/csv/csv.go
+++ b/util/pinmap/readers/csv/csv.go
@@ -9,6 +9,7 @@ import (
"encoding/csv"
"fmt"
"os"
+ "strings"
"pinmap/pm"
)
@@ -23,11 +24,20 @@ func (r *CSVReader) Name() string {
return "csv"
}
-// Read reads the CSV file (provided as the argument) and extracts
+// Read reads the CSV file (provided as an argument) and extracts
// the pin reference data. The first line is expected to be column
// titles that are used to identify the columns.
-func (r *CSVReader) Read(chipName, arg string) (*pm.Pins, error) {
- f, err := os.Open(arg)
+// columnKey identifies the column to use for the pin allocations,
+// such as "A", "B" etc.
+func (r *CSVReader) Read(columnKey, filepath string) (*pm.Pins, error) {
+ if len(columnKey) != 1 {
+ return nil, fmt.Errorf("illegal column name: '%s'", columnKey)
+ }
+ column := int(strings.ToLower(columnKey)[0] - 'a')
+ if column < 0 || column > 'Z'-'A' {
+ return nil, fmt.Errorf("illegal column name (should be 'A' - 'Z')")
+ }
+ f, err := os.Open(filepath)
if err != nil {
return nil, err
}
@@ -40,6 +50,9 @@ func (r *CSVReader) Read(chipName, arg string) (*pm.Pins, error) {
if len(data) < 2 {
return nil, fmt.Errorf("no data in file")
}
+ if len(data[0]) < column {
+ return nil, fmt.Errorf("Column '%s' is out of range", columnKey)
+ }
// Put the CSV headers into a map.
cmap := make(map[string]int)
for c, s := range data[0] {
@@ -50,10 +63,10 @@ func (r *CSVReader) Read(chipName, arg string) (*pm.Pins, error) {
if !ok {
return nil, fmt.Errorf("missing 'Signal Name' column")
}
- // Find chip column
- chip, ok := cmap[chipName]
+ chipKey := data[0][column]
+ chip, ok := cmap[chipKey]
if !ok {
- return nil, fmt.Errorf("missing '%s' chip column", chipName)
+ return nil, fmt.Errorf("missing '%s' chip column", chipKey)
}
ptype, ok := cmap["Type"]
if !ok {
@@ -69,7 +82,7 @@ func (r *CSVReader) Read(chipName, arg string) (*pm.Pins, error) {
p := new(pm.Pin)
switch row[ptype] {
default:
- fmt.Printf("%s:%d: Unknown signal type (%s) - ignored", arg, i+1, row[ptype])
+ fmt.Printf("%s:%d: Unknown signal type (%s) - ignored", filepath, i+1, row[ptype])
continue
case "OTHER":
// Skipped
diff --git a/util/pinmap/readers/csv/csv_test.go b/util/pinmap/readers/csv/csv_test.go
index 94b134ee79..639ec4f8fe 100644
--- a/util/pinmap/readers/csv/csv_test.go
+++ b/util/pinmap/readers/csv/csv_test.go
@@ -14,14 +14,14 @@ import (
"pinmap/readers/csv"
)
-const chipName = "MyCHIP"
+const column = "B"
func TestName(t *testing.T) {
var r csv.CSVReader
if r.Name() != "csv" {
t.Errorf("expected %s, got %s", "csv", r.Name())
}
- pins, err := r.Read(chipName, filepath.Join("testdata", "data.csv"))
+ pins, err := r.Read(column, filepath.Join("testdata", "data.csv"))
if err != nil {
t.Fatalf("data.csv: %v", err)
}