|
8 | 8 | #define IMAGE_HEADER_SIZE 256 |
9 | 9 | #define BOOT_PART_A 0 |
10 | 10 | #define BOOT_PART_B 1 |
| 11 | +#define MOCK_ADDRESS_BOOT 0xCD000000 |
11 | 12 |
|
12 | 13 | #include <stdio.h> |
13 | 14 | #include <stdint.h> |
14 | 15 | #include <string.h> |
15 | 16 | #include <check.h> |
16 | 17 |
|
| 18 | +#include "hal.h" |
17 | 19 | #include "target.h" |
18 | 20 | #include "wolfboot/wolfboot.h" |
19 | 21 | #include "image.h" |
@@ -190,6 +192,13 @@ void do_boot(const uint32_t *address) |
190 | 192 | mock_boot_address = address; |
191 | 193 | } |
192 | 194 |
|
| 195 | +int hal_flash_protect(haladdr_t address, int len) |
| 196 | +{ |
| 197 | + (void)address; |
| 198 | + (void)len; |
| 199 | + return 0; |
| 200 | +} |
| 201 | + |
193 | 202 | #include "update_disk.c" |
194 | 203 |
|
195 | 204 | START_TEST(test_update_disk_zeroizes_key_material_on_panic) |
@@ -232,6 +241,24 @@ START_TEST(test_update_disk_zeroizes_key_material_before_boot) |
232 | 241 | } |
233 | 242 | END_TEST |
234 | 243 |
|
| 244 | +START_TEST(test_update_disk_prefers_primary_partition_when_versions_equal) |
| 245 | +{ |
| 246 | + reset_mocks(); |
| 247 | + build_image(part_a_image, 7, 0xA1); |
| 248 | + build_image(part_b_image, 7, 0xB2); |
| 249 | + |
| 250 | + wolfBoot_start(); |
| 251 | + |
| 252 | + ck_assert_int_eq(wolfBoot_panicked, 0); |
| 253 | + ck_assert_int_eq(mock_do_boot_called, 1); |
| 254 | + ck_assert_ptr_eq(mock_boot_address, (const uint32_t *)WOLFBOOT_LOAD_ADDRESS); |
| 255 | + ck_assert_int_eq(memcmp(load_buffer, part_a_image + IMAGE_HEADER_SIZE, |
| 256 | + TEST_PAYLOAD_SIZE), 0); |
| 257 | + ck_assert_int_ne(memcmp(load_buffer, part_b_image + IMAGE_HEADER_SIZE, |
| 258 | + TEST_PAYLOAD_SIZE), 0); |
| 259 | +} |
| 260 | +END_TEST |
| 261 | + |
235 | 262 | START_TEST(test_get_decrypted_blob_version_rejects_truncated_version_tlv) |
236 | 263 | { |
237 | 264 | uint8_t hdr[IMAGE_HEADER_SIZE + 2]; |
@@ -268,6 +295,7 @@ Suite *wolfboot_suite(void) |
268 | 295 |
|
269 | 296 | tcase_add_test(tc, test_update_disk_zeroizes_key_material_on_panic); |
270 | 297 | tcase_add_test(tc, test_update_disk_zeroizes_key_material_before_boot); |
| 298 | + tcase_add_test(tc, test_update_disk_prefers_primary_partition_when_versions_equal); |
271 | 299 | tcase_add_test(tc, test_get_decrypted_blob_version_rejects_truncated_version_tlv); |
272 | 300 | suite_add_tcase(s, tc); |
273 | 301 |
|
|
0 commit comments