Rob Barnes | 5baadba | 2020-02-20 14:35:51 -0700 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # |
| 3 | # This file is part of the coreboot project. |
| 4 | # |
| 5 | # This program is free software; you can redistribute it and/or modify |
| 6 | # it under the terms of the GNU General Public License as published by |
| 7 | # the Free Software Foundation; version 2 of the License. |
| 8 | # |
| 9 | # This program is distributed in the hope that it will be useful, |
| 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | # GNU General Public License for more details. |
| 13 | # |
| 14 | # |
| 15 | # Parses spd hex files and outputs the contents in various formats |
| 16 | # |
| 17 | # |
| 18 | # Outputs csv, set, and json in same folder as SPD_HEX_FILE |
| 19 | # |
| 20 | # Example: |
| 21 | # decode_spd.sh ../../src/mainboard/google/zork/spd/micron-MT40A512M16TB-062E-J.spd.hex |
| 22 | # |
| 23 | # Outputs ../../src/mainboard/google/zork/spd/micron-MT40A512M16TB-062E-J.spd.{json|csv|set} |
| 24 | # |
| 25 | # TODO: This script assumes bincfg binary is at ../bincfg/bincfg (which is the |
| 26 | # result of running the bincfg make), and the specs are at |
| 27 | # ../bincfg/*.spec. This dependency should be made more resilliant and |
| 28 | # configurable. |
| 29 | |
| 30 | set -e |
| 31 | |
| 32 | function read8 () { |
| 33 | echo $(( 16#$(xxd -s "${2}" -l 1 -p "${1}") )) |
| 34 | } |
| 35 | |
| 36 | for file in "$@" |
| 37 | do |
| 38 | bintmp=$(mktemp) |
| 39 | outfile="${file%.hex}.set" |
| 40 | |
| 41 | echo "Decoding ${file}, outputting to ${outfile}" |
| 42 | |
| 43 | grep -v '^#' "${file}" | xxd -r -p - "${bintmp}" |
| 44 | dram_type=$(read8 "${bintmp}" 2) |
| 45 | if [ ! "${dram_type}" -eq 12 ] |
| 46 | then |
| 47 | #TODO: Handle other dram types |
| 48 | printf "Error: Expecting dram4 (12), got %d\n" "${dram_type}" |
| 49 | continue |
| 50 | fi |
| 51 | |
| 52 | revision=$(read8 "${bintmp}" 1) |
| 53 | if [ ! "${revision}" -eq $((0x13)) ] |
| 54 | then |
| 55 | printf "Warning: Expecting revision 0x13, got 0x%x.\n" "${revision}" |
| 56 | fi |
| 57 | |
| 58 | module_type=$(read8 "${bintmp}" 3) |
| 59 | case "${module_type}" in |
| 60 | 1) # RDIMM |
| 61 | spec="../bincfg/ddr4_registered_spd_512.spec" |
| 62 | ;; |
| 63 | 2 | 3) #UDIMM | SO-DIMM |
| 64 | spec="../bincfg/ddr4_unbuffered_spd_512.spec" |
| 65 | ;; |
| 66 | * ) |
| 67 | printf "Error: Unhandled module type %d.\n" "${module_type}" |
| 68 | ;; |
| 69 | esac |
| 70 | |
| 71 | ../bincfg/bincfg -d "${spec}" "${bintmp}" "${outfile}" |
| 72 | grep -v '^#' "${outfile}" | sed -e 's/ = \([^,]\+\)/: "\1"/g' \ |
| 73 | > "${file%.hex}.json" |
| 74 | grep -v -e '^#' -e '^{' -e '^}' "${outfile}" | sed -e 's/=/,/g' \ |
| 75 | > "${file%.hex}.csv" |
| 76 | done |