Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DRAFT] Bootloader Upgrade #14

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions accessory_widgets/bootloader/bootloader_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

# Helper class for sending bootloader commands over CAN
class BootloaderCommand():

APP_IDs = [
"main_module",
"dashboard",
Expand All @@ -20,7 +20,9 @@ class BootloaderCommand():
"BLCMD_START": 0x1, # Request to start firmware download
"BLCMD_FW_DATA": 0x2, # Firmware data message
"BLCMD_CRC": 0x3, # Final CRC-32b check of firmware
"BLCMD_RST": 0x5 # Request for reset (from app)
"BLCMD_RST": 0x5, # Request for reset (from app)
"BLCMD_SET_ADDR": 0x6, # Change flash base address
"BLCMD_SET_SIZE": 0x7,
}

RX_CMD = {
Expand All @@ -32,7 +34,7 @@ class BootloaderCommand():
"BLSTAT_DONE": 5, # Completed the application download with CRC pass
"BLSTAT_JUMP_TO_APP": 6, # About to jump to application
"BLSTAT_INVAID_APP": 7, # Did not attempt to boot because the starting address was invalid
"BLSTAT_UNKNOWN_CMD": 8 # Incorrect CAN command message format
"BLSTAT_UNKNOWN_CMD": 8, # Incorrect CAN command message format
}

BL_ERROR = {
Expand All @@ -50,7 +52,7 @@ def __init__(self, application_name, can_db) -> None:
self.RX_MSG = can_db.get_message_by_name(f"{application_name}_bl_resp")
self.DATA_MSG = can_db.get_message_by_name(f"bitstream_data")

def firmware_size_msg(self, fw_size) -> can.Message:
def firmware_start_msg(self, fw_size) -> can.Message:
data = self.TX_MSG.encode({"cmd": self.TX_CMD["BLCMD_START"], "data": fw_size})
return can.Message(arbitration_id=self.TX_MSG.frame_id, data=data)

Expand All @@ -62,9 +64,17 @@ def firmware_crc_msg(self, crc) -> can.Message:
data = self.TX_MSG.encode({"cmd": self.TX_CMD["BLCMD_CRC"], "data": crc})
return can.Message(arbitration_id=self.TX_MSG.frame_id, data=data)

def firmware_addr_msg(self, addr) -> can.Message:
data = self.TX_MSG.encode({"cmd": self.TX_CMD["BLCMD_SET_ADDR"], "data": addr})
return can.Message(arbitration_id=self.TX_MSG.frame_id, data=data)

def firmware_size_msg(self, size) -> can.Message:
data = self.TX_MSG.encode({"cmd": self.TX_CMD["BLCMD_SET_SIZE"], "data": size})
return can.Message(arbitration_id=self.TX_MSG.frame_id, data=data)

def firmware_rst_msg(self) -> can.Message:
data = self.TX_MSG.encode({"cmd": self.TX_CMD["BLCMD_RST"], "data": 0})
return can.Message(arbitration_id=self.TX_MSG.frame_id, data=data)

def decode_msg(self, msg: can.Message):
return self.RX_MSG.decode(msg.data)
return self.RX_MSG.decode(msg.data)
Loading