Skip to content
Snippets Groups Projects
Commit 6dd0516f authored by Samuel Tardieu's avatar Samuel Tardieu
Browse files

Remove unused bootloader.py module

parent bce7a398
No related branches found
No related tags found
2 merge requests!16Resolve "Add README to the firmware package",!15Resolve "Remove bootloader.py"
Pipeline #98565 canceled
......@@ -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:
......
......@@ -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,
......
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"))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment