Maxim Polyakov | 82ec61e | 2020-04-26 22:12:01 +0300 | [diff] [blame] | 1 | package main |
| 2 | |
Maxim Polyakov | 8b35851 | 2021-06-30 16:14:53 +0300 | [diff] [blame] | 3 | import ( |
| 4 | "flag" |
| 5 | "fmt" |
| 6 | "os" |
Maxim Polyakov | 593b0f1 | 2022-05-11 22:49:14 +0300 | [diff] [blame] | 7 | |
| 8 | "review.coreboot.org/coreboot.git/util/intelp2m/config" |
| 9 | "review.coreboot.org/coreboot.git/util/intelp2m/parser" |
Maxim Polyakov | 8b35851 | 2021-06-30 16:14:53 +0300 | [diff] [blame] | 10 | ) |
Maxim Polyakov | 82ec61e | 2020-04-26 22:12:01 +0300 | [diff] [blame] | 11 | |
| 12 | // generateOutputFile - generates include file |
| 13 | // parser : parser data structure |
| 14 | func 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 */ |
| 24 | static 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 |
| 36 | func 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 Polyakov | 726282b | 2020-09-30 16:46:11 +0300 | [diff] [blame] | 56 | 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 Polyakov | 82ec61e | 2020-04-26 22:12:01 +0300 | [diff] [blame] | 62 | |
| 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 DeVillier | 5eeead2d | 2020-08-09 14:13:56 -0500 | [diff] [blame] | 71 | "\tapl - Apollo Lake SoC\n"+ |
Michał Kopeć | d3b550d | 2022-04-06 10:15:22 +0200 | [diff] [blame] | 72 | "\tcnl - CannonLake-LP or Whiskeylake/Coffeelake/Cometlake-U SoC\n"+ |
Jonathon Hall | 1af3e3c | 2023-01-27 18:05:30 -0500 | [diff] [blame] | 73 | "\tadl - AlderLake PCH\n"+ |
| 74 | "\tjsl - Jasper Lake SoC\n") |
Maxim Polyakov | 82ec61e | 2020-04-26 22:12:01 +0300 | [diff] [blame] | 75 | |
Benjamin Doron | 0310279 | 2020-10-22 16:36:29 +0000 | [diff] [blame] | 76 | fieldstyle := flag.String("fld", "none", "set fields macros style:\n"+ |
Maxim Polyakov | 82ec61e | 2020-04-26 22:12:01 +0300 | [diff] [blame] | 77 | "\tcb - use coreboot style for bit fields macros\n"+ |
| 78 | "\tfsp - use fsp style\n"+ |
| 79 | "\traw - do not convert, print as is\n") |
| 80 | |
| 81 | flag.Parse() |
| 82 | |
| 83 | config.IgnoredFieldsFlagSet(*ignFlag) |
| 84 | config.NonCheckingFlagSet(*nonCheckFlag) |
| 85 | |
Maxim Polyakov | 726282b | 2020-09-30 16:46:11 +0300 | [diff] [blame] | 86 | for level, flag := range infoLevels { |
| 87 | if *flag { |
| 88 | config.InfoLevelSet(level + 1) |
| 89 | fmt.Printf("Info level: Use level %d!\n", level + 1) |
| 90 | break |
| 91 | } |
Maxim Polyakov | 82ec61e | 2020-04-26 22:12:01 +0300 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | if !config.TemplateSet(*template) { |
| 95 | fmt.Printf("Error! Unknown template format of input file!\n") |
| 96 | os.Exit(1) |
| 97 | } |
| 98 | |
| 99 | if valid := config.PlatformSet(*platform); valid != 0 { |
| 100 | fmt.Printf("Error: invalid platform -%s!\n", *platform) |
| 101 | os.Exit(1) |
| 102 | } |
| 103 | |
| 104 | fmt.Println("Log file:", *inputFileName) |
| 105 | fmt.Println("Output generated file:", *outputFileName) |
| 106 | |
| 107 | inputRegDumpFile, err := os.Open(*inputFileName) |
| 108 | if err != nil { |
| 109 | fmt.Printf("Error: inteltool log file was not found!\n") |
| 110 | os.Exit(1) |
| 111 | } |
| 112 | |
Benjamin Doron | 0310279 | 2020-10-22 16:36:29 +0000 | [diff] [blame] | 113 | if config.FldStyleSet(*fieldstyle) != 0 { |
| 114 | fmt.Printf("Error! Unknown bit fields style option -%s!\n", *fieldstyle) |
Maxim Polyakov | 82ec61e | 2020-04-26 22:12:01 +0300 | [diff] [blame] | 115 | os.Exit(1) |
| 116 | } |
| 117 | |
| 118 | // create dir for output files |
| 119 | err = os.MkdirAll("generate", os.ModePerm) |
| 120 | if err != nil { |
| 121 | fmt.Printf("Error! Can not create a directory for the generated files!\n") |
| 122 | os.Exit(1) |
| 123 | } |
| 124 | |
| 125 | // create empty gpio.h file |
| 126 | outputGenFile, err := os.Create(*outputFileName) |
| 127 | if err != nil { |
| 128 | fmt.Printf("Error: unable to generate GPIO config file!\n") |
| 129 | os.Exit(1) |
| 130 | } |
| 131 | |
| 132 | defer inputRegDumpFile.Close() |
| 133 | defer outputGenFile.Close() |
| 134 | |
| 135 | config.OutputGenFile = outputGenFile |
| 136 | config.InputRegDumpFile = inputRegDumpFile |
| 137 | |
| 138 | parser := parser.ParserData{} |
| 139 | parser.Parse() |
| 140 | |
| 141 | // gpio.h |
| 142 | err = generateOutputFile(&parser) |
| 143 | if err != nil { |
| 144 | fmt.Printf("Error! Can not create the file with GPIO configuration!\n") |
| 145 | os.Exit(1) |
| 146 | } |
| 147 | } |