blob: f797e7f36be9027b50ab243213689b557a439965 [file] [log] [blame]
Yegor Timoshenkoc2e49412018-10-07 01:58:27 +00001#!/usr/bin/env bash
Pratik Prajapati21deb062015-09-02 13:14:20 -07002
3#
4# This file is part of the coreboot project.
5#
6# Copyright (C) 2015 Intel Corporation.
7#
8# This program is free software; you can redistribute it and/or modify
9# it under the terms of the GNU General Public License as published by
10# the Free Software Foundation; version 2 of the License.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15# GNU General Public License for more details.
16#
Pratik Prajapati21deb062015-09-02 13:14:20 -070017
18mma_results_op_bin="${1}"
19mma_results_op_bin_tmp="${mma_results_op_bin}".tmp
20mma_cbmem_id="0x4d4d4144"
21
22show_usage() {
23 printf "usage: $(basename "${0}") <output_results.bin>\n"
24 printf "pass path of a bin file where you want to save results.\n"
25}
26
27#
28# main entry point
29#
30
31main() {
32 if [ ! "${mma_results_op_bin}" ];then
33 show_usage
34 exit -1
35 fi
36
37 printf "Reading cbmem ...\n"
38 cbmem -r ${mma_cbmem_id} > "${mma_results_op_bin_tmp}" || \
39 {
40 printf "error in executing cbmem utility\n" ;
41 exit -1;
42 }
43
44 #format of o/p is :
45 # <mma_signature><mma_test_header+data>
46 #
47 # where,
48 # <mma_signature> is 32bit length string "MMAD"
49 #
50 # <mma_test_header+data> is the FULL HOB which coreboot
51 # receives from FSP
52 # <mma_test_header> is 22 bytes long at the start of the HOB.
53 # MMA data starts right after 26 bytes
54 # 26 bytes = (4 bytes of "MMAD"
55 # + 22 bytes of mma_test_header)
56 #
57
58 mma_signature=$(dd if="${mma_results_op_bin_tmp}" bs=1 count=4 )
59
60 if [[ ${mma_signature} != "MMAD" ]];then
61 printf "MMA signature mismatch" > "${mma_results_op_bin}"
62 rm -r "${mma_results_op_bin_tmp}"
63 cbmem -l >> "${mma_results_op_bin}"
64 printf "MMA signature mismatch\n"
65 exit -1
66 fi
67
68 dd if="${mma_results_op_bin_tmp}" of="${mma_results_op_bin}" bs=1 skip=26 || \
69 {
70 printf "error in generating "${mma_results_op_bin}"\n" ;
71 exit -1;
72 }
73 rm -r "${mma_results_op_bin_tmp}"
74 printf "MMA data saved to "${mma_results_op_bin}"\n"
75}
76
77main "$@"