diff options
author | Robert Zieba <robertzieba@google.com> | 2022-04-01 09:48:28 -0600 |
---|---|---|
committer | Felix Held <felix-coreboot@felixheld.de> | 2022-04-05 14:50:56 +0000 |
commit | 255b1fb38bed3abf0086cb7f363c56f80509debd (patch) | |
tree | bdab8c9822eeab86814348d09f9a9cc74ecdbeb9 /util/spd_tools/src | |
parent | be1a050772a41b9927db2a94fa00874d6f789094 (diff) |
util/spd_tools: Add ability to override SPD file for parts
This commit adds the ability to override the SPD file that is used for a
specific part.
BUG=b:224884904
TEST=Verified that generated makefile uses specified SPD file and that
it remains unchanged when this capability is not used
Signed-off-by: Robert Zieba <robertzieba@google.com>
Change-Id: I078dd04fead2bf19f53bc6ca8295187d439adc20
Reviewed-on: https://review.coreboot.org/c/coreboot/+/63281
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Rob Barnes <robbarnes@google.com>
Diffstat (limited to 'util/spd_tools/src')
-rw-r--r-- | util/spd_tools/src/part_id_gen/part_id_gen.go | 75 |
1 files changed, 54 insertions, 21 deletions
diff --git a/util/spd_tools/src/part_id_gen/part_id_gen.go b/util/spd_tools/src/part_id_gen/part_id_gen.go index 65e07f426f..edbad9c540 100644 --- a/util/spd_tools/src/part_id_gen/part_id_gen.go +++ b/util/spd_tools/src/part_id_gen/part_id_gen.go @@ -102,9 +102,10 @@ const ( ) type usedPart struct { - partName string - index int - mapping mappingType + partName string + index int + mapping mappingType + SPDOverride string } func readPlatformsManifest(memTech string) (map[string]string, error) { @@ -183,30 +184,44 @@ func readParts(memPartsUsedFileName string) ([]usedPart, error) { } if len(fields) == 1 { - parts = append(parts, usedPart{fields[0], -1, Auto}) - } else if len(fields) == 2 { + parts = append(parts, usedPart{fields[0], -1, Auto, ""}) + } else { var mapping = Auto var assignedId = -1 var err error = nil + var spdOverride string = "" + + // Second column, ID override + if len(fields) >= 2 { + if len(fields[1]) >= 2 && fields[1][0] == '*' { + // Exclusive mapping + mapping = Exclusive + assignedId, err = strconv.Atoi(fields[1][1:]) + } else if fields[1] != "" { + // Fixed mapping + mapping = Fixed + assignedId, err = strconv.Atoi(fields[1]) + } + } - if len(fields[1]) >= 2 && fields[1][0] == '*' { - // Exclusive mapping - mapping = Exclusive - assignedId, err = strconv.Atoi(fields[1][1:]) - } else { - mapping = Fixed - assignedId, err = strconv.Atoi(fields[1]) + // Third column, SPD file override + if len(fields) >= 3 { + if len(fields[2]) == 0 { + err = fmt.Errorf("mem_parts_used_file file is incorrectly formatted, SPD file column is empty") + } else { + spdOverride = fields[2] + } } if err != nil { return nil, err } - if assignedId > MaxMemoryId || assignedId < 0 { + + if assignedId > MaxMemoryId { return nil, fmt.Errorf("Out of bounds assigned id %d for part %s", assignedId, fields[0]) } - parts = append(parts, usedPart{fields[0], assignedId, mapping}) - } else { - return nil, fmt.Errorf("mem_parts_used_file file is incorrectly formatted") + + parts = append(parts, usedPart{fields[0], assignedId, mapping, spdOverride}) } } @@ -288,7 +303,6 @@ func genPartIdInfo(parts []usedPart, partToSPDMap map[string]string, SPDToIndexM // Assign parts with fixed ids first for _, p := range parts { - if p.index == -1 { continue } @@ -299,7 +313,7 @@ func genPartIdInfo(parts []usedPart, partToSPDMap map[string]string, SPDToIndexM SPDFileName, ok := partToSPDMap[p.partName] if !ok { - return nil, fmt.Errorf("Failed to find part ", p.partName, " in SPD Manifest. Please add the part to global part list and regenerate SPD Manifest") + return nil, fmt.Errorf("Failed to find part %s in SPD Manifest. Please add the part to global part list and regenerate SPD Manifest", p.partName) } // Extend partIdList and assignedMapping with empty entries if needed @@ -396,7 +410,7 @@ func genPartIdInfo(parts []usedPart, partToSPDMap map[string]string, SPDToIndexM * This function generates Makefile.inc under the variant directory path and adds assigned SPDs * to SPD_SOURCES. */ -func genMakefile(partIdList []partIds, makefileDirName string, SPDDir string) error { +func genMakefile(partIdList []partIds, makefileDirName string, SPDDir string, partsDir string) error { s := getFileHeader() s += fmt.Sprintf("SPD_SOURCES =\n") @@ -405,7 +419,18 @@ func genMakefile(partIdList []partIds, makefileDirName string, SPDDir string) er s += fmt.Sprintf("SPD_SOURCES += %v ", filepath.Join(SPDDir, SPDEmptyFileName)) s += fmt.Sprintf(" # ID = %d(0b%04b)\n", i, int64(i)) } else { - s += fmt.Sprintf("SPD_SOURCES += %v ", filepath.Join(SPDDir, partIdList[i].SPDFileName)) + SPDFileName := partIdList[i].SPDFileName + path := filepath.Join(partsDir, SPDFileName) + + // Check if the file exists in the directory of the parts file + if _, err := os.Stat(path); err != nil { + // File doesn't exist, check spd directory + path = filepath.Join(SPDDir, SPDFileName) + if _, err = os.Stat(path); err != nil { + return fmt.Errorf("Failed to write Makefile, SPD file '%s' doesn't exist", SPDFileName) + } + } + s += fmt.Sprintf("SPD_SOURCES += %v ", path) s += fmt.Sprintf(" # ID = %d(0b%04b) ", i, int64(i)) s += fmt.Sprintf(" Parts = %04s\n", partIdList[i].memParts) } @@ -442,12 +467,20 @@ func main() { log.Fatal(err) } + // Update our SPD maps with part specific overrides + for _, p := range parts { + if p.SPDOverride != "" { + partToSPDMap[p.partName] = p.SPDOverride + SPDToIndexMap[p.SPDOverride] = -1 + } + } + partIdList, err := genPartIdInfo(parts, partToSPDMap, SPDToIndexMap, makefileDir) if err != nil { log.Fatal(err) } - if err := genMakefile(partIdList, makefileDir, SPDDir); err != nil { + if err := genMakefile(partIdList, makefileDir, SPDDir, filepath.Dir(memPartsUsedFile)); err != nil { log.Fatal(err) } } |