util/spd_tools: output binaries instead of hexdumps
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 <foss@mniewoehner.de> Reviewed-on: https://review.coreboot.org/c/coreboot/+/44878 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Patrick Georgi <pgeorgi@google.com> Reviewed-by: Angel Pons <th3fanbus@gmail.com>
This commit is contained in:
parent
e10efa3a03
commit
f23794cf04
|
@ -171,7 +171,7 @@ string like "9 10 11 12 14".
|
||||||
This tool generates the following files using the global list of
|
This tool generates the following files using the global list of
|
||||||
memory parts in JSON format as described above:
|
memory parts in JSON format as described above:
|
||||||
* De-duplicated SPDs required for the different memory parts. These
|
* De-duplicated SPDs required for the different memory parts. These
|
||||||
SPD files are named (ddr4-spd-1.hex, ddr4-spd-2.hex, and so on)
|
SPD files are named (ddr4-spd-1.bin, ddr4-spd-2.bin, and so on)
|
||||||
and placed in the directory provided as an input to the tool.
|
and placed in the directory provided as an input to the tool.
|
||||||
* CSV file representing which of the deduplicated SPD files is used
|
* CSV file representing which of the deduplicated SPD files is used
|
||||||
by which memory part. This file is named as
|
by which memory part. This file is named as
|
||||||
|
@ -179,11 +179,11 @@ memory parts in JSON format as described above:
|
||||||
as an input to the tool along with the generated SPD
|
as an input to the tool along with the generated SPD
|
||||||
files. Example CSV file:
|
files. Example CSV file:
|
||||||
```
|
```
|
||||||
MEMORY_PART_A, ddr4-spd-1.hex
|
MEMORY_PART_A, ddr4-spd-1.bin
|
||||||
MEMORY_PART_B, ddr4-spd-2.hex
|
MEMORY_PART_B, ddr4-spd-2.bin
|
||||||
MEMORY_PART_C, ddr4-spd-3.hex
|
MEMORY_PART_C, ddr4-spd-3.bin
|
||||||
MEMORY_PART_D, ddr4-spd-2.hex
|
MEMORY_PART_D, ddr4-spd-2.bin
|
||||||
MEMORY_PART_E, ddr4-spd-2.hex
|
MEMORY_PART_E, ddr4-spd-2.bin
|
||||||
```
|
```
|
||||||
|
|
||||||
## Tool 2 - gen_part_id.go
|
## Tool 2 - gen_part_id.go
|
||||||
|
@ -242,10 +242,10 @@ Sample Makefile.inc:
|
||||||
## This is an auto-generated file. Do not edit!!
|
## This is an auto-generated file. Do not edit!!
|
||||||
|
|
||||||
SPD_SOURCES =
|
SPD_SOURCES =
|
||||||
SPD_SOURCES += ddr4-spd-1.hex # ID = 0(0b0000) Parts = MEMORY_PART_A
|
SPD_SOURCES += ddr4-spd-1.bin # ID = 0(0b0000) Parts = MEMORY_PART_A
|
||||||
SPD_SOURCES += ddr4-spd-2.hex # ID = 1(0b0001) Parts = MEMORY_PART_B, MEMORY_PART_D
|
SPD_SOURCES += ddr4-spd-2.bin # ID = 1(0b0001) Parts = MEMORY_PART_B, MEMORY_PART_D
|
||||||
SPD_SOURCES += ddr4-spd-empty.hex # ID = 2(0b0010)
|
SPD_SOURCES += ddr4-spd-empty.bin # ID = 2(0b0010)
|
||||||
SPD_SOURCES += ddr4-spd-3.hex # ID = 2(0b0010) Parts = MEMORY_PART_C
|
SPD_SOURCES += ddr4-spd-3.bin # ID = 2(0b0010) Parts = MEMORY_PART_C
|
||||||
```
|
```
|
||||||
NOTE: Empty entries may be required if there is a gap created by a memory part
|
NOTE: Empty entries may be required if there is a gap created by a memory part
|
||||||
with a fixed id.
|
with a fixed id.
|
||||||
|
|
|
@ -265,7 +265,7 @@ func genMakefile(partIdList []partIds, makefileDirName string) error {
|
||||||
|
|
||||||
for i := 0; i < len(partIdList); i++ {
|
for i := 0; i < len(partIdList); i++ {
|
||||||
if partIdList[i].SPDFileName == "" {
|
if partIdList[i].SPDFileName == "" {
|
||||||
s += fmt.Sprintf("SPD_SOURCES += %s ", "ddr4-spd-empty.hex")
|
s += fmt.Sprintf("SPD_SOURCES += %s ", "ddr4-spd-empty.bin")
|
||||||
s += fmt.Sprintf(" # ID = %d(0b%04b)\n", i, int64(i))
|
s += fmt.Sprintf(" # ID = %d(0b%04b)\n", i, int64(i))
|
||||||
} else {
|
} else {
|
||||||
s += fmt.Sprintf("SPD_SOURCES += %s ", partIdList[i].SPDFileName)
|
s += fmt.Sprintf("SPD_SOURCES += %s ", partIdList[i].SPDFileName)
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
@ -968,8 +969,8 @@ func getSPDByte(index int, memAttribs *memAttributes) byte {
|
||||||
return e.constVal
|
return e.constVal
|
||||||
}
|
}
|
||||||
|
|
||||||
func createSPD(memAttribs *memAttributes) string {
|
func createSPD(memAttribs *memAttributes) bytes.Buffer {
|
||||||
var s string
|
var spd bytes.Buffer
|
||||||
|
|
||||||
for i := 0; i < 512; i++ {
|
for i := 0; i < 512; i++ {
|
||||||
var b byte = 0
|
var b byte = 0
|
||||||
|
@ -977,14 +978,10 @@ func createSPD(memAttribs *memAttributes) string {
|
||||||
b = getSPDByte(i, memAttribs)
|
b = getSPDByte(i, memAttribs)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (i + 1) % 16 == 0 {
|
spd.WriteByte(b)
|
||||||
s += fmt.Sprintf("%02X\n", b)
|
|
||||||
} else {
|
|
||||||
s += fmt.Sprintf("%02X ", b)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return s
|
return spd
|
||||||
}
|
}
|
||||||
|
|
||||||
func dedupeMemoryPart(dedupedParts []*memPart, memPart *memPart) bool {
|
func dedupeMemoryPart(dedupedParts []*memPart, memPart *memPart) bool {
|
||||||
|
@ -999,16 +996,16 @@ func dedupeMemoryPart(dedupedParts []*memPart, memPart *memPart) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
func generateSPD(memPart *memPart, SPDId int, SPDDirName string) {
|
func generateSPD(memPart *memPart, SPDId int, SPDDirName string) {
|
||||||
s := createSPD(&memPart.Attribs)
|
spd := createSPD(&memPart.Attribs)
|
||||||
memPart.SPDFileName = fmt.Sprintf("ddr4-spd-%d.hex", SPDId)
|
memPart.SPDFileName = fmt.Sprintf("ddr4-spd-%d.bin", SPDId)
|
||||||
ioutil.WriteFile(filepath.Join(SPDDirName, memPart.SPDFileName), []byte(s), 0644)
|
ioutil.WriteFile(filepath.Join(SPDDirName, memPart.SPDFileName), spd.Bytes(), 0644)
|
||||||
}
|
}
|
||||||
|
|
||||||
func generateEmptySPD(SPDDirName string) {
|
func generateEmptySPD(SPDDirName string) {
|
||||||
|
|
||||||
s := createSPD(nil)
|
spd := createSPD(nil)
|
||||||
SPDFileName := "ddr4-spd-empty.hex"
|
SPDFileName := "ddr4-spd-empty.bin"
|
||||||
ioutil.WriteFile(filepath.Join(SPDDirName, SPDFileName), []byte(s), 0644)
|
ioutil.WriteFile(filepath.Join(SPDDirName, SPDFileName), spd.Bytes(), 0644)
|
||||||
}
|
}
|
||||||
|
|
||||||
func readMemoryParts(memParts *memParts, memPartsFileName string) error {
|
func readMemoryParts(memParts *memParts, memPartsFileName string) error {
|
||||||
|
|
|
@ -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
|
This tool generates the following files using the global list of
|
||||||
memory parts in JSON format as described above:
|
memory parts in JSON format as described above:
|
||||||
* De-duplicated SPDs required for the different memory parts. These
|
* 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.
|
and placed in the directory provided as an input to the tool.
|
||||||
* CSV file representing which of the deduplicated SPD files is used
|
* CSV file representing which of the deduplicated SPD files is used
|
||||||
by which memory part. This file is named as
|
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
|
as an input to the tool along with the generated SPD
|
||||||
files. Example CSV file:
|
files. Example CSV file:
|
||||||
```
|
```
|
||||||
MEMORY_PART_A, spd_1.hex
|
MEMORY_PART_A, spd_1.bin
|
||||||
MEMORY_PART_B, spd_2.hex
|
MEMORY_PART_B, spd_2.bin
|
||||||
MEMORY_PART_C, spd_3.hex
|
MEMORY_PART_C, spd_3.bin
|
||||||
MEMORY_PART_D, spd_2.hex
|
MEMORY_PART_D, spd_2.bin
|
||||||
MEMORY_PART_E, spd_2.hex
|
MEMORY_PART_E, spd_2.bin
|
||||||
```
|
```
|
||||||
|
|
||||||
## Tool 2 - gen_part_id.go
|
## Tool 2 - gen_part_id.go
|
||||||
|
@ -222,9 +222,9 @@ Sample Makefile.inc:
|
||||||
## This is an auto-generated file. Do not edit!!
|
## This is an auto-generated file. Do not edit!!
|
||||||
|
|
||||||
SPD_SOURCES =
|
SPD_SOURCES =
|
||||||
SPD_SOURCES += spd_1.hex # ID = 0(0b0000) Parts = MEMORY_PART_A
|
SPD_SOURCES += spd_1.bin # 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_2.bin # 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_3.bin # ID = 2(0b0010) Parts = MEMORY_PART_C
|
||||||
```
|
```
|
||||||
|
|
||||||
### Note of caution
|
### Note of caution
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
@ -637,20 +638,14 @@ func getSPDByte(index int, memAttribs *memAttributes) byte {
|
||||||
return e.constVal
|
return e.constVal
|
||||||
}
|
}
|
||||||
|
|
||||||
func createSPD(memAttribs *memAttributes) string {
|
func createSPD(memAttribs *memAttributes) bytes.Buffer {
|
||||||
var s string
|
var spd bytes.Buffer
|
||||||
|
|
||||||
for i := 0; i < 512; i++ {
|
for i := 0; i < 512; i++ {
|
||||||
b := getSPDByte(i, memAttribs)
|
spd.WriteByte(getSPDByte(i, memAttribs))
|
||||||
|
|
||||||
if (i + 1) % 16 == 0 {
|
|
||||||
s += fmt.Sprintf("%02X\n", b)
|
|
||||||
} else {
|
|
||||||
s += fmt.Sprintf("%02X ", b)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return s
|
return spd
|
||||||
}
|
}
|
||||||
|
|
||||||
func dedupeMemoryPart(dedupedParts []*memPart, memPart *memPart) bool {
|
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) {
|
func generateSPD(memPart *memPart, SPDId int, SPDDirName string) {
|
||||||
s := createSPD(&memPart.Attribs)
|
spd := createSPD(&memPart.Attribs)
|
||||||
memPart.SPDFileName = fmt.Sprintf("lp4x-spd-%d.hex", SPDId)
|
memPart.SPDFileName = fmt.Sprintf("lp4x-spd-%d.bin", SPDId)
|
||||||
ioutil.WriteFile(filepath.Join(SPDDirName, memPart.SPDFileName), []byte(s), 0644)
|
ioutil.WriteFile(filepath.Join(SPDDirName, memPart.SPDFileName), spd.Bytes(), 0644)
|
||||||
}
|
}
|
||||||
|
|
||||||
func readMemoryParts(memParts *memParts, memPartsFileName string) error {
|
func readMemoryParts(memParts *memParts, memPartsFileName string) error {
|
||||||
|
|
Loading…
Reference in New Issue