blob: ec7baf92ce06c45a5cfb6b03975af5c8af22af71 [file] [log] [blame]
Pratik Prajapati21deb062015-09-02 13:14:20 -07001#!/bin/bash
2
3#
4# This file is part of the coreboot project.
5#
Pratik Prajapati0bb611d2017-04-10 15:45:40 -07006# Copyright (C) 2017 Intel Corporation.
Pratik Prajapati21deb062015-09-02 13:14:20 -07007#
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
18file_type_mma="mma"
19flashrom_temp_image=/tmp/flash_image_mma.bin
20mma_test_metadata_bin=mma_test_metadata.bin
21mma_test_metadata_bin_path=/tmp/"${mma_test_metadata_bin}"
22
23printf_separator() {
24 printf '=%.0s' {1..80}
25 printf '\n'
26}
27
28show_usage() {
Pratik Prajapati0bb611d2017-04-10 15:45:40 -070029 printf "MMA blobs version : 2.1018\n"
Pratik Prajapati21deb062015-09-02 13:14:20 -070030 printf "usage: $(basename "${0}") %s\n" \
31 "set [<mma_test_name_efi> <mma_test_param_bin>] | reset"
32 printf '=%.0s' {1..29}
33 printf "All possible MMA tests"
34 printf '=%.0s' {1..29}
35 printf "\n"
36 printf_separator
37 printf "Test Name \tMargin1D.efi\n"
38 printf "Test Config\n"
39 printf "\t\t%s %s\n" \
40 Margin1DCkAllConfig.bin \
41 Margin1DCmdAllConfig.bin \
42 Margin1DCmdVrefConfig.bin \
43 Margin1DCtlAllConfig.bin \
44 Margin1DRxDqsDelayConfig.bin \
45 Margin1DRxVrefConfig.bin \
46 Margin1DTxDqDelayConfig.bin \
47 Margin1DTxVrefConfig.bin
48 printf_separator
49 printf "Test Name \tMargin2D.efi\n"
50 printf "Test Config\n"
51 printf "\t\t%s %s\n" \
52 Margin2D_Cmd_Ch0_D0_R0_Config.bin \
53 Margin2D_Cmd_Ch0_D1_R0_Config.bin \
54 Margin2D_Cmd_Ch1_D0_R0_Config.bin \
55 Margin2D_Cmd_Ch1_D1_R0_Config.bin \
56 Margin2D_Rx_Ch0_D0_R0_Config.bin \
57 Margin2D_Rx_Ch0_D0_R1_Config.bin \
58 Margin2D_Rx_Ch0_D1_R0_Config.bin \
59 Margin2D_Rx_Ch0_D1_R1_Config.bin \
60 Margin2D_Rx_Ch1_D0_R0_Config.bin \
61 Margin2D_Rx_Ch1_D0_R1_Config.bin \
62 Margin2D_Rx_Ch1_D1_R0_Config.bin \
63 Margin2D_Rx_Ch1_D1_R1_Config.bin \
64 Margin2D_Tx_Ch0_D0_R0_Config.bin \
65 Margin2D_Tx_Ch0_D0_R1_Config.bin \
66 Margin2D_Tx_Ch0_D1_R0_Config.bin \
67 Margin2D_Tx_Ch0_D1_R1_Config.bin \
68 Margin2D_Tx_Ch1_D0_R0_Config.bin \
69 Margin2D_Tx_Ch1_D0_R1_Config.bin \
70 Margin2D_Tx_Ch1_D1_R0_Config.bin \
71 Margin2D_Tx_Ch1_D1_R1_Config.bin
72 printf_separator
73 printf "Test name \tMarginMapper.efi\n"
74 printf "Test Config\n"
75 printf "\t\t%s %s\n" \
Pratik Prajapati0bb611d2017-04-10 15:45:40 -070076 MarginMapperRxVref-RxDqsDelayConfigVCh0ACh0_single_ch.bin \
77 MarginMapperRxVref-RxDqsDelayConfigVCh0ACh1_dual_ch.bin \
78 MarginMapperRxVref-RxDqsDelayConfigVCh1ACh0_dual_ch.bin \
79 MarginMapperRxVref-RxDqsDelayConfigVCh1ACh1_single_ch.bin \
80 MarginMapperTxVref-TxDqDelayConfigVCh0ACh0_single_ch.bin \
81 MarginMapperTxVref-TxDqDelayConfigVCh0ACh1_dual_ch.bin \
82 MarginMapperTxVref-TxDqDelayConfigVCh1ACh0_dual_ch.bin \
83 MarginMapperTxVref-TxDqDelayConfigVCh1ACh1_single_ch.bin \
84 ScoreRxVref-RxDqsDelayConfigVCh0ACh0_single_ch.bin \
85 ScoreRxVref-RxDqsDelayConfigVCh0ACh1_dual_ch.bin \
86 ScoreRxVref-RxDqsDelayConfigVCh1ACh0_dual_ch.bin \
87 ScoreRxVref-RxDqsDelayConfigVCh1ACh1_single_ch.bin \
88 ScoreTxVref-TxDqDelayConfigVCh0ACh0_single_ch.bin \
89 ScoreTxVref-TxDqDelayConfigVCh0ACh1_dual_ch.bin \
90 ScoreTxVref-TxDqDelayConfigVCh1ACh0_dual_ch.bin \
91 ScoreTxVref-TxDqDelayConfigVCh1ACh1_single_ch.bin
Pratik Prajapati21deb062015-09-02 13:14:20 -070092 printf_separator
93 printf "Test Name \tRMT.efi\n"
94 printf "Test Config\n"
95 printf "\t\t%s %s\n" \
96 RMTConfig.bin
97 printf_separator
98}
99
100write_flash() {
101 printf "Writing back flash contents "${flashrom_temp_image}"\n"
Pratik Prajapatide62e0f2016-02-22 16:50:31 -0800102 flashrom -p host -w "${flashrom_temp_image}" --fast-verify || \
Pratik Prajapati21deb062015-09-02 13:14:20 -0700103 {
104 printf "failed to read flash\n" ;
105 exit -1;
106 }
107}
108
109remove_file_if_exists() {
110 if [ -f "${1}" ]; then
111 printf "removing old "${1}"\n"
112 rm -f "${1}"
113 fi
114}
115
116remove_metadata() {
117 printf "Removing "${mma_test_metadata_bin}" from "${flashrom_temp_image}"\n"
118 cbfstool "${flashrom_temp_image}" remove -n ${mma_test_metadata_bin}
119 outout=$(cbfstool "${flashrom_temp_image}" print | \
120 grep ${mma_test_metadata_bin})
121
122 if [ -z "${outout}" ];then
123 printf "Removed ${mma_test_metadata_bin} from %s\n" \
124 "${flashrom_temp_image}"
125 else
126 printf "Failed to remove ${mma_test_metadata_bin} from %s\n" \
127 "${flashrom_temp_image}"
128 print_failed
129 exit -1;
130 fi
131}
132
133generate_metadata() {
134 remove_file_if_exists "${mma_test_metadata_bin_path}"
135
136 printf "Creating "${mma_test_metadata_bin_path}"\n"
137 #
138 #Format of $mma_test_metadata_bin
139 #MMA_TEST_NAME=xxxxxx.efi;MMA_TEST_PARAM=xxxxxx.bin;
140 #
141 printf "MMA_TEST_NAME=${mma_test_name};MMA_TEST_PARAM=${mma_test_param};" \
142 > "${mma_test_metadata_bin_path}"
143}
144
145add_metadata_to_flashfile() {
146 cbfstool "${flashrom_temp_image}" add -f "${mma_test_metadata_bin_path}" \
147 -n ${mma_test_metadata_bin} -t ${file_type_mma} || \
148 {
149 printf "failed to add "${mma_test_metadata_bin_path}"\n" ;
150 exit -1;
151 }
152}
153
154cleanup() {
155 remove_file_if_exists "${flashrom_temp_image}"
156 remove_file_if_exists "${mma_test_metadata_bin_path}"
157}
158
159print_success() {
160 printf "============== SUCCESS ==============\n"
161}
162
163print_failed() {
164 printf "============== FAILED ==============\n"
165}
166
167#
168# main entry point
169#
170
171main() {
172 case "${#}:${1}" in
173 (3:set)
174 mma_test_name=${2}
175 mma_test_param=${3}
176 ;;
177 (1:reset)
178 ;;
179 (*)
180 show_usage
181 exit -1
182 esac
183
184 if [ "${1}" != "reset" ];then
185 printf "mma_test_name = ${mma_test_name}\n"
186 printf "mma_test_param = ${mma_test_param}\n"
187 fi
188
189 remove_file_if_exists "${flashrom_temp_image}"
190
191 printf "Reading flash contents to "${flashrom_temp_image}"\n"
Pratik Prajapatide62e0f2016-02-22 16:50:31 -0800192 flashrom -p host -r "${flashrom_temp_image}" || \
Pratik Prajapati21deb062015-09-02 13:14:20 -0700193 {
194 printf "failed to read flash\n" ;
195 exit -1;
196 }
197
198 outdata=$(cbfstool "${flashrom_temp_image}" print | \
199 grep ${mma_test_metadata_bin})
200
201 case "$1" in
202 ("set")
203 [ "${outdata}" ] && remove_metadata
204 generate_metadata
205 add_metadata_to_flashfile
206 write_flash
207 ;;
208 ("reset")
209 if [ -z "${outdata}" ];then
210 printf "${mma_test_metadata_bin} not found at all.\n"
211 else
212 remove_metadata
213 write_flash
214 fi
215 ;;
216 esac
217 cleanup
218 print_success
219}
220
221main "$@"