Maxim Polyakov has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/67321 )
Change subject: util/intelp2m: Print the current project verion ......................................................................
util/intelp2m: Print the current project verion
Print the current project version in the console and in the generated file with the pad configuration: version = major-minor; major = 1.0; minor = last commit in the intelp2m directory.
Change-Id: Id2fd0757c003004af976309a44dbbfff0eb517a7 Signed-off-by: Maxim Polyakov max.senia.poliak@gmail.com --- M util/intelp2m/Makefile M util/intelp2m/main.go 2 files changed, 52 insertions(+), 21 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/21/67321/1
diff --git a/util/intelp2m/Makefile b/util/intelp2m/Makefile index 74aa09d..f7e7640 100644 --- a/util/intelp2m/Makefile +++ b/util/intelp2m/Makefile @@ -1,14 +1,21 @@ -# simple makefile for the project +PROJECT_NAME := intelp2m
-OUTPUT_DIR = generate -PROJECT_NAME = intelp2m +THIS_FILE := $(lastword $(MAKEFILE_LIST)) +THIS_DIR := $(abspath $(dir $(THIS_FILE)))
-default: +P2M_OUTPUT_DIR := $(THIS_DIR)/generate +P2M_VERSION ?= 1.0-$(shell git log --oneline -n 1 --pretty=format:%h $(THIS_DIR)) +P2M_LDFLAGS = "-X main.Version=$(P2M_VERSION)" + +default: version go version - go build -v -o $(PROJECT_NAME) + go build -ldflags=$(P2M_LDFLAGS) -v -o $(PROJECT_NAME)
test: go test ./... -v -count=1
clean: - rm -Rf $(PROJECT_NAME) $(OUTPUT_DIR) + rm -Rf $(PROJECT_NAME) $(P2M_OUTPUT_DIR) + +version: + @echo $(P2M_VERSION) diff --git a/util/intelp2m/main.go b/util/intelp2m/main.go index b79b728..bb9ddca 100644 --- a/util/intelp2m/main.go +++ b/util/intelp2m/main.go @@ -9,20 +9,29 @@ "review.coreboot.org/coreboot/coreboot/util/intelp2m/parser" )
+var ( + // Version is injected into main during project build + Version string = "Unknown" +) + +// printVersion - print the utility version in the console +func printVersion() { + fmt.Printf("[ intelp2m ] Version: %s\n", Version) +} + // 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 */ + header := fmt.Sprintf(`/* 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[] = { -`) +/* Pad configuration was generated automatically using intelp2m %s */ +static const struct pad_config gpio_table[] = {`, Version) + config.OutputGenFile.WriteString(header + "\n") // Add the pads map parser.PadMapFprint() config.OutputGenFile.WriteString(`}; @@ -49,14 +58,14 @@
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") + "Generate macros without checking.\n"+ + "\tIn this case, some fields of the configuration registers\n"+ + "\tDW0 will be ignored.\n")
- 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"), + 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"), }
@@ -65,18 +74,19 @@ "\t1 - gpio.h\n"+ "\t2 - your template\n\t")
- platform := flag.String("p", "snr", "set platform:\n"+ + 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"+ + 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")
+ printVersion() flag.Parse()
config.IgnoredFieldsFlagSet(*ignFlag) @@ -85,7 +95,7 @@ for level, flag := range infoLevels { if *flag { config.InfoLevelSet(level + 1) - fmt.Printf("Info level: Use level %d!\n", level + 1) + fmt.Printf("Info level: Use level %d!\n", level+1) break } }