soc/intel/xeon_sp: Drop uncore_fill_ssdt
[coreboot2.git] / util / scripts / decode_spd.sh
blob252a4b7d324d07263164f4939609a3adb3e54336
1 #!/usr/bin/env bash
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
11 # Example:
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
19 # configurable.
21 set -e
23 function read8 () {
24 echo $(( 16#$(xxd -s "${2}" -l 1 -p "${1}") ))
27 for file in "$@"
29 bintmp=$(mktemp)
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 ]
37 then
38 #TODO: Handle other dram types
39 printf "Error: Expecting dram4 (12), got %d\n" "${dram_type}"
40 continue
43 revision=$(read8 "${bintmp}" 1)
44 if [ ! "${revision}" -eq $((0x13)) ]
45 then
46 printf "Warning: Expecting revision 0x13, got 0x%x.\n" "${revision}"
49 module_type=$(read8 "${bintmp}" 3)
50 case "${module_type}" in
51 1) # RDIMM
52 spec="../bincfg/ddr4_registered_spd_512.spec"
54 2 | 3) #UDIMM | SO-DIMM
55 spec="../bincfg/ddr4_unbuffered_spd_512.spec"
57 * )
58 printf "Error: Unhandled module type %d.\n" "${module_type}"
60 esac
62 ../bincfg/bincfg -d "${spec}" "${bintmp}" "${outfile}"
63 grep -v '^#' "${outfile}" | sed -e 's/ = \([^,]\+\)/: "\1"/g' \
64 > "${file%.hex}.json"
65 grep -v -e '^#' -e '^{' -e '^}' "${outfile}" | sed -e 's/=/,/g' \
66 > "${file%.hex}.csv"
67 done