示例#1
0
    def flash(self, target, images):
        assert len(images) == 1, \
            "only one image suported, got %d: %s" \
            % (len(images), " ".join("%s:%s" % (k, v)
                                     for k, v in images.items()))
        image_name = images.values()[0]

        if self.serial_port == None:
            serial_port = "/dev/tty-%s" % target.id
        else:
            serial_port = self.serial_port
        if self.console == None:
            console = "serial0"
        else:
            console = self.console

        target.power.put_cycle(target, ttbl.who_daemon(), {}, None)
        # give up the serial port, we need it to flash
        # we don't care it is off because then we are switching off
        # the whole thing and then someone else will power it on
        target.console.put_disable(target, ttbl.who_daemon(),
                                   dict(component=console), None)
        # erase the flash by opening the serial port at 1200bps
        target.log.debug("erasing the flash")
        with serial.Serial(port=serial_port, baudrate=1200):
            time.sleep(0.25)
        target.log.info("erased the flash")

        # now write it
        cmdline = [
            self.path,
            "-p",
            os.path.basename(serial_port),
            "-e",  # Erase current
            "-w",  # Write a new one
            "-v",  # Verify,
            "-b",  # Boot from Flash
            image_name
        ]
        target.log.info("flashing image with: %s" % " ".join(cmdline))
        try:
            subprocess.check_output(cmdline,
                                    stdin=None,
                                    cwd="/tmp",
                                    stderr=subprocess.STDOUT)
            target.log.info("ran %s" % (" ".join(cmdline)))
        except subprocess.CalledProcessError as e:
            target.log.error("flashing with %s failed: (%d) %s" %
                             (" ".join(cmdline), e.returncode, e.output))
            raise
        target.power.put_off(target, ttbl.who_daemon(), {}, None)
        target.log.info("flashed image")
示例#2
0
    def flash(self, target, images):
        cmdline = [self.path, "-S", self.usb_serial_number]
        # for each image we are writing to a different interface, we
        # add a -a IFNAME -D IMGNAME to the commandline, so we can
        # flash multiple images in a single shot
        for image_type, image_name in images.iteritems():
            # FIXME: we shall make sure all images are like this?
            if not image_type.startswith("kernel-"):
                raise RuntimeError(
                    "Unknown image type '%s' (valid: kernel-{%s})" %
                    (image_type, ",".join(target.tags['bsps'].keys())))
            bsp = image_type.replace("kernel-", "")
            tags_bsp = target.tags.get('bsps', {}).get(bsp, None)
            if tags_bsp == None:
                raise RuntimeError(
                    "Unknown BSP %s from image type '%s' (valid: %s)" %
                    (bsp, image_type, " ".join(target.tags['bsps'].keys())))
            dfu_if_name = tags_bsp.get('dfu_interface_name', None)
            if dfu_if_name == None:
                raise RuntimeError(
                    "Misconfigured target: image type %s (BSP %s) has "
                    "no 'dfu_interface_name' key to indicate which DFU "
                    "interface shall it flash" % (image_type, bsp))
            cmdline += ["-a", dfu_if_name, "-D", image_name]

        # Power cycle the board so it goes into DFU mode; it then
        # stays there for five seconds (FIXME: all of them?)
        target.power.put_cycle(target, ttbl.who_daemon(), {}, None)

        # let's do this
        try:
            target.log.info("flashing image with: %s" % " ".join(cmdline))
            subprocess.check_output(cmdline,
                                    cwd="/tmp",
                                    stderr=subprocess.STDOUT)
            target.log.info("flashed with %s: %s" % (" ".join(cmdline)))
        except subprocess.CalledProcessError as e:
            target.log.error("flashing with %s failed: (%d) %s" %
                             (" ".join(cmdline), e.returncode, e.output))
            raise
        target.power.put_off(target, ttbl.who_daemon(), {}, None)
        target.log.info("flashed image")
示例#3
0
    def flash(self, target, images):
        assert len(images) == 1, \
            "only one image suported, got %d: %s" \
            % (len(images), " ".join("%s:%s" % (k, v)
                                     for k, v in images.items()))
        if self.serial_port == None:
            serial_port = "/dev/tty-%s" % target.id
        else:
            serial_port = self.serial_port
        if self.console == None:
            console = "serial0"
        else:
            console = self.console

        cmdline_convert = [
            self.path,
            "--chip",
            "esp32",
            "elf2image",
        ]
        cmdline_flash = [
            self.path,
            "--chip",
            "esp32",
            "--port",
            serial_port,
            "--baud",
            "921600",
            "--before",
            "default_reset",
            # with no power control, at least it starts
            "--after",
            "hard_reset",
            "write_flash",
            "-u",
            "--flash_mode",
            "dio",
            "--flash_freq",
            "40m",
            "--flash_size",
            "detect",
            "0x1000",
        ]

        image_type = 'kernel'
        image_name = images.values()[0]
        image_name_bin = image_name + ".bin"
        try:
            cmdline = cmdline_convert + [
                image_name, "--output", image_name_bin
            ]
            target.log.info("%s: converting with %s" %
                            (image_type, " ".join(cmdline)))
            s = subprocess.check_output(cmdline,
                                        cwd="/tmp",
                                        stderr=subprocess.STDOUT)
        except subprocess.CalledProcessError as e:
            target.log.error(
                "%s: converting image with %s failed: (%d) %s" %
                (image_type, " ".join(cmdline), e.returncode, e.output))
            raise

        target.power.put_cycle(target, ttbl.who_daemon(), {}, None)
        # give up the serial port, we need it to flash
        # we don't care it is off because then we are switching off
        # the whole thing and then someone else will power it on
        target.console.put_disable(target, ttbl.who_daemon(),
                                   dict(component=console), None)
        try:
            cmdline = cmdline_flash + [image_name_bin]
            target.log.info("%s: flashing with %s" %
                            (image_type, " ".join(cmdline)))
            s = subprocess.check_output(cmdline,
                                        cwd="/tmp",
                                        stderr=subprocess.STDOUT)
            target.log.info("%s: flashed with %s: %s" %
                            (image_type, " ".join(cmdline), s))
        except subprocess.CalledProcessError as e:
            target.log.error(
                "%s: flashing with %s failed: (%d) %s" %
                (image_type, " ".join(cmdline), e.returncode, e.output))
            raise
        target.power.put_off(target, ttbl.who_daemon(), {}, None)
        target.log.info("%s: flashing succeeded" % image_type)