1*** Settings ***
2Documentation    Module to test In band firmware update.
3
4Resource         ../../lib/ipmi_client.robot
5Resource         ../../lib/openbmc_ffdc.robot
6Resource         ../../lib/connection_client.robot
7Resource         ../../lib/code_update_utils.robot
8
9Suite Setup      Suite Setup Execution
10
11*** Variables ***
12${image-bios}        image-bios
13${image-bios-sig}    image-bios.sig
14${image-bmc}         image-bmc
15${image-bmc-sig}     image-bmc.sig
16${BAD_IMG}           tmp.bin
17${BAD_SIG}           tmp.sig
18${lpcshm_address}    ${0}
19
20*** Test Cases ***
21
22Test BIOS Firmware Update
23    [Documentation]  Test BIOS firmware update over IPMI.
24    [Tags]  Test_BIOS_Firmware_Update
25
26    Run Keyword  Wait For Host To Ping  ${OS_HOST}  3 mins
27
28    Get LPC SHM Address
29    Update BIOS Firmware  ${IMAGE_HOST_FILE_PATH_0}
30    Verify BIOS Version  ${IMAGE_HOST_FILE_PATH_0}
31    BMC Execute Command
32    ...  systemctl restart phosphor-ipmi-host.service
33    Sleep  10s
34    Get LPC SHM Address
35    Update BIOS Firmware  ${IMAGE_HOST_FILE_PATH_1}
36    Verify BIOS Version  ${IMAGE_HOST_FILE_PATH_1}
37    BMC Execute Command
38    ...  systemctl restart phosphor-ipmi-host.service
39    Sleep  10s
40
41Test Invalid BIOS Firmware Update
42    [Documentation]  Test Invalid BIOS firmware update over IPMI.
43    [Tags]  Test_Invalid_BIOS_Firmware_Update
44
45    Run Keyword  Wait For Host To Ping  ${OS_HOST}  3 mins
46    Get LPC SHM Address
47
48    ${cmd}=  Catenate  ${HOST_WORK_DIR}/burn_my_bmc --command update --interface ipmilpc
49    ...  --image ${HOST_WORK_DIR}/${BAD_IMG} --sig ${HOST_WORK_DIR}/${BAD_SIG} --type bios
50    ...  --address 0x${lpcshmaddress} --length 0xFFC
51
52    ${output}  ${stderr}  ${rc}=  OS Execute Command  ${cmd}  ignore_err=1
53    Should Contain  ${stderr}  Verification failed
54
55Test BMC Firmware Update
56    [Documentation]  Test BMC firmware update over IPMI.
57    [Tags]  Test_BMC_Firmware_Update
58
59    Run Keyword  Wait For Host To Ping  ${OS_HOST}  3 mins
60    Get LPC SHM Address
61    Update BMC Firmware  ${IMAGE_BMC_FILE_PATH_0}
62    Verify BMC Version  ${IMAGE_BMC_FILE_PATH_0}
63    Sleep  10s
64    Update BMC Firmware  ${IMAGE_BMC_FILE_PATH_1}
65    Verify BMC Version  ${IMAGE_BMC_FILE_PATH_1}
66
67Test Invalid BMC Firmware Update
68    [Documentation]  Test Invalid BMC firmware update over IPMI.
69    [Tags]  Test_Invalid_BMC_Firmware_Update
70
71    Run Keyword  Wait For Host To Ping  ${OS_HOST}  3 mins
72    Get LPC SHM Address
73
74    ${cmd}=  Catenate  ${HOST_WORK_DIR}/burn_my_bmc --command update --interface ipmilpc
75    ...  --image ${HOST_WORK_DIR}/${BAD_IMG} --sig ${HOST_WORK_DIR}/${BAD_SIG} --type image
76    ...  --address 0x${lpcshmaddress} --length 0xFFC
77
78    ${output}  ${stderr}  ${rc}=  OS Execute Command  ${cmd}  ignore_err=1
79    Should Contain  ${stderr}  Verification failed
80
81
82*** Keywords ***
83
84Suite Setup Execution
85    [Documentation]  Suite Setup Execution.
86
87    ${os_state}=  Get Host State Attribute  OperatingSystemState
88    Rprint Vars  os_state
89    Run Keyword if  '${OS_BOOT_COMPLETE}' != '${os_state}'
90    ...  Redfish Power On
91
92    # generate bad image for test
93    ${cmd}=  Catenate  dd if=/dev/urandom of=${HOST_WORK_DIR}/${BAD_IMG} bs=1K count=4
94    OS Execute Command  ${cmd}  ignore_err=1
95    ${cmd}=  Catenate  dd if=/dev/urandom of=${HOST_WORK_DIR}/${BAD_SIG} bs=1 count=128
96    OS Execute Command  ${cmd}  ignore_err=1
97
98
99Get LPC SHM Address
100    [Documentation]  Get Mapped Address of LPC hare Memory.
101
102    # select SHM logic device
103    OS Execute Command  outb 0x4e 0x07
104    OS Execute Command  outb 0x4f 0x0f
105
106    OS Execute Command  outb 0x4e 0xf4
107    ${output}  ${stderr}  ${rc}=  OS Execute Command  inb 0x4f
108    ${output}=  Evaluate  ${output} + 4
109    ${b0}=  Convert To Hex  ${output}  length=2
110
111    OS Execute Command  outb 0x4e 0xf5
112    ${output}  ${stderr}  ${rc}=  OS Execute Command  inb 0x4f
113    ${b1}=  Convert To Hex  ${output}  length=2
114
115    OS Execute Command  outb 0x4e 0xf6
116    ${output}  ${stderr}  ${rc}=  OS Execute Command  inb 0x4f
117    ${b2}=  Convert To Hex  ${output}  length=2
118
119    OS Execute Command  outb 0x4e 0xf7
120    ${output}  ${stderr}  ${rc}=  OS Execute Command  inb 0x4f
121    ${b3}=  Convert To Hex  ${output}  length=2
122
123    Set Global Variable  ${lpcshm_address}  ${b3}${b2}${b1}${b0}
124    Rprint Vars  lpcshm_address
125
126BIOS Update Status Should Be
127    [Documentation]  Check the Update Process is Activating.
128    [Arguments]  ${state}
129
130    # Description of argument(s):
131    # state   The state of update process.
132
133    ${cmd}=  Catenate  systemctl show --property=ActiveState --property=LoadState
134    ...  --property=Result phosphor-ipmi-flash-bios-update.service
135    ${output}  ${stderr}  ${rc}=  BMC Execute Command  ${cmd}
136
137    Should Contain  ${output}  ${state}  case_insensitive=True
138
139Verify BIOS Version
140    [Documentation]  Verify BIOS Version.
141    [Arguments]      ${image_file_path}
142
143    # Description of argument(s):
144    # image_file_path   Path to the image tarball.
145
146    ${image_version}=  Get Version Tar  ${image_file_path}
147    Rprint Vars  image_version
148
149    ${BIOS_Version}=  Get BIOS Version
150    Rprint Vars  BIOS_Version
151    Should Be Equal  ${BIOS_Version}  ${image_version}
152
153Verify BMC Version
154    [Documentation]  Verify that the version on the BMC is the same as the
155    ...              version in the given image via Redfish.
156    [Arguments]      ${image_file_path}
157
158    # Description of argument(s):
159    # image_file_path   Path to the image tarball.
160
161    # Extract the version from the image tarball on our local system.
162    ${image_version}=  Get Version Tar  ${image_file_path}
163    Rprint Vars  image_version
164    Redfish.Login
165    ${bmc_version}=  Redfish Get BMC Version
166    Rprint Vars  bmc_version
167
168    Valid Value  bmc_version  valid_values=['${image_version}']
169
170Update BIOS Firmware
171    [Documentation]  Update BIOS Firmware.
172    [Arguments]      ${image_file_path}
173
174    # Description of argument(s):
175    # image_file_path   Path to the image tarball.
176
177    OperatingSystem.File Should Exist  ${image_file_path}
178
179    Run Keyword  Wait For Host To Ping  ${OS_HOST}  3 mins
180
181    scp.Open connection  ${OS_HOST}  username=${OS_USERNAME}
182    ...  password=${OS_PASSWORD}
183    scp.Put File  ${image_file_path}  ${HOST_WORK_DIR}/${image_file_path}
184
185    ${cmd}=  Catenate  tar -xf ${HOST_WORK_DIR}/${image_file_path} -C ${HOST_WORK_DIR}
186    ${output}  ${stderr}  ${rc}=  OS Execute Command  ${cmd}
187
188    ${cmd}=  Catenate  ${HOST_WORK_DIR}/burn_my_bmc --command update --interface ipmilpc
189    ...  --image ${HOST_WORK_DIR}/${image-bios} --sig ${HOST_WORK_DIR}/${image-bios-sig} --type bios
190    ...  --address 0x${lpcshm_address} --length 0xFFC
191
192    OS Execute Command  ${cmd}  fork=1
193
194    Wait Until Keyword Succeeds  5 mins  10 secs
195    ...  BIOS Update Status Should Be  ActiveState=activating
196
197    Wait Until Keyword Succeeds  20 mins  30 secs
198    ...  BIOS Update Status Should Be  ActiveState=inactive
199
200    ${cmd}=  Catenate  systemctl show --property=Result
201    ...  phosphor-ipmi-flash-bios-update.service
202    ${output}  ${stderr}  ${rc}=  BMC Execute Command  ${cmd}
203    Should Contain  ${output}  Result=success
204
205    Run Keyword  Wait For Host To Ping  ${OS_HOST}  5 mins
206
207Update BMC Firmware
208    [Documentation]  Update BIOS Firmware.
209    [Arguments]      ${image_file_path}
210
211    # Description of argument(s):
212    # image_file_path   Path to the image tarball.
213
214    OperatingSystem.File Should Exist  ${image_file_path}
215
216    Run Keyword  Wait For Host To Ping  ${OS_HOST}  3 mins
217
218    scp.Open connection  ${OS_HOST}  username=${OS_USERNAME}
219    ...  password=${OS_PASSWORD}
220    scp.Put File  ${image_file_path}  ${HOST_WORK_DIR}/${image_file_path}
221
222    ${cmd}=  Catenate  tar -xf ${HOST_WORK_DIR}/${image_file_path} -C ${HOST_WORK_DIR}
223    ${output}  ${stderr}  ${rc}=  OS Execute Command  ${cmd}
224
225    ${cmd}=  Catenate  ${HOST_WORK_DIR}/burn_my_bmc --command update --interface ipmilpc
226    ...  --image ${HOST_WORK_DIR}/${image-bmc} --sig ${HOST_WORK_DIR}/${image-bmc-sig} --type image
227    ...  --address 0x${lpcshm_address} --length 0xFFC --ignore-update
228
229    ${output}  ${stderr}  ${rc}=  OS Execute Command  ${cmd}  ignore_err=1
230    Should Not Contain  ${stderr}  Exception received
231
232    Sleep  10s
233    Check If BMC is Up  20 min  20 sec
234    Wait For BMC Ready
235