Debian Codegraph @

util/scripts/decode_spd.sh

raw symbols SCIP
1 #!/usr/bin/envscip-shell filesystem . . `/usr/bin/env`. bash
2 #
3 #
4 # SPDX-License-Identifier: GPL-2.0-only
5
6 # Parses spd hex files and outputs the contents in various formats
7 #
8 #
9 # Outputs csv, set, and json in same folder as SPD_HEX_FILE
10 #
11 # Example:
12 # decode_spd.sh ../../src/mainboard/google/zork/spd/micron-MT40A512M16TB-062E-J.spd.hex
13 #
14 # Outputs ../../src/mainboard/google/zork/spd/micron-MT40A512M16TB-062E-J.spd.{json|csv|set}
15 #
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.
20
21 set -e
22
23 function read8scip-shell shell coreboot 25.09+dfsg-1 read8(). () {
24 echoscip-shell system . . echo. $(( 16#$(xxd -s "${2}" -l 1 -p "${1}") ))
25 }
26
27 for file in "$@"
28 do
29 bintmp=$(mktempscip-shell system . . mktemp.)
30 outfile="${file%.hex}.set"
31
32 echoscip-shell system . . echo. "Decoding ${file}, outputting to ${outfile}"
33
34 grepscip-shell system . . grep. -v '^#' "${file}" | xxd -r -p - "${bintmp}"
35 dram_type=$(read8scip-shell shell coreboot 25.09+dfsg-1 read8(). "${bintmp}" 2)
36 if [scip-shell system . . `[`. ! "${dram_type}" -eq 12 ]
37 then
38 #TODO: Handle other dram types
39 printfscip-shell system . . printf. "Error: Expecting dram4 (12), got %d\n" "${dram_type}"
40 continue
41 fi
42
43 revision=$(read8scip-shell shell coreboot 25.09+dfsg-1 read8(). "${bintmp}" 1)
44 if [scip-shell system . . `[`. ! "${revision}" -eq $((0x13)) ]
45 then
46 printfscip-shell system . . printf. "Warning: Expecting revision 0x13, got 0x%x.\n" "${revision}"
47 fi
48
49 module_type=$(read8scip-shell shell coreboot 25.09+dfsg-1 read8(). "${bintmp}" 3)
50 case "${module_type}" in
51 1) # RDIMM
52 spec="../bincfg/ddr4_registered_spd_512.spec"
53 ;;
54 2 | 3) #UDIMM | SO-DIMM
55 spec="../bincfg/ddr4_unbuffered_spd_512.spec"
56 ;;
57 * )
58 printfscip-shell system . . printf. "Error: Unhandled module type %d.\n" "${module_type}"
59 ;;
60 esac
61
62 ../bincfg/bincfg -d "${spec}" "${bintmp}" "${outfile}"
63 grepscip-shell system . . grep. -v '^#' "${outfile}" | sedscip-shell system . . sed. -e 's/ = \([^,]\+\)/: "\1"/g' \
64 > "${file%.hex}.json"
65 grepscip-shell system . . grep. -v -e '^#' -e '^{' -e '^}' "${outfile}" | sedscip-shell system . . sed. -e 's/=/,/g' \
66 > "${file%.hex}.csv"
67 done