Add oem folder for verify mcu, in-band firmware update and jtag master

changes:
   - Added test robot "oem/nuvoton/test_redfish_mcu_fw_update.robot"
   - Added test robot "oem/nuvoton/test_jtag_master.robot"
   - Added test robot "oem/nuvoton/test_ipmi_flash.robot"

Signed-off-by: Tim Lee <timlee660101@gmail.com>
Change-Id: I85afa7db6952781211230c660d1831474b734586
diff --git a/data/oem/nuvoton/olympus.json b/data/oem/nuvoton/olympus.json
new file mode 100644
index 0000000..7c9de53
--- /dev/null
+++ b/data/oem/nuvoton/olympus.json
@@ -0,0 +1,15 @@
+{
+    "npcm7xx": {
+        "cpld" : {
+            "fw1" : "2A01.svf",
+            "fw1ver" : "00 00 2a 01",
+            "fw2" : "2A02.svf",
+            "fw2ver" : "00 00 2a 02",
+            "readid" : "readid.svf",
+            "readusercode" : "read_usercode.svf"
+        },
+        "jtag_dev" : "/dev/jtag0",
+        "power_cycle_cmd" : "/usr/sbin/i2cset -f -y 8 0x11 0xd9"
+    }
+}
+
diff --git a/oem/nuvoton/test_ipmi_flash.robot b/oem/nuvoton/test_ipmi_flash.robot
new file mode 100644
index 0000000..6946f8b
--- /dev/null
+++ b/oem/nuvoton/test_ipmi_flash.robot
@@ -0,0 +1,234 @@
+*** Settings ***
+Documentation    Module to test In band firmware update.
+
+Resource         ../lib/ipmi_client.robot
+Resource         ../lib/openbmc_ffdc.robot
+Resource         ../lib/connection_client.robot
+Resource         ../lib/code_update_utils.robot
+
+Suite Setup      Suite Setup Execution
+
+*** Variables ***
+${image-bios}        image-bios
+${image-bios-sig}    image-bios.sig
+${image-bmc}         image-bmc
+${image-bmc-sig}     image-bmc.sig
+${BAD_IMG}           tmp.bin
+${BAD_SIG}           tmp.sig
+${lpcshm_address}    ${0}
+
+*** Test Cases ***
+
+Test BIOS Firmware Update
+    [Documentation]  Test BIOS firmware update over IPMI.
+    [Tags]  Test_BIOS_Firmware_Update
+
+    Run Keyword  Wait For Host To Ping  ${OS_HOST}  3 mins
+
+    Get LPC SHM Address
+    Update BIOS Firmware  ${IMAGE_HOST_FILE_PATH_0}
+    Verify BIOS Version  ${IMAGE_HOST_FILE_PATH_0}
+    BMC Execute Command
+    ...  systemctl restart phosphor-ipmi-host.service
+    Sleep  10s
+    Get LPC SHM Address
+    Update BIOS Firmware  ${IMAGE_HOST_FILE_PATH_1}
+    Verify BIOS Version  ${IMAGE_HOST_FILE_PATH_1}
+    BMC Execute Command
+    ...  systemctl restart phosphor-ipmi-host.service
+    Sleep  10s
+
+Test Invalid BIOS Firmware Update
+    [Documentation]  Test Invalid BIOS firmware update over IPMI.
+    [Tags]  Test_Invalid_BIOS_Firmware_Update
+
+    Run Keyword  Wait For Host To Ping  ${OS_HOST}  3 mins
+    Get LPC SHM Address
+
+    ${cmd}=  Catenate  ${HOST_WORK_DIR}/burn_my_bmc --command update --interface ipmilpc
+    ...  --image ${HOST_WORK_DIR}/${BAD_IMG} --sig ${HOST_WORK_DIR}/${BAD_SIG} --type bios
+    ...  --address 0x${lpcshmaddress} --length 0xFFC
+
+    ${output}  ${stderr}  ${rc}=  OS Execute Command  ${cmd}  ignore_err=1
+    Should Contain  ${stderr}  Verification failed
+
+Test BMC Firmware Update
+    [Documentation]  Test BMC firmware update over IPMI.
+    [Tags]  Test_BMC_Firmware_Update
+
+    Run Keyword  Wait For Host To Ping  ${OS_HOST}  3 mins
+    Get LPC SHM Address
+    Update BMC Firmware  ${IMAGE_BMC_FILE_PATH_0}
+    Verify BMC Version  ${IMAGE_BMC_FILE_PATH_0}
+    Sleep  10s
+    Update BMC Firmware  ${IMAGE_BMC_FILE_PATH_1}
+    Verify BMC Version  ${IMAGE_BMC_FILE_PATH_1}
+
+Test Invalid BMC Firmware Update
+    [Documentation]  Test Invalid BMC firmware update over IPMI.
+    [Tags]  Test_Invalid_BMC_Firmware_Update
+
+    Run Keyword  Wait For Host To Ping  ${OS_HOST}  3 mins
+    Get LPC SHM Address
+
+    ${cmd}=  Catenate  ${HOST_WORK_DIR}/burn_my_bmc --command update --interface ipmilpc
+    ...  --image ${HOST_WORK_DIR}/${BAD_IMG} --sig ${HOST_WORK_DIR}/${BAD_SIG} --type image
+    ...  --address 0x${lpcshmaddress} --length 0xFFC
+
+    ${output}  ${stderr}  ${rc}=  OS Execute Command  ${cmd}  ignore_err=1
+    Should Contain  ${stderr}  Verification failed
+
+
+*** Keywords ***
+
+Suite Setup Execution
+    [Documentation]  Suite Setup Exection.
+
+    ${os_state}=  Get Host State Attribute  OperatingSystemState
+    Rprint Vars  os_state
+    Run Keyword if  '${OS_BOOT_COMPLETE}' != '${os_state}'
+    ...  Redfish Power On
+
+    # generate bad image for test
+    ${cmd}=  Catenate  dd if=/dev/urandom of=${HOST_WORK_DIR}/${BAD_IMG} bs=1K count=4
+    OS Execute Command  ${cmd}  ignore_err=1
+    ${cmd}=  Catenate  dd if=/dev/urandom of=${HOST_WORK_DIR}/${BAD_SIG} bs=1 count=128
+    OS Execute Command  ${cmd}  ignore_err=1
+
+
+Get LPC SHM Address
+    [Documentation]  Get Mapped Address of LPC hare Memory.
+
+    # select SHM logic device
+    OS Execute Command  outb 0x4e 0x07
+    OS Execute Command  outb 0x4f 0x0f
+
+    OS Execute Command  outb 0x4e 0xf4
+    ${output}  ${stderr}  ${rc}=  OS Execute Command  inb 0x4f
+    ${output}=  Evaluate  ${output} + 4
+    ${b0}=  Convert To Hex  ${output}  length=2
+
+    OS Execute Command  outb 0x4e 0xf5
+    ${output}  ${stderr}  ${rc}=  OS Execute Command  inb 0x4f
+    ${b1}=  Convert To Hex  ${output}  length=2
+
+    OS Execute Command  outb 0x4e 0xf6
+    ${output}  ${stderr}  ${rc}=  OS Execute Command  inb 0x4f
+    ${b2}=  Convert To Hex  ${output}  length=2
+
+    OS Execute Command  outb 0x4e 0xf7
+    ${output}  ${stderr}  ${rc}=  OS Execute Command  inb 0x4f
+    ${b3}=  Convert To Hex  ${output}  length=2
+
+    Set Global Variable  ${lpcshm_address}  ${b3}${b2}${b1}${b0}
+    Rprint Vars  lpcshm_address
+
+BIOS Update Status Should Be
+    [Documentation]  Check the Update Process is Activating.
+    [Arguments]  ${state}
+
+    # Description of argument(s):
+    # state   The state of update process.
+
+    ${cmd}=  Catenate  systemctl show --property=ActiveState --property=LoadState
+    ...  --property=Result phosphor-ipmi-flash-bios-update.service
+    ${output}  ${stderr}  ${rc}=  BMC Execute Command  ${cmd}
+
+    Should Contain  ${output}  ${state}  case_insensitive=True
+
+Verify BIOS Version
+    [Documentation]  Verify BIOS Version.
+    [Arguments]      ${image_file_path}
+
+    # Description of argument(s):
+    # image_file_path   Path to the image tarball.
+
+    ${image_version}=  Get Version Tar  ${image_file_path}
+    Rprint Vars  image_version
+
+    ${BIOS_Version}=  Get BIOS Version
+    Rprint Vars  BIOS_Version
+    Should Be Equal  ${BIOS_Version}  ${image_version}
+
+Verify BMC Version
+    [Documentation]  Verify that the version on the BMC is the same as the
+    ...              version in the given image via Redfish.
+    [Arguments]      ${image_file_path}
+
+    # Description of argument(s):
+    # image_file_path   Path to the image tarball.
+
+    # Extract the version from the image tarball on our local system.
+    ${image_version}=  Get Version Tar  ${image_file_path}
+    Rprint Vars  image_version
+    Redfish.Login
+    ${bmc_version}=  Redfish Get BMC Version
+    Rprint Vars  bmc_version
+
+    Valid Value  bmc_version  valid_values=['${image_version}']
+
+Update BIOS Firmware
+    [Documentation]  Update BIOS Firmware.
+    [Arguments]      ${image_file_path}
+
+    # Description of argument(s):
+    # image_file_path   Path to the image tarball.
+
+    OperatingSystem.File Should Exist  ${image_file_path}
+
+    Run Keyword  Wait For Host To Ping  ${OS_HOST}  3 mins
+
+    scp.Open connection  ${OS_HOST}  username=${OS_USERNAME}
+    ...  password=${OS_PASSWORD}
+    scp.Put File  ${image_file_path}  ${HOST_WORK_DIR}/${image_file_path}
+
+    ${cmd}=  Catenate  tar -xf ${HOST_WORK_DIR}/${image_file_path} -C ${HOST_WORK_DIR}
+    ${output}  ${stderr}  ${rc}=  OS Execute Command  ${cmd}
+
+    ${cmd}=  Catenate  ${HOST_WORK_DIR}/burn_my_bmc --command update --interface ipmilpc
+    ...  --image ${HOST_WORK_DIR}/${image-bios} --sig ${HOST_WORK_DIR}/${image-bios-sig} --type bios
+    ...  --address 0x${lpcshm_address} --length 0xFFC
+
+    OS Execute Command  ${cmd}  fork=1
+
+    Wait Until Keyword Succeeds  5 mins  10 secs
+    ...  BIOS Update Status Should Be  ActiveState=activating
+
+    Wait Until Keyword Succeeds  20 mins  30 secs
+    ...  BIOS Update Status Should Be  ActiveState=inactive
+
+    ${cmd}=  Catenate  systemctl show --property=Result
+    ...  phosphor-ipmi-flash-bios-update.service
+    ${output}  ${stderr}  ${rc}=  BMC Execute Command  ${cmd}
+    Should Contain  ${output}  Result=success
+
+    Run Keyword  Wait For Host To Ping  ${OS_HOST}  5 mins
+
+Update BMC Firmware
+    [Documentation]  Update BIOS Firmware.
+    [Arguments]      ${image_file_path}
+
+    # Description of argument(s):
+    # image_file_path   Path to the image tarball.
+
+    OperatingSystem.File Should Exist  ${image_file_path}
+
+    Run Keyword  Wait For Host To Ping  ${OS_HOST}  3 mins
+
+    scp.Open connection  ${OS_HOST}  username=${OS_USERNAME}
+    ...  password=${OS_PASSWORD}
+    scp.Put File  ${image_file_path}  ${HOST_WORK_DIR}/${image_file_path}
+
+    ${cmd}=  Catenate  tar -xf ${HOST_WORK_DIR}/${image_file_path} -C ${HOST_WORK_DIR}
+    ${output}  ${stderr}  ${rc}=  OS Execute Command  ${cmd}
+
+    ${cmd}=  Catenate  ${HOST_WORK_DIR}/burn_my_bmc --command update --interface ipmilpc
+    ...  --image ${HOST_WORK_DIR}/${image-bmc} --sig ${HOST_WORK_DIR}/${image-bmc-sig} --type image
+    ...  --address 0x${lpcshm_address} --length 0xFFC --ignore-update
+
+    ${output}  ${stderr}  ${rc}=  OS Execute Command  ${cmd}  ignore_err=1
+    Should Not Contain  ${stderr}  Exception received
+
+    Sleep  10s
+    Check If BMC is Up  20 min  20 sec
+    Wait For BMC Ready
diff --git a/oem/nuvoton/test_jtag_master.robot b/oem/nuvoton/test_jtag_master.robot
new file mode 100644
index 0000000..cba956b
--- /dev/null
+++ b/oem/nuvoton/test_jtag_master.robot
@@ -0,0 +1,121 @@
+*** Settings ***
+Documentation    Module to test npcm750 JTAG Master.
+
+Resource         ../lib/openbmc_ffdc.robot
+Resource         ../lib/connection_client.robot
+
+Suite Setup      Suite Setup Execution
+
+*** Variables ***
+${wrong_cpld}         0
+${program_cpld}       0
+
+*** Test Cases ***
+
+Test Read CPLD ID
+    [Documentation]  Test Read CPLD ID.
+    [Tags]  Test_Read_CPLD_ID
+
+    ${cmd}=  Catenate  loadsvf -d ${jtag_dev} -s /var/${readid_svf}
+    ${output}  ${stderr}  ${rc}=  BMC Execute Command  ${cmd}
+    Set Global Variable  ${wrong_cpld}  1
+    Should Not Contain  ${stderr}  tdo check error
+    Set Global Variable  ${wrong_cpld}  0
+
+
+Test Program CPLD
+    [Documentation]  Test Program CPLD.
+    [Tags]  Test_Program_CPLD
+
+    Pass Execution If  ${wrong_cpld}==1  Wrong CPLD chip
+    Pass Execution If  ${program_cpld}==0  skip programming cpld
+
+    Program CPLD  ${cpld_firmware2}  ${firmware_version2}
+    Program CPLD  ${cpld_firmware1}  ${firmware_version1}
+
+*** Keywords ***
+
+Get File From SFTP Server
+    [Documentation]  SCP Get File.
+    [Arguments]      ${filename}
+
+    # Description of argument(s):
+    # filename   The file to be downloaded.
+
+    Shell Cmd
+    ...  scp ${SFTP_USER}@${SFTP_SERVER}:${SFTP_PATH}/${filename} ${filename}
+
+
+Put File To BMC
+    [Documentation]  SCP Put File.
+    [Arguments]      ${filename}
+
+    # Description of argument(s):
+    # filename   The file to be uploaded.
+
+    scp.Put File  ${filename}  /var/${filename}
+
+Suite Setup Execution
+    [Documentation]  Suite Setup Exection.
+
+    ${status}=  Run Keyword And Return Status  Variable Should Exist
+    ...  ${TEST_PROGRAM_CPLD}
+    ${value}=  Set Variable if  ${status} == ${TRUE}  ${TEST_PROGRAM_CPLD}  0
+    Set Global Variable  ${program_cpld}  ${value}
+
+    ${code_base_dir_path}=  Get Code Base Dir Path
+    ${olympus_json}=  Evaluate
+    ...  json.load(open('${code_base_dir_path}data/oem/nuvoton/olympus.json'))  modules=json
+
+    ${cpld_firmware1}=  Set Variable  ${olympus_json["npcm7xx"]["cpld"]["fw1"]}
+    ${cpld_firmware2}=  Set Variable  ${olympus_json["npcm7xx"]["cpld"]["fw2"]}
+    ${firmware_version1}=  Set Variable  ${olympus_json["npcm7xx"]["cpld"]["fw1ver"]}
+    ${firmware_version2}=  Set Variable  ${olympus_json["npcm7xx"]["cpld"]["fw2ver"]}
+    ${readusercode_svf}=  Set Variable  ${olympus_json["npcm7xx"]["cpld"]["readusercode"]}
+    ${readid_svf}=  Set Variable  ${olympus_json["npcm7xx"]["cpld"]["readid"]}
+    ${jtag_dev}=  Set Variable  ${olympus_json["npcm7xx"]["jtag_dev"]}
+    ${power_cycle_cmd}=  Set Variable  ${olympus_json["npcm7xx"]["power_cycle_cmd"]}
+
+    Set Suite Variable  ${cpld_firmware1}
+    Set Suite Variable  ${cpld_firmware2}
+    Set Suite Variable  ${firmware_version1}
+    Set Suite Variable  ${firmware_version2}
+    Set Suite Variable  ${readusercode_svf}
+    Set Suite Variable  ${readid_svf}
+    Set Suite Variable  ${jtag_dev}
+    Set Suite Variable  ${power_cycle_cmd}
+
+    Get File From SFTP Server  ${readid_svf}
+    Run KeyWord If  ${program_cpld} == 1  Get File From SFTP Server  ${readusercode_svf}
+    Run KeyWord If  ${program_cpld} == 1  Get File From SFTP Server  ${cpld_firmware1}
+    Run KeyWord If  ${program_cpld} == 1  Get File From SFTP Server  ${cpld_firmware2}
+
+    scp.Open connection  ${OPENBMC_HOST}  username=${OPENBMC_USERNAME}
+    ...  password=${OPENBMC_PASSWORD}
+    Put File To BMC  ${readid_svf}
+    Run KeyWord If  ${program_cpld} == 1  Put File To BMC  ${readusercode_svf}
+    Run KeyWord If  ${program_cpld} == 1  Put File To BMC  ${cpld_firmware1}
+    Run KeyWord If  ${program_cpld} == 1  Put File To BMC  ${cpld_firmware2}
+    Sleep  5s
+    scp.Close Connection
+
+Program CPLD
+    [Documentation]  Program CPLD.
+    [Arguments]      ${svf_file}  ${version}
+
+    # Description of argument(s):
+    # svf_file   The firmware file.
+    # version    The firmware version.
+
+    ${cmd}=  Catenate  loadsvf -d ${jtag_dev} -s /var/${svf_file}
+    ${output}  ${stderr}  ${rc}=  BMC Execute Command  ${cmd}
+    Should Not Contain  ${stderr}  tdo check error
+
+    # control hot swap controller to power cycle whole system
+    BMC Execute Command  ${power_cycle_cmd}  ignore_err=1  fork=1
+
+    Sleep  10s
+    Run Keyword  Wait For Host To Ping  ${OPENBMC_HOST}  5 mins
+    ${cmd}=  Catenate  loadsvf -d ${jtag_dev} -s /var/${readusercode_svf}
+    ${output}  ${stderr}  ${rc}=  BMC Execute Command  ${cmd}
+    Should Contain  ${output}  ${version}
diff --git a/oem/nuvoton/test_redfish_mcu_fw_update.robot b/oem/nuvoton/test_redfish_mcu_fw_update.robot
new file mode 100644
index 0000000..387cfe8
--- /dev/null
+++ b/oem/nuvoton/test_redfish_mcu_fw_update.robot
@@ -0,0 +1,111 @@
+*** Settings ***

+Documentation            Update firmware on a target MCU via Redifsh.

+

+# Test Parameters:

+# IMAGE_MCU_FILE_PATH    The path to the MCU image file.

+#

+# Firmware update states:

+#     Enabled            Image is installed and either functional or active.

+#     Disabled           Image installation failed or ready for activation.

+#     Updating           Image installation currently in progress.

+

+Resource                 ../lib/resource.robot

+Resource                 ../lib/bmc_redfish_resource.robot

+Resource                 ../lib/boot_utils.robot

+Resource                 ../lib/openbmc_ffdc.robot

+Resource                 ../lib/common_utils.robot

+Resource                 ../lib/code_update_utils.robot

+Resource                 ../lib/dump_utils.robot

+Resource                 ../lib/logging_utils.robot

+Resource                 ../lib/redfish_code_update_utils.robot

+Resource                 ../lib/utils.robot

+Library                  ../lib/gen_robot_valid.py

+Library                  ../lib/tftp_update_utils.py

+

+Suite Setup              Suite Setup Execution

+Suite Teardown           Redfish.Logout

+Test Setup               Printn

+Test Teardown            FFDC On Test Case Fail

+

+Force Tags               Mcu_Code_Update

+

+*** Test Cases ***

+

+Redfish Mcu Code Update With ApplyTime OnReset

+    [Documentation]  Update the firmaware image with ApplyTime of OnReset.

+    [Tags]  Redfish_Mcu_Code_Update_With_ApplyTime_OnReset

+    [Template]  Redfish Update Firmware

+

+    # policy

+    OnReset    ${IMAGE_MCU_FILE_PATH_0}

+

+

+Redfish Mcu Code Update With ApplyTime Immediate

+    [Documentation]  Update the firmaware image with ApplyTime of Immediate.

+    [Tags]  Redfish_Mcu_Code_Update_With_ApplyTime_Immediate

+    [Template]  Redfish Update Firmware

+

+    # policy

+    Immediate  ${IMAGE_MCU_FILE_PATH_1}

+

+

+*** Keywords ***

+

+Suite Setup Execution

+    [Documentation]  Do the suite setup.

+

+    # Checking for file existence.

+    Valid File Path  IMAGE_MCU_FILE_PATH_0

+    Valid File Path  IMAGE_MCU_FILE_PATH_1

+

+    Redfish.Login

+    Delete All BMC Dump

+    Redfish Purge Event Log

+

+

+Redfish Verify MCU Version

+    [Documentation]  Verify that the version on the MCU is the same as the

+    ...              version in the given image via Redfish.

+    [Arguments]      ${image_file_path}

+

+    # Description of argument(s):

+    # image_file_path   Path to the image tarball.

+

+    # Extract the version from the image tarball on our local system.

+    ${tar_version}=  Get Version Tar  ${image_file_path}

+

+    ${image_info}=  Get Software Inventory State By Version  ${tar_version}

+    ${image_id}=  Get Image Id By Image Info  ${image_info}

+

+    ${mcu_version}=  Redfish.Get Attribute  /redfish/v1/UpdateService/FirmwareInventory/${image_id}  Version

+

+    Valid Value  mcu_version  valid_values=['${tar_version}']

+

+

+Redfish Update Firmware

+    [Documentation]  Update the BMC firmware via redfish interface.

+    [Arguments]  ${apply_time}  ${image_file_path}

+

+    # Description of argument(s):

+    # policy     ApplyTime allowed values (e.g. "OnReset", "Immediate").

+

+    Redfish.Login

+

+    Set ApplyTime  policy=${apply_time}

+

+    Redfish Upload Image  /redfish/v1/UpdateService  ${image_file_path}

+    Sleep  30s

+

+    ${image_version}=  Get Version Tar  ${image_file_path}

+    ${image_info}=  Get Software Inventory State By Version  ${image_version}

+    ${image_id}=  Get Image Id By Image Info  ${image_info}

+

+    Redfish.Login

+    Redfish Verify MCU Version  ${image_file_path}

+

+

+Get Image Id By Image Info

+    [Documentation]  Get image ID from image_info.

+    [Arguments]  ${image_info}

+

+    [Return]  ${image_info["image_id"]}