blob: 3de34dd3a5efb335fa0f9919d6fb85a359295408 [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"
Maxim Polyakov593b0f12022-05-11 22:49:14 +03007
8 "review.coreboot.org/coreboot.git/util/intelp2m/config"
9 "review.coreboot.org/coreboot.git/util/intelp2m/parser"
Maxim Polyakov8b358512021-06-30 16:14:53 +030010)
Maxim Polyakov82ec61e2020-04-26 22:12:01 +030011
12// generateOutputFile - generates include file
13// parser : parser data structure
14func generateOutputFile(parser *parser.ParserData) (err error) {
15
16 config.OutputGenFile.WriteString(`/* SPDX-License-Identifier: GPL-2.0-only */
17
18#ifndef CFG_GPIO_H
19#define CFG_GPIO_H
20
21#include <gpio.h>
22
23/* Pad configuration was generated automatically using intelp2m utility */
24static const struct pad_config gpio_table[] = {
25`)
26 // Add the pads map
27 parser.PadMapFprint()
28 config.OutputGenFile.WriteString(`};
29
30#endif /* CFG_GPIO_H */
31`)
32 return nil
33}
34
35// main
36func main() {
37 // Command line arguments
38 inputFileName := flag.String("file",
39 "inteltool.log",
40 "the path to the inteltool log file\n")
41
42 outputFileName := flag.String("o",
43 "generate/gpio.h",
44 "the path to the generated file with GPIO configuration\n")
45
46 ignFlag := flag.Bool("ign",
47 false,
48 "exclude fields that should be ignored from advanced macros\n")
49
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")
55
Maxim Polyakov726282b2020-09-30 16:46:11 +030056 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"),
61 }
Maxim Polyakov82ec61e2020-04-26 22:12:01 +030062
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")
67
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"+
Matt DeVillier5eeead2d2020-08-09 14:13:56 -050071 "\tapl - Apollo Lake SoC\n"+
Michał Kopećd3b550d2022-04-06 10:15:22 +020072 "\tcnl - CannonLake-LP or Whiskeylake/Coffeelake/Cometlake-U SoC\n"+
73 "\tadl - AlderLake PCH\n")
Maxim Polyakov82ec61e2020-04-26 22:12:01 +030074
Benjamin Doron03102792020-10-22 16:36:29 +000075 fieldstyle := flag.String("fld", "none", "set fields macros style:\n"+
Maxim Polyakov82ec61e2020-04-26 22:12:01 +030076 "\tcb - use coreboot style for bit fields macros\n"+
77 "\tfsp - use fsp style\n"+
78 "\traw - do not convert, print as is\n")
79
80 flag.Parse()
81
82 config.IgnoredFieldsFlagSet(*ignFlag)
83 config.NonCheckingFlagSet(*nonCheckFlag)
84
Maxim Polyakov726282b2020-09-30 16:46:11 +030085 for level, flag := range infoLevels {
86 if *flag {
87 config.InfoLevelSet(level + 1)
88 fmt.Printf("Info level: Use level %d!\n", level + 1)
89 break
90 }
Maxim Polyakov82ec61e2020-04-26 22:12:01 +030091 }
92
93 if !config.TemplateSet(*template) {
94 fmt.Printf("Error! Unknown template format of input file!\n")
95 os.Exit(1)
96 }
97
98 if valid := config.PlatformSet(*platform); valid != 0 {
99 fmt.Printf("Error: invalid platform -%s!\n", *platform)
100 os.Exit(1)
101 }
102
103 fmt.Println("Log file:", *inputFileName)
104 fmt.Println("Output generated file:", *outputFileName)
105
106 inputRegDumpFile, err := os.Open(*inputFileName)
107 if err != nil {
108 fmt.Printf("Error: inteltool log file was not found!\n")
109 os.Exit(1)
110 }
111
Benjamin Doron03102792020-10-22 16:36:29 +0000112 if config.FldStyleSet(*fieldstyle) != 0 {
113 fmt.Printf("Error! Unknown bit fields style option -%s!\n", *fieldstyle)
Maxim Polyakov82ec61e2020-04-26 22:12:01 +0300114 os.Exit(1)
115 }
116
117 // create dir for output files
118 err = os.MkdirAll("generate", os.ModePerm)
119 if err != nil {
120 fmt.Printf("Error! Can not create a directory for the generated files!\n")
121 os.Exit(1)
122 }
123
124 // create empty gpio.h file
125 outputGenFile, err := os.Create(*outputFileName)
126 if err != nil {
127 fmt.Printf("Error: unable to generate GPIO config file!\n")
128 os.Exit(1)
129 }
130
131 defer inputRegDumpFile.Close()
132 defer outputGenFile.Close()
133
134 config.OutputGenFile = outputGenFile
135 config.InputRegDumpFile = inputRegDumpFile
136
137 parser := parser.ParserData{}
138 parser.Parse()
139
140 // gpio.h
141 err = generateOutputFile(&parser)
142 if err != nil {
143 fmt.Printf("Error! Can not create the file with GPIO configuration!\n")
144 os.Exit(1)
145 }
146}