Esempio n. 1
0
def generate_pdi(config) -> None:

    if has_key(config, "console"):
        console = config["console"]
    else:
        console = Xexpect(log)
        config["console"] = console

    remove(os.path.join(config["imagesDir"], config["pdiFile"]))
    if is_file(config["bifFile"]):
        copy_file(config["bifFile"], config["imagesDir"])

    console.runcmd(f"cd {config['imagesDir']}")
    bootgen_cmd = [
        config["bootgenCmd"],
        "-arch",
        config["platform"].lower(),
        config["bootgenExtraArgs"],
        "-log",
        "info",
        "-image",
        config["bifFile"],
        "-o",
        config["pdiFile"],
    ]
    cmd = " ".join(bootgen_cmd)
    console.runcmd(cmd, expected="Bootimage generated successfully")

    if is_file(os.path.join(config["imagesDir"], config["pdiFile"])):
        log.info("PDI generated successfully")
    else:
        err_msg = f"{config['pdiFile']} creation failed"
        log.error(err_msg)
        raise Exception(err_msg)
Esempio n. 2
0
def copy_linux_test_images(config, test):
    linux_images = f"{config['buildDir']}/{config['machine']}/{test}/linux/images/"
    src_file = f"{linux_images}/deploy_artifacts.tar.xz"
    if not is_file(src_file):
        log.error(f"ERROR: No Such File {src_file}")
        raise Exception("Build test Failed")
    copyDirectory(linux_images, config["imagesDir"])
    check_cardano(config)
Esempio n. 3
0
def run_std_app(board, procname, load_boot_pdi=False):
    load_pdi(board, pdi_file=board.config["aie_pdi"])
    if load_boot_pdi:
        load_pdi(board, expected_msg="SBI PDI Load: Done")
    board.xsdb.set_proc(procname)
    board.xsdb.rst_proc()
    time.sleep(5)
    aie_elf = f"{board.config['imagesDir']}/aie_control.elf"
    if not is_file(aie_elf):
        print(f"ERROR: No Such File {aie_elf}", file=sys.stderr)
        raise Exception("Build test Failed")
    board.xsdb.load_elf(f"{board.config['imagesDir']}/aie_control.elf")
    board.xsdb.runcmd("con")
Esempio n. 4
0
def petalinux_aie_boot(config, board_session, boottype):
    config["plnx_proj"] = config["PLNX_BSP"]
    config["load_interface"] = "tcl"
    config["boottype"] = boottype
    plnx_bsp_path = get_original_path(f"{config.BSP_PATH}/{config.PLNX_BSP}")

    # check for PLNX BSP before acquiring board
    if not is_file(plnx_bsp_path):
        print(f"Petalinux BSP {plnx_bsp_path} Not found", file=sys.stderr)
        raise Exception("Petalinux BSP Not found")

    if config.get("load_interface") == "tcl":
        for artifact in config.get("plnx_artifacts", []):
            if not is_file(f"{config.get('deploy_dir')}/{artifact}"):
                log.error(
                    f"{artifact} not found in {config.get('deploy_dir')}")
                raise Exception("Petalinux Build test Failed")
    if boottype == "kernel":
        config[
            "plnx_proj_path"] = f"{config['buildDir']}/{config['machine']}/petalinux/default_build/work/{config['PLNX_BSP']}"

    board_session.invoke_xsdb = False
    board = linuxcons(config, board_session)
    return board
Esempio n. 5
0
def copy_init_files(board):
    # Copy init files after boot.
    if board.first_boot:
        for dst_path, src_files in (board.config["board_init_files"]).items():
            for src_file in src_files:
                board.config["tmp_value"] = src_file
                # Check if file is present on host machine
                if not is_file(board.config["tmp_value"]):
                    print(f"ERROR: No Such File: {board.config['tmp_value']}")
                    raise OSError
                board.put(board.config["tmp_value"], dst_path)
                # Check if file is tar, then extract it with -C dst_path
                f_name = get_base_name(board.config["tmp_value"])
                if re.search(r"\.tar", f_name):
                    board.serial.runcmd(f"cd {dst_path}")
                    board.serial.runcmd(f"tar xvf {f_name}")
        board.serial.runcmd("cd")
        board.first_boot = False
Esempio n. 6
0
def gen_boot_bin(config) -> None:

    console = Xexpect(log)
    remove(os.path.join(config["imagesDir"], config["binFile"]))
    if config["bifFile"]:
        copy_file(config["bifFile"], config["imagesDir"])

    console.runcmd(f"cd {config['imagesDir']}")

    bootgen_cmd = [
        config["bootgenCmd"],
        "-arch",
        config["platform"].lower(),
        config["bootgenExtraArgs"],
        "-log",
        "info",
        "-image",
        config["bifFile"],
        "-o",
        config["binFile"],
    ]
    cmd = " ".join(bootgen_cmd)

    if "BOOTGEN_ENV" in config:
        for env in config["BOOTGEN_ENV"]:
            console.runcmd(f"export {env}")

    console.runcmd(cmd,
                   expected="Bootimage generated successfully",
                   wait_for_prompt=False)

    if is_file(os.path.join(config["imagesDir"], config["binFile"])):
        log.info("Bootable Image generate successful")
    else:
        err_msg = f"{config['binFile']} creation failed"
        log.error(err_msg)
        raise Exception(err_msg)
Esempio n. 7
0
def run_linux_app(board):
    test = board.config["test"]
    src_file = f"{board.config['imagesDir']}/deploy_artifacts.tar.xz"
    if not is_file(src_file):
        print(f"ERROR: No Such File {src_file}", file=sys.stderr)
        raise Exception("Build test Failed")
    board.put(src_file, "~/")
    # board.serial.terminal.interact()

    board.serial.runcmd(f"mkdir -p ~/{test}")
    cmd_list = [f"tar xvf deploy_artifacts.tar.xz -C {test}/", f"cd {test}"]
    board.serial.runcmd_list(cmd_list)
    # Load pdi through fpga manager if present
    if board.config["cardano_app"]:
        # Reset AIE Array
        board.serial.runcmd("../reset-aie.run",
                            expected="Resetting AIE Array Done.")

        board.serial.runcmd("echo 1 >  /sys/class/fpga_manager/fpga0/flags")
        board.serial.runcmd("cp boot.pdi /lib/firmware/")
        board.serial.runcmd(
            "echo boot.pdi > /sys/class/fpga_manager/fpga0/firmware",
            expected=["Subsystem PDI Load: Done"],
        )

    wait_for_prompt = False if test == "clock_gating" else True
    try:
        board.serial.runcmd(
            "./aie_control.run",
            wait_for_prompt=wait_for_prompt,
            expected=["SUCCESS", "Killed", "Kernel panic"],
            expected_failures=["FAILED", "Segmentation fault", "Aborted"],
        )
    except Exception as err:
        # Reset console to normal state for consecutive tests
        is_linux(board)
        assert False, err
Esempio n. 8
0
def generate_bif(config, format_type: str) -> None:
    bif_path = os.path.join(config["workDir"], config["bifFile"])
    with open(bif_path, "w") as biffile:
        if format_type == "new":
            defdata = {
                "plm": ["type = bootloader", "path"],
                "pmccdo": ["type = pmcdata,load=0xF2000000", "path"],
                "cdo": ["type = cdo", "path"],
                "sys_dtb": ["load=0x1000", "path"],
                "linux_image": ["load=0x2000000", "path"],
                "uboot": ["", "path"],
                "puf": ["puf_file", "path"],
                "aie-elf": ["core = aie", "path"],
                "psm": ["core = psm", "psmElf"],
                "a72": ["core = a72-0", "path"],
                "r5": ["core = r5-0", "path"],
                "a72_1": ["core = a72-1", "path"],
                "r5_1": ["core = r5-1", "path"],
                "r5_lock": ["core = r5-lockstep", "path"],
            }
            subsys_data = {
                "pmc_subsys": "0x1c000001",
                "lpd_subsys": "0x4210002",
                "pl_cfi_subsys": "0x18700000",
                "aie_subsys": "0x421c005",
                "fpd_subsys": "0x420c003",
                "subsystem": "0x1c000000",
            }
            biffile.write("new_bif:\n{\n")
            id_code = "0x04ca8093"
            extended_id_code = "0x01"
            if has_key(config, "id_code"):
                id_code = config["id_code"]
            if has_key(config, "extended_id_code"):
                extended_id_code = config["extended_id_code"]
            if has_key(config, "bootheader"):
                biffile.write(config["bootheader"].format())
            biffile.write(
                f" id_code = {id_code}\n extended_id_code = {extended_id_code} \n id = 0x1\n"
            )
            id = 2
            headers, l_components = zip(*config.bif)
            for header, components in zip(headers, l_components):
                # config library returns list so cast back to namedtuple
                header = Header(*header)
                components = [
                    Component(*component) for component in components
                ]
                if header.header == "image":
                    subsystem_id = subsys_data[header.name]
                    biffile.write(
                        f" {header.header}\n {{\n  name = {header.name}\n  id = {subsystem_id}\n"
                    )
                    if header.args:
                        biffile.write(f"  {header.args}\n")
                    for component in components:
                        extra_args = bifstring("",
                                               "".join(component.params[:-1]),
                                               config)
                        image_path = bifstring("", component.params[-1],
                                               config)
                        str_component = create_partition(
                            id, defdata[component.name][0], extra_args,
                            image_path)
                        biffile.write(str_component)
                elif header.header == "metaheader":
                    for component in components:
                        extra_args = bifstring("",
                                               "".join(component.params[:-1]),
                                               config)
                        str_component = (f"\n  metaheader \n"
                                         f"  {{\n"
                                         f"    {extra_args}\n"
                                         f"  }}\n")
                        biffile.write(str_component)
                biffile.write(" }\n")
                id = id + 1
            biffile.write("}\n")
        elif format_type == "old":
            defdata = {
                "plm": ["bootloader", "path"],
                "pmccdo": ["pmcdata,load=0xF2000000", "path"],
                "cdo": ["partition_type=cdo", "path"],
                "aie-elf": ["destination_cpu=aie", "path"],
                "psm": ["destination_cpu=psm", "psmElf"],
                "a72": ["destination_cpu=a72-0", "path"],
                "r5": ["destination_cpu=r5-0", "path"],
            }
            if config["boot_header"]:
                biffile.write(f"{config['boot_header']}" ":\n{\n")
            else:
                biffile.write("all:\n{\n")
            for image in config["bif"]:
                comp = image[0]
                value = image[1]
                bifstr = "[{}] ".format(defdata[comp][0])
                bifstr = bifstring(bifstr, value, config)
                bifstr = "\t{}\n".format(bifstr)
                biffile.write(bifstr)
            biffile.write("}\n")

    if is_file(bif_path):
        copy_file(
            bif_path,
            os.path.join(config["imagesDir"], config["bifFile"]),
        )
        log.info("Bif Generated successfully")
    else:
        err_msg = "Bif generation failed"
        log.error(err_msg)
        raise Exception(err_msg)
Esempio n. 9
0
def generate_bif(config, format_type: str) -> None:

    if format_type == "new":
        b = BifProvider(seed=config.get("seed"), randomize=config["randomize"])
        # reconstruct bif data structure
        bif = tuple()
        headers, l_components = zip(*config.bif)
        for header, components in zip(headers, l_components):
            # config library returns list so cast back to namedtuple
            header = Header(*header)
            components = [Component(*component) for component in components]
            bif = bif + (Block(header, components), )
        # randomize
        bif = b.shuffle_sections(bif, config.get("block_constraints", {}))

    bif_path = os.path.join(config["workDir"], config["bifFile"])
    with open(bif_path, "w") as biffile:
        if format_type == "new":
            defdata = {
                "plm": ["type = bootloader", "path"],
                "bootimg": ["type = bootimage", "path"],
                "pmccdo": ["type = pmcdata,load=0xF2000000", "path"],
                "cdo": ["type = cdo", "path"],
                "sys_dtb": ["load=0x1000", "path"],
                "linux_image": ["load=0x2000000", "path"],
                "uboot": ["", "path"],
                "puf": ["puf_file", "path"],
                "aie-elf": ["core = aie", "path"],
                "psm": ["core = psm", "psmElf"],
                "a72": ["core = a72-0", "path"],
                "r5": ["core = r5-0", "path"],
                "a72_1": ["core = a72-1", "path"],
                "r5_1": ["core = r5-1", "path"],
                "r5_lock": ["core = r5-lockstep", "path"],
                "sys_dtb_osl": ["offset=0x300000", "load=0x1000", "path"],
                "linux_image_osl": ["offset=0x380000", "load=0x80000", "path"],
                "rootfs_osl": ["offset=0x2080000", "load=0x30000000", "path"],
            }
            subsys_data = {
                "pmc_subsys": "0x1c000001",
                "lpd_subsys": "0x4210002",
                "pl_cfi_subsys": "0x18700000",
                "aie_subsys": "0x421c005",
                "fpd_subsys": "0x420c003",
                "subsystem": "0x1c000000",
                "apu_subsys": "0x1c000003",
                "rpulock_subsys": "0x1c000004",
                "rpu0_subsys": "0x1c000005",
                "rpu1_subsys": "0x1c000006",
            }
            biffile.write("new_bif:\n{\n")
            id_code = "0x04ca8093"
            extended_id_code = "0x01"
            if "id_code" in config:
                id_code = config["id_code"]
            if "extended_id_code" in config:
                extended_id_code = config["extended_id_code"]
            if "bootheader" in config:
                if "{{" in config["bootheader"]:
                    biffile.write(config["bootheader"].format())
                else:
                    biffile.write(config["bootheader"])
            biffile.write(
                f" id_code = {id_code}\n extended_id_code = {extended_id_code} \n id = 0x1\n"
            )
            id = 1
            # write partitions
            for block in bif:
                header = block.header
                components = block.components
                if header.header == "image":
                    subsystem_id = subsys_data[header.name]
                    biffile.write(
                        f" {header.header}\n {{\n  name = {header.name}\n  id = {subsystem_id}\n"
                    )
                    if header.args:
                        biffile.write(f"  {header.args}\n")
                    for component in components:
                        id = id + 1
                        extra_args = bifstring("",
                                               "".join(component.params[:-1]),
                                               config)
                        image_path = bifstring("", component.params[-1],
                                               config)
                        str_component = create_partition(
                            id, defdata[component.name][0], extra_args,
                            image_path)
                        biffile.write(str_component)
                elif header.header == "metaheader":
                    for component in components:
                        extra_args = bifstring("",
                                               "".join(component.params[:-1]),
                                               config)
                        str_component = (f"\n  metaheader \n"
                                         f"  {{\n"
                                         f"    {extra_args}\n")
                        biffile.write(str_component)
                biffile.write(" }\n")
            biffile.write("}\n")
        elif format_type == "old":
            defdata = {
                "plm": ["bootloader", "path"],
                "pmccdo": ["pmcdata,load=0xF2000000", "path"],
                "cdo": ["partition_type=cdo", "path"],
                "aie-elf": ["destination_cpu=aie", "path"],
                "psm": ["destination_cpu=psm", "psmElf"],
                "a72": ["destination_cpu=a72-0", "path"],
                "a72_1": ["destination_cpu=a72-1", "path"],
                "r5": ["destination_cpu=r5-0", "path"],
                "r5_1": ["destination_cpu=r5-1", "path"],
                "r5_lock": ["destination_cpu=r5-lockstep", "path"],
                "a53": ["destination_cpu=a53-0", "path"],
                "a53_1": ["destination_cpu=a53-1", "path"],
                "a53_2": ["destination_cpu=a53-2", "path"],
                "a53_3": ["destination_cpu=a53-3", "path"],
                "fsbl_a53": ["bootloader", "destination_cpu=a53-0", "path"],
                "fsbl_r5": ["bootloader", "destination_cpu=r5-0", "path"],
                "fsbl_a9": ["bootloader", "path"],
                "pmu": ["destination_cpu=pmu", "path"],
                "atf": [
                    "destination_cpu=a53-0",
                    "exception_level=el-3",
                    "trustzone",
                    "path",
                ],
                "dtb_uboot":
                ["destination_cpu=a53-0", "load=0x100000", "path"],
                "uboot":
                ["destination_cpu=a53-0", "exception_level=el-2", "path"],
                "zynq_uboot": ["", "path"],
                "dtb_linux": [
                    "destination_device=ps",
                    "offset=0x200000",
                    "partition_owner=uboot",
                    "path",
                ],
                "linux_image": [
                    "destination_device=ps",
                    "offset=0x280000",
                    "partition_owner=uboot",
                    "path",
                ],
                "bitstream": ["destination_device=pl", "path"],
                "pmufw_image": ["pmufw_image", "path"],
            }
            if config["boot_header"]:
                biffile.write(f"{config['boot_header']}" ":\n{\n")
            else:
                biffile.write("all:\n{\n")
            for image in config["bif"]:
                comp = image[0]
                value = image[1]
                if defdata[comp][0] == "":
                    bifstr = ""
                else:
                    bifstr = "[{}] ".format(defdata[comp][0])
                bifstr = bifstring(bifstr, value, config)
                bifstr = "\t{}\n".format(bifstr)
                biffile.write(bifstr)
            biffile.write("}\n")

    if is_file(bif_path):
        copy_file(
            bif_path,
            os.path.join(config["imagesDir"], config["bifFile"]),
        )
        log.info("Bif Generated successfully")
    else:
        err_msg = "Bif generation failed"
        log.error(err_msg)
        raise Exception(err_msg)