Maxim Polyakov has uploaded this change for review.

View Change

intelp2m: Update cli options

Use the new options format:

basic functions:
-file <path> path to the inteltool log file
-out <path> path to the generated file
-platform <type> set the PCH platform type <sunrise>
enter ? to show datails

generation of long composite macros with bit field definitions:
-fields <type> generate a long macro consisting of bitfield macros
enter ? to show datails

control flags:
-exclude exclude fields that should be ignored to gen macro
-unchecked disable automatic checking of macro fields before gen

generate additional information:
-i add function to the comments
-ii add DW0/DW1 register value to the comments
-iii add ignored bitfields to the comments
-iiii add target PAD_CFG() macro to the comments

Use the following bash command:
$ complete `-C `pwd`/intelp2m ./intelp2m
to allow automatic completion of arguments

Change-Id: I08ff379b99b018b1099aa5d70fea47026bc84045
Signed-off-by: Maxim Polyakov <max.senia.poliak@gmail.com>
---
A util/intelp2m/cli/completion.go
A util/intelp2m/cli/options.go
M util/intelp2m/config/p2m/config.go
M util/intelp2m/main.go
4 files changed, 198 insertions(+), 68 deletions(-)

git pull ssh://review.coreboot.org:29418/coreboot refs/changes/10/70310/1
diff --git a/util/intelp2m/cli/completion.go b/util/intelp2m/cli/completion.go
new file mode 100644
index 0000000..b322a87
--- /dev/null
+++ b/util/intelp2m/cli/completion.go
@@ -0,0 +1,22 @@
+package cli
+
+import (
+ "flag"
+ "fmt"
+ "os"
+ "strings"
+)
+
+func UseComplete() bool {
+ if _, ok := os.LookupEnv("COMP_LINE"); ok {
+ argument := os.Args[2]
+ argument = strings.TrimLeft(argument, "-")
+ flag.VisitAll(func(f *flag.Flag) {
+ if argument == "" || strings.HasPrefix(f.Name, argument) {
+ fmt.Println("-" + f.Name)
+ }
+ })
+ return true
+ }
+ return false
+}
diff --git a/util/intelp2m/cli/options.go b/util/intelp2m/cli/options.go
new file mode 100644
index 0000000..9da4632
--- /dev/null
+++ b/util/intelp2m/cli/options.go
@@ -0,0 +1,127 @@
+package cli
+
+import (
+ "flag"
+ "fmt"
+ "os"
+ "path/filepath"
+
+ "review.coreboot.org/coreboot.git/util/intelp2m/config/p2m"
+)
+
+var Version = ""
+
+const usagePlatform string = `usage: -platform <type>
+ type: adl | apl | cnl | lbg | snr | ?
+ adl - AlderLake PCH
+ apl - Apollo Lake SoC
+ cnl - CannonLake-LP or Whiskeylake/Coffeelake/Cometlake-U SoC
+ lbg - Lewisburg PCH with Xeon SP
+ snr - Sunrise PCH or Skylake/Kaby Lake SoC
+ ? - show details
+`
+
+const usageFields string = `usage: -fields <type>
+ type: cb | fsp | raw | ?
+ cb - coreboot style
+ fsp - Intel FSP style
+ raw - raw register value (don't convert, print as is)
+ ? - show details
+`
+
+func Usage() {
+ fmt.Printf(`
+%s converts inteltool.log register dump to coreboot macros
+version %s
+
+usage: options... <arguments>
+
+basic functions:
+ -file <path> path to the inteltool log file <inteltool.log> by default
+ -out <path> path to the generated file. <generate/gpio.h> by default
+ -platform <type> set the PCH platform type. <sunrise> by default
+ enter ? to show datails
+
+generation of long composite macros with bit field definitions:
+ -fields <type> generate a long macro consisting of bitfield macros and set its type
+ enter ? to show datails
+
+control flags:
+ -exclude exclude fields that should be ignored to generate a gpio macro
+ -unchecked disable automatic checking of macro fields before generating
+
+generate additional information:
+ -i add function to the comments
+ -ii add DW0/DW1 register value to the comments
+ -iii add ignored bitfields to the comments
+ -iiii add target PAD_CFG() macro to the comments
+`, filepath.Base(os.Args[0]), Version)
+}
+
+func ParseOptions(version string) {
+ config := p2m.SettingsGet()
+ Version = version
+
+ flag.Usage = Usage
+ flag.StringVar(&config.InputPath, "file", "inteltool.log", "")
+ flag.StringVar(&config.OutputPath, "out", "generate/gpio.h", "")
+ flag.BoolVar(&config.IgnoredFields, "exclude", false, "")
+ unchecked := flag.Bool("unchecked", false, "")
+ flag.Func(
+ "platform",
+ usagePlatform,
+ func(value string) error {
+ if value == "?" {
+ fmt.Printf("%s", usagePlatform)
+ os.Exit(0)
+ }
+
+ if err := config.SetPlatformType(value); err != nil {
+ fmt.Printf("error: %v\n%s", err, usagePlatform)
+ os.Exit(0)
+ }
+ return nil
+ },
+ )
+
+ flag.Func(
+ "fields",
+ usageFields,
+ func(value string) error {
+ if value == "?" {
+ fmt.Printf("%s", usageFields)
+ os.Exit(0)
+ }
+
+ if err := config.SetFieldType(value); err != nil {
+ fmt.Printf("error: %v\n%s", err, usageFields)
+ os.Exit(0)
+ }
+ return nil
+ },
+ )
+
+ levels := map[int]*bool{
+ 1: flag.Bool("i", false, ""),
+ 2: flag.Bool("ii", false, ""),
+ 3: flag.Bool("iii", false, ""),
+ 4: flag.Bool("iiii", false, ""),
+ }
+
+ if UseComplete() {
+ os.Exit(0)
+ }
+
+ flag.Parse()
+
+ for level, selected := range levels {
+ if *selected {
+ config.GenLevel = level
+ break
+ }
+ }
+ config.AutoCheck = !(*unchecked)
+ config.Version = version
+
+ p2m.SettingsUpdate(config)
+}
diff --git a/util/intelp2m/config/p2m/config.go b/util/intelp2m/config/p2m/config.go
index 43f8226..9449d22 100644
--- a/util/intelp2m/config/p2m/config.go
+++ b/util/intelp2m/config/p2m/config.go
@@ -42,6 +42,8 @@
Version string
Platform PlatformType
Field FieldType
+ InputPath string
+ OutputPath string
InputFile *os.File
OutputFile *os.File
IgnoredFields bool
@@ -52,7 +54,7 @@
var p2mConfig = Settings{
Version: "unknown",
Platform: Sunrise,
- Field: CbFlds,
+ Field: NoFlds,
IgnoredFields: false,
AutoCheck: true,
GenLevel: 0,
diff --git a/util/intelp2m/main.go b/util/intelp2m/main.go
index 0b0c9d5..aa856bd 100644
--- a/util/intelp2m/main.go
+++ b/util/intelp2m/main.go
@@ -1,11 +1,11 @@
package main

import (
- "flag"
"fmt"
"os"
"path/filepath"

+ "review.coreboot.org/coreboot.git/util/intelp2m/cli"
"review.coreboot.org/coreboot.git/util/intelp2m/config/p2m"
"review.coreboot.org/coreboot.git/util/intelp2m/parser"
)
@@ -36,86 +36,29 @@

// main
func main() {
- // Command line arguments
- inputFilePath := flag.String("file", "inteltool.log",
- "the path to the inteltool log file\n")
+ cli.ParseOptions(Version)

- outputFilePath := flag.String("o",
- "generate/gpio.h",
- "the path to the generated file with GPIO configuration\n")
-
- ignored := flag.Bool("ign", false,
- "exclude fields that should be ignored from advanced macros\n")
-
- unchecking := flag.Bool("n", false,
- "Generate macros without checking.\n"+
- "\tIn this case, some fields of the configuration registers\n"+
- "\tDW0 will be ignored.\n")
-
- levels := []*bool{
- flag.Bool("i", false, "Show pads function in the comments"),
- flag.Bool("ii", false, "Show DW0/DW1 value in the comments"),
- flag.Bool("iii", false, "Show ignored bit fields in the comments"),
- flag.Bool("iiii", false, "Show target PAD_CFG() macro in the comments"),
- }
-
- platform := flag.String("p", "snr", "set platform:\n"+
- "\tsnr - Sunrise PCH or Skylake/Kaby Lake SoC\n"+
- "\tlbg - Lewisburg PCH with Xeon SP\n"+
- "\tapl - Apollo Lake SoC\n"+
- "\tcnl - CannonLake-LP or Whiskeylake/Coffeelake/Cometlake-U SoC\n"+
- "\tadl - AlderLake PCH\n")
-
- field := flag.String("fld", "none", "set fields macros style:\n"+
- "\tcb - use coreboot style for bit fields macros\n"+
- "\tfsp - use fsp style\n"+
- "\traw - do not convert, print as is\n")
-
- flag.Parse()
- printVersion()
-
- // settings
config := p2m.SettingsGet()
- config.Version = Version
- config.IgnoredFields = *ignored
- config.AutoCheck = !(*unchecking)
- for level, set := range levels {
- if *set {
- config.GenLevel = level + 1
- fmt.Printf("Info level: Use level %d!\n", level+1)
- break
- }
- }

- if err := config.SetPlatformType(*platform); err != nil {
- fmt.Printf("Error: %v\n", err)
- os.Exit(1)
- }
-
- if err := config.SetFieldType(*field); err != nil {
- fmt.Printf("Error: %v\n", err)
- os.Exit(1)
- }
-
- if file, err := os.Open(*inputFilePath); err != nil {
- fmt.Printf("input file error: %v", err)
+ if file, err := os.Open(config.InputPath); err != nil {
+ fmt.Printf("input file error: %v\n", err)
os.Exit(1)
} else {
config.InputFile = file
+ defer file.Close()
}
- defer config.InputFile.Close()

- if err := os.MkdirAll(filepath.Dir(*outputFilePath), os.ModePerm); err != nil {
- fmt.Printf("failed to create output directory: %v", err)
+ if err := os.MkdirAll(filepath.Dir(config.OutputPath), os.ModePerm); err != nil {
+ fmt.Printf("failed to create output directory: %v\n", err)
os.Exit(1)
}
- if file, err := os.Create(*outputFilePath); err != nil {
- fmt.Printf("failed to create output file: %v", err)
+ if file, err := os.Create(config.OutputPath); err != nil {
+ fmt.Printf("failed to create output file: %v\n", err)
os.Exit(1)
} else {
config.OutputFile = file
+ defer file.Close()
}
- defer config.OutputFile.Close()

p2m.SettingsUpdate(config)


To view, visit change 70310. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: coreboot
Gerrit-Branch: master
Gerrit-Change-Id: I08ff379b99b018b1099aa5d70fea47026bc84045
Gerrit-Change-Number: 70310
Gerrit-PatchSet: 1
Gerrit-Owner: Maxim Polyakov <max.senia.poliak@gmail.com>
Gerrit-MessageType: newchange