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