coreboot-kgpe-d16/util/intelp2m/main.go

147 lines
3.7 KiB
Go
Raw Normal View History

package main
import (
"flag"
"fmt"
"os"
intelp2m: Add Go Managing Dependencies System support Add go.mod containing the full name of the project according to the docs [1]: review.coreboot.org/coreboot.git/util/intelp2m, and also, based on this, rename the internal packages to point to the absolute path. This will allow Go Managing Dependencies System to integrate packages from intelp2m to third-party Go written on the Go language [1]. This also requires fixing the Golang compiler version in go.mod: use go1.18 [2], the latest up-to-date version. [1] https://web.archive.org/web/20220910100342/https://go.dev/doc/modules/managing-dependencies [2] https://web.archive.org/web/20220910100206/https://tip.golang.org/doc/go1.18 [ TEST ] 1) Import the coreboot project into some go project: $cd path/to/go-project $go get review.coreboot.org/coreboot.git go: downloading review.coreboot.org/coreboot.git v0.0.0-20220903004133 -39914a50ae16 go: added review.coreboot.org/coreboot.git v0.0.0-20220903004133 -39914a50ae16 Thus, 'go get' correctly downloaded the contents of the repository. 2) Import intelp2m: $cd path/to/go-project $go get review.coreboot.org/coreboot.git/util/intelp2m review.coreboot.org/coreboot.git/util/intelp2m imports ./config: "./config" is relative, but relative import paths are not supported in module mode review.coreboot.org/coreboot.git/util/intelp2m imports ./parser: "./parser" is relative, but relative import paths are not supported in module mode Thus, the problem is in the package names, but after this patch, the import should be without errors. 3) Import a repository with an incorrect url: $cd path/to/go-project $go get review.coreboot.org/coreboot/test go: unrecognized import path "review.coreboot.org/coreboot/test": reading https://review.coreboot.org/coreboot/test?go-get=1: 404 Not Found This has not happened in previous cases. Change-Id: I12efae31227129b8c884af10fb233f398c4094e7 Signed-off-by: Maxim Polyakov <max.senia.poliak@gmail.com> Reviewed-on: https://review.coreboot.org/c/coreboot/+/64724 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: David Hendricks <david.hendricks@gmail.com>
2022-05-11 21:49:14 +02:00
"review.coreboot.org/coreboot.git/util/intelp2m/config"
"review.coreboot.org/coreboot.git/util/intelp2m/parser"
)
// generateOutputFile - generates include file
// parser : parser data structure
func generateOutputFile(parser *parser.ParserData) (err error) {
config.OutputGenFile.WriteString(`/* SPDX-License-Identifier: GPL-2.0-only */
#ifndef CFG_GPIO_H
#define CFG_GPIO_H
#include <gpio.h>
/* Pad configuration was generated automatically using intelp2m utility */
static const struct pad_config gpio_table[] = {
`)
// Add the pads map
parser.PadMapFprint()
config.OutputGenFile.WriteString(`};
#endif /* CFG_GPIO_H */
`)
return nil
}
// main
func main() {
// Command line arguments
inputFileName := flag.String("file",
"inteltool.log",
"the path to the inteltool log file\n")
outputFileName := flag.String("o",
"generate/gpio.h",
"the path to the generated file with GPIO configuration\n")
ignFlag := flag.Bool("ign",
false,
"exclude fields that should be ignored from advanced macros\n")
nonCheckFlag := flag.Bool("n",
false,
"Generate macros without checking.\n" +
"\tIn this case, some fields of the configuration registers\n" +
"\tDW0 will be ignored.\n")
util/intelp2m: Update output information format in the comments Update the information format in the comments above the macros in the generated gpio.h file: PAD_CFG_NF_IOSSTATE_IOSTERM(GPIO_39, UP_20K, DEEP, NF1, TxLASTRxE, DISPUPD), /* LPSS_UART0_TXD */ -->(i) /* GPIO_39 - LPSS_UART0_TXD */ --> (ii) /* DW0: 0x44000400, DW1: 0x00003100 */ --> (ii) /* DW0 : PAD_TRIG(OFF) - IGNORED */ --> (iii) /* _PAD_CFG_STRUCT(GPIO_39, PAD_FUNC(NF1) | PAD_RESET(DEEP) | PAD_TRIG(OFF), PAD_PULL(UP_20K) | PAD_IOSTERM(DISPUPD)), */ --> (iiii) PAD_CFG_NF_IOSSTATE_IOSTERM(GPIO_39, UP_20K, DEEP, NF1, TxLASTRxE, DISPUPD), Also, in the case of field macros: /* GPIO_39 - LPSS_UART0_TXD */ --> (ii) /* DW0: 0x44000400, DW1: 0x00003100 */ --> (ii) /* DW0 : PAD_TRIG(OFF) - IGNORED */ --> (iii) /* PAD_CFG_NF_IOSSTATE_IOSTERM(GPIO_39, UP_20K, DEEP, NF1, TxLASTRxE, DISPUPD), */ --> (iiii) PAD_CFG_STRUCT(GPIO_39, PAD_FUNC(NF1) | PAD_RESET(DEEP) | PAD_TRIG(OFF), PAD_PULL(UP_20K) | PAD_IOSTERM(DISPUPD)), By default, if do not use the -i... option, then additional information in comments will not be generated. TEST: git clone https://github.com/maxpoliak/inteltool-examples.git test ./intelp2m -n -file test/inteltool-asrock-h110m-stx.log ./intelp2m -fld cb -file test/inteltool-asrock-h110m-stx.log ./intelp2m -fld fsp -file test/inteltool-asrock-h110m-stx.log ./intelp2m -fld raw -file test/inteltool-asrock-h110m-stx.log Before and after (now with -i key) the patch, gpio.h is no different. Change-Id: I760f4aadece786ea455fb7569f42e06fefce2b61 Signed-off-by: Maxim Polyakov <max.senia.poliak@gmail.com> Reviewed-on: https://review.coreboot.org/c/coreboot/+/45168 Reviewed-by: Matt DeVillier <matt.devillier@gmail.com> Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
2020-09-30 15:46:11 +02:00
infoLevels := []*bool {
flag.Bool("i", false, "Show pads function in the comments"),
flag.Bool("ii", false, "Show DW0/DW1 value in the comments"),
flag.Bool("iii", false, "Show ignored bit fields in the comments"),
flag.Bool("iiii", false, "Show target PAD_CFG() macro in the comments"),
}
template := flag.Int("t", 0, "template type number\n"+
"\t0 - inteltool.log (default)\n"+
"\t1 - gpio.h\n"+
"\t2 - your template\n\t")
platform := flag.String("p", "snr", "set platform:\n"+
"\tsnr - Sunrise PCH or Skylake/Kaby Lake SoC\n"+
"\tlbg - Lewisburg PCH with Xeon SP\n"+
"\tapl - Apollo Lake SoC\n"+
"\tcnl - CannonLake-LP or Whiskeylake/Coffeelake/Cometlake-U SoC\n"+
"\tadl - AlderLake PCH\n")
fieldstyle := flag.String("fld", "none", "set fields macros style:\n"+
"\tcb - use coreboot style for bit fields macros\n"+
"\tfsp - use fsp style\n"+
"\traw - do not convert, print as is\n")
flag.Parse()
config.IgnoredFieldsFlagSet(*ignFlag)
config.NonCheckingFlagSet(*nonCheckFlag)
util/intelp2m: Update output information format in the comments Update the information format in the comments above the macros in the generated gpio.h file: PAD_CFG_NF_IOSSTATE_IOSTERM(GPIO_39, UP_20K, DEEP, NF1, TxLASTRxE, DISPUPD), /* LPSS_UART0_TXD */ -->(i) /* GPIO_39 - LPSS_UART0_TXD */ --> (ii) /* DW0: 0x44000400, DW1: 0x00003100 */ --> (ii) /* DW0 : PAD_TRIG(OFF) - IGNORED */ --> (iii) /* _PAD_CFG_STRUCT(GPIO_39, PAD_FUNC(NF1) | PAD_RESET(DEEP) | PAD_TRIG(OFF), PAD_PULL(UP_20K) | PAD_IOSTERM(DISPUPD)), */ --> (iiii) PAD_CFG_NF_IOSSTATE_IOSTERM(GPIO_39, UP_20K, DEEP, NF1, TxLASTRxE, DISPUPD), Also, in the case of field macros: /* GPIO_39 - LPSS_UART0_TXD */ --> (ii) /* DW0: 0x44000400, DW1: 0x00003100 */ --> (ii) /* DW0 : PAD_TRIG(OFF) - IGNORED */ --> (iii) /* PAD_CFG_NF_IOSSTATE_IOSTERM(GPIO_39, UP_20K, DEEP, NF1, TxLASTRxE, DISPUPD), */ --> (iiii) PAD_CFG_STRUCT(GPIO_39, PAD_FUNC(NF1) | PAD_RESET(DEEP) | PAD_TRIG(OFF), PAD_PULL(UP_20K) | PAD_IOSTERM(DISPUPD)), By default, if do not use the -i... option, then additional information in comments will not be generated. TEST: git clone https://github.com/maxpoliak/inteltool-examples.git test ./intelp2m -n -file test/inteltool-asrock-h110m-stx.log ./intelp2m -fld cb -file test/inteltool-asrock-h110m-stx.log ./intelp2m -fld fsp -file test/inteltool-asrock-h110m-stx.log ./intelp2m -fld raw -file test/inteltool-asrock-h110m-stx.log Before and after (now with -i key) the patch, gpio.h is no different. Change-Id: I760f4aadece786ea455fb7569f42e06fefce2b61 Signed-off-by: Maxim Polyakov <max.senia.poliak@gmail.com> Reviewed-on: https://review.coreboot.org/c/coreboot/+/45168 Reviewed-by: Matt DeVillier <matt.devillier@gmail.com> Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
2020-09-30 15:46:11 +02:00
for level, flag := range infoLevels {
if *flag {
config.InfoLevelSet(level + 1)
fmt.Printf("Info level: Use level %d!\n", level + 1)
break
}
}
if !config.TemplateSet(*template) {
fmt.Printf("Error! Unknown template format of input file!\n")
os.Exit(1)
}
if valid := config.PlatformSet(*platform); valid != 0 {
fmt.Printf("Error: invalid platform -%s!\n", *platform)
os.Exit(1)
}
fmt.Println("Log file:", *inputFileName)
fmt.Println("Output generated file:", *outputFileName)
inputRegDumpFile, err := os.Open(*inputFileName)
if err != nil {
fmt.Printf("Error: inteltool log file was not found!\n")
os.Exit(1)
}
if config.FldStyleSet(*fieldstyle) != 0 {
fmt.Printf("Error! Unknown bit fields style option -%s!\n", *fieldstyle)
os.Exit(1)
}
// create dir for output files
err = os.MkdirAll("generate", os.ModePerm)
if err != nil {
fmt.Printf("Error! Can not create a directory for the generated files!\n")
os.Exit(1)
}
// create empty gpio.h file
outputGenFile, err := os.Create(*outputFileName)
if err != nil {
fmt.Printf("Error: unable to generate GPIO config file!\n")
os.Exit(1)
}
defer inputRegDumpFile.Close()
defer outputGenFile.Close()
config.OutputGenFile = outputGenFile
config.InputRegDumpFile = inputRegDumpFile
parser := parser.ParserData{}
parser.Parse()
// gpio.h
err = generateOutputFile(&parser)
if err != nil {
fmt.Printf("Error! Can not create the file with GPIO configuration!\n")
os.Exit(1)
}
}