blob: 6c6dc34369a5ac3b61af7e42a2c235c9f2e6dd1e [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
54 infoLevel1 := flag.Bool("i",
55 false,
56 "\n\tInfo Level 1: adds DW0/DW1 value to the comments:\n" +
57 "\t/* GPIO_173 - SDCARD_D0 */\n")
58
59 infoLevel2 := flag.Bool("ii",
60 false,
61 "Info Level 2: adds original macro to the comments:\n" +
62 "\t/* GPIO_173 - SDCARD_D0 (DW0: 0x44000400, DW1: 0x00021000) */\n")
63
64 infoLevel3 := flag.Bool("iii",
65 false,
66 "Info Level 3: adds information about bit fields that (need to be ignored)\n" +
67 "\twere ignored to generate a macro:\n" +
68 "\t/* GPIO_173 - SDCARD_D0 (DW0: 0x44000400, DW1: 0x00021000) */\n" +
69 "\t/* PAD_CFG_NF_IOSSTATE(GPIO_173, DN_20K, DEEP, NF1, HIZCRx1), */\n")
70
71 infoLevel4 := flag.Bool("iiii",
72 false,
73 "Info Level 4: show decoded DW0/DW1 register:\n" +
74 "\t/* DW0: PAD_TRIG(DEEP) | PAD_BUF(TX_RX_DISABLE) - IGNORED */\n")
75
76 template := flag.Int("t", 0, "template type number\n"+
77 "\t0 - inteltool.log (default)\n"+
78 "\t1 - gpio.h\n"+
79 "\t2 - your template\n\t")
80
81 platform := flag.String("p", "snr", "set platform:\n"+
82 "\tsnr - Sunrise PCH or Skylake/Kaby Lake SoC\n"+
83 "\tlbg - Lewisburg PCH with Xeon SP\n"+
84 "\tapl - Apollo Lake SoC\n")
85
86 filedstyle := flag.String("fld", "none", "set fileds macros style:\n"+
87 "\tcb - use coreboot style for bit fields macros\n"+
88 "\tfsp - use fsp style\n"+
89 "\traw - do not convert, print as is\n")
90
91 flag.Parse()
92
93 config.IgnoredFieldsFlagSet(*ignFlag)
94 config.NonCheckingFlagSet(*nonCheckFlag)
95
96 if *infoLevel1 {
97 config.InfoLevelSet(1)
98 } else if *infoLevel2 {
99 config.InfoLevelSet(2)
100 } else if *infoLevel3 {
101 config.InfoLevelSet(3)
102 } else if *infoLevel4 {
103 config.InfoLevelSet(4)
104 }
105
106 if !config.TemplateSet(*template) {
107 fmt.Printf("Error! Unknown template format of input file!\n")
108 os.Exit(1)
109 }
110
111 if valid := config.PlatformSet(*platform); valid != 0 {
112 fmt.Printf("Error: invalid platform -%s!\n", *platform)
113 os.Exit(1)
114 }
115
116 fmt.Println("Log file:", *inputFileName)
117 fmt.Println("Output generated file:", *outputFileName)
118
119 inputRegDumpFile, err := os.Open(*inputFileName)
120 if err != nil {
121 fmt.Printf("Error: inteltool log file was not found!\n")
122 os.Exit(1)
123 }
124
125 if config.FldStyleSet(*filedstyle) != 0 {
126 fmt.Printf("Error! Unknown bit fields style option -%s!\n", *filedstyle)
127 os.Exit(1)
128 }
129
130 // create dir for output files
131 err = os.MkdirAll("generate", os.ModePerm)
132 if err != nil {
133 fmt.Printf("Error! Can not create a directory for the generated files!\n")
134 os.Exit(1)
135 }
136
137 // create empty gpio.h file
138 outputGenFile, err := os.Create(*outputFileName)
139 if err != nil {
140 fmt.Printf("Error: unable to generate GPIO config file!\n")
141 os.Exit(1)
142 }
143
144 defer inputRegDumpFile.Close()
145 defer outputGenFile.Close()
146
147 config.OutputGenFile = outputGenFile
148 config.InputRegDumpFile = inputRegDumpFile
149
150 parser := parser.ParserData{}
151 parser.Parse()
152
153 // gpio.h
154 err = generateOutputFile(&parser)
155 if err != nil {
156 fmt.Printf("Error! Can not create the file with GPIO configuration!\n")
157 os.Exit(1)
158 }
159}