David Hendricks has submitted this change. ( https://review.coreboot.org/c/coreboot/+/67321?usp=email )
Change subject: util/intelp2m: Print the current project version ......................................................................
util/intelp2m: Print the current project version
Print the current project version in the console and in the generated file with the pad configuration. This makes support easier, since we know which version of the utility was used and whether we need to re-generate the configuration file if an error was made in the latest changes in the code. The version string includes several parts:
{major}.{minor}-{last commit in the intelp2m directory}-{?dirty}
The major is incremented if a new platform is added, minor - if changes in functionality are made. Add dirty if the changes were not taken into account using git.
Use the following command to print the version:
make version
Change-Id: Id2fd0757c003004af976309a44dbbfff0eb517a7 Signed-off-by: Maxim Polyakov max.senia.poliak@gmail.com Reviewed-on: https://review.coreboot.org/c/coreboot/+/67321 Reviewed-by: David Hendricks david.hendricks@gmail.com Tested-by: build bot (Jenkins) no-reply@coreboot.org --- M util/intelp2m/Makefile M util/intelp2m/main.go A util/intelp2m/scripts/linux/version.sh A util/intelp2m/version.txt 4 files changed, 54 insertions(+), 20 deletions(-)
Approvals: David Hendricks: Looks good to me, approved build bot (Jenkins): Verified
diff --git a/util/intelp2m/Makefile b/util/intelp2m/Makefile index ea44db4..5f6bc29 100644 --- a/util/intelp2m/Makefile +++ b/util/intelp2m/Makefile @@ -1,15 +1,23 @@ ## SPDX-License-Identifier: GPL-2.0-only -# simple makefile for the project
-OUTPUT_DIR = generate -PROJECT_NAME = intelp2m +PROJECT_NAME := intelp2m +THIS_FILE := $(lastword $(MAKEFILE_LIST)) +THIS_DIR := $(abspath $(dir $(THIS_FILE))) +SCRIPTS_DIR := $(THIS_DIR)/scripts/linux
-default: +OUTPUT_DIR := $(THIS_DIR)/generate +VERSION ?= $(shell $(SCRIPTS_DIR)/version.sh) +LDFLAGS = "-X main.Version=$(VERSION)" + +default: version go version - go build -v -o $(PROJECT_NAME) + go build -ldflags=$(LDFLAGS) -v
test: go test ./... -v -count=1
clean: - rm -Rf $(PROJECT_NAME) $(OUTPUT_DIR) + rm -Rf $(THIS_DIR)/$(PROJECT_NAME) $(OUTPUT_DIR) + +version: + @echo $(VERSION) diff --git a/util/intelp2m/main.go b/util/intelp2m/main.go index 38a3b5fc..1f3333b 100644 --- a/util/intelp2m/main.go +++ b/util/intelp2m/main.go @@ -9,19 +9,29 @@ "review.coreboot.org/coreboot.git/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(`}; @@ -48,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"), }
@@ -64,7 +74,7 @@ "\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"+ @@ -75,11 +85,12 @@ "\tmtl - MeteorLake SoC\n"+ "\tebg - Emmitsburg PCH with Xeon SP\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) @@ -88,7 +99,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 } } diff --git a/util/intelp2m/scripts/linux/version.sh b/util/intelp2m/scripts/linux/version.sh new file mode 100755 index 0000000..565063a --- /dev/null +++ b/util/intelp2m/scripts/linux/version.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env sh + +SCRIPTS_DIR=$(cd "$(dirname "$0")" && pwd) +PROJECT_DIR="${SCRIPTS_DIR}/../.." + +VERSION=$(cat ${PROJECT_DIR}/version.txt) +LAST_COMMIT=$(git log --oneline -n 1 --pretty=format:%h ${PROJECT_DIR}) +DIFF=$(git diff ${PROJECT_DIR}) + +if [ -z "$DIFF" ]; then + echo "${VERSION}-${LAST_COMMIT}" +else + echo "${VERSION}-${LAST_COMMIT}-dirty" +fi diff --git a/util/intelp2m/version.txt b/util/intelp2m/version.txt new file mode 100644 index 0000000..9459d4b --- /dev/null +++ b/util/intelp2m/version.txt @@ -0,0 +1 @@ +1.1