4 # SPDX-License-Identifier: GPL-2.0-only
6 # Parses spd hex files and outputs the contents in various formats
9 # Outputs csv, set, and json in same folder as SPD_HEX_FILE
12 # decode_spd.sh ../../src/mainboard/google/zork/spd/micron-MT40A512M16TB-062E-J.spd.hex
14 # Outputs ../../src/mainboard/google/zork/spd/micron-MT40A512M16TB-062E-J.spd.{json|csv|set}
16 # TODO: This script assumes bincfg binary is at ../bincfg/bincfg (which is the
17 # result of running the bincfg make), and the specs are at
18 # ../bincfg/*.spec. This dependency should be made more resilliant and
24 echo $
(( 16#$(xxd -s "${2}" -l 1 -p "${1}") ))
30 outfile
="${file%.hex}.set"
32 echo "Decoding ${file}, outputting to ${outfile}"
34 grep -v '^#' "${file}" | xxd
-r -p - "${bintmp}"
35 dram_type
=$
(read8
"${bintmp}" 2)
36 if [ ! "${dram_type}" -eq 12 ]
38 #TODO: Handle other dram types
39 printf "Error: Expecting dram4 (12), got %d\n" "${dram_type}"
43 revision
=$
(read8
"${bintmp}" 1)
44 if [ ! "${revision}" -eq $
((0x13)) ]
46 printf "Warning: Expecting revision 0x13, got 0x%x.\n" "${revision}"
49 module_type
=$
(read8
"${bintmp}" 3)
50 case "${module_type}" in
52 spec
="../bincfg/ddr4_registered_spd_512.spec"
54 2 |
3) #UDIMM | SO-DIMM
55 spec
="../bincfg/ddr4_unbuffered_spd_512.spec"
58 printf "Error: Unhandled module type %d.\n" "${module_type}"
62 ..
/bincfg
/bincfg
-d "${spec}" "${bintmp}" "${outfile}"
63 grep -v '^#' "${outfile}" |
sed -e 's/ = \([^,]\+\)/: "\1"/g' \
65 grep -v -e '^#' -e '^{' -e '^}' "${outfile}" |
sed -e 's/=/,/g' \