From 1a4d655a1860b8a6fddadcef7503f851d02e6388 Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Thu, 7 Oct 2021 19:34:36 -0400 Subject: [PATCH] spi_flash: Improve Python3 compatibility Signed-off-by: Kevin O'Connor --- scripts/spi_flash/spi_flash.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/scripts/spi_flash/spi_flash.py b/scripts/spi_flash/spi_flash.py index 4352b23e..617c2d4f 100644 --- a/scripts/spi_flash/spi_flash.py +++ b/scripts/spi_flash/spi_flash.py @@ -16,6 +16,7 @@ import traceback import json import board_defs import fatfs_lib +import util import reactor import serialhdl import clocksync @@ -274,7 +275,7 @@ class FatFS: def remove_item(self, sd_path): # Can be path to directory or file - ret = self.ffi_lib.fatfs_remove(sd_path) + ret = self.ffi_lib.fatfs_remove(sd_path.encode()) if ret != 0: raise OSError("flash_sdcard: Error deleting item at path '%s'," " result: %s" @@ -282,7 +283,7 @@ class FatFS: def get_file_info(self, sd_file_path): finfo = self.ffi_main.new("struct ff_file_info *") - ret = self.ffi_lib.fatfs_get_fstats(finfo, sd_file_path) + ret = self.ffi_lib.fatfs_get_fstats(finfo, sd_file_path.encode()) if ret != 0: raise OSError( "flash_sdcard: Failed to retreive file info for path '%s'," @@ -292,7 +293,7 @@ class FatFS: def list_sd_directory(self, sd_dir_path): flist = self.ffi_main.new("struct ff_file_info[128]") - ret = self.ffi_lib.fatfs_list_dir(flist, 128, sd_dir_path) + ret = self.ffi_lib.fatfs_list_dir(flist, 128, sd_dir_path.encode()) if ret != 0: raise OSError("flash_sdcard: Failed to retreive file list at path" " '%s', result: %s" @@ -357,7 +358,7 @@ class SDCardFile: if self.fhdl is not None: # already open return - self.fhdl = self.ffi_lib.fatfs_open(self.path, self.mode) + self.fhdl = self.ffi_lib.fatfs_open(self.path.encode(), self.mode) self.eof = False if self.fhdl == self.ffi_main.NULL: self.fhdl = None @@ -895,7 +896,7 @@ class MCUConnection: SPI_CFG_CMD % (SPI_OID, cs_pin), bus_cmd, ] - config_crc = zlib.crc32('\n'.join(cfg_cmds)) & 0xffffffff + config_crc = zlib.crc32('\n'.join(cfg_cmds).encode()) & 0xffffffff cfg_cmds.append(FINALIZE_CFG_CMD % (config_crc,)) for cmd in cfg_cmds: self._serial.send(cmd)