diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index a98ba5e1ff888b1003b602585626b08f401ef4e2..6a515b479061955da724a01f4fc6937a89482f91 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -46,7 +46,6 @@ lint:python: stage: check script: - apk add py3-flake8 - - flake8 bootloader/python - flake8 controller/python build:rust:embedded: @@ -114,7 +113,6 @@ deploy: - cp target/thumbv7m-none-eabi/production/controller firmware/ - cp target/thumbv7m-none-eabi/production/controller-without-bootloader firmware/ - cp target/aarch64-unknown-linux-musl/production/firmware-updater firmware/ - - cp bootloader/python/bootloader.py firmware/ - cp controller/python/controller.py firmware/ artifacts: paths: diff --git a/bootloader/build.rs b/bootloader/build.rs index 761b57fce3c4bfb8c604e4b045192206db98ce03..8127571e4feb59715be676873752d7a1b337fefe 100644 --- a/bootloader/build.rs +++ b/bootloader/build.rs @@ -2,7 +2,6 @@ use bootloader_params::{BOOTLOADER_SIZE, FLASH_START}; use build_support::MemoryConfig; fn main() -> Result<(), build_support::Error> { - build_support::check_python_library_consistency("python/bootloader.py")?; build_support::make_version()?; build_support::make_memory_x(&MemoryConfig { flash_start: FLASH_START, diff --git a/bootloader/python/bootloader.py b/bootloader/python/bootloader.py deleted file mode 100644 index 7c7241706a8cba3de4ff05d717e45a904924036a..0000000000000000000000000000000000000000 --- a/bootloader/python/bootloader.py +++ /dev/null @@ -1,90 +0,0 @@ -import struct - -# Major and minor version of required firmware -_REQUIRED_FIRMWARE_VERSION = (0, 2) - - -class FirmwareVersionMismatch(Exception): - pass - - -class WhoAmIMismatch(Exception): - pass - - -class Bootloader: - - I2C_ADDR = 0x58 - - FIRMWARE_VERSION = 0x08 - WHO_AM_I = 0x0F - RESET = 0xE0 - DEVICE_ID = 0xF0 - - def __init__(self, i2c_bus=8): - import smbus - - self.i2c_bus = i2c_bus - self.i2c = smbus.SMBus(self.i2c_bus) - - self.check_who_am_i() - self.check_firmware_version() - - def _read(self, command, n, unpack_spec) -> tuple: - return struct.unpack( - unpack_spec, - bytes(self.i2c.read_i2c_block_data(self.I2C_ADDR, command, n)), - ) - - def _write(self, command: int, data: list[int]): - self.i2c.write_i2c_block_data(self.I2C_ADDR, command, data) - - def who_am_i(self) -> int: - """Check that the motors controller board is present. This - should return the same value as Bootloader.I2C_ADDR.""" - return self._read(self.WHO_AM_I, 1, "B")[0] - - def check_who_am_i(self): - """Check that the device answers to WHO_AM_I is correct.""" - w = self.who_am_i() - if w != self.I2C_ADDR: - error = ( - f"WHO_AM_I returns {w:#04x} " - f"instead of the expected {self.I2C_ADDR:#04x}" - ) - raise WhoAmIMismatch(error) - - def get_firmware_version(self) -> tuple[int, int, int]: - """Get the firmware version (major, minor, patch).""" - return self._read(self.FIRMWARE_VERSION, 3, "BBB") - - def check_firmware_version(self): - """Check that the firmware uses a version compatible with this - library.""" - version = self.get_firmware_version() - Bootloader._check_firmware_version_consistency( - _REQUIRED_FIRMWARE_VERSION, version - ) - - def _check_firmware_version_consistency( - required: tuple[int, int], version: tuple[int, int, int] - ): - (MAJOR, MINOR) = required - (major, minor, patch) = version - error = None - if major != MAJOR or minor < MINOR: - version = f"{major}.{minor}.{patch}" - VERSION = f"{MAJOR}.{MINOR}.*" - error = ( - f"Hardware runs firmware version {version} which " - f"is not compatible with this library version ({VERSION})" - ) - raise FirmwareVersionMismatch(error) - - def reset(self): - """Reset the device. Used mainly for testing.""" - self._write(self.RESET, []) - - def get_device_id(self): - """Return the 8 bytes composing the device id.""" - return list(self._read(self.DEVICE_ID, 8, "BBBBBBBB"))