blob: 7eb3c7c2258a4793ec52f0ac25fff37789e2b6ca [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#
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
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() {
29 printf "usage: $(basename "${0}") %s\n" \
30 "set [<mma_test_name_efi> <mma_test_param_bin>] | reset"
31 printf '=%.0s' {1..29}
32 printf "All possible MMA tests"
33 printf '=%.0s' {1..29}
34 printf "\n"
35 printf_separator
36 printf "Test Name \tMargin1D.efi\n"
37 printf "Test Config\n"
38 printf "\t\t%s %s\n" \
39 Margin1DCkAllConfig.bin \
40 Margin1DCmdAllConfig.bin \
41 Margin1DCmdVrefConfig.bin \
42 Margin1DCtlAllConfig.bin \
43 Margin1DRxDqsDelayConfig.bin \
44 Margin1DRxVrefConfig.bin \
45 Margin1DTxDqDelayConfig.bin \
46 Margin1DTxVrefConfig.bin
47 printf_separator
48 printf "Test Name \tMargin2D.efi\n"
49 printf "Test Config\n"
50 printf "\t\t%s %s\n" \
51 Margin2D_Cmd_Ch0_D0_R0_Config.bin \
52 Margin2D_Cmd_Ch0_D1_R0_Config.bin \
53 Margin2D_Cmd_Ch1_D0_R0_Config.bin \
54 Margin2D_Cmd_Ch1_D1_R0_Config.bin \
55 Margin2D_Rx_Ch0_D0_R0_Config.bin \
56 Margin2D_Rx_Ch0_D0_R1_Config.bin \
57 Margin2D_Rx_Ch0_D1_R0_Config.bin \
58 Margin2D_Rx_Ch0_D1_R1_Config.bin \
59 Margin2D_Rx_Ch1_D0_R0_Config.bin \
60 Margin2D_Rx_Ch1_D0_R1_Config.bin \
61 Margin2D_Rx_Ch1_D1_R0_Config.bin \
62 Margin2D_Rx_Ch1_D1_R1_Config.bin \
63 Margin2D_Tx_Ch0_D0_R0_Config.bin \
64 Margin2D_Tx_Ch0_D0_R1_Config.bin \
65 Margin2D_Tx_Ch0_D1_R0_Config.bin \
66 Margin2D_Tx_Ch0_D1_R1_Config.bin \
67 Margin2D_Tx_Ch1_D0_R0_Config.bin \
68 Margin2D_Tx_Ch1_D0_R1_Config.bin \
69 Margin2D_Tx_Ch1_D1_R0_Config.bin \
70 Margin2D_Tx_Ch1_D1_R1_Config.bin
71 printf_separator
72 printf "Test name \tMarginMapper.efi\n"
73 printf "Test Config\n"
74 printf "\t\t%s %s\n" \
75 MarginMapperRxVref-RxDqsDelayConfigCh0.bin \
76 MarginMapperRxVref-RxDqsDelayConfigCh1.bin \
77 MarginMapperTxVref-TxDqDelayConfigCh0.bin \
78 MarginMapperTxVref-TxDqDelayConfigCh1.bin \
79 ScoreRxVref-RxDqsDelayConfigCh0.bin \
80 ScoreRxVref-RxDqsDelayConfigCh1.bin \
81 ScoreTxVref-TxDqDelayConfigCh0.bin \
82 ScoreTxVref-TxDqDelayConfigCh1.bin
83 printf_separator
84 printf "Test Name \tRMT.efi\n"
85 printf "Test Config\n"
86 printf "\t\t%s %s\n" \
87 RMTConfig.bin
88 printf_separator
89}
90
91write_flash() {
92 printf "Writing back flash contents "${flashrom_temp_image}"\n"
Pratik Prajapatide62e0f2016-02-22 16:50:31 -080093 flashrom -p host -w "${flashrom_temp_image}" --fast-verify || \
Pratik Prajapati21deb062015-09-02 13:14:20 -070094 {
95 printf "failed to read flash\n" ;
96 exit -1;
97 }
98}
99
100remove_file_if_exists() {
101 if [ -f "${1}" ]; then
102 printf "removing old "${1}"\n"
103 rm -f "${1}"
104 fi
105}
106
107remove_metadata() {
108 printf "Removing "${mma_test_metadata_bin}" from "${flashrom_temp_image}"\n"
109 cbfstool "${flashrom_temp_image}" remove -n ${mma_test_metadata_bin}
110 outout=$(cbfstool "${flashrom_temp_image}" print | \
111 grep ${mma_test_metadata_bin})
112
113 if [ -z "${outout}" ];then
114 printf "Removed ${mma_test_metadata_bin} from %s\n" \
115 "${flashrom_temp_image}"
116 else
117 printf "Failed to remove ${mma_test_metadata_bin} from %s\n" \
118 "${flashrom_temp_image}"
119 print_failed
120 exit -1;
121 fi
122}
123
124generate_metadata() {
125 remove_file_if_exists "${mma_test_metadata_bin_path}"
126
127 printf "Creating "${mma_test_metadata_bin_path}"\n"
128 #
129 #Format of $mma_test_metadata_bin
130 #MMA_TEST_NAME=xxxxxx.efi;MMA_TEST_PARAM=xxxxxx.bin;
131 #
132 printf "MMA_TEST_NAME=${mma_test_name};MMA_TEST_PARAM=${mma_test_param};" \
133 > "${mma_test_metadata_bin_path}"
134}
135
136add_metadata_to_flashfile() {
137 cbfstool "${flashrom_temp_image}" add -f "${mma_test_metadata_bin_path}" \
138 -n ${mma_test_metadata_bin} -t ${file_type_mma} || \
139 {
140 printf "failed to add "${mma_test_metadata_bin_path}"\n" ;
141 exit -1;
142 }
143}
144
145cleanup() {
146 remove_file_if_exists "${flashrom_temp_image}"
147 remove_file_if_exists "${mma_test_metadata_bin_path}"
148}
149
150print_success() {
151 printf "============== SUCCESS ==============\n"
152}
153
154print_failed() {
155 printf "============== FAILED ==============\n"
156}
157
158#
159# main entry point
160#
161
162main() {
163 case "${#}:${1}" in
164 (3:set)
165 mma_test_name=${2}
166 mma_test_param=${3}
167 ;;
168 (1:reset)
169 ;;
170 (*)
171 show_usage
172 exit -1
173 esac
174
175 if [ "${1}" != "reset" ];then
176 printf "mma_test_name = ${mma_test_name}\n"
177 printf "mma_test_param = ${mma_test_param}\n"
178 fi
179
180 remove_file_if_exists "${flashrom_temp_image}"
181
182 printf "Reading flash contents to "${flashrom_temp_image}"\n"
Pratik Prajapatide62e0f2016-02-22 16:50:31 -0800183 flashrom -p host -r "${flashrom_temp_image}" || \
Pratik Prajapati21deb062015-09-02 13:14:20 -0700184 {
185 printf "failed to read flash\n" ;
186 exit -1;
187 }
188
189 outdata=$(cbfstool "${flashrom_temp_image}" print | \
190 grep ${mma_test_metadata_bin})
191
192 case "$1" in
193 ("set")
194 [ "${outdata}" ] && remove_metadata
195 generate_metadata
196 add_metadata_to_flashfile
197 write_flash
198 ;;
199 ("reset")
200 if [ -z "${outdata}" ];then
201 printf "${mma_test_metadata_bin} not found at all.\n"
202 else
203 remove_metadata
204 write_flash
205 fi
206 ;;
207 esac
208 cleanup
209 print_success
210}
211
212main "$@"