mb/google/parrot: Fix smbus subsystem ID
[coreboot.git] / util / intelp2m / main.go
blob64db9fee5ac698088bb6cf7088e2b51afef30c90
1 package main
3 import (
4 "flag"
5 "fmt"
6 "os"
8 "review.coreboot.org/coreboot.git/util/intelp2m/config"
9 "review.coreboot.org/coreboot.git/util/intelp2m/parser"
12 // generateOutputFile - generates include file
13 // parser : parser data structure
14 func generateOutputFile(parser *parser.ParserData) (err error) {
16 config.OutputGenFile.WriteString(`/* SPDX-License-Identifier: GPL-2.0-only */
18 #ifndef CFG_GPIO_H
19 #define CFG_GPIO_H
21 #include <gpio.h>
23 /* Pad configuration was generated automatically using intelp2m utility */
24 static const struct pad_config gpio_table[] = {
26 // Add the pads map
27 parser.PadMapFprint()
28 config.OutputGenFile.WriteString(`};
30 #endif /* CFG_GPIO_H */
32 return nil
35 // main
36 func main() {
37 // Command line arguments
38 inputFileName := flag.String("file",
39 "inteltool.log",
40 "the path to the inteltool log file\n")
42 outputFileName := flag.String("o",
43 "generate/gpio.h",
44 "the path to the generated file with GPIO configuration\n")
46 ignFlag := flag.Bool("ign",
47 false,
48 "exclude fields that should be ignored from advanced macros\n")
50 nonCheckFlag := flag.Bool("n",
51 false,
52 "Generate macros without checking.\n" +
53 "\tIn this case, some fields of the configuration registers\n" +
54 "\tDW0 will be ignored.\n")
56 infoLevels := []*bool {
57 flag.Bool("i", false, "Show pads function in the comments"),
58 flag.Bool("ii", false, "Show DW0/DW1 value in the comments"),
59 flag.Bool("iii", false, "Show ignored bit fields in the comments"),
60 flag.Bool("iiii", false, "Show target PAD_CFG() macro in the comments"),
63 template := flag.Int("t", 0, "template type number\n"+
64 "\t0 - inteltool.log (default)\n"+
65 "\t1 - gpio.h\n"+
66 "\t2 - your template\n\t")
68 platform := flag.String("p", "snr", "set platform:\n"+
69 "\tsnr - Sunrise PCH or Skylake/Kaby Lake SoC\n"+
70 "\tlbg - Lewisburg PCH with Xeon SP\n"+
71 "\tapl - Apollo Lake SoC\n"+
72 "\tcnl - CannonLake-LP or Whiskeylake/Coffeelake/Cometlake-U SoC\n"+
73 "\ttgl - TigerLake-H SoC\n"+
74 "\tadl - AlderLake PCH\n"+
75 "\tjsl - Jasper Lake SoC\n")
77 fieldstyle := flag.String("fld", "none", "set fields macros style:\n"+
78 "\tcb - use coreboot style for bit fields macros\n"+
79 "\tfsp - use fsp style\n"+
80 "\traw - do not convert, print as is\n")
82 flag.Parse()
84 config.IgnoredFieldsFlagSet(*ignFlag)
85 config.NonCheckingFlagSet(*nonCheckFlag)
87 for level, flag := range infoLevels {
88 if *flag {
89 config.InfoLevelSet(level + 1)
90 fmt.Printf("Info level: Use level %d!\n", level + 1)
91 break
95 if !config.TemplateSet(*template) {
96 fmt.Printf("Error! Unknown template format of input file!\n")
97 os.Exit(1)
100 if valid := config.PlatformSet(*platform); valid != 0 {
101 fmt.Printf("Error: invalid platform -%s!\n", *platform)
102 os.Exit(1)
105 fmt.Println("Log file:", *inputFileName)
106 fmt.Println("Output generated file:", *outputFileName)
108 inputRegDumpFile, err := os.Open(*inputFileName)
109 if err != nil {
110 fmt.Printf("Error: inteltool log file was not found!\n")
111 os.Exit(1)
114 if config.FldStyleSet(*fieldstyle) != 0 {
115 fmt.Printf("Error! Unknown bit fields style option -%s!\n", *fieldstyle)
116 os.Exit(1)
119 // create dir for output files
120 err = os.MkdirAll("generate", os.ModePerm)
121 if err != nil {
122 fmt.Printf("Error! Can not create a directory for the generated files!\n")
123 os.Exit(1)
126 // create empty gpio.h file
127 outputGenFile, err := os.Create(*outputFileName)
128 if err != nil {
129 fmt.Printf("Error: unable to generate GPIO config file!\n")
130 os.Exit(1)
133 defer inputRegDumpFile.Close()
134 defer outputGenFile.Close()
136 config.OutputGenFile = outputGenFile
137 config.InputRegDumpFile = inputRegDumpFile
139 parser := parser.ParserData{}
140 parser.Parse()
142 // gpio.h
143 err = generateOutputFile(&parser)
144 if err != nil {
145 fmt.Printf("Error! Can not create the file with GPIO configuration!\n")
146 os.Exit(1)