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