blob: 38a3b5fc707e3809e70c23210ef5cffabec1bad5 [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 */
Maxim Polyakov81f4beb2024-06-07 18:10:24 +030024static const struct pad_config gpio_table[] = {`)
Maxim Polyakov82ec61e2020-04-26 22:12:01 +030025 // 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"+
Alicja Michalskac45d5c82024-03-29 14:01:23 +010072 "\ttgl - TigerLake-H SoC\n"+
Jonathon Hall1af3e3c2023-01-27 18:05:30 -050073 "\tadl - AlderLake PCH\n"+
Filip Lewiński78985942024-04-15 16:46:04 +020074 "\tjsl - Jasper Lake SoC\n"+
Fabian Meyer92e372b2024-05-06 16:54:48 +020075 "\tmtl - MeteorLake SoC\n"+
76 "\tebg - Emmitsburg PCH with Xeon SP\n")
Maxim Polyakov82ec61e2020-04-26 22:12:01 +030077
Benjamin Doron03102792020-10-22 16:36:29 +000078 fieldstyle := flag.String("fld", "none", "set fields macros style:\n"+
Maxim Polyakov82ec61e2020-04-26 22:12:01 +030079 "\tcb - use coreboot style for bit fields macros\n"+
80 "\tfsp - use fsp style\n"+
81 "\traw - do not convert, print as is\n")
82
83 flag.Parse()
84
85 config.IgnoredFieldsFlagSet(*ignFlag)
86 config.NonCheckingFlagSet(*nonCheckFlag)
87
Maxim Polyakov726282b2020-09-30 16:46:11 +030088 for level, flag := range infoLevels {
89 if *flag {
90 config.InfoLevelSet(level + 1)
91 fmt.Printf("Info level: Use level %d!\n", level + 1)
92 break
93 }
Maxim Polyakov82ec61e2020-04-26 22:12:01 +030094 }
95
96 if !config.TemplateSet(*template) {
97 fmt.Printf("Error! Unknown template format of input file!\n")
98 os.Exit(1)
99 }
100
101 if valid := config.PlatformSet(*platform); valid != 0 {
102 fmt.Printf("Error: invalid platform -%s!\n", *platform)
103 os.Exit(1)
104 }
105
106 fmt.Println("Log file:", *inputFileName)
107 fmt.Println("Output generated file:", *outputFileName)
108
109 inputRegDumpFile, err := os.Open(*inputFileName)
110 if err != nil {
111 fmt.Printf("Error: inteltool log file was not found!\n")
112 os.Exit(1)
113 }
114
Benjamin Doron03102792020-10-22 16:36:29 +0000115 if config.FldStyleSet(*fieldstyle) != 0 {
116 fmt.Printf("Error! Unknown bit fields style option -%s!\n", *fieldstyle)
Maxim Polyakov82ec61e2020-04-26 22:12:01 +0300117 os.Exit(1)
118 }
119
120 // create dir for output files
121 err = os.MkdirAll("generate", os.ModePerm)
122 if err != nil {
123 fmt.Printf("Error! Can not create a directory for the generated files!\n")
124 os.Exit(1)
125 }
126
127 // create empty gpio.h file
128 outputGenFile, err := os.Create(*outputFileName)
129 if err != nil {
130 fmt.Printf("Error: unable to generate GPIO config file!\n")
131 os.Exit(1)
132 }
133
134 defer inputRegDumpFile.Close()
135 defer outputGenFile.Close()
136
137 config.OutputGenFile = outputGenFile
138 config.InputRegDumpFile = inputRegDumpFile
139
140 parser := parser.ParserData{}
141 parser.Parse()
142
143 // gpio.h
144 err = generateOutputFile(&parser)
145 if err != nil {
146 fmt.Printf("Error! Can not create the file with GPIO configuration!\n")
147 os.Exit(1)
148 }
149}