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