blob: 499d91cb742da45ed9812db1ed385633ae1c0a8b [file] [log] [blame]
Yegor Timoshenkoc2e49412018-10-07 01:58:27 +00001#!/usr/bin/env bash
Pratik Prajapati21deb062015-09-02 13:14:20 -07002#
Patrick Georgi7333a112020-05-08 20:48:04 +02003# SPDX-License-Identifier: GPL-2.0-only
Pratik Prajapati21deb062015-09-02 13:14:20 -07004
5mma_results_op_bin="${1}"
6mma_results_op_bin_tmp="${mma_results_op_bin}".tmp
7mma_cbmem_id="0x4d4d4144"
8
9show_usage() {
10 printf "usage: $(basename "${0}") <output_results.bin>\n"
11 printf "pass path of a bin file where you want to save results.\n"
12}
13
14#
15# main entry point
16#
17
18main() {
19 if [ ! "${mma_results_op_bin}" ];then
20 show_usage
21 exit -1
22 fi
23
24 printf "Reading cbmem ...\n"
25 cbmem -r ${mma_cbmem_id} > "${mma_results_op_bin_tmp}" || \
26 {
27 printf "error in executing cbmem utility\n" ;
28 exit -1;
29 }
30
31 #format of o/p is :
32 # <mma_signature><mma_test_header+data>
33 #
34 # where,
35 # <mma_signature> is 32bit length string "MMAD"
36 #
37 # <mma_test_header+data> is the FULL HOB which coreboot
38 # receives from FSP
39 # <mma_test_header> is 22 bytes long at the start of the HOB.
40 # MMA data starts right after 26 bytes
41 # 26 bytes = (4 bytes of "MMAD"
42 # + 22 bytes of mma_test_header)
43 #
44
45 mma_signature=$(dd if="${mma_results_op_bin_tmp}" bs=1 count=4 )
46
47 if [[ ${mma_signature} != "MMAD" ]];then
48 printf "MMA signature mismatch" > "${mma_results_op_bin}"
49 rm -r "${mma_results_op_bin_tmp}"
50 cbmem -l >> "${mma_results_op_bin}"
51 printf "MMA signature mismatch\n"
52 exit -1
53 fi
54
55 dd if="${mma_results_op_bin_tmp}" of="${mma_results_op_bin}" bs=1 skip=26 || \
56 {
57 printf "error in generating "${mma_results_op_bin}"\n" ;
58 exit -1;
59 }
60 rm -r "${mma_results_op_bin_tmp}"
61 printf "MMA data saved to "${mma_results_op_bin}"\n"
62}
63
64main "$@"