148d80bdfSTim Lee*** Settings ***
248d80bdfSTim LeeDocumentation    Module to test npcm750 JTAG Master.
348d80bdfSTim Lee
4*bc284352SStanley ChuResource         ../../lib/openbmc_ffdc.robot
5*bc284352SStanley ChuResource         ../../lib/connection_client.robot
648d80bdfSTim Lee
748d80bdfSTim LeeSuite Setup      Suite Setup Execution
848d80bdfSTim Lee
948d80bdfSTim Lee*** Variables ***
1048d80bdfSTim Lee${wrong_cpld}         0
1148d80bdfSTim Lee${program_cpld}       0
1248d80bdfSTim Lee
1348d80bdfSTim Lee*** Test Cases ***
1448d80bdfSTim Lee
1548d80bdfSTim LeeTest Read CPLD ID
1648d80bdfSTim Lee    [Documentation]  Test Read CPLD ID.
1748d80bdfSTim Lee    [Tags]  Test_Read_CPLD_ID
1848d80bdfSTim Lee
1948d80bdfSTim Lee    ${cmd}=  Catenate  loadsvf -d ${jtag_dev} -s /var/${readid_svf}
2048d80bdfSTim Lee    ${output}  ${stderr}  ${rc}=  BMC Execute Command  ${cmd}
2148d80bdfSTim Lee    Set Global Variable  ${wrong_cpld}  1
2248d80bdfSTim Lee    Should Not Contain  ${stderr}  tdo check error
2348d80bdfSTim Lee    Set Global Variable  ${wrong_cpld}  0
2448d80bdfSTim Lee
2548d80bdfSTim Lee
2648d80bdfSTim LeeTest Program CPLD
2748d80bdfSTim Lee    [Documentation]  Test Program CPLD.
2848d80bdfSTim Lee    [Tags]  Test_Program_CPLD
2948d80bdfSTim Lee
3048d80bdfSTim Lee    Pass Execution If  ${wrong_cpld}==1  Wrong CPLD chip
3148d80bdfSTim Lee    Pass Execution If  ${program_cpld}==0  skip programming cpld
3248d80bdfSTim Lee
3348d80bdfSTim Lee    Program CPLD  ${cpld_firmware2}  ${firmware_version2}
3448d80bdfSTim Lee    Program CPLD  ${cpld_firmware1}  ${firmware_version1}
3548d80bdfSTim Lee
3648d80bdfSTim Lee*** Keywords ***
3748d80bdfSTim Lee
3848d80bdfSTim LeeGet File From SFTP Server
3948d80bdfSTim Lee    [Documentation]  SCP Get File.
4048d80bdfSTim Lee    [Arguments]      ${filename}
4148d80bdfSTim Lee
4248d80bdfSTim Lee    # Description of argument(s):
4348d80bdfSTim Lee    # filename   The file to be downloaded.
4448d80bdfSTim Lee
4548d80bdfSTim Lee    Shell Cmd
4648d80bdfSTim Lee    ...  scp ${SFTP_USER}@${SFTP_SERVER}:${SFTP_PATH}/${filename} ${filename}
4748d80bdfSTim Lee
4848d80bdfSTim Lee
4948d80bdfSTim LeePut File To BMC
5048d80bdfSTim Lee    [Documentation]  SCP Put File.
5148d80bdfSTim Lee    [Arguments]      ${filename}
5248d80bdfSTim Lee
5348d80bdfSTim Lee    # Description of argument(s):
5448d80bdfSTim Lee    # filename   The file to be uploaded.
5548d80bdfSTim Lee
5648d80bdfSTim Lee    scp.Put File  ${filename}  /var/${filename}
5748d80bdfSTim Lee
5848d80bdfSTim LeeSuite Setup Execution
593fb75582SGeorge Keishing    [Documentation]  Suite Setup Execution.
6048d80bdfSTim Lee
6148d80bdfSTim Lee    ${status}=  Run Keyword And Return Status  Variable Should Exist
6248d80bdfSTim Lee    ...  ${TEST_PROGRAM_CPLD}
6348d80bdfSTim Lee    ${value}=  Set Variable if  ${status} == ${TRUE}  ${TEST_PROGRAM_CPLD}  0
6448d80bdfSTim Lee    Set Global Variable  ${program_cpld}  ${value}
6548d80bdfSTim Lee
6648d80bdfSTim Lee    ${code_base_dir_path}=  Get Code Base Dir Path
6748d80bdfSTim Lee    ${olympus_json}=  Evaluate
6848d80bdfSTim Lee    ...  json.load(open('${code_base_dir_path}data/oem/nuvoton/olympus.json'))  modules=json
6948d80bdfSTim Lee
7048d80bdfSTim Lee    ${cpld_firmware1}=  Set Variable  ${olympus_json["npcm7xx"]["cpld"]["fw1"]}
7148d80bdfSTim Lee    ${cpld_firmware2}=  Set Variable  ${olympus_json["npcm7xx"]["cpld"]["fw2"]}
7248d80bdfSTim Lee    ${firmware_version1}=  Set Variable  ${olympus_json["npcm7xx"]["cpld"]["fw1ver"]}
7348d80bdfSTim Lee    ${firmware_version2}=  Set Variable  ${olympus_json["npcm7xx"]["cpld"]["fw2ver"]}
7448d80bdfSTim Lee    ${readusercode_svf}=  Set Variable  ${olympus_json["npcm7xx"]["cpld"]["readusercode"]}
7548d80bdfSTim Lee    ${readid_svf}=  Set Variable  ${olympus_json["npcm7xx"]["cpld"]["readid"]}
7648d80bdfSTim Lee    ${jtag_dev}=  Set Variable  ${olympus_json["npcm7xx"]["jtag_dev"]}
7748d80bdfSTim Lee    ${power_cycle_cmd}=  Set Variable  ${olympus_json["npcm7xx"]["power_cycle_cmd"]}
7848d80bdfSTim Lee
7948d80bdfSTim Lee    Set Suite Variable  ${cpld_firmware1}
8048d80bdfSTim Lee    Set Suite Variable  ${cpld_firmware2}
8148d80bdfSTim Lee    Set Suite Variable  ${firmware_version1}
8248d80bdfSTim Lee    Set Suite Variable  ${firmware_version2}
8348d80bdfSTim Lee    Set Suite Variable  ${readusercode_svf}
8448d80bdfSTim Lee    Set Suite Variable  ${readid_svf}
8548d80bdfSTim Lee    Set Suite Variable  ${jtag_dev}
8648d80bdfSTim Lee    Set Suite Variable  ${power_cycle_cmd}
8748d80bdfSTim Lee
8848d80bdfSTim Lee    Get File From SFTP Server  ${readid_svf}
8948d80bdfSTim Lee    Run KeyWord If  ${program_cpld} == 1  Get File From SFTP Server  ${readusercode_svf}
9048d80bdfSTim Lee    Run KeyWord If  ${program_cpld} == 1  Get File From SFTP Server  ${cpld_firmware1}
9148d80bdfSTim Lee    Run KeyWord If  ${program_cpld} == 1  Get File From SFTP Server  ${cpld_firmware2}
9248d80bdfSTim Lee
9348d80bdfSTim Lee    scp.Open connection  ${OPENBMC_HOST}  username=${OPENBMC_USERNAME}
9448d80bdfSTim Lee    ...  password=${OPENBMC_PASSWORD}
9548d80bdfSTim Lee    Put File To BMC  ${readid_svf}
9648d80bdfSTim Lee    Run KeyWord If  ${program_cpld} == 1  Put File To BMC  ${readusercode_svf}
9748d80bdfSTim Lee    Run KeyWord If  ${program_cpld} == 1  Put File To BMC  ${cpld_firmware1}
9848d80bdfSTim Lee    Run KeyWord If  ${program_cpld} == 1  Put File To BMC  ${cpld_firmware2}
9948d80bdfSTim Lee    Sleep  5s
10048d80bdfSTim Lee    scp.Close Connection
10148d80bdfSTim Lee
10248d80bdfSTim LeeProgram CPLD
10348d80bdfSTim Lee    [Documentation]  Program CPLD.
10448d80bdfSTim Lee    [Arguments]      ${svf_file}  ${version}
10548d80bdfSTim Lee
10648d80bdfSTim Lee    # Description of argument(s):
10748d80bdfSTim Lee    # svf_file   The firmware file.
10848d80bdfSTim Lee    # version    The firmware version.
10948d80bdfSTim Lee
11048d80bdfSTim Lee    ${cmd}=  Catenate  loadsvf -d ${jtag_dev} -s /var/${svf_file}
11148d80bdfSTim Lee    ${output}  ${stderr}  ${rc}=  BMC Execute Command  ${cmd}
11248d80bdfSTim Lee    Should Not Contain  ${stderr}  tdo check error
11348d80bdfSTim Lee
11448d80bdfSTim Lee    # control hot swap controller to power cycle whole system
11548d80bdfSTim Lee    BMC Execute Command  ${power_cycle_cmd}  ignore_err=1  fork=1
11648d80bdfSTim Lee
11748d80bdfSTim Lee    Sleep  10s
11848d80bdfSTim Lee    Run Keyword  Wait For Host To Ping  ${OPENBMC_HOST}  5 mins
11948d80bdfSTim Lee    ${cmd}=  Catenate  loadsvf -d ${jtag_dev} -s /var/${readusercode_svf}
12048d80bdfSTim Lee    ${output}  ${stderr}  ${rc}=  BMC Execute Command  ${cmd}
12148d80bdfSTim Lee    Should Contain  ${output}  ${version}
122