canboot_main: Add mcu type to connect response message

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2022-05-09 14:38:11 -04:00 committed by Eric Callahan
parent 466a9de594
commit a00c4c78c5
3 changed files with 15 additions and 5 deletions

View File

@ -38,7 +38,7 @@ Responds with [acknowledged](#acknowledged-0xa0) containing a 16 byte payload
in the following format: in the following format:
``` ```
<4 byte orig_command><4 byte protocol_version><4 byte start_address><4 byte block_size> <4 byte orig_command><4 byte protocol_version><4 byte start_address><4 byte block_size><n byte mcu_type_string>
``` ```
- `orig_command` - must be `0x11` - `orig_command` - must be `0x11`
@ -50,6 +50,7 @@ in the following format:
address. address.
- `block_size` - the size of a block (in bytes) expected in the `send block` and - `block_size` - the size of a block (in bytes) expected in the `send block` and
`request block` commands. Typically this should be 64 bytes. `request block` commands. Typically this should be 64 bytes.
- `mcu_type_string` - The type of micro-controller (eg, "stm32f103xe").
#### Send Block: `0x12` #### Send Block: `0x12`

View File

@ -86,15 +86,21 @@ class CanFlasher:
async def connect_btl(self): async def connect_btl(self):
output_line("Attempting to connect to bootloader") output_line("Attempting to connect to bootloader")
ret = await self.send_command('CONNECT') ret = await self.send_command('CONNECT')
ver_bytes, start_addr, self.block_size = struct.unpack("<4sII", ret) pinfo = ret[:12]
mcu_type = ret[12:]
ver_bytes, start_addr, self.block_size = struct.unpack("<4sII", pinfo)
self.app_start_addr = start_addr self.app_start_addr = start_addr
proto_version = ".".join([str(v) for v in reversed(ver_bytes[:3])]) proto_version = ".".join([str(v) for v in reversed(ver_bytes[:3])])
if self.block_size not in [64, 128, 256, 512]: if self.block_size not in [64, 128, 256, 512]:
raise FlashCanError("Invalid Block Size: %d" % (self.block_size,)) raise FlashCanError("Invalid Block Size: %d" % (self.block_size,))
while mcu_type and mcu_type[-1] == 0x00:
mcu_type = mcu_type[:-1]
mcu_type = mcu_type.decode()
output_line( output_line(
f"CanBoot Connected\nProtocol Version: {proto_version}\n" f"CanBoot Connected\nProtocol Version: {proto_version}\n"
f"Block Size: {self.block_size} bytes\n" f"Block Size: {self.block_size} bytes\n"
f"Application Start: 0x{self.app_start_addr:4X}" f"Application Start: 0x{self.app_start_addr:4X}\n"
f"MCU type: {mcu_type}"
) )
async def send_command( async def send_command(

View File

@ -126,12 +126,15 @@ process_complete(void)
static void static void
process_connnect(void) process_connnect(void)
{ {
uint32_t out[6]; uint32_t mcuwords = DIV_ROUND_UP(strlen(CONFIG_MCU), 4);
uint32_t out[6 + mcuwords];
memset(out, 0, (6 + mcuwords) * 4);
out[1] = cpu_to_le32(CMD_CONNECT); out[1] = cpu_to_le32(CMD_CONNECT);
out[2] = cpu_to_le32(PROTO_VERSION); out[2] = cpu_to_le32(PROTO_VERSION);
out[3] = cpu_to_le32(CONFIG_APPLICATION_START); out[3] = cpu_to_le32(CONFIG_APPLICATION_START);
out[4] = cpu_to_le32(CONFIG_BLOCK_SIZE); out[4] = cpu_to_le32(CONFIG_BLOCK_SIZE);
send_ack(out, 4); memcpy(&out[5], CONFIG_MCU, strlen(CONFIG_MCU));
send_ack(out, 4 + mcuwords);
} }
static inline void static inline void