Felix Held has submitted this change. ( https://review.coreboot.org/c/coreboot/+/83184?usp=email )
Change subject: util/autoport: Make printing of SPDX headers generic ......................................................................
util/autoport: Make printing of SPDX headers generic
Previously, Add_gpl() was only used with C and ASL source code files, and was hard coded to use the C /* */ style comment, preventing it from being used with files with other comment styles. Convert this into a generic function for adding arbitrary SPDX license identifiers for arbitrary filetypes. This replaces the hard coded GPL-2.0-or-later string used in gma-mainboard.ads with a call to the new function.
This is also used to add SPDX headers to Kconfig and Makefile sources; as previous commits added them to all such files in the tree.
Tested against logs from a Latitude E6430 (Ivy Bridge) and Precision M6800 (Haswell) to check that license headers that were already being generated did not change.
Change-Id: I24a1ccd0afb7045e878bf6eaae7a23f828a9240d Signed-off-by: Nicholas Chin nic.c3.14@gmail.com Reviewed-on: https://review.coreboot.org/c/coreboot/+/83184 Tested-by: build bot (Jenkins) no-reply@coreboot.org Reviewed-by: Nico Huber nico.h@gmx.de Reviewed-by: Angel Pons th3fanbus@gmail.com --- M util/autoport/azalia.go M util/autoport/bd82x6x.go M util/autoport/ec_fixme.go M util/autoport/ec_lenovo.go M util/autoport/ec_none.go M util/autoport/gpio_common.go M util/autoport/lynxpoint.go M util/autoport/lynxpoint_lp_gpio.go M util/autoport/main.go 9 files changed, 55 insertions(+), 22 deletions(-)
Approvals: Angel Pons: Looks good to me, approved build bot (Jenkins): Verified Nico Huber: Looks good to me, approved
diff --git a/util/autoport/azalia.go b/util/autoport/azalia.go index 6dd78b1..1540398 100644 --- a/util/autoport/azalia.go +++ b/util/autoport/azalia.go @@ -12,7 +12,7 @@ az := Create(ctx, "hda_verb.c") defer az.Close()
- Add_gpl(az) + Add_SPDX(az, C, GPL2_only) az.WriteString( `#include <device/azalia_device.h>
diff --git a/util/autoport/bd82x6x.go b/util/autoport/bd82x6x.go index 2dc4961..71b97d4 100644 --- a/util/autoport/bd82x6x.go +++ b/util/autoport/bd82x6x.go @@ -181,7 +181,7 @@
sb := Create(ctx, "early_init.c") defer sb.Close() - Add_gpl(sb) + Add_SPDX(sb, C, GPL2_only)
sb.WriteString(`#include <bootblock_common.h> #include <device/pci_ops.h> @@ -246,7 +246,7 @@ gnvs := Create(ctx, "acpi_tables.c") defer gnvs.Close()
- Add_gpl(gnvs) + Add_SPDX(gnvs, C, GPL2_only) gnvs.WriteString(`#include <acpi/acpi_gnvs.h> #include <soc/nvs.h>
diff --git a/util/autoport/ec_fixme.go b/util/autoport/ec_fixme.go index 54f78ab..e0a6554 100644 --- a/util/autoport/ec_fixme.go +++ b/util/autoport/ec_fixme.go @@ -19,7 +19,7 @@ SouthBridge.EnableGPE(SouthBridge.DecodeGPE(sbGPE)) }
- Add_gpl(ap) + Add_SPDX(ap, ASL, GPL2_only) ap.WriteString( `Method(_WAK, 1) { @@ -65,7 +65,7 @@ defer si.Close()
if hasKeyboard { - Add_gpl(si) + Add_SPDX(si, ASL, GPL2_only) si.WriteString("#include <drivers/pc80/pc/ps2_controller.asl>\n") MainboardInit += fmt.Sprintf("\tpc_keyboard_init(NO_AUX_DEVICE);\n") MainboardIncludes = append(MainboardIncludes, "pc80/keyboard.h") @@ -74,7 +74,7 @@ ec := Create(ctx, "acpi/ec.asl") defer ec.Close()
- Add_gpl(ec) + Add_SPDX(ec, ASL, GPL2_only) ec.WriteString(`Device(EC) { Name (_HID, EISAID("PNP0C09")) diff --git a/util/autoport/ec_lenovo.go b/util/autoport/ec_lenovo.go index a34960f..38257d0 100644 --- a/util/autoport/ec_lenovo.go +++ b/util/autoport/ec_lenovo.go @@ -39,7 +39,7 @@ Value: "1", }, GPEDefine)
- Add_gpl(ap) + Add_SPDX(ap, ASL, GPL2_only) ap.WriteString( `Method(_WAK, 1) { @@ -58,7 +58,7 @@ si := Create(ctx, "acpi/superio.asl") defer si.Close()
- Add_gpl(si) + Add_SPDX(si, ASL, GPL2_only) si.WriteString("#include <drivers/pc80/pc/ps2_controller.asl>\n")
/* FIXME:XX Move this to ec/lenovo. */ @@ -67,7 +67,7 @@
AddSMMFile("smihandler.c", "")
- Add_gpl(smi) + Add_SPDX(smi, C, GPL2_only) smi.WriteString( `#include <arch/io.h> #include <console/console.h> @@ -146,7 +146,7 @@ ec := Create(ctx, "acpi/ec.asl") defer ec.Close()
- Add_gpl(ec) + Add_SPDX(ec, ASL, GPL2_only) ec.WriteString("#include <ec/lenovo/h8/acpi/ec.asl>\n")
KconfigBool["EC_LENOVO_PMH7"] = true diff --git a/util/autoport/ec_none.go b/util/autoport/ec_none.go index bcb61bf..a1a0df9 100644 --- a/util/autoport/ec_none.go +++ b/util/autoport/ec_none.go @@ -4,7 +4,7 @@ ap := Create(ctx, "acpi/platform.asl") defer ap.Close()
- Add_gpl(ap) + Add_SPDX(ap, ASL, GPL2_only) ap.WriteString( `Method(_WAK, 1) { diff --git a/util/autoport/gpio_common.go b/util/autoport/gpio_common.go index a869dce..36e1ed0 100644 --- a/util/autoport/gpio_common.go +++ b/util/autoport/gpio_common.go @@ -41,7 +41,7 @@ AddBootBlockFile("gpio.c", "") AddROMStageFile("gpio.c", "")
- Add_gpl(gpio) + Add_SPDX(gpio, C, GPL2_only) gpio.WriteString("#include <southbridge/intel/common/gpio.h>\n\n")
addresses := [3][6]int{ diff --git a/util/autoport/lynxpoint.go b/util/autoport/lynxpoint.go index 7168686..899736e 100644 --- a/util/autoport/lynxpoint.go +++ b/util/autoport/lynxpoint.go @@ -258,7 +258,7 @@ AddBootBlockFile("bootblock.c", "") bb := Create(ctx, "bootblock.c") defer bb.Close() - Add_gpl(bb) + Add_SPDX(bb, C, GPL2_only) bb.WriteString(`#include <southbridge/intel/lynxpoint/pch.h>
/* FIXME: remove this if not needed */ @@ -269,7 +269,7 @@
sb := Create(ctx, "romstage.c") defer sb.Close() - Add_gpl(sb) + Add_SPDX(sb, C, GPL2_only) sb.WriteString(`#include <stdint.h> #include <northbridge/intel/haswell/haswell.h> #include <southbridge/intel/lynxpoint/pch.h> diff --git a/util/autoport/lynxpoint_lp_gpio.go b/util/autoport/lynxpoint_lp_gpio.go index ee5944c..7163a8e 100644 --- a/util/autoport/lynxpoint_lp_gpio.go +++ b/util/autoport/lynxpoint_lp_gpio.go @@ -230,7 +230,7 @@
AddROMStageFile("gpio.c", "")
- Add_gpl(gpio) + Add_SPDX(gpio, C, GPL2_only) gpio.WriteString(`#include <southbridge/intel/lynxpoint/lp_gpio.h>
const struct pch_lp_gpio_map mainboard_lp_gpio_map[] = { diff --git a/util/autoport/main.go b/util/autoport/main.go index 3b08515..c4f884a9 100644 --- a/util/autoport/main.go +++ b/util/autoport/main.go @@ -99,6 +99,31 @@ SaneVendor string }
+type Filetype int + +const ( + Ada Filetype = iota + ASL + C + Kconfig + Makefile +) + +var CommentFormatStrings map[Filetype]string = map[Filetype]string { + Ada: "-- %s\n", + ASL: "/* %s */\n", + C: "/* %s */\n", + Kconfig: "## %s\n", + Makefile: "## %s\n", +} + +type License string + +const ( + GPL2_only License = "GPL-2.0-only" + GPL2_or_later = "GPL-2.0-or-later" +) + var KconfigBool map[string]bool = map[string]bool{} var KconfigComment map[string]string = map[string]string{} var KconfigString map[string]string = map[string]string{} @@ -209,11 +234,15 @@ return mf }
-func Add_gpl(f *os.File) { - fmt.Fprintln(f, "/* SPDX-License-Identifier: GPL-2.0-only */") +func Add_SPDX(f *os.File, filetype Filetype, license License) { + Add_Comment(f, filetype, "SPDX-License-Identifier: " + string(license)) fmt.Fprintln(f) }
+func Add_Comment(f *os.File, filetype Filetype, comment string) { + fmt.Fprintf(f, CommentFormatStrings[filetype], comment) +} + func RestorePCI16Simple(f *os.File, pcidev PCIDevData, addr uint16) { fmt.Fprintf(f, " pci_write_config16(PCI_DEV(%d, 0x%02x, %d), 0x%02x, 0x%02x%02x);\n", pcidev.Bus, pcidev.Dev, pcidev.Func, addr, @@ -522,6 +551,7 @@ func makeKconfigName(ctx Context) { kn := Create(ctx, "Kconfig.name") defer kn.Close() + Add_SPDX(kn, Kconfig, GPL2_only)
fmt.Fprintf(kn, "config %s\n\tbool "%s"\n", ctx.KconfigName, ctx.Model) } @@ -537,6 +567,7 @@ func makeKconfig(ctx Context) { kc := Create(ctx, "Kconfig") defer kc.Close() + Add_SPDX(kc, Kconfig, GPL2_only)
fmt.Fprintf(kc, "if %s\n\n", ctx.KconfigName)
@@ -633,6 +664,7 @@ log.Fatal(err) } defer f.Close() + Add_SPDX(f, Kconfig, GPL2_only) f.WriteString(`if VENDOR_` + vendorUpper + `
choice @@ -657,6 +689,7 @@ log.Fatal(err) } defer f.Close() + Add_SPDX(f, Kconfig, GPL2_only) f.WriteString(`config VENDOR_` + vendorUpper + ` bool "` + vendor + `" `) @@ -734,6 +767,7 @@ if len(BootBlockFiles) > 0 || len(ROMStageFiles) > 0 || len(RAMStageFiles) > 0 || len(SMMFiles) > 0 { mf := Create(ctx, "Makefile.mk") defer mf.Close() + Add_SPDX(mf, Makefile, GPL2_only) writeMF(mf, BootBlockFiles, "bootblock") writeMF(mf, ROMStageFiles, "romstage") writeMF(mf, RAMStageFiles, "ramstage") @@ -749,7 +783,7 @@ if MainboardInit != "" || MainboardEnable != "" || MainboardIncludes != nil { mainboard := Create(ctx, "mainboard.c") defer mainboard.Close() - Add_gpl(mainboard) + Add_SPDX(mainboard, C, GPL2_only) mainboard.WriteString("#include <device/device.h>\n") for _, include := range MainboardIncludes { mainboard.WriteString("#include <" + include + ">\n") @@ -820,7 +854,7 @@
dsdt := Create(ctx, "dsdt.asl") defer dsdt.Close() - Add_gpl(dsdt) + Add_SPDX(dsdt, ASL, GPL2_only)
for _, define := range DSDTDefines { if define.Comment != "" { @@ -870,10 +904,9 @@ if IGDEnabled { gma := Create(ctx, "gma-mainboard.ads") defer gma.Close() + Add_SPDX(gma, Ada, GPL2_or_later)
- gma.WriteString(`-- SPDX-License-Identifier: GPL-2.0-or-later - -with HW.GFX.GMA; + gma.WriteString(`with HW.GFX.GMA; with HW.GFX.GMA.Display_Probing;
use HW.GFX.GMA;