Yegor Timoshenko | c2e4941 | 2018-10-07 01:58:27 +0000 | [diff] [blame] | 1 | #!/usr/bin/env bash |
Pratik Prajapati | 21deb06 | 2015-09-02 13:14:20 -0700 | [diff] [blame] | 2 | # |
Patrick Georgi | 7333a11 | 2020-05-08 20:48:04 +0200 | [diff] [blame] | 3 | # SPDX-License-Identifier: GPL-2.0-only |
Pratik Prajapati | 21deb06 | 2015-09-02 13:14:20 -0700 | [diff] [blame] | 4 | |
| 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}" |
| 9 | |
| 10 | printf_separator() { |
| 11 | printf '=%.0s' {1..80} |
| 12 | printf '\n' |
| 13 | } |
| 14 | |
| 15 | show_usage() { |
Pratik Prajapati | 0bb611d | 2017-04-10 15:45:40 -0700 | [diff] [blame] | 16 | printf "MMA blobs version : 2.1018\n" |
Pratik Prajapati | 21deb06 | 2015-09-02 13:14:20 -0700 | [diff] [blame] | 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" \ |
Pratik Prajapati | 0bb611d | 2017-04-10 15:45:40 -0700 | [diff] [blame] | 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 |
Pratik Prajapati | 21deb06 | 2015-09-02 13:14:20 -0700 | [diff] [blame] | 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 |
| 85 | } |
| 86 | |
| 87 | write_flash() { |
| 88 | printf "Writing back flash contents "${flashrom_temp_image}"\n" |
Pratik Prajapati | de62e0f | 2016-02-22 16:50:31 -0800 | [diff] [blame] | 89 | flashrom -p host -w "${flashrom_temp_image}" --fast-verify || \ |
Pratik Prajapati | 21deb06 | 2015-09-02 13:14:20 -0700 | [diff] [blame] | 90 | { |
| 91 | printf "failed to read flash\n" ; |
| 92 | exit -1; |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | remove_file_if_exists() { |
| 97 | if [ -f "${1}" ]; then |
| 98 | printf "removing old "${1}"\n" |
| 99 | rm -f "${1}" |
| 100 | fi |
| 101 | } |
| 102 | |
| 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}) |
| 108 | |
| 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; |
| 117 | fi |
| 118 | } |
| 119 | |
| 120 | generate_metadata() { |
| 121 | remove_file_if_exists "${mma_test_metadata_bin_path}" |
| 122 | |
| 123 | printf "Creating "${mma_test_metadata_bin_path}"\n" |
| 124 | # |
| 125 | #Format of $mma_test_metadata_bin |
| 126 | #MMA_TEST_NAME=xxxxxx.efi;MMA_TEST_PARAM=xxxxxx.bin; |
| 127 | # |
| 128 | printf "MMA_TEST_NAME=${mma_test_name};MMA_TEST_PARAM=${mma_test_param};" \ |
| 129 | > "${mma_test_metadata_bin_path}" |
| 130 | } |
| 131 | |
| 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} || \ |
| 135 | { |
| 136 | printf "failed to add "${mma_test_metadata_bin_path}"\n" ; |
| 137 | exit -1; |
| 138 | } |
| 139 | } |
| 140 | |
| 141 | cleanup() { |
| 142 | remove_file_if_exists "${flashrom_temp_image}" |
| 143 | remove_file_if_exists "${mma_test_metadata_bin_path}" |
| 144 | } |
| 145 | |
| 146 | print_success() { |
| 147 | printf "============== SUCCESS ==============\n" |
| 148 | } |
| 149 | |
| 150 | print_failed() { |
| 151 | printf "============== FAILED ==============\n" |
| 152 | } |
| 153 | |
| 154 | # |
| 155 | # main entry point |
| 156 | # |
| 157 | |
| 158 | main() { |
| 159 | case "${#}:${1}" in |
| 160 | (3:set) |
| 161 | mma_test_name=${2} |
| 162 | mma_test_param=${3} |
| 163 | ;; |
| 164 | (1:reset) |
| 165 | ;; |
| 166 | (*) |
| 167 | show_usage |
| 168 | exit -1 |
| 169 | esac |
| 170 | |
| 171 | if [ "${1}" != "reset" ];then |
| 172 | printf "mma_test_name = ${mma_test_name}\n" |
| 173 | printf "mma_test_param = ${mma_test_param}\n" |
| 174 | fi |
| 175 | |
| 176 | remove_file_if_exists "${flashrom_temp_image}" |
| 177 | |
| 178 | printf "Reading flash contents to "${flashrom_temp_image}"\n" |
Pratik Prajapati | de62e0f | 2016-02-22 16:50:31 -0800 | [diff] [blame] | 179 | flashrom -p host -r "${flashrom_temp_image}" || \ |
Pratik Prajapati | 21deb06 | 2015-09-02 13:14:20 -0700 | [diff] [blame] | 180 | { |
| 181 | printf "failed to read flash\n" ; |
| 182 | exit -1; |
| 183 | } |
| 184 | |
| 185 | outdata=$(cbfstool "${flashrom_temp_image}" print | \ |
| 186 | grep ${mma_test_metadata_bin}) |
| 187 | |
| 188 | case "$1" in |
| 189 | ("set") |
| 190 | [ "${outdata}" ] && remove_metadata |
| 191 | generate_metadata |
| 192 | add_metadata_to_flashfile |
| 193 | write_flash |
| 194 | ;; |
| 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 |
| 201 | fi |
| 202 | ;; |
| 203 | esac |
| 204 | cleanup |
| 205 | print_success |
| 206 | } |
| 207 | |
| 208 | main "$@" |