protocan-boot: support single-slot targets
This commit is contained in:
@@ -115,17 +115,27 @@ void pcan_boot_abort(pcan_boot_t *boot)
|
||||
bool pcan_boot_init(pcan_boot_t *boot, const pcan_boot_config_t *config,
|
||||
const pcan_boot_port_t *port, void *port_user)
|
||||
{
|
||||
uint8_t slot_count;
|
||||
if ((boot == NULL) || (config == NULL) || (port == NULL)
|
||||
|| (config->device_type > 7U) || (config->device_id > 15U)
|
||||
|| (config->active_slot > 1U)
|
||||
|| (port->send == NULL) || (port->erase_slot == NULL)
|
||||
|| (port->write_slot == NULL) || (port->set_pending_slot == NULL)) {
|
||||
|| (port->write_slot == NULL)) {
|
||||
return false;
|
||||
}
|
||||
slot_count = config->slot_count == 0U ? 2U : config->slot_count;
|
||||
if ((slot_count > 2U) || (config->active_slot >= slot_count)
|
||||
|| ((slot_count == 2U) && (port->set_pending_slot == NULL))) {
|
||||
return false;
|
||||
}
|
||||
(void)memset(boot, 0, sizeof(*boot));
|
||||
boot->config = *config;
|
||||
boot->port = *port;
|
||||
boot->port_user = port_user;
|
||||
boot->config.slot_count = slot_count;
|
||||
if (boot->config.max_image_size == 0U) {
|
||||
boot->config.max_image_size = PCAN_BOOT_SLOT_SIZE;
|
||||
}
|
||||
if (boot->config.ack_window == 0U) {
|
||||
boot->config.ack_window = 1U;
|
||||
}
|
||||
@@ -140,7 +150,7 @@ static bool metadata_complete(pcan_boot_t *boot, uint8_t command)
|
||||
return send_status(boot, command, PCAN_BOOT_STATUS_OK);
|
||||
}
|
||||
if ((boot->manifest.image_size == 0U)
|
||||
|| (boot->manifest.image_size > PCAN_BOOT_SLOT_SIZE)) {
|
||||
|| (boot->manifest.image_size > boot->config.max_image_size)) {
|
||||
boot->state = PCAN_BOOT_STATE_FAILED;
|
||||
return send_status(boot, command, PCAN_BOOT_STATUS_INVALID_SIZE);
|
||||
}
|
||||
@@ -155,7 +165,9 @@ static bool metadata_complete(pcan_boot_t *boot, uint8_t command)
|
||||
boot->state = PCAN_BOOT_STATE_FAILED;
|
||||
return send_status(boot, command, PCAN_BOOT_STATUS_SIGNATURE_ERROR);
|
||||
}
|
||||
boot->target_slot = (uint8_t)(boot->config.active_slot ^ 1U);
|
||||
boot->target_slot = boot->config.slot_count == 1U
|
||||
? boot->config.active_slot
|
||||
: (uint8_t)(boot->config.active_slot ^ 1U);
|
||||
boot->state = PCAN_BOOT_STATE_READY_TO_ERASE;
|
||||
return send_status(boot, command, PCAN_BOOT_STATUS_OK);
|
||||
}
|
||||
@@ -239,8 +251,9 @@ static bool process_control(pcan_boot_t *boot, uint16_t body,
|
||||
if (boot->state != PCAN_BOOT_STATE_VERIFIED) {
|
||||
return send_status(boot, command, PCAN_BOOT_STATUS_INVALID_STATE);
|
||||
}
|
||||
if (!boot->port.set_pending_slot(boot->port_user, boot->target_slot,
|
||||
&boot->manifest)) {
|
||||
if ((boot->config.slot_count == 2U)
|
||||
&& !boot->port.set_pending_slot(boot->port_user, boot->target_slot,
|
||||
&boot->manifest)) {
|
||||
return send_status(boot, command, PCAN_BOOT_STATUS_FLASH_ERROR);
|
||||
}
|
||||
return send_status(boot, command, PCAN_BOOT_STATUS_OK);
|
||||
|
||||
Reference in New Issue
Block a user