Library to get FIR address translation through HOST OS.

Resolves openbmc/openbmc-test-automation#1033

Change-Id: I33501fc9ba4a12b289096820f14874a50566c38c
Signed-off-by: Sridevi Ramesh <sridevra@in.ibm.com>
diff --git a/lib/ras/host_utils.robot b/lib/ras/host_utils.robot
index 1d332ee..ddfec43 100644
--- a/lib/ras/host_utils.robot
+++ b/lib/ras/host_utils.robot
@@ -2,6 +2,8 @@
 Documentation       This module is for OS checkstop opertions.
 Resource            ../../lib/rest_client.robot
 Resource            ../../lib/utils.robot
+Resource            ../../lib/ras/variables.py
+Resource            ../../lib/bmc_ssh_utils.py
 Library             OperatingSystem
 
 *** Keywords ***
@@ -14,8 +16,7 @@
     # input_cmd      -l|--list-chips
     #                -c|--chip <chip-id> <addr>
 
-    ${output}  ${stderr}=  Execute Command  getscom ${input_cmd}
-    ...        return_stderr=True
+    ${output}  ${stderr}  ${rc}=  OS Execute Command  getscom ${input_cmd}
     Should Be Empty  ${stderr}
     [Return]  ${output}
 
@@ -26,36 +27,64 @@
     # Description of arguments:
     # input_cmd      list/clear all/show <gard_record_id>
 
-    ${output}  ${stderr}=  Execute Command  opal-gard ${input_cmd}
-    ...        return_stderr=True
+    ${output}  ${stderr}  ${rc}=  OS Execute Command  opal-gard ${input_cmd}
     Should Be Empty  ${stderr}
     [Return]  ${output}
 
-Putscom Through OS
+Putscom Operations On OS
     [Documentation]  Executes putscom command on OS with the given
     ...              input arguments.
-    [Arguments]      ${chip_id}  ${fru}  ${address}
+    [Arguments]      ${proc_chip_id}  ${fru}  ${address}
     # Description of arguments:
-    # chip_id        processor ID (e.g 00000000).
+    # proc_chip_id        Processor ID (e.g '0', '8').
     # fru            FRU value (e.g. 2011400).
-    # address        chip address (e.g 4000000000000000).
+    # address        Chip address (e.g 4000000000000000).
 
-    ${cmd}=  Catenate  putscom -c 0x${chip_id} 0x${fru} 0x${address}
+    ${cmd}=  Catenate  putscom -c 0x${proc_chip_id} 0x${fru} 0x${address}
     Start Command  ${cmd}
 
-Get Cores Values From OS
-    [Documentation]  Check if cores present on HOST OS & return core values.
-    ${cmd}=  Catenate  cat /sys/firmware/opal/msglog|grep -i chip|grep -i core
-    ${output}=  Execute Command  ${cmd}
-    Should Not Be Empty  ${output}
-    [Return]  ${output}
-
-Get ChipID From OS
-    [Documentation]  Get chip ID values based on the input.
+Get ProcChipId From OS
+    [Documentation]  Get processor chip ID values based on the input.
     [Arguments]      ${chip_type}
     # Description of arguments:
     # chip_type      The chip type (Processor/Centaur).
 
     ${cmd}=  Catenate  -l | grep -i ${chip_type} | cut -c1-8
-    ${chip_id}=  Getscom Operations On OS  ${cmd}
-    [Return]  ${chip_id}
+    ${proc_chip_id}=  Getscom Operations On OS  ${cmd}
+    # Example output:
+    # 00000008
+    # 00000000
+    [Return]  ${proc_chip_id}
+
+Get Core IDs From OS
+    [Documentation]  Get Core IDs corresponding to the input processor chip ID.
+    [Arguments]      ${proc_chip_id}
+    # Description of argument(s):
+    # proc_chip_id        Processor ID (e.g '0', '8').
+
+    ${cmd}=  Catenate  set -o pipefail ; ${probe_cpu_file_path}
+    ...    | grep -i 'CHIP ID: ${proc_chip_id}' | cut -c21-22
+    ${output}  ${stderr}  ${rc}=  OS Execute Command  ${cmd}
+    Should Be Empty  ${stderr}
+    ${core_ids}=  Split String  ${output}
+    # Example output:
+    # ['2', '3', '4', '5', '6']
+    [Return]  ${core_ids}
+
+FIR Address Translation Through HOST
+    [Documentation]  Do FIR address translation through host for given FIR,
+    ...              core value & target type.
+    [Arguments]  ${fir}  ${core_id}  ${target_type}
+    # Description of argument(s):
+    # fir          FIR (Fault isolation register) value (e.g. 2011400).
+    # core_id      Core ID (e.g. 9).
+    # target_type  Target type (e.g. 'EQ', 'EX', 'C').
+
+    ${cmd}=  Catenate  set -o pipefail ; ${addr_translation_file_path} ${fir}
+    ...  ${core_id} | grep -i ${target_type}
+    ${output}  ${stderr}  ${rc}=  OS Execute Command  ${cmd}
+    Should Be Empty  ${stderr}
+    ${translated_addr}=  Split String  ${output}  :${SPACE}0x
+    # Example output:
+    # 0x10010c00
+    [Return]  ${translated_addr[1]}