From f23794cf04030bb8d1d7ebe0a3634dffd092e2f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Niew=C3=B6hner?= Date: Fri, 28 Aug 2020 00:59:19 +0200 Subject: util/spd_tools: output binaries instead of hexdumps MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Instead of generating hexdumps, output binary SPD files since we plan to convert all hex SPD files to binary. Also adjust the file extension where needed. Test: compared generated binaries with converted binaries from hex files Change-Id: Ie99d108ca90758d09dbefad20fe6c9f7fc263ef1 Signed-off-by: Michael Niewöhner Reviewed-on: https://review.coreboot.org/c/coreboot/+/44878 Tested-by: build bot (Jenkins) Reviewed-by: Patrick Georgi Reviewed-by: Angel Pons --- util/spd_tools/lp4x/README.md | 18 +++++++++--------- util/spd_tools/lp4x/gen_spd.go | 21 ++++++++------------- 2 files changed, 17 insertions(+), 22 deletions(-) (limited to 'util/spd_tools/lp4x') diff --git a/util/spd_tools/lp4x/README.md b/util/spd_tools/lp4x/README.md index e614f259cf..0c49dadc4f 100644 --- a/util/spd_tools/lp4x/README.md +++ b/util/spd_tools/lp4x/README.md @@ -168,7 +168,7 @@ Input JSON file requires the following two fields for every memory part: This tool generates the following files using the global list of memory parts in JSON format as described above: * De-duplicated SPDs required for the different memory parts. These - SPD files are named (spd_1.hex, spd_2.hex, spd_3.hex and so on) + SPD files are named (spd_1.bin, spd_2.bin, spd_3.bin and so on) and placed in the directory provided as an input to the tool. * CSV file representing which of the deduplicated SPD files is used by which memory part. This file is named as @@ -176,11 +176,11 @@ memory parts in JSON format as described above: as an input to the tool along with the generated SPD files. Example CSV file: ``` - MEMORY_PART_A, spd_1.hex - MEMORY_PART_B, spd_2.hex - MEMORY_PART_C, spd_3.hex - MEMORY_PART_D, spd_2.hex - MEMORY_PART_E, spd_2.hex + MEMORY_PART_A, spd_1.bin + MEMORY_PART_B, spd_2.bin + MEMORY_PART_C, spd_3.bin + MEMORY_PART_D, spd_2.bin + MEMORY_PART_E, spd_2.bin ``` ## Tool 2 - gen_part_id.go @@ -222,9 +222,9 @@ Sample Makefile.inc: ## This is an auto-generated file. Do not edit!! SPD_SOURCES = -SPD_SOURCES += spd_1.hex # ID = 0(0b0000) Parts = MEMORY_PART_A -SPD_SOURCES += spd_2.hex # ID = 1(0b0001) Parts = MEMORY_PART_B, MEMORY_PART_D -SPD_SOURCES += spd_3.hex # ID = 2(0b0010) Parts = MEMORY_PART_C +SPD_SOURCES += spd_1.bin # ID = 0(0b0000) Parts = MEMORY_PART_A +SPD_SOURCES += spd_2.bin # ID = 1(0b0001) Parts = MEMORY_PART_B, MEMORY_PART_D +SPD_SOURCES += spd_3.bin # ID = 2(0b0010) Parts = MEMORY_PART_C ``` ### Note of caution diff --git a/util/spd_tools/lp4x/gen_spd.go b/util/spd_tools/lp4x/gen_spd.go index e63ca8df6f..17388336d1 100644 --- a/util/spd_tools/lp4x/gen_spd.go +++ b/util/spd_tools/lp4x/gen_spd.go @@ -3,6 +3,7 @@ package main import ( + "bytes" "encoding/json" "fmt" "io/ioutil" @@ -637,20 +638,14 @@ func getSPDByte(index int, memAttribs *memAttributes) byte { return e.constVal } -func createSPD(memAttribs *memAttributes) string { - var s string +func createSPD(memAttribs *memAttributes) bytes.Buffer { + var spd bytes.Buffer for i := 0; i < 512; i++ { - b := getSPDByte(i, memAttribs) - - if (i + 1) % 16 == 0 { - s += fmt.Sprintf("%02X\n", b) - } else { - s += fmt.Sprintf("%02X ", b) - } + spd.WriteByte(getSPDByte(i, memAttribs)) } - return s + return spd } func dedupeMemoryPart(dedupedParts []*memPart, memPart *memPart) bool { @@ -665,9 +660,9 @@ func dedupeMemoryPart(dedupedParts []*memPart, memPart *memPart) bool { } func generateSPD(memPart *memPart, SPDId int, SPDDirName string) { - s := createSPD(&memPart.Attribs) - memPart.SPDFileName = fmt.Sprintf("lp4x-spd-%d.hex", SPDId) - ioutil.WriteFile(filepath.Join(SPDDirName, memPart.SPDFileName), []byte(s), 0644) + spd := createSPD(&memPart.Attribs) + memPart.SPDFileName = fmt.Sprintf("lp4x-spd-%d.bin", SPDId) + ioutil.WriteFile(filepath.Join(SPDDirName, memPart.SPDFileName), spd.Bytes(), 0644) } func readMemoryParts(memParts *memParts, memPartsFileName string) error { -- cgit v1.2.3