Exemplo n.º 1
0
def uplink_by_probe(target, probe, linked_bytecode, address, skip_layout,
                    layout_root, tmpdir):
    """
.. _ztc-cmd-uplink-by-probe:

Uplink by probe
===============

It is possible to perform an uplink against a configured device by using a probe. Contrary to other uplink commands that require a bytecode file argument, the :samp:`uplink_by_probe` command requires a linked bytecode file argument (obtained with the :ref:`link <ztc-cmd-link>` command).

The command: ::

    ztc uplink_by_probe target probe linked_bytecode

perform an uplink on the device type :samp:`target` using probe :samp:`probe` to transfer the :samp:`linked_bytecode` file to the running VM.
It is possible to change the address where the bytecode will be flashed by specifying the :option:`--address` option followed by the hexadecimal representation of the address (useful for OTA VMs scenarios)

    """
    dev = get_device_by_target(target, {}, skip_reset=True)
    if not dev.jtag_capable:
        fatal("Target does not support probes!")
    if not skip_layout:
        _uplink_layout(dev, linked_bytecode, dczpath=layout_root)
    tp = start_temporary_probe(target, probe)
    res, out = dev.burn_with_probe(fs.readfile(linked_bytecode, "b"),
                                   offset=address or dev.bytecode_offset)
    stop_temporary_probe(tp)
    if res:
        info("Uplink done")
    else:
        fatal("Uplink failed:", out)
Exemplo n.º 2
0
def retrieve_vm_uid_raw(target, __specs):
    options = {}
    for spec in __specs:
        pc = spec.find(":")
        if pc < 0:
            fatal("invalid spec format. Give key:value")
        options[spec[:pc]] = spec[pc + 1:]
    dev = get_device_by_target(target, options)
    vm_uid, version, target, chipid = _vmuid_dev(dev)
    if target != dev.target:
        fatal("Target mismatch!", target, "vs", dev.target)
    return vm_uid, version, target, chipid, dev
Exemplo n.º 3
0
def own_by_probe(target, probe):
    dev = get_device_by_target(target, {}, skip_reset=True)
    if not dev.jtag_capable:
        fatal("Target does not support probes!")
    tp = start_temporary_probe(target, probe)
    try:
        vm_uid = dev.get_vmuid()
    except Exception as e:
        vm_uid = None
        warning(e)
    stop_temporary_probe(tp)
    if vm_uid:
        chipid, devtype, remote_uid = _own_vm(vm_uid)
        # _reg_owning(dev,remote_uid,chipid)
    else:
        fatal("Can't retrieve vm uid!")
Exemplo n.º 4
0
def _uplink_raw(target, bytecode, loop, __specs, skip_layout, layout_root,
                tmpdir):
    options = {}
    for spec in __specs:
        pc = spec.find(":")
        if pc < 0:
            fatal("invalid spec format. Give key:value")
        options[spec[:pc]] = spec[pc + 1:]
    dev = get_device_by_target(target, options)
    if not skip_layout:
        _uplink_layout(dev, bytecode, dczpath=layout_root)
    if dev.preferred_uplink_with_jtag:
        # uplink code with jtag
        _link_uplink_jtag(dev, bytecode, tmpdir)
    else:
        _uplink_dev(dev, bytecode, loop, tmpdir)
Exemplo n.º 5
0
def mp_start(mppath, clean):
    """
.. _ztc-cmd-massprog:

Massprog command
================

The command: ::

    ztc massprog start path

will start a register-virtualize-uplink process in a single command using information contained in the :samp:`massprog.yml` file present at :samp:`path`.
If the project specified in :samp:`massprog.yml` contains a :samp:`dcz.yml` file, resources will be provisioned and flashed to the device together with the VM and the firmware.

The :command:`massprog` may take the additional :option:`--clean` option that forces a firmware compilation and link.


    """
    mapfile = fs.path(mppath, "massprog.yml")
    map = fs.get_yaml(mapfile)
    config = map["config"]
    target = config["target"]
    register = config["register"]
    project = config["project"]
    vmopts = config["vm"]
    shareable = vmopts.get("shareable", False)
    locked = vmopts.get("locked", False)
    vm_rtos = vmopts["rtos"]
    vm_version = vmopts["version"]
    vm_patch = vmopts["patch"]
    vm_feats = vmopts.get("feats", [])
    dev_options = config.get("dev", {})
    dczmapfile = fs.path(project, "dcz.yml")
    dcz_map = map.get("dcz", {})
    resources = {}

    info("===== Registration")
    dev = get_device_by_target(target, dev_options, skip_reset=True)
    info("Target", target)
    if register == "target_custom":
        chipid = dev.custom_get_chipid(outfn=info)
    elif register == "jtag":
        if not dev.jtag_capable:
            fatal("Target does not support probes!")
        probe = dev_options.get("probe")
        if not probe:
            fatal("Missing probe definition in dev_options section!")
        tp = start_temporary_probe(target, probe)
        chipid = dev.get_chipid()
        stop_temporary_probe(tp)
    elif register == "standard":
        chipid = True
    else:
        fatal("Unknown registration method!")

    if not chipid:
        fatal("Can't find chipid!")

    if register == "standard":
        res, out, _ = proc.run_ztc("device",
                                   "register_raw",
                                   target,
                                   "--spec",
                                   "port:%s" % dev_options["port"],
                                   "--spec",
                                   "baud:%s" % dev_options["baud"],
                                   outfn=log)
    else:
        res, out, _ = proc.run_ztc("device",
                                   "register_by_uid",
                                   chipid,
                                   target,
                                   outfn=log)
    if res:
        fatal("Can't register!")
    lines = out.split("\n")
    for line in lines:
        if "registered with uid:" in line:
            pos = line.rindex(":")
            dev_uid = line[pos + 1:].strip()
            print("[", dev_uid, "]")
            break
    else:
        fatal("Can't find device uid!")

    info("===== Licensing")
    args = []
    for feat in vm_feats:
        args.append("--feat")
        args.append(feat)
    if shareable:
        args.append("--reshare")
        args.append("--share")
    if locked:
        args.append("--locked")
    info("Getting vm for", dev_uid, vm_version, vm_rtos, vm_patch, *args)
    res, out, _ = proc.run_ztc("vm",
                               "create_by_uid",
                               dev_uid,
                               vm_version,
                               vm_rtos,
                               vm_patch,
                               *args,
                               outfn=log)
    if res:
        fatal("Can't create vm!")
    lines = out.split("\n")
    for line in lines:
        if "created with uid:" in line:
            pos = line.rindex(":")
            vm_uid = line[pos + 1:].strip()
            print("[", vm_uid, "]")
            break
    else:
        fatal("Can't find vm uid!")

    info("===== VM")
    # get vm bin
    vmfile = tools.get_vm_by_uid(vm_uid)
    vm = fs.get_json(vmfile)
    vmpath = fs.path(mppath, "vms", vm_uid)
    if not fs.exists(vmpath):
        fs.makedirs(vmpath)
    if isinstance(vm["bin"], str):
        vmbin = bytearray(base64.standard_b64decode(vm["bin"]))
        vmbinfile = fs.path(vmpath, "vm.bin")
        fs.write_file(vmbin, vmbinfile)
        vmloc = vm["loc"]
        resources["VM"] = Resource({
            "type": "file",
            "name": "VM",
            "mapping": vm["loc"],
            "args": vmbinfile
        })
        resources["VM"].load_from_file()
    else:
        vmbin = [base64.standard_b64decode(x) for x in vm["bin"]]
        for i, vv in enumerate(vmbin):
            vmbinfile = fs.path(vmpath, "vm" + str(i) + ".bin")
            fs.write_file(vv, vmbinfile)
            resources["VM-Fragment-" + str(i)] = Resource({
                "type":
                "file",
                "name":
                "VM-Fragment-" + str(i),
                "mapping": [vm["loc"][i]],
                "args":
                vmbinfile
            })
            resources["VM-Fragment-" + str(i)].load_from_file()
    info("     using", vmpath)

    # check for binary fw
    info("===== Firmware")
    fwbin = fs.path(mppath, "fw.bin")
    bytecode = fs.path(mppath, "fw.vbo")
    if clean:
        info("Cleaning...")
        fs.rm_file(fwbin)
        fs.rm_file(bytecode)
        clean = False
    if not fs.exists(fwbin):
        warning("No binary bytecode present, checking vbo for", project)
        if not fs.exists(bytecode):
            warning("No bytecode present either, compiling project at",
                    project)
            res, out, _ = proc.run_ztc("compile",
                                       project,
                                       target,
                                       "-o",
                                       fs.path(mppath, "fw.vbo"),
                                       outfn=log)
            if res:
                fatal("Can't compile project at", project)
        res, out, _ = proc.run_ztc("link",
                                   vm_uid,
                                   bytecode,
                                   "--bin",
                                   "--file",
                                   fs.path(mppath, "fw.bin"),
                                   outfn=log)
        if res:
            fatal("Can't link project at", project)
    info("     using", fwbin)
    resources["Firmware"] = Resource({
        "type": "file",
        "args": fwbin,
        "mapping": vm["bcloc"],
        "name": "Firmware"
    })
    resources["Firmware"].load_from_file()

    info("===== Provisioning Resources")
    layout = get_layout_at(project, fail=True)
    layout.add_resources(resources)
    layout.validate()
    log_table(layout.to_table(),
              headers=["Name", "Address", "Size", "Checksum"])

    info("===== Burn Layout")
    # burn layout
    dev.do_burn_layout(layout, dev_options, outfn=info)