#!/usr/bin/python ''' ########################################################### # @file sbeCmvcUtility.py # @author: George Keishing # @brief Utilility Module to Patching files for SBE simics # # Created on March 23, 2016 # ---------------------------------------------------- # @version Developer Date Description # ---------------------------------------------------- # 1.0 gkeishin 23/03/16 Initial create ########################################################### ''' #------------------------- # Imports #------------------------- import os, sys import time import os.path import subprocess import shutil import hashlib from subprocess import Popen, PIPE from os.path import expanduser # for getting $HOME PATH import stat # for File permission op # Libraries/utility funcs and user define const import sbeCmvcConstants as errorcode import sbeCmvcUtility as utilcode ########################################################################## # Function : utilPatchSimics # # @param i_sandbox_path : Sandbox full path # # @param i_sandbox_root : Sandbox RC root path # # @brief Patch pre-req patches for simics # ########################################################################## def utilPatchSimics(i_sandbox_path, i_sandbox_root): print "\n ... Patching simics files " sb_name=os.path.basename(i_sandbox_path) # Write the hooks for sim setup l_sim_file = utilShell_hooks(i_sandbox_path) if not l_sim_file: return errorcode.ERROR_HOOKING_FILE l_sim_cmd = "workon -m ppc " + sb_name + " -c " + l_sim_file + " -rc " + i_sandbox_root +"/sbesandboxrc" print " ", l_sim_cmd os.system(l_sim_cmd) # Copy action files. As we are taking actions files from ppe, copy them here # so that any workaround necessary can be applied over them in pre-simsetup path # mkdir -p $SANDBOXBASE/src/simu/data/cec-chip # cp $SBEROOT/import/chips/p9/sw_simulation/* $SANDBOXBASE/src/simu/data/cec-chip || exit -1 print " [ Copying action files to fips Sandbox ]" # Ge the Sandbox base sandbox_base = utilcode.utilFind_ENV_string("SANDBOXBASE").rstrip('\n') sandbox_path = sandbox_base + "/src/simu/data/cec-chip" cmd = "mkdir -p " + sandbox_path print " * Executing : ",cmd os.system(cmd) # Ge the ppe root ppe_base = utilcode.utilFind_ENV_string("SBEROOT").rstrip('\n') ppe_path = ppe_base + "/import/chips/p9/sw_simulation/" p_cmd = "cp -f " + ppe_path + "* " + sandbox_path print " * Executing : ",p_cmd rc = os.system(p_cmd) if rc: print " ERROR rc :",rc return rc return errorcode.SUCCESS_EXIT ########################################################################## # Function : utilExecuteShell # # @param i_ppe_root : Root folder for PPE. This script must be # from PPE repo. # # @param i_sandbox_path : fips Sandbox path # # @param i_shell_file : User defined shell script name # # @brief Apply the simics patches pre define in shell script. # ########################################################################## def utilExecuteShell(i_ppe_root, i_sandbox_path, i_shell_file): print "\n ... Executing shell : ",i_shell_file # Sanbox name if i_sandbox_path != "None": sb_name=os.path.basename(i_sandbox_path) # Find the file and execute l_path_name = i_ppe_root + '/sbe/build/' l_shell_path=utilcode.utilFindFile(i_shell_file, l_path_name) print " [ %s ]"%l_shell_path if i_sandbox_path != "None": # Load the shell onto the Sandbox env and execute l_shell_exec = "workon -m ppc " + sb_name + " -c " + l_shell_path + " -rc " + i_sandbox_path.replace(sb_name,"") +"/sbesandboxrc" else: # Execute a stand alone script l_shell_exec = l_shell_path #rc = subprocess.call([l_shell_exec]) rc = os.system(l_shell_exec) if rc : return rc return errorcode.SUCCESS_EXIT ########################################################################## # Function : utilShell_hooks # # @param i_sandbox_path : Sandbox full path # # @brief find the ENV string set in the env # ########################################################################## def utilShell_hooks(i_sandbox_path): # Find the simics machine from ENV l_machine = os.environ['MACHINE'].rstrip('\n') print " Machine : ",l_machine l_cmd_exec = 'start_simics -no_start -machine ' + l_machine + ' -batch_mode ' # Write the compile shell hook on the fips sandbox location hook_file=i_sandbox_path + '/src/simsb' f = open(hook_file,'w') # simsb: This hook schell script will look like this # # #!/bin/sh # start_simics -no_start -machine NIMBUS -batch_mode f.write('#!/bin/sh \n') f.write('\n') f.write(l_cmd_exec) f.close() # Change the file permission for execute perm_st = os.stat(hook_file) os.chmod(hook_file, perm_st.st_mode | stat.S_IEXEC) return hook_file # path of the shell file