示例#1
0
def main():
    parser = argparse.ArgumentParser(
        description="Build and install ISP kernels with policies")
    parser.add_argument("policy",
                        type=str,
                        help='''
    The name of the policy to compile and install
    ''')
    parser.add_argument("-o",
                        "--output",
                        type=str,
                        default="",
                        help='''
    Directory where the compiled pex kernel is stored
    Default is ISP_PREFIX/kernels or current working directory if ISP_PREFIX is not set
    ''')
    parser.add_argument("-d",
                        "--debug",
                        action="store_true",
                        help='''
    Enable debug logging
    ''')

    args = parser.parse_args()

    isp_prefix = isp_utils.getIspPrefix()
    policies_dir = os.path.join(isp_prefix, "sources", "policies")
    engine_dir = os.path.join(isp_prefix, "sources", "policy-engine")
    policy_out_dir = os.path.join(engine_dir, "policy")
    soc_cfg_path = os.path.join(engine_dir, "soc_cfg")
    entities_dir = os.path.join(policies_dir, "entities")

    base_output_dir = os.getcwd()

    if args.output == "":
        kernels_dir = os.path.join(isp_utils.getIspPrefix(), "kernels")
        if os.path.isdir(kernels_dir):
            base_output_dir = kernels_dir
    else:
        base_output_dir = args.output

    output_dir = os.path.abspath(os.path.join(base_output_dir, args.policy))
    if args.debug is True:
        output_dir = output_dir + "-debug"

    shutil.rmtree(output_dir, ignore_errors=True)
    isp_utils.doMkDir(output_dir)

    copyEngineSources(engine_dir, output_dir)
    copyPolicyYaml(args.policy, policies_dir, entities_dir, output_dir)
    if runPolicyTool(args.policy, policies_dir, entities_dir, output_dir,
                     args.debug) is False:
        print("Failed to run policy tool")
        sys.exit(1)

    if buildPolicyKernel(args.policy, policies_dir, entities_dir,
                         output_dir) is False:
        print("Failed to build policy kernel")
        sys.exit(1)
示例#2
0
def sel4_setup_source(build_dir, template_dir):
    sel4_prefix_source_dir = os.path.join(isp_utils.getIspPrefix(),
                                          "hope-seL4-app-template")
    sel4_local_source_dir = os.path.join(build_dir, "hope-seL4-app-template")

    try:
        shutil.copytree(sel4_prefix_source_dir, sel4_local_source_dir)
    except OSError as e:
        logging.warn("WARNING - seL4 copy failed with message: {}".format(e))
示例#3
0
def doInstall(build_dir, template_dir, runtime, sim, stock):
    if not os.path.isdir(build_dir):
        return retVals.NO_TEST

    if not os.path.isdir(template_dir):
        return retVals.NO_TEMPLATE

    runtime_dir = os.path.join(build_dir, "isp-runtime-{}".format(runtime))

    isp_utils.removeIfExists(runtime_dir)
    isp_utils.doMkDir(runtime_dir)

    shutil.copy(os.path.join(template_dir, "isp_utils.h"),
                os.path.join(runtime_dir, "isp_utils.h"))

    runtime_main_c = os.path.join(template_dir, (runtime + "_main.c"))
    sim_utils_c = os.path.join(template_dir, sim, "isp_utils.c")

    makefile_path = os.path.join(template_dir, sim)
    if stock:
        makefile_path = os.path.join(makefile_path, "stock")

    makefile = os.path.join(makefile_path, (runtime + ".mk"))
    try:
        shutil.copy(runtime_main_c, runtime_dir)
        shutil.copy(sim_utils_c, runtime_dir)
        shutil.copy(
            makefile,
            os.path.join(build_dir, ("isp-runtime-" + runtime + ".mk")))

        if "bare" == runtime:
            shutil.copytree(
                os.path.join(isp_utils.getIspPrefix(), bare_bsp[sim]),
                os.path.join(runtime_dir, "bsp"))

        if "sel4" == runtime:
            sel4_setup_source(build_dir, template_dir)
            sel4_dir = os.path.join(runtime_dir, "sel4")
            if stock:
                sel4_dir = os.path.join(runtime_dir, "stock_sel4")
            isp_utils.doMkDir(sel4_dir)
    except:
        logging.error("Runtime {} is incompatible with sim {}".format(
            runtime, sim))
        return retVals.NO_RUNTIME

    return retVals.SUCCESS
示例#4
0
import isp_utils
import os
import argparse
import logging
import multiprocessing
import pexpect
import subprocess
import sys
import time

sys.path.append(os.path.join(isp_utils.getIspPrefix(), "runtime"))
import isp_load_image
import isp_pex_kernel

logger = logging.getLogger()

isp_prefix = isp_utils.getIspPrefix()

fpga = "gfe-sim"

#################################
# Build/Install PEX kernel
# Invoked by isp_install_policy
#################################


def defaultPexPath(policy_name, arch, extra):
    extra_args = parseExtra(extra)
    return os.path.join(
        isp_prefix, "pex-kernel",
        isp_pex_kernel.pexKernelName(policy_name, fpga, extra_args.processor))
示例#5
0
def main():
    parser = argparse.ArgumentParser(
        description="Run standalone ISP applications")
    parser.add_argument("exe_path",
                        type=str,
                        help='''
    Path of the executable to run
    ''')
    parser.add_argument("-p",
                        "--policy",
                        type=str,
                        default="none",
                        help='''
    Name of the installed policy to run or directory containing policy. Default is none
    ''')
    parser.add_argument("-s",
                        "--simulator",
                        type=str,
                        default="qemu",
                        help='''
    Module for simulating/running application. Must be installed to $ISP_PREFIX/runtime_modules
    ''')
    parser.add_argument("-r",
                        "--runtime",
                        type=str,
                        default="bare",
                        help='''
    Currently supported: frtos, sel4, bare (bare metal) (default), stock_frtos, stock_sel4, stock_bare
    ''')
    parser.add_argument("-o",
                        "--output",
                        type=str,
                        default="",
                        help='''
    Location of simulator output directory. Contains supporting files and
    runtime logs.
    Default is current working directory.
    ''')
    parser.add_argument("-u",
                        "--uart",
                        action="store_true",
                        help='''
    Forward UART output from the simulator to stdout
    ''')
    parser.add_argument("-g",
                        "--gdb",
                        type=int,
                        default=0,
                        help='''
    Start the simulator in gdbserver mode on specified port
    ''')
    parser.add_argument("-d",
                        "--debug",
                        action="store_true",
                        help='''
    Enable debug logging
    ''')
    parser.add_argument("-t",
                        "--tag-only",
                        action="store_true",
                        help='''
    Run the tagging tools without running the application
    ''')
    parser.add_argument("-C",
                        "--rule-cache-name",
                        type=str,
                        default="",
                        help='''
    Name of the rule cache
    ''')
    parser.add_argument("-c",
                        "--rule-cache-size",
                        type=int,
                        default=16,
                        help='''
    Size of the rule cache (if name is provided). Default is 16
    ''')
    parser.add_argument("-e",
                        "--extra",
                        nargs="+",
                        help='''
    Extra command line arguments for the simulator
    ''')
    parser.add_argument("-S",
                        "--suffix",
                        type=str,
                        help='''
    Extra suffix to add to the test directory name
    ''')
    parser.add_argument("--soc",
                        type=str,
                        help='''
    SOC configuration YAML file (default is <policy_dir>/soc_cfg/hifive_e_cfg.yml)
    ''')
    parser.add_argument("-N",
                        "--no_validator",
                        action="store_true",
                        help='''
    Do not use the validator and run the stock version of the simulator (which
    must be located at ISP_PREFIX/stock-tools/bin/qemu-system-riscv32.
    ''')
    parser.add_argument("--disable-colors",
                        action="store_true",
                        help='''
    Disable colored logging
    ''')

    args = parser.parse_args()

    log_level = logging.INFO
    if args.debug is True:
        log_level = logging.DEBUG

    logger = isp_utils.setupLogger(log_level, (not args.disable_colors))

    sys.path.append(
        os.path.join(isp_utils.getIspPrefix(), "runtime", "modules"))

    output_dir = args.output
    if args.output == "":
        output_dir = os.getcwd()

    if args.runtime not in [
            "frtos", "sel4", "bare", "stock_frtos", "stock_sel4", "stock_bare"
    ]:
        logger.error(
            "Invalid choice of runtime. Valid choices: frtos, sel4, bare, stock_frtos, stock_sel4, stock_bare"
        )
        return

    if args.rule_cache_name not in ["", "finite", "infinite", "dmhc"]:
        logger.error(
            "Invalid choice of rule cache name. Valid choices: finite, infinite, dmhc"
        )

    # Policy Directory Building
    # Force policy to none if we're using stock
    if "stock_" in args.simulator or "stock_" in args.runtime:
        logger.info(
            "Using a stock simulator or runtime, setting policy to 'none'")
        policy_name = 'none'
        policy_full_name = 'osv.bare.main.none'
    else:
        policy_name = args.policy

    policy_full_name = isp_utils.getPolicyFullName(policy_name, args.runtime)
    if os.path.isdir(policy_name):
        policy_full_name = os.path.abspath(policy_name)
        policy_name = os.path.basename(policy_full_name)

    kernels_dir = os.path.join(isp_utils.getIspPrefix(), "kernels")
    policy_dir = os.path.join(kernels_dir, policy_full_name)

    exe_name = os.path.basename(args.exe_path)
    exe_full_path = os.path.abspath(args.exe_path)
    run_dir = os.path.join(output_dir,
                           "isp-run-{}-{}".format(exe_name, policy_name))
    if args.rule_cache_name != "":
        run_dir = run_dir + "-{}-{}".format(args.rule_cache_name,
                                            args.rule_cache_size)

    if args.suffix:
        run_dir = run_dir + "-" + args.suffix

    soc_path = os.path.join(policy_dir, "soc_cfg", "hifive_e_cfg.yml")
    if args.soc is not None:
        soc_path = os.path.abspath(args.soc)

    use_validator = True
    if args.no_validator == True:
        use_validator = False

    run_dir_full_path = os.path.abspath(run_dir)
    isp_utils.removeIfExists(run_dir_full_path)

    logger.debug("Starting simulator...")
    result = isp_run.runSim(exe_full_path, policy_dir, run_dir_full_path,
                            args.simulator, args.runtime,
                            (args.rule_cache_name, args.rule_cache_size),
                            args.gdb, args.tag_only, soc_path, use_validator,
                            args.extra)

    if result != isp_run.retVals.SUCCESS:
        logger.error(result)
        sys.exit(-1)

    if args.tag_only is True:
        return

    if args.uart is True:
        printUartOutput(run_dir)

    process_exit_code = getProcessExitCode(run_dir, args.runtime)
    logger.debug("Process exited with code {}".format(process_exit_code))

    if result is not isp_run.retVals.SUCCESS:
        logger.error("Failed to run application: {}".format(result))
示例#6
0
def getTemplatesDir():
    isp_prefix = isp_utils.getIspPrefix()
    return os.path.join(isp_prefix, "sources", "tools", "runtime", "templates")
示例#7
0
def doInstall(build_dir, template_dir, runtime):
    if not os.path.isdir(build_dir):
        return retVals.NO_TEST

    if not os.path.isdir(template_dir):
        return retVals.NO_TEMPLATE

    runtime_dir = os.path.join(build_dir, "isp-runtime-{}".format(runtime))

    isp_utils.removeIfExists(runtime_dir)
    isp_utils.doMkDir(runtime_dir)

    shutil.copy(os.path.join(template_dir, "isp_utils.h"),
                os.path.join(runtime_dir, "isp_utils.h"))
    shutil.copy(os.path.join(template_dir, "mem.h"),
                os.path.join(runtime_dir, "mem.h"))

    if "frtos" == runtime:
        frtos_dir = os.path.join(runtime_dir, "frtos")
        isp_utils.doMkDir(frtos_dir)
        shutil.copy(os.path.join(template_dir, "frtos.mk"),
                    os.path.join(build_dir, "isp-runtime-frtos.mk"))

    elif "sel4" == runtime:
        sel4_setup_source(build_dir, template_dir)

        sel4_dir = os.path.join(runtime_dir, "sel4")
        isp_utils.doMkDir(sel4_dir)

        shutil.copy(os.path.join(template_dir, "sel4.mk"),
                    os.path.join(build_dir, "isp-runtime-sel4.mk"))

    elif "bare" == runtime:
        shutil.copy(os.path.join(template_dir, "bare.c"),
                    os.path.join(runtime_dir, "bare.c"))
        shutil.copy(os.path.join(template_dir, "bare.mk"),
                    os.path.join(build_dir, "isp-runtime-bare.mk"))
        shutil.copytree(os.path.join(isp_utils.getIspPrefix(), "hifive_bsp"),
                        os.path.join(runtime_dir, "bsp"))

    elif "stock_frtos" == runtime:
        frtos_dir = os.path.join(runtime_dir, "stock_frtos")
        isp_utils.doMkDir(frtos_dir)
        shutil.copy(os.path.join(template_dir, "stock_frtos.mk"),
                    os.path.join(build_dir, "isp-runtime-stock_frtos.mk"))

    elif "stock_sel4" == runtime:
        sel4_setup_source(build_dir, template_dir)

        sel4_dir = os.path.join(runtime_dir, "stock_sel4")
        isp_utils.doMkDir(sel4_dir)
        shutil.copy(os.path.join(template_dir, "stock_sel4.mk"),
                    os.path.join(build_dir, "isp-runtime-stock_sel4.mk"))

    elif "stock_bare" == runtime:
        shutil.copy(os.path.join(template_dir, "bare.c"),
                    os.path.join(runtime_dir, "bare.c"))
        shutil.copy(os.path.join(template_dir, "stock_bare.mk"),
                    os.path.join(build_dir, "isp-runtime-stock_bare.mk"))
        shutil.copytree(os.path.join(isp_utils.getIspPrefix(), "hifive_bsp"),
                        os.path.join(runtime_dir, "bsp"))

    else:
        return retVals.NO_RUNTIME

    return retVals.SUCCESS
示例#8
0
import shutil
import logging
import os
import isp_utils
import multiprocessing
import subprocess 

logger = logging.getLogger()
isp_prefix = isp_utils.getIspPrefix()

def copyPexKernelSources(source_dir, output_dir):
    logger.info("Copying pex-kernel sources")
    pex_kernel_output_dir = os.path.join(output_dir, "pex-kernel")

    try:
        shutil.copytree(source_dir, pex_kernel_output_dir)
    except Exception as e:
        logger.error("Copying pex-kernel sources failed with error: {}".format(str(e)))
        return False

    subprocess.call(["make", "clean"], stdout=subprocess.DEVNULL, stderr=subprocess.STDOUT,
                    cwd=pex_kernel_output_dir)

    return True


def copyPolicySources(policy_dir, output_dir, fpga, processor):
    logger.debug("Copying policy source to pex kernel")
    policy_name = os.path.basename(policy_dir)
    pex_kernel_output_dir = os.path.join(output_dir, "pex-kernel")
    build_dir_name = "-".join([fpga, processor, policy_name])
示例#9
0
def getGdbScriptPath(sim):
    isp_prefix = isp_utils.getIspPrefix()
    return os.path.join(isp_prefix, "gdb-scripts", "{}.gdb".format(sim))