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