treewide: Move device_tree to commonlib
[coreboot2.git] / util / mma / mma_setup_test.sh
blobf07cd900cd3d7fbb7b0d31ea83c26f098eab68e7
1 #!/usr/bin/env bash
3 # SPDX-License-Identifier: GPL-2.0-only
5 file_type_mma="mma"
6 flashrom_temp_image=/tmp/flash_image_mma.bin
7 mma_test_metadata_bin=mma_test_metadata.bin
8 mma_test_metadata_bin_path=/tmp/"${mma_test_metadata_bin}"
10 printf_separator() {
11 printf '=%.0s' {1..80}
12 printf '\n'
15 show_usage() {
16 printf "MMA blobs version : 2.1018\n"
17 printf "usage: $(basename "${0}") %s\n" \
18 "set [<mma_test_name_efi> <mma_test_param_bin>] | reset"
19 printf '=%.0s' {1..29}
20 printf "All possible MMA tests"
21 printf '=%.0s' {1..29}
22 printf "\n"
23 printf_separator
24 printf "Test Name \tMargin1D.efi\n"
25 printf "Test Config\n"
26 printf "\t\t%s %s\n" \
27 Margin1DCkAllConfig.bin \
28 Margin1DCmdAllConfig.bin \
29 Margin1DCmdVrefConfig.bin \
30 Margin1DCtlAllConfig.bin \
31 Margin1DRxDqsDelayConfig.bin \
32 Margin1DRxVrefConfig.bin \
33 Margin1DTxDqDelayConfig.bin \
34 Margin1DTxVrefConfig.bin
35 printf_separator
36 printf "Test Name \tMargin2D.efi\n"
37 printf "Test Config\n"
38 printf "\t\t%s %s\n" \
39 Margin2D_Cmd_Ch0_D0_R0_Config.bin \
40 Margin2D_Cmd_Ch0_D1_R0_Config.bin \
41 Margin2D_Cmd_Ch1_D0_R0_Config.bin \
42 Margin2D_Cmd_Ch1_D1_R0_Config.bin \
43 Margin2D_Rx_Ch0_D0_R0_Config.bin \
44 Margin2D_Rx_Ch0_D0_R1_Config.bin \
45 Margin2D_Rx_Ch0_D1_R0_Config.bin \
46 Margin2D_Rx_Ch0_D1_R1_Config.bin \
47 Margin2D_Rx_Ch1_D0_R0_Config.bin \
48 Margin2D_Rx_Ch1_D0_R1_Config.bin \
49 Margin2D_Rx_Ch1_D1_R0_Config.bin \
50 Margin2D_Rx_Ch1_D1_R1_Config.bin \
51 Margin2D_Tx_Ch0_D0_R0_Config.bin \
52 Margin2D_Tx_Ch0_D0_R1_Config.bin \
53 Margin2D_Tx_Ch0_D1_R0_Config.bin \
54 Margin2D_Tx_Ch0_D1_R1_Config.bin \
55 Margin2D_Tx_Ch1_D0_R0_Config.bin \
56 Margin2D_Tx_Ch1_D0_R1_Config.bin \
57 Margin2D_Tx_Ch1_D1_R0_Config.bin \
58 Margin2D_Tx_Ch1_D1_R1_Config.bin
59 printf_separator
60 printf "Test name \tMarginMapper.efi\n"
61 printf "Test Config\n"
62 printf "\t\t%s %s\n" \
63 MarginMapperRxVref-RxDqsDelayConfigVCh0ACh0_single_ch.bin \
64 MarginMapperRxVref-RxDqsDelayConfigVCh0ACh1_dual_ch.bin \
65 MarginMapperRxVref-RxDqsDelayConfigVCh1ACh0_dual_ch.bin \
66 MarginMapperRxVref-RxDqsDelayConfigVCh1ACh1_single_ch.bin \
67 MarginMapperTxVref-TxDqDelayConfigVCh0ACh0_single_ch.bin \
68 MarginMapperTxVref-TxDqDelayConfigVCh0ACh1_dual_ch.bin \
69 MarginMapperTxVref-TxDqDelayConfigVCh1ACh0_dual_ch.bin \
70 MarginMapperTxVref-TxDqDelayConfigVCh1ACh1_single_ch.bin \
71 ScoreRxVref-RxDqsDelayConfigVCh0ACh0_single_ch.bin \
72 ScoreRxVref-RxDqsDelayConfigVCh0ACh1_dual_ch.bin \
73 ScoreRxVref-RxDqsDelayConfigVCh1ACh0_dual_ch.bin \
74 ScoreRxVref-RxDqsDelayConfigVCh1ACh1_single_ch.bin \
75 ScoreTxVref-TxDqDelayConfigVCh0ACh0_single_ch.bin \
76 ScoreTxVref-TxDqDelayConfigVCh0ACh1_dual_ch.bin \
77 ScoreTxVref-TxDqDelayConfigVCh1ACh0_dual_ch.bin \
78 ScoreTxVref-TxDqDelayConfigVCh1ACh1_single_ch.bin
79 printf_separator
80 printf "Test Name \tRMT.efi\n"
81 printf "Test Config\n"
82 printf "\t\t%s %s\n" \
83 RMTConfig.bin
84 printf_separator
87 write_flash() {
88 printf "Writing back flash contents "${flashrom_temp_image}"\n"
89 flashrom -p internal -w "${flashrom_temp_image}" --noverify-all || \
91 printf "failed to read flash\n" ;
92 exit -1;
96 remove_file_if_exists() {
97 if [ -f "${1}" ]; then
98 printf "removing old "${1}"\n"
99 rm -f "${1}"
103 remove_metadata() {
104 printf "Removing "${mma_test_metadata_bin}" from "${flashrom_temp_image}"\n"
105 cbfstool "${flashrom_temp_image}" remove -n ${mma_test_metadata_bin}
106 outout=$(cbfstool "${flashrom_temp_image}" print | \
107 grep ${mma_test_metadata_bin})
109 if [ -z "${outout}" ];then
110 printf "Removed ${mma_test_metadata_bin} from %s\n" \
111 "${flashrom_temp_image}"
112 else
113 printf "Failed to remove ${mma_test_metadata_bin} from %s\n" \
114 "${flashrom_temp_image}"
115 print_failed
116 exit -1;
120 generate_metadata() {
121 remove_file_if_exists "${mma_test_metadata_bin_path}"
123 printf "Creating "${mma_test_metadata_bin_path}"\n"
125 #Format of $mma_test_metadata_bin
126 #MMA_TEST_NAME=xxxxxx.efi;MMA_TEST_PARAM=xxxxxx.bin;
128 printf "MMA_TEST_NAME=${mma_test_name};MMA_TEST_PARAM=${mma_test_param};" \
129 > "${mma_test_metadata_bin_path}"
132 add_metadata_to_flashfile() {
133 cbfstool "${flashrom_temp_image}" add -f "${mma_test_metadata_bin_path}" \
134 -n ${mma_test_metadata_bin} -t ${file_type_mma} || \
136 printf "failed to add "${mma_test_metadata_bin_path}"\n" ;
137 exit -1;
141 cleanup() {
142 remove_file_if_exists "${flashrom_temp_image}"
143 remove_file_if_exists "${mma_test_metadata_bin_path}"
146 print_success() {
147 printf "============== SUCCESS ==============\n"
150 print_failed() {
151 printf "============== FAILED ==============\n"
155 # main entry point
158 main() {
159 case "${#}:${1}" in
160 (3:set)
161 mma_test_name=${2}
162 mma_test_param=${3}
164 (1:reset)
167 show_usage
168 exit -1
169 esac
171 if [ "${1}" != "reset" ];then
172 printf "mma_test_name = ${mma_test_name}\n"
173 printf "mma_test_param = ${mma_test_param}\n"
176 remove_file_if_exists "${flashrom_temp_image}"
178 printf "Reading flash contents to "${flashrom_temp_image}"\n"
179 flashrom -p internal -r "${flashrom_temp_image}" || \
181 printf "failed to read flash\n" ;
182 exit -1;
185 outdata=$(cbfstool "${flashrom_temp_image}" print | \
186 grep ${mma_test_metadata_bin})
188 case "$1" in
189 ("set")
190 [ "${outdata}" ] && remove_metadata
191 generate_metadata
192 add_metadata_to_flashfile
193 write_flash
195 ("reset")
196 if [ -z "${outdata}" ];then
197 printf "${mma_test_metadata_bin} not found at all.\n"
198 else
199 remove_metadata
200 write_flash
203 esac
204 cleanup
205 print_success
208 main "$@"