Beispiel #1
0
def perform_dfu(dev, args):
    info = fwinfo(dev)
    if info is None:
        print('Cannot get FW info from device')
        return
    img_ver_dev = info.get_fw_version()

    img_file = DfuImage(args.dfu_image, info, dev.get_board_name())

    img_file_bin = img_file.get_dfu_image_bin_path()
    if img_file_bin is None:
        print('No proper update image in file')
        return

    print('DFU will use file {}'.format(os.path.basename(img_file_bin)))

    img_ver_file = img_file.get_dfu_image_version()
    if img_ver_file is None:
        print('Cannot read image version from file')
        return

    print('Current FW version from device: ' +
          '.'.join([str(i) for i in img_ver_dev]))
    print('Current FW version from file: ' +
          '.'.join([str(i) for i in img_ver_file]))
    print('Perform update? [y/n]')

    if not args.autoconfirm:
        rsp = input().lower()
        if rsp == 'y':
            pass

        elif rsp == 'n':
            print('DFU rejected by user')
            return

        else:
            print('Improper user input. Operation terminated.')
            return

    success = dfu_transfer(dev, img_file_bin, progress_bar)

    if success:
        success = fwreboot(dev)

    if success:
        print('DFU transfer completed')
    else:
        print('DFU transfer failed')
def perform_dfu(dev, args):
    dfu_image = args.dfu_image

    img_ver_file = get_dfu_image_version(dfu_image)
    if img_ver_file is None:
        print('Cannot read image version from file')
        return

    info = fwinfo(dev)
    if info is None:
        print('Cannot get FW info from device')
        return
    img_ver_dev = info.get_fw_version()

    print('Current FW version from device: ' +
          '.'.join([str(i) for i in img_ver_dev]))
    print('Current FW version from file: ' +
          '.'.join([str(i) for i in img_ver_file]))
    print('Perform update? [y/n]')

    if not args.autoconfirm:
        rsp = input().lower()
        if rsp == 'y':
            pass

        elif rsp == 'n':
            print('DFU rejected by user')
            return

        else:
            print('Improper user input. Operation terminated.')
            return

    success = dfu_transfer(dev, dfu_image, progress_bar)

    if success:
        success = fwreboot(dev)

    if success:
        print('DFU transfer completed')
    else:
        print('DFU transfer failed')
Beispiel #3
0
 def perform_dfu(self, file, update_progressbar):
     dfu_image = file
     return dfu_transfer(self.dev, dfu_image, update_progressbar)
def perform_dfu(dev, args):
    dfu_package = args.dfu_image

    if not zipfile.is_zipfile(dfu_package):
        print('Invalid DFU package format')
        return

    info = fwinfo(dev)
    if info is None:
        print('Cannot get FW info from device')
        return
    img_ver_dev = info.get_fw_version()

    flash_area_id = info.get_flash_area_id()
    if flash_area_id not in (0, 1):
        print('Invalid area id in FW info')
        return
    dfu_slot_id = 1 - flash_area_id

    dfu_image_name = 'signed_by_b0_s{}_image.bin'.format(dfu_slot_id)

    temp_dir = tempfile.TemporaryDirectory(dir='.')
    dfu_path = temp_dir.name

    with ZipFile(dfu_package, 'r') as zip_file:
        zip_file.extract(dfu_image_name, dfu_path)

    dfu_image = os.path.join(dfu_path, dfu_image_name)

    print('DFU will use file {}'.format(dfu_image))

    img_ver_file = get_dfu_image_version(dfu_image)
    if img_ver_file is None:
        print('Cannot read image version from file')
        return

    print('Current FW version from device: ' +
          '.'.join([str(i) for i in img_ver_dev]))
    print('Current FW version from file: ' +
          '.'.join([str(i) for i in img_ver_file]))
    print('Perform update? [y/n]')

    if not args.autoconfirm:
        rsp = input().lower()
        if rsp == 'y':
            pass

        elif rsp == 'n':
            print('DFU rejected by user')
            return

        else:
            print('Improper user input. Operation terminated.')
            return

    success = dfu_transfer(dev, dfu_image, progress_bar)

    if success:
        success = fwreboot(dev)

    temp_dir.cleanup()

    if success:
        print('DFU transfer completed')
    else:
        print('DFU transfer failed')