protocan-boot: support single-slot targets

This commit is contained in:
2026-08-31 01:06:16 +03:00
parent 5f3a9879d5
commit 648457e587
4 changed files with 67 additions and 6 deletions

View File

@@ -255,6 +255,44 @@ static void test_rejects_wrong_session_and_compatibility(void)
assert(boot.state == PCAN_BOOT_STATE_FAILED);
}
static void test_single_slot_update(void)
{
static const uint8_t image[8] = { 1U, 2U, 3U, 4U, 5U, 6U, 7U, 8U };
pcan_boot_t boot;
fake_t fake;
pcan_boot_config_t config;
pcan_boot_port_t port;
(void)memset(&fake, 0, sizeof(fake));
(void)memset(&config, 0, sizeof(config));
(void)memset(&port, 0, sizeof(port));
fake.pending_slot = PCAN_BOOT_SLOT_NONE;
fake.authorized = true;
fake.verified = true;
config.device_type = 3U;
config.device_id = 5U;
config.product_type = 0x1234U;
config.hardware_revision = 2U;
config.slot_count = 1U;
config.max_image_size = sizeof(fake.flash[0]);
config.ack_window = 16U;
port.send = fake_send;
port.erase_slot = fake_erase;
port.write_slot = fake_write;
port.authorize = fake_authorize;
port.verify_image = fake_verify;
port.reboot = fake_reboot;
assert(pcan_boot_init(&boot, &config, &port, &fake));
begin_update(&boot, image, sizeof(image));
assert(boot.target_slot == 0U);
assert(command(&boot, 7U, PCAN_BOOT_CMD_ERASE, NULL, 0U));
assert(pcan_boot_process(&boot, request_id(PCAN_BOOT_MSG_DATA_A, 0U), image, 8U));
assert(command(&boot, 7U, PCAN_BOOT_CMD_VERIFY, NULL, 0U));
assert(command(&boot, 7U, PCAN_BOOT_CMD_COMMIT, NULL, 0U));
assert(fake.pending_slot == PCAN_BOOT_SLOT_NONE);
assert(memcmp(fake.flash[0], image, sizeof(image)) == 0);
}
int main(void)
{
test_id_layout();
@@ -262,6 +300,7 @@ int main(void)
test_complete_update();
test_rejects_wrong_address_and_sequence();
test_rejects_wrong_session_and_compatibility();
test_single_slot_update();
puts("pcan_boot tests: OK");
return 0;
}