blob: 511f54d0d0b7aacc968c0af41f0fd3242cdd57c7 [file] [log] [blame]
Maxim Polyakov82ec61e2020-04-26 22:12:01 +03001package main
2
3import "flag"
4import "fmt"
5import "os"
6
7import "./parser"
8import "./config"
9
10// generateOutputFile - generates include file
11// parser : parser data structure
12func generateOutputFile(parser *parser.ParserData) (err error) {
13
14 config.OutputGenFile.WriteString(`/* SPDX-License-Identifier: GPL-2.0-only */
15
16#ifndef CFG_GPIO_H
17#define CFG_GPIO_H
18
19#include <gpio.h>
20
21/* Pad configuration was generated automatically using intelp2m utility */
22static const struct pad_config gpio_table[] = {
23`)
24 // Add the pads map
25 parser.PadMapFprint()
26 config.OutputGenFile.WriteString(`};
27
28#endif /* CFG_GPIO_H */
29`)
30 return nil
31}
32
33// main
34func main() {
35 // Command line arguments
36 inputFileName := flag.String("file",
37 "inteltool.log",
38 "the path to the inteltool log file\n")
39
40 outputFileName := flag.String("o",
41 "generate/gpio.h",
42 "the path to the generated file with GPIO configuration\n")
43
44 ignFlag := flag.Bool("ign",
45 false,
46 "exclude fields that should be ignored from advanced macros\n")
47
48 nonCheckFlag := flag.Bool("n",
49 false,
50 "Generate macros without checking.\n" +
51 "\tIn this case, some fields of the configuration registers\n" +
52 "\tDW0 will be ignored.\n")
53
Maxim Polyakov726282b2020-09-30 16:46:11 +030054 infoLevels := []*bool {
55 flag.Bool("i", false, "Show pads function in the comments"),
56 flag.Bool("ii", false, "Show DW0/DW1 value in the comments"),
57 flag.Bool("iii", false, "Show ignored bit fields in the comments"),
58 flag.Bool("iiii", false, "Show target PAD_CFG() macro in the comments"),
59 }
Maxim Polyakov82ec61e2020-04-26 22:12:01 +030060
61 template := flag.Int("t", 0, "template type number\n"+
62 "\t0 - inteltool.log (default)\n"+
63 "\t1 - gpio.h\n"+
64 "\t2 - your template\n\t")
65
66 platform := flag.String("p", "snr", "set platform:\n"+
67 "\tsnr - Sunrise PCH or Skylake/Kaby Lake SoC\n"+
68 "\tlbg - Lewisburg PCH with Xeon SP\n"+
Matt DeVillier5eeead2d2020-08-09 14:13:56 -050069 "\tapl - Apollo Lake SoC\n"+
Benjamin Doron03102792020-10-22 16:36:29 +000070 "\tcnl - CannonLake-LP or Whiskeylake/Coffeelake/Cometlake-U SoC\n")
Maxim Polyakov82ec61e2020-04-26 22:12:01 +030071
Benjamin Doron03102792020-10-22 16:36:29 +000072 fieldstyle := flag.String("fld", "none", "set fields macros style:\n"+
Maxim Polyakov82ec61e2020-04-26 22:12:01 +030073 "\tcb - use coreboot style for bit fields macros\n"+
74 "\tfsp - use fsp style\n"+
75 "\traw - do not convert, print as is\n")
76
77 flag.Parse()
78
79 config.IgnoredFieldsFlagSet(*ignFlag)
80 config.NonCheckingFlagSet(*nonCheckFlag)
81
Maxim Polyakov726282b2020-09-30 16:46:11 +030082 for level, flag := range infoLevels {
83 if *flag {
84 config.InfoLevelSet(level + 1)
85 fmt.Printf("Info level: Use level %d!\n", level + 1)
86 break
87 }
Maxim Polyakov82ec61e2020-04-26 22:12:01 +030088 }
89
90 if !config.TemplateSet(*template) {
91 fmt.Printf("Error! Unknown template format of input file!\n")
92 os.Exit(1)
93 }
94
95 if valid := config.PlatformSet(*platform); valid != 0 {
96 fmt.Printf("Error: invalid platform -%s!\n", *platform)
97 os.Exit(1)
98 }
99
100 fmt.Println("Log file:", *inputFileName)
101 fmt.Println("Output generated file:", *outputFileName)
102
103 inputRegDumpFile, err := os.Open(*inputFileName)
104 if err != nil {
105 fmt.Printf("Error: inteltool log file was not found!\n")
106 os.Exit(1)
107 }
108
Benjamin Doron03102792020-10-22 16:36:29 +0000109 if config.FldStyleSet(*fieldstyle) != 0 {
110 fmt.Printf("Error! Unknown bit fields style option -%s!\n", *fieldstyle)
Maxim Polyakov82ec61e2020-04-26 22:12:01 +0300111 os.Exit(1)
112 }
113
114 // create dir for output files
115 err = os.MkdirAll("generate", os.ModePerm)
116 if err != nil {
117 fmt.Printf("Error! Can not create a directory for the generated files!\n")
118 os.Exit(1)
119 }
120
121 // create empty gpio.h file
122 outputGenFile, err := os.Create(*outputFileName)
123 if err != nil {
124 fmt.Printf("Error: unable to generate GPIO config file!\n")
125 os.Exit(1)
126 }
127
128 defer inputRegDumpFile.Close()
129 defer outputGenFile.Close()
130
131 config.OutputGenFile = outputGenFile
132 config.InputRegDumpFile = inputRegDumpFile
133
134 parser := parser.ParserData{}
135 parser.Parse()
136
137 // gpio.h
138 err = generateOutputFile(&parser)
139 if err != nil {
140 fmt.Printf("Error! Can not create the file with GPIO configuration!\n")
141 os.Exit(1)
142 }
143}