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 | |
| 54 | infoLevel1 := flag.Bool("i", |
| 55 | false, |
| 56 | "\n\tInfo Level 1: adds DW0/DW1 value to the comments:\n" + |
| 57 | "\t/* GPIO_173 - SDCARD_D0 */\n") |
| 58 | |
| 59 | infoLevel2 := flag.Bool("ii", |
| 60 | false, |
| 61 | "Info Level 2: adds original macro to the comments:\n" + |
| 62 | "\t/* GPIO_173 - SDCARD_D0 (DW0: 0x44000400, DW1: 0x00021000) */\n") |
| 63 | |
| 64 | infoLevel3 := flag.Bool("iii", |
| 65 | false, |
| 66 | "Info Level 3: adds information about bit fields that (need to be ignored)\n" + |
| 67 | "\twere ignored to generate a macro:\n" + |
| 68 | "\t/* GPIO_173 - SDCARD_D0 (DW0: 0x44000400, DW1: 0x00021000) */\n" + |
| 69 | "\t/* PAD_CFG_NF_IOSSTATE(GPIO_173, DN_20K, DEEP, NF1, HIZCRx1), */\n") |
| 70 | |
| 71 | infoLevel4 := flag.Bool("iiii", |
| 72 | false, |
| 73 | "Info Level 4: show decoded DW0/DW1 register:\n" + |
| 74 | "\t/* DW0: PAD_TRIG(DEEP) | PAD_BUF(TX_RX_DISABLE) - IGNORED */\n") |
| 75 | |
| 76 | template := flag.Int("t", 0, "template type number\n"+ |
| 77 | "\t0 - inteltool.log (default)\n"+ |
| 78 | "\t1 - gpio.h\n"+ |
| 79 | "\t2 - your template\n\t") |
| 80 | |
| 81 | platform := flag.String("p", "snr", "set platform:\n"+ |
| 82 | "\tsnr - Sunrise PCH or Skylake/Kaby Lake SoC\n"+ |
| 83 | "\tlbg - Lewisburg PCH with Xeon SP\n"+ |
Matt DeVillier | 5eeead2d | 2020-08-09 14:13:56 -0500 | [diff] [blame^] | 84 | "\tapl - Apollo Lake SoC\n"+ |
| 85 | "\tcnl - CannonLake-LP or Whiskeylake/Coffelake/Cometlake-U SoC\n") |
Maxim Polyakov | 82ec61e | 2020-04-26 22:12:01 +0300 | [diff] [blame] | 86 | |
| 87 | filedstyle := flag.String("fld", "none", "set fileds macros style:\n"+ |
| 88 | "\tcb - use coreboot style for bit fields macros\n"+ |
| 89 | "\tfsp - use fsp style\n"+ |
| 90 | "\traw - do not convert, print as is\n") |
| 91 | |
| 92 | flag.Parse() |
| 93 | |
| 94 | config.IgnoredFieldsFlagSet(*ignFlag) |
| 95 | config.NonCheckingFlagSet(*nonCheckFlag) |
| 96 | |
| 97 | if *infoLevel1 { |
| 98 | config.InfoLevelSet(1) |
| 99 | } else if *infoLevel2 { |
| 100 | config.InfoLevelSet(2) |
| 101 | } else if *infoLevel3 { |
| 102 | config.InfoLevelSet(3) |
| 103 | } else if *infoLevel4 { |
| 104 | config.InfoLevelSet(4) |
| 105 | } |
| 106 | |
| 107 | if !config.TemplateSet(*template) { |
| 108 | fmt.Printf("Error! Unknown template format of input file!\n") |
| 109 | os.Exit(1) |
| 110 | } |
| 111 | |
| 112 | if valid := config.PlatformSet(*platform); valid != 0 { |
| 113 | fmt.Printf("Error: invalid platform -%s!\n", *platform) |
| 114 | os.Exit(1) |
| 115 | } |
| 116 | |
| 117 | fmt.Println("Log file:", *inputFileName) |
| 118 | fmt.Println("Output generated file:", *outputFileName) |
| 119 | |
| 120 | inputRegDumpFile, err := os.Open(*inputFileName) |
| 121 | if err != nil { |
| 122 | fmt.Printf("Error: inteltool log file was not found!\n") |
| 123 | os.Exit(1) |
| 124 | } |
| 125 | |
| 126 | if config.FldStyleSet(*filedstyle) != 0 { |
| 127 | fmt.Printf("Error! Unknown bit fields style option -%s!\n", *filedstyle) |
| 128 | os.Exit(1) |
| 129 | } |
| 130 | |
| 131 | // create dir for output files |
| 132 | err = os.MkdirAll("generate", os.ModePerm) |
| 133 | if err != nil { |
| 134 | fmt.Printf("Error! Can not create a directory for the generated files!\n") |
| 135 | os.Exit(1) |
| 136 | } |
| 137 | |
| 138 | // create empty gpio.h file |
| 139 | outputGenFile, err := os.Create(*outputFileName) |
| 140 | if err != nil { |
| 141 | fmt.Printf("Error: unable to generate GPIO config file!\n") |
| 142 | os.Exit(1) |
| 143 | } |
| 144 | |
| 145 | defer inputRegDumpFile.Close() |
| 146 | defer outputGenFile.Close() |
| 147 | |
| 148 | config.OutputGenFile = outputGenFile |
| 149 | config.InputRegDumpFile = inputRegDumpFile |
| 150 | |
| 151 | parser := parser.ParserData{} |
| 152 | parser.Parse() |
| 153 | |
| 154 | // gpio.h |
| 155 | err = generateOutputFile(&parser) |
| 156 | if err != nil { |
| 157 | fmt.Printf("Error! Can not create the file with GPIO configuration!\n") |
| 158 | os.Exit(1) |
| 159 | } |
| 160 | } |