mirror of https://github.com/wolfSSL/wolfBoot.git
Unit tests: cleanup warnings
parent
6737d7e7ad
commit
a1a7601314
|
@ -26,6 +26,9 @@
|
||||||
#ifndef IMAGE_H_
|
#ifndef IMAGE_H_
|
||||||
#define IMAGE_H_
|
#define IMAGE_H_
|
||||||
|
|
||||||
|
#ifdef UNIT_TEST
|
||||||
|
#include <stdio.h>
|
||||||
|
#endif
|
||||||
#include <wolfssl/wolfcrypt/settings.h> /* for wolfCrypt hash/sign routines */
|
#include <wolfssl/wolfcrypt/settings.h> /* for wolfCrypt hash/sign routines */
|
||||||
|
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
|
|
@ -1504,13 +1504,13 @@ ChaCha chacha;
|
||||||
int RAMFUNCTION chacha_init(void)
|
int RAMFUNCTION chacha_init(void)
|
||||||
{
|
{
|
||||||
#if defined(MMU) || defined(UNIT_TEST)
|
#if defined(MMU) || defined(UNIT_TEST)
|
||||||
uint8_t *key = ENCRYPT_KEY;
|
const uint8_t *key = ENCRYPT_KEY;
|
||||||
#else
|
#else
|
||||||
uint8_t *key = (uint8_t *)(WOLFBOOT_PARTITION_BOOT_ADDRESS +
|
const uint8_t *key = (uint8_t *)(WOLFBOOT_PARTITION_BOOT_ADDRESS +
|
||||||
ENCRYPT_TMP_SECRET_OFFSET);
|
ENCRYPT_TMP_SECRET_OFFSET);
|
||||||
#endif
|
#endif
|
||||||
uint8_t ff[ENCRYPT_KEY_SIZE];
|
uint8_t ff[ENCRYPT_KEY_SIZE];
|
||||||
uint8_t* stored_nonce;
|
const uint8_t* stored_nonce;
|
||||||
|
|
||||||
#ifdef NVM_FLASH_WRITEONCE
|
#ifdef NVM_FLASH_WRITEONCE
|
||||||
key -= WOLFBOOT_SECTOR_SIZE * nvm_select_fresh_sector(PART_BOOT);
|
key -= WOLFBOOT_SECTOR_SIZE * nvm_select_fresh_sector(PART_BOOT);
|
||||||
|
|
|
@ -180,12 +180,12 @@ static void cache_commit(uint32_t offset)
|
||||||
|
|
||||||
|
|
||||||
/* Write backup sector first */
|
/* Write backup sector first */
|
||||||
hal_flash_erase((uint32_t)BACKUP_SECTOR_ADDRESS, WOLFBOOT_SECTOR_SIZE);
|
hal_flash_erase((uintptr_t)BACKUP_SECTOR_ADDRESS, WOLFBOOT_SECTOR_SIZE);
|
||||||
hal_flash_write((uint32_t)BACKUP_SECTOR_ADDRESS, cached_sector, WOLFBOOT_SECTOR_SIZE);
|
hal_flash_write((uintptr_t)BACKUP_SECTOR_ADDRESS, cached_sector, WOLFBOOT_SECTOR_SIZE);
|
||||||
|
|
||||||
/* Erase + write actual destination sector */
|
/* Erase + write actual destination sector */
|
||||||
hal_flash_erase((uint32_t)vault_base + offset, WOLFBOOT_SECTOR_SIZE);
|
hal_flash_erase((uintptr_t)vault_base + offset, WOLFBOOT_SECTOR_SIZE);
|
||||||
hal_flash_write((uint32_t)vault_base + offset, cached_sector, WOLFBOOT_SECTOR_SIZE);
|
hal_flash_write((uintptr_t)vault_base + offset, cached_sector, WOLFBOOT_SECTOR_SIZE);
|
||||||
|
|
||||||
hal_flash_lock();
|
hal_flash_lock();
|
||||||
}
|
}
|
||||||
|
@ -194,8 +194,8 @@ static void restore_backup(uint32_t offset)
|
||||||
{
|
{
|
||||||
hal_flash_unlock();
|
hal_flash_unlock();
|
||||||
/* Erase + copy from backup */
|
/* Erase + copy from backup */
|
||||||
hal_flash_erase((uint32_t)vault_base + offset, WOLFBOOT_SECTOR_SIZE);
|
hal_flash_erase((uintptr_t)vault_base + offset, WOLFBOOT_SECTOR_SIZE);
|
||||||
hal_flash_write((uint32_t)vault_base + offset, BACKUP_SECTOR_ADDRESS,
|
hal_flash_write((uintptr_t)vault_base + offset, BACKUP_SECTOR_ADDRESS,
|
||||||
WOLFBOOT_SECTOR_SIZE);
|
WOLFBOOT_SECTOR_SIZE);
|
||||||
hal_flash_lock();
|
hal_flash_lock();
|
||||||
}
|
}
|
||||||
|
@ -220,7 +220,7 @@ static void check_vault(void)
|
||||||
memset(cached_sector + sizeof(uint32_t), 0x00, BITMAP_SIZE);
|
memset(cached_sector + sizeof(uint32_t), 0x00, BITMAP_SIZE);
|
||||||
cache_commit(0);
|
cache_commit(0);
|
||||||
hal_flash_unlock();
|
hal_flash_unlock();
|
||||||
hal_flash_erase((uint32_t)vault_base + WOLFBOOT_SECTOR_SIZE * 2, total_vault_size);
|
hal_flash_erase((uintptr_t)vault_base + WOLFBOOT_SECTOR_SIZE * 2, total_vault_size);
|
||||||
hal_flash_lock();
|
hal_flash_lock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -253,7 +253,7 @@ static uint8_t *find_object_buffer(int32_t type, uint32_t tok_id, uint32_t obj_i
|
||||||
{
|
{
|
||||||
struct obj_hdr *hdr = NODES_TABLE;
|
struct obj_hdr *hdr = NODES_TABLE;
|
||||||
uint32_t *tok_obj_stored = NULL;
|
uint32_t *tok_obj_stored = NULL;
|
||||||
while ((uint32_t)hdr < ((uint32_t)NODES_TABLE + WOLFBOOT_SECTOR_SIZE)) {
|
while ((uintptr_t)hdr < ((uintptr_t)NODES_TABLE + WOLFBOOT_SECTOR_SIZE)) {
|
||||||
if ((hdr->token_id == tok_id) && (hdr->object_id == obj_id)
|
if ((hdr->token_id == tok_id) && (hdr->object_id == obj_id)
|
||||||
&& (hdr->type == type)) {
|
&& (hdr->type == type)) {
|
||||||
tok_obj_stored = (uint32_t *) (vault_base + (2 * WOLFBOOT_SECTOR_SIZE) + (hdr->pos * KEYVAULT_OBJ_SIZE));
|
tok_obj_stored = (uint32_t *) (vault_base + (2 * WOLFBOOT_SECTOR_SIZE) + (hdr->pos * KEYVAULT_OBJ_SIZE));
|
||||||
|
@ -285,7 +285,7 @@ static struct obj_hdr *find_object_header(int32_t type, uint32_t tok_id,
|
||||||
{
|
{
|
||||||
struct obj_hdr *hdr = NODES_TABLE;
|
struct obj_hdr *hdr = NODES_TABLE;
|
||||||
uint32_t *tok_obj_stored = NULL;
|
uint32_t *tok_obj_stored = NULL;
|
||||||
while ((uint32_t)hdr < ((uint32_t)NODES_TABLE + WOLFBOOT_SECTOR_SIZE)) {
|
while ((uintptr_t)hdr < ((uintptr_t)NODES_TABLE + WOLFBOOT_SECTOR_SIZE)) {
|
||||||
if ((hdr->token_id == tok_id) && (hdr->object_id == obj_id)
|
if ((hdr->token_id == tok_id) && (hdr->object_id == obj_id)
|
||||||
&& (hdr->type == type)) {
|
&& (hdr->type == type)) {
|
||||||
return hdr;
|
return hdr;
|
||||||
|
@ -307,7 +307,7 @@ static struct obj_hdr *create_object(int32_t type, uint32_t tok_id, uint32_t obj
|
||||||
/* Caching sector 0 */
|
/* Caching sector 0 */
|
||||||
memcpy(cached_sector, vault_base , WOLFBOOT_SECTOR_SIZE);
|
memcpy(cached_sector, vault_base , WOLFBOOT_SECTOR_SIZE);
|
||||||
hdr = (struct obj_hdr *)(cached_sector + STORE_PRIV_HDR_OFFSET);
|
hdr = (struct obj_hdr *)(cached_sector + STORE_PRIV_HDR_OFFSET);
|
||||||
while ((uint32_t)hdr < ((uint32_t)cached_sector + WOLFBOOT_SECTOR_SIZE)) {
|
while ((uintptr_t)hdr < ((uintptr_t)cached_sector + WOLFBOOT_SECTOR_SIZE)) {
|
||||||
if (hdr->token_id == PKCS11_INVALID_ID) {
|
if (hdr->token_id == PKCS11_INVALID_ID) {
|
||||||
uint32_t sector_base, in_sector_off;
|
uint32_t sector_base, in_sector_off;
|
||||||
int pos = bitmap_find_free_pos();
|
int pos = bitmap_find_free_pos();
|
||||||
|
@ -337,7 +337,7 @@ static struct obj_hdr *create_object(int32_t type, uint32_t tok_id, uint32_t obj
|
||||||
*/
|
*/
|
||||||
memcpy(cached_sector, vault_base + sector_base,
|
memcpy(cached_sector, vault_base + sector_base,
|
||||||
WOLFBOOT_SECTOR_SIZE);
|
WOLFBOOT_SECTOR_SIZE);
|
||||||
tok_obj_id = (uint32_t *)(cached_sector + in_sector_off);
|
tok_obj_id = (void*)(cached_sector + in_sector_off);
|
||||||
tok_obj_id[0] = tok_id;
|
tok_obj_id[0] = tok_id;
|
||||||
tok_obj_id[1] = obj_id;
|
tok_obj_id[1] = obj_id;
|
||||||
cache_commit(sector_base);
|
cache_commit(sector_base);
|
||||||
|
@ -357,7 +357,7 @@ static void update_store_size(struct obj_hdr *hdr, uint32_t size)
|
||||||
((uint8_t *)hdr > vault_base + WOLFBOOT_SECTOR_SIZE))
|
((uint8_t *)hdr > vault_base + WOLFBOOT_SECTOR_SIZE))
|
||||||
return;
|
return;
|
||||||
check_vault();
|
check_vault();
|
||||||
off = (uint32_t)hdr - (uint32_t)vault_base;
|
off = (uintptr_t)hdr - (uintptr_t)vault_base;
|
||||||
memcpy(cached_sector, vault_base, WOLFBOOT_SECTOR_SIZE);
|
memcpy(cached_sector, vault_base, WOLFBOOT_SECTOR_SIZE);
|
||||||
hdr_mem = (struct obj_hdr *)(cached_sector + off);
|
hdr_mem = (struct obj_hdr *)(cached_sector + off);
|
||||||
hdr_mem->size = size;
|
hdr_mem->size = size;
|
||||||
|
@ -426,7 +426,7 @@ int wolfPKCS11_Store_Open(int type, CK_ULONG id1, CK_ULONG id2, int read,
|
||||||
|
|
||||||
/* Set the position of the buffer in the handle */
|
/* Set the position of the buffer in the handle */
|
||||||
handle->buffer = buf;
|
handle->buffer = buf;
|
||||||
handle->pos = (((uint32_t)buf) - (uint32_t)vault_base) / KEYVAULT_OBJ_SIZE;
|
handle->pos = (((uintptr_t)buf) - (uintptr_t)vault_base) / KEYVAULT_OBJ_SIZE;
|
||||||
/* Set the 'open' flag */
|
/* Set the 'open' flag */
|
||||||
handle->flags |= STORE_FLAGS_OPEN;
|
handle->flags |= STORE_FLAGS_OPEN;
|
||||||
|
|
||||||
|
@ -508,22 +508,22 @@ int wolfPKCS11_Store_Write(void* store, unsigned char* buffer, int len)
|
||||||
|
|
||||||
|
|
||||||
while (written < len) {
|
while (written < len) {
|
||||||
in_sector_offset = ((uint32_t)(handle->buffer) + handle->in_buffer_offset)
|
in_sector_offset = ((uintptr_t)(handle->buffer) + handle->in_buffer_offset)
|
||||||
% WOLFBOOT_SECTOR_SIZE;
|
% WOLFBOOT_SECTOR_SIZE;
|
||||||
sector_base = (uint32_t)handle->buffer + handle->in_buffer_offset - in_sector_offset;
|
sector_base = (uintptr_t)handle->buffer + handle->in_buffer_offset - in_sector_offset;
|
||||||
in_sector_len = WOLFBOOT_SECTOR_SIZE - in_sector_offset;
|
in_sector_len = WOLFBOOT_SECTOR_SIZE - in_sector_offset;
|
||||||
if (in_sector_len > (uint32_t)len)
|
if (in_sector_len > (uint32_t)len)
|
||||||
in_sector_len = len;
|
in_sector_len = len;
|
||||||
|
|
||||||
/* Cache the corresponding sector */
|
/* Cache the corresponding sector */
|
||||||
memcpy(cached_sector, (void *)sector_base, WOLFBOOT_SECTOR_SIZE);
|
memcpy(cached_sector, (void *)(uintptr_t)sector_base, WOLFBOOT_SECTOR_SIZE);
|
||||||
/* Write content into cache */
|
/* Write content into cache */
|
||||||
memcpy(cached_sector + in_sector_offset, buffer + written, in_sector_len);
|
memcpy(cached_sector + in_sector_offset, buffer + written, in_sector_len);
|
||||||
/* Adjust in_buffer position for the handle accordingly */
|
/* Adjust in_buffer position for the handle accordingly */
|
||||||
handle->in_buffer_offset += in_sector_len;
|
handle->in_buffer_offset += in_sector_len;
|
||||||
written += in_sector_len;
|
written += in_sector_len;
|
||||||
/* Write sector to flash */
|
/* Write sector to flash */
|
||||||
cache_commit((uint32_t)sector_base - (uint32_t)vault_base);
|
cache_commit((uintptr_t)sector_base - (uintptr_t)vault_base);
|
||||||
}
|
}
|
||||||
obj_size += written;
|
obj_size += written;
|
||||||
update_store_size(handle->hdr, obj_size);
|
update_store_size(handle->hdr, obj_size);
|
||||||
|
|
|
@ -10,6 +10,7 @@ CFLAGS+=-g -ggdb
|
||||||
CFLAGS+=-fprofile-arcs
|
CFLAGS+=-fprofile-arcs
|
||||||
CFLAGS+=-ftest-coverage
|
CFLAGS+=-ftest-coverage
|
||||||
CFLAGS+=--coverage
|
CFLAGS+=--coverage
|
||||||
|
CFLAGS+=-DUNIT_TEST -DWOLFSSL_USER_SETTINGS
|
||||||
LDFLAGS+=-fprofile-arcs
|
LDFLAGS+=-fprofile-arcs
|
||||||
LDFLAGS+=-ftest-coverage
|
LDFLAGS+=-ftest-coverage
|
||||||
WOLFCRYPT=../../lib/wolfssl/
|
WOLFCRYPT=../../lib/wolfssl/
|
||||||
|
@ -58,16 +59,15 @@ unit-enc-nvm-flagshome:CFLAGS+=-DNVM_FLASH_WRITEONCE -DMOCK_PARTITIONS \
|
||||||
-DEXT_ENCRYPTED -DENCRYPT_WITH_CHACHA -DEXT_FLASH -DHAVE_CHACHA -DFLAGS_HOME
|
-DEXT_ENCRYPTED -DENCRYPT_WITH_CHACHA -DEXT_FLASH -DHAVE_CHACHA -DFLAGS_HOME
|
||||||
unit-enc-nvm-flagshome:WOLFCRYPT_SRC+=$(WOLFCRYPT)/wolfcrypt/src/chacha.c
|
unit-enc-nvm-flagshome:WOLFCRYPT_SRC+=$(WOLFCRYPT)/wolfcrypt/src/chacha.c
|
||||||
unit-delta:CFLAGS+=-DNVM_FLASH_WRITEONCE -DMOCK_PARTITIONS -DDELTA_UPDATES -DDELTA_BLOCK_SIZE=512
|
unit-delta:CFLAGS+=-DNVM_FLASH_WRITEONCE -DMOCK_PARTITIONS -DDELTA_UPDATES -DDELTA_BLOCK_SIZE=512
|
||||||
|
unit-pkcs11_store:CFLAGS+=-I$(WOLFPKCS11) -DMOCK_PARTITIONS -DMOCK_KEYVAULT -DSECURE_PKCS11
|
||||||
unit-update-flash:CFLAGS+=-DMOCK_PARTITIONS -DWOLFBOOT_NO_SIGN -DUNIT_TEST_AUTH \
|
unit-update-flash:CFLAGS+=-DMOCK_PARTITIONS -DWOLFBOOT_NO_SIGN -DUNIT_TEST_AUTH \
|
||||||
-DWOLFBOOT_HASH_SHA256 -DPRINTF_ENABLED -DEXT_FLASH -DPART_UPDATE_EXT -DPART_SWAP_EXT
|
-DWOLFBOOT_HASH_SHA256 -DPRINTF_ENABLED -DEXT_FLASH -DPART_UPDATE_EXT -DPART_SWAP_EXT
|
||||||
unit-update-ram:CFLAGS+=-DMOCK_PARTITIONS -DWOLFBOOT_NO_SIGN -DUNIT_TEST_AUTH \
|
unit-update-ram:CFLAGS+=-DMOCK_PARTITIONS -DWOLFBOOT_NO_SIGN -DUNIT_TEST_AUTH \
|
||||||
-DWOLFBOOT_HASH_SHA256 -DPRINTF_ENABLED -DEXT_FLASH -DPART_UPDATE_EXT \
|
-DWOLFBOOT_HASH_SHA256 -DPRINTF_ENABLED -DEXT_FLASH -DPART_UPDATE_EXT \
|
||||||
-DPART_SWAP_EXT -DPART_BOOT_EXT -DWOLFBOOT_DUALBOOT -DNO_XIP
|
-DPART_SWAP_EXT -DPART_BOOT_EXT -DWOLFBOOT_DUALBOOT -DNO_XIP
|
||||||
unit-pkcs11_store:CFLAGS+=-I$(WOLFPKCS11) -DMOCK_PARTITIONS -DMOCK_KEYVAULT -DSECURE_PKCS11
|
|
||||||
|
|
||||||
|
|
||||||
|
WOLFCRYPT_CFLAGS+=-DWOLFBOOT_SIGN_ECC256 -DWOLFBOOT_SIGN_ECC256 -DHAVE_ECC_KEY_IMPORT -D__WOLFBOOT
|
||||||
WOLFCRYPT_CFLAGS+=-DWOLFSSL_USER_SETTINGS -DWOLFBOOT_SIGN_ECC256 -DWOLFBOOT_SIGN_ECC256 -DHAVE_ECC_KEY_IMPORT -D__WOLFBOOT
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#include "delta.h"
|
#include "delta.h"
|
||||||
|
#define WC_RSA_BLINDING
|
||||||
#include "delta.c"
|
#include "delta.c"
|
||||||
|
|
||||||
#define SRC_SIZE 4096
|
#define SRC_SIZE 4096
|
||||||
|
@ -33,6 +34,8 @@
|
||||||
#define DST_SIZE 4096
|
#define DST_SIZE 4096
|
||||||
#define DIFF_SIZE 8192
|
#define DIFF_SIZE 8192
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
START_TEST(test_wb_patch_init_invalid)
|
START_TEST(test_wb_patch_init_invalid)
|
||||||
{
|
{
|
||||||
WB_PATCH_CTX ctx;
|
WB_PATCH_CTX ctx;
|
||||||
|
|
|
@ -22,8 +22,6 @@
|
||||||
*/
|
*/
|
||||||
#define WOLFBOOT_HASH_SHA256
|
#define WOLFBOOT_HASH_SHA256
|
||||||
#define IMAGE_HEADER_SIZE 256
|
#define IMAGE_HEADER_SIZE 256
|
||||||
#define UNIT_TEST
|
|
||||||
#define WC_NO_HARDEN
|
|
||||||
#define MOCK_ADDRESS 0xCC000000
|
#define MOCK_ADDRESS 0xCC000000
|
||||||
#define MOCK_ADDRESS_BOOT 0xCD000000
|
#define MOCK_ADDRESS_BOOT 0xCD000000
|
||||||
#define MOCK_ADDRESS_SWAP 0xCE000000
|
#define MOCK_ADDRESS_SWAP 0xCE000000
|
||||||
|
@ -57,18 +55,18 @@ START_TEST (test_nvm_update_with_encryption)
|
||||||
uint32_t base_addr = WOLFBOOT_PARTITION_UPDATE_ADDRESS;
|
uint32_t base_addr = WOLFBOOT_PARTITION_UPDATE_ADDRESS;
|
||||||
uint32_t home_off = 0;
|
uint32_t home_off = 0;
|
||||||
|
|
||||||
ret = mmap_file("/tmp/wolfboot-unit-file.bin", MOCK_ADDRESS,
|
ret = mmap_file("/tmp/wolfboot-unit-file.bin", (void *)MOCK_ADDRESS,
|
||||||
WOLFBOOT_PARTITION_SIZE, NULL);
|
WOLFBOOT_PARTITION_SIZE, NULL);
|
||||||
fail_if(ret < 0);
|
fail_if(ret < 0);
|
||||||
#ifdef FLAGS_HOME
|
#ifdef FLAGS_HOME
|
||||||
ret = mmap_file("/tmp/wolfboot-unit-int-file.bin", MOCK_ADDRESS_BOOT,
|
ret = mmap_file("/tmp/wolfboot-unit-int-file.bin", (void *)MOCK_ADDRESS_BOOT,
|
||||||
WOLFBOOT_PARTITION_SIZE, NULL);
|
WOLFBOOT_PARTITION_SIZE, NULL);
|
||||||
fail_if(ret < 0);
|
fail_if(ret < 0);
|
||||||
part = PART_BOOT;
|
part = PART_BOOT;
|
||||||
base_addr = WOLFBOOT_PARTITION_BOOT_ADDRESS;
|
base_addr = WOLFBOOT_PARTITION_BOOT_ADDRESS;
|
||||||
home_off = PART_BOOT_ENDFLAGS - PART_UPDATE_ENDFLAGS;
|
home_off = PART_BOOT_ENDFLAGS - PART_UPDATE_ENDFLAGS;
|
||||||
#endif
|
#endif
|
||||||
ret = mmap_file("/tmp/wolfboot-unit-swap.bin", MOCK_ADDRESS_SWAP,
|
ret = mmap_file("/tmp/wolfboot-unit-swap.bin", (void *)MOCK_ADDRESS_SWAP,
|
||||||
WOLFBOOT_SECTOR_SIZE, NULL);
|
WOLFBOOT_SECTOR_SIZE, NULL);
|
||||||
fail_if(ret < 0);
|
fail_if(ret < 0);
|
||||||
|
|
||||||
|
@ -82,7 +80,7 @@ START_TEST (test_nvm_update_with_encryption)
|
||||||
wolfBoot_erase_partition(PART_SWAP);
|
wolfBoot_erase_partition(PART_SWAP);
|
||||||
fail_if(erased_swap != 1);
|
fail_if(erased_swap != 1);
|
||||||
for (i = 0; i < WOLFBOOT_SECTOR_SIZE; i+=4) {
|
for (i = 0; i < WOLFBOOT_SECTOR_SIZE; i+=4) {
|
||||||
uint32_t *word = ((uint32_t *)(WOLFBOOT_PARTITION_SWAP_ADDRESS + i));
|
uint32_t *word = ((uint32_t *)((uintptr_t)WOLFBOOT_PARTITION_SWAP_ADDRESS + i));
|
||||||
fail_if(*word != 0xFFFFFFFF);
|
fail_if(*word != 0xFFFFFFFF);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -191,13 +189,13 @@ START_TEST (test_nvm_update_with_encryption)
|
||||||
wolfBoot_set_update_sector_flag(1, SECT_FLAG_UPDATED);
|
wolfBoot_set_update_sector_flag(1, SECT_FLAG_UPDATED);
|
||||||
|
|
||||||
/* Copy flags from 0 to 1 */
|
/* Copy flags from 0 to 1 */
|
||||||
src = (uint8_t *)(base_addr + WOLFBOOT_PARTITION_SIZE - WOLFBOOT_SECTOR_SIZE);
|
src = (uint8_t *)((uintptr_t)base_addr + WOLFBOOT_PARTITION_SIZE - WOLFBOOT_SECTOR_SIZE);
|
||||||
dst = (uint8_t *)(base_addr + WOLFBOOT_PARTITION_SIZE - (2 * WOLFBOOT_SECTOR_SIZE));
|
dst = (uint8_t *)((uintptr_t)base_addr + WOLFBOOT_PARTITION_SIZE - (2 * WOLFBOOT_SECTOR_SIZE));
|
||||||
for (i = 0; i < WOLFBOOT_SECTOR_SIZE; i++)
|
for (i = 0; i < WOLFBOOT_SECTOR_SIZE; i++)
|
||||||
dst[i] = src[i];
|
dst[i] = src[i];
|
||||||
|
|
||||||
/* Force-erase 4B of sector flags in 0 */
|
/* Force-erase 4B of sector flags in 0 */
|
||||||
dst = (uint8_t *)(base_addr + WOLFBOOT_PARTITION_SIZE - (8 + home_off +
|
dst = (uint8_t *)((uintptr_t)base_addr + WOLFBOOT_PARTITION_SIZE - (8 + home_off +
|
||||||
TRAILER_SKIP + ENCRYPT_KEY_SIZE + ENCRYPT_NONCE_SIZE));
|
TRAILER_SKIP + ENCRYPT_KEY_SIZE + ENCRYPT_NONCE_SIZE));
|
||||||
for (i = 0; i < 4; i++)
|
for (i = 0; i < 4; i++)
|
||||||
dst[i] = 0xFF;
|
dst[i] = 0xFF;
|
||||||
|
@ -214,7 +212,7 @@ START_TEST (test_nvm_update_with_encryption)
|
||||||
wolfBoot_set_update_sector_flag(3, SECT_FLAG_UPDATED);
|
wolfBoot_set_update_sector_flag(3, SECT_FLAG_UPDATED);
|
||||||
wolfBoot_set_update_sector_flag(4, SECT_FLAG_SWAPPING);
|
wolfBoot_set_update_sector_flag(4, SECT_FLAG_SWAPPING);
|
||||||
st = IMG_STATE_UPDATING;
|
st = IMG_STATE_UPDATING;
|
||||||
wolfBoot_set_partition_state(PART_UPDATE, &st);
|
wolfBoot_set_partition_state(PART_UPDATE, (uintptr_t)&st);
|
||||||
|
|
||||||
/* Current selected should now be 1 */
|
/* Current selected should now be 1 */
|
||||||
ret = nvm_select_fresh_sector(PART_UPDATE);
|
ret = nvm_select_fresh_sector(PART_UPDATE);
|
||||||
|
@ -237,13 +235,13 @@ START_TEST (test_nvm_update_with_encryption)
|
||||||
fail_if(ret != 1, "Failed to select right sector after reading sector state\n");
|
fail_if(ret != 1, "Failed to select right sector after reading sector state\n");
|
||||||
|
|
||||||
/* Copy flags from 1 to 0 */
|
/* Copy flags from 1 to 0 */
|
||||||
src = (uint8_t *)(base_addr + WOLFBOOT_PARTITION_SIZE - (2 * WOLFBOOT_SECTOR_SIZE));
|
src = (uint8_t *)((uintptr_t)base_addr + WOLFBOOT_PARTITION_SIZE - (2 * WOLFBOOT_SECTOR_SIZE));
|
||||||
dst = (uint8_t *)(base_addr + WOLFBOOT_PARTITION_SIZE - (WOLFBOOT_SECTOR_SIZE));
|
dst = (uint8_t *)((uintptr_t)base_addr + WOLFBOOT_PARTITION_SIZE - (WOLFBOOT_SECTOR_SIZE));
|
||||||
for (i = 0; i < WOLFBOOT_SECTOR_SIZE; i++)
|
for (i = 0; i < WOLFBOOT_SECTOR_SIZE; i++)
|
||||||
dst[i] = src[i];
|
dst[i] = src[i];
|
||||||
|
|
||||||
/* Force to F0 last sector flag in 0, so that the sector '4' is 'updated' */
|
/* Force to F0 last sector flag in 0, so that the sector '4' is 'updated' */
|
||||||
dst = (uint8_t *)(base_addr + WOLFBOOT_PARTITION_SIZE - (8 + home_off +
|
dst = (uint8_t *)((uintptr_t)base_addr + WOLFBOOT_PARTITION_SIZE - (8 + home_off +
|
||||||
TRAILER_SKIP + ENCRYPT_KEY_SIZE + ENCRYPT_NONCE_SIZE));
|
TRAILER_SKIP + ENCRYPT_KEY_SIZE + ENCRYPT_NONCE_SIZE));
|
||||||
dst[0] = 0xF0;
|
dst[0] = 0xF0;
|
||||||
|
|
||||||
|
|
|
@ -39,11 +39,8 @@
|
||||||
#if defined(ENCRYPT_WITH_CHACHA)
|
#if defined(ENCRYPT_WITH_CHACHA)
|
||||||
#define HAVE_CHACHA
|
#define HAVE_CHACHA
|
||||||
#endif
|
#endif
|
||||||
#define WC_NO_HARDEN
|
|
||||||
|
|
||||||
#define WOLFSSL_USER_SETTINGS
|
|
||||||
#define ENCRYPT_KEY "123456789abcdef0123456789abcdef0123456789abcdef"
|
#define ENCRYPT_KEY "123456789abcdef0123456789abcdef0123456789abcdef"
|
||||||
#define UNIT_TEST
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <check.h>
|
#include <check.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
|
@ -39,15 +39,10 @@
|
||||||
#if defined(ENCRYPT_WITH_CHACHA)
|
#if defined(ENCRYPT_WITH_CHACHA)
|
||||||
#define HAVE_CHACHA
|
#define HAVE_CHACHA
|
||||||
#endif
|
#endif
|
||||||
//#define WC_NO_HARDEN
|
|
||||||
#define ECC_TIMING_RESISTANT
|
#define ECC_TIMING_RESISTANT
|
||||||
|
|
||||||
#define WOLFSSL_USER_SETTINGS
|
|
||||||
#define ENCRYPT_KEY "123456789abcdef0123456789abcdef0123456789abcdef"
|
#define ENCRYPT_KEY "123456789abcdef0123456789abcdef0123456789abcdef"
|
||||||
#define UNIT_TEST
|
|
||||||
#define WOLFBOOT_SIGN_ECC256
|
|
||||||
#define KEYSTORE_PUBKEY_SIZE KEYSTORE_PUBKEY_SIZE_ECC256
|
#define KEYSTORE_PUBKEY_SIZE KEYSTORE_PUBKEY_SIZE_ECC256
|
||||||
#define __WOLFBOOT
|
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <check.h>
|
#include <check.h>
|
||||||
|
@ -80,7 +75,7 @@ static const unsigned char pubkey_digest[SHA256_DIGEST_SIZE] = {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
static const unsigned char test_img_v200000000_signed_bin[] = {
|
static unsigned char test_img_v200000000_signed_bin[] = {
|
||||||
0x57, 0x4f, 0x4c, 0x46, 0x13, 0x00, 0x00, 0x00, 0x01, 0x00, 0x04, 0x00,
|
0x57, 0x4f, 0x4c, 0x46, 0x13, 0x00, 0x00, 0x00, 0x01, 0x00, 0x04, 0x00,
|
||||||
0x00, 0xc2, 0xeb, 0x0b, 0xff, 0xff, 0xff, 0xff, 0x02, 0x00, 0x08, 0x00,
|
0x00, 0xc2, 0xeb, 0x0b, 0xff, 0xff, 0xff, 0xff, 0x02, 0x00, 0x08, 0x00,
|
||||||
0x77, 0x33, 0x29, 0x65, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x02, 0x00,
|
0x77, 0x33, 0x29, 0x65, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x02, 0x00,
|
||||||
|
@ -407,28 +402,28 @@ START_TEST(test_headers)
|
||||||
img.part = PART_BOOT;
|
img.part = PART_BOOT;
|
||||||
find_header_fail = 1;
|
find_header_fail = 1;
|
||||||
find_header_called = 0;
|
find_header_called = 0;
|
||||||
ret = get_header(&img, type, &ptr);
|
ret = get_header(&img, type, (void *)&ptr);
|
||||||
ck_assert_uint_eq(ret, 0xFFFF);
|
ck_assert_uint_eq(ret, 0xFFFF);
|
||||||
ck_assert_int_eq(find_header_called, 1);
|
ck_assert_int_eq(find_header_called, 1);
|
||||||
|
|
||||||
img.part = PART_BOOT;
|
img.part = PART_BOOT;
|
||||||
find_header_fail = 0;
|
find_header_fail = 0;
|
||||||
find_header_called = 0;
|
find_header_called = 0;
|
||||||
ret = get_header(&img, type, &ptr);
|
ret = get_header(&img, type, (void *)&ptr);
|
||||||
ck_assert_uint_ne(ret, 0xFFFF);
|
ck_assert_uint_ne(ret, 0xFFFF);
|
||||||
ck_assert_int_eq(find_header_called, 1);
|
ck_assert_int_eq(find_header_called, 1);
|
||||||
|
|
||||||
img.part = PART_UPDATE;
|
img.part = PART_UPDATE;
|
||||||
find_header_fail = 1;
|
find_header_fail = 1;
|
||||||
find_header_called = 0;
|
find_header_called = 0;
|
||||||
ret = get_header(&img, type, &ptr);
|
ret = get_header(&img, type, (void *)&ptr);
|
||||||
ck_assert_uint_eq(ret, 0xFFFF);
|
ck_assert_uint_eq(ret, 0xFFFF);
|
||||||
ck_assert_int_eq(find_header_called, 1);
|
ck_assert_int_eq(find_header_called, 1);
|
||||||
|
|
||||||
img.part = PART_UPDATE;
|
img.part = PART_UPDATE;
|
||||||
find_header_fail = 0;
|
find_header_fail = 0;
|
||||||
find_header_called = 0;
|
find_header_called = 0;
|
||||||
ret = get_header(&img, type, &ptr);
|
ret = get_header(&img, type, (void *)&ptr);
|
||||||
ck_assert_uint_ne(ret, 0xFFFF);
|
ck_assert_uint_ne(ret, 0xFFFF);
|
||||||
ck_assert_int_eq(find_header_called, 1);
|
ck_assert_int_eq(find_header_called, 1);
|
||||||
|
|
||||||
|
@ -444,7 +439,7 @@ START_TEST(test_headers)
|
||||||
ck_assert_ptr_eq(ptr, hdr_cpy);
|
ck_assert_ptr_eq(ptr, hdr_cpy);
|
||||||
|
|
||||||
/* Test image_size */
|
/* Test image_size */
|
||||||
sz = wolfBoot_image_size(test_img_v200000000_signed_bin);
|
sz = wolfBoot_image_size((void *)(uintptr_t)test_img_v200000000_signed_bin);
|
||||||
ck_assert_uint_eq(sz, test_img_len - 256);
|
ck_assert_uint_eq(sz, test_img_len - 256);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -514,7 +509,7 @@ START_TEST(test_verify_integrity)
|
||||||
test_img_v123_signed_bin_len);
|
test_img_v123_signed_bin_len);
|
||||||
ret = wolfBoot_open_image(&test_img, PART_UPDATE);
|
ret = wolfBoot_open_image(&test_img, PART_UPDATE);
|
||||||
ck_assert_int_eq(ret, 0);
|
ck_assert_int_eq(ret, 0);
|
||||||
ck_assert_uint_eq(test_img.hdr, WOLFBOOT_PARTITION_UPDATE_ADDRESS);
|
ck_assert_ptr_eq(test_img.hdr, (void*)WOLFBOOT_PARTITION_UPDATE_ADDRESS);
|
||||||
ret = wolfBoot_verify_integrity(&test_img);
|
ret = wolfBoot_verify_integrity(&test_img);
|
||||||
ck_assert_int_eq(ret, 0);
|
ck_assert_int_eq(ret, 0);
|
||||||
}
|
}
|
||||||
|
@ -540,7 +535,7 @@ START_TEST(test_open_image)
|
||||||
/* Swap partition */
|
/* Swap partition */
|
||||||
ret = wolfBoot_open_image(&img, PART_SWAP);
|
ret = wolfBoot_open_image(&img, PART_SWAP);
|
||||||
ck_assert_uint_eq(img.hdr_ok, 1);
|
ck_assert_uint_eq(img.hdr_ok, 1);
|
||||||
ck_assert_ptr_eq(img.hdr, WOLFBOOT_PARTITION_SWAP_ADDRESS);
|
ck_assert_ptr_eq(img.hdr, (void *)WOLFBOOT_PARTITION_SWAP_ADDRESS);
|
||||||
ck_assert_ptr_eq(img.hdr, img.fw_base);
|
ck_assert_ptr_eq(img.hdr, img.fw_base);
|
||||||
ck_assert_uint_eq(img.fw_size, WOLFBOOT_SECTOR_SIZE);
|
ck_assert_uint_eq(img.fw_size, WOLFBOOT_SECTOR_SIZE);
|
||||||
|
|
||||||
|
@ -552,7 +547,8 @@ START_TEST(test_open_image)
|
||||||
ck_assert_int_eq(ret, 0);
|
ck_assert_int_eq(ret, 0);
|
||||||
ck_assert_uint_eq(img.hdr_ok, 1);
|
ck_assert_uint_eq(img.hdr_ok, 1);
|
||||||
ck_assert_ptr_eq(img.hdr, WOLFBOOT_PARTITION_UPDATE_ADDRESS);
|
ck_assert_ptr_eq(img.hdr, WOLFBOOT_PARTITION_UPDATE_ADDRESS);
|
||||||
ck_assert_ptr_eq(img.fw_base, WOLFBOOT_PARTITION_UPDATE_ADDRESS + 256);
|
ck_assert_ptr_eq(img.fw_base, (uint8_t *)WOLFBOOT_PARTITION_UPDATE_ADDRESS
|
||||||
|
+ 256);
|
||||||
|
|
||||||
}
|
}
|
||||||
END_TEST
|
END_TEST
|
||||||
|
|
|
@ -41,7 +41,7 @@ void hal_init(void)
|
||||||
int hal_flash_write(haladdr_t address, const uint8_t *data, int len)
|
int hal_flash_write(haladdr_t address, const uint8_t *data, int len)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
uint8_t *a = (uint8_t *)address;
|
uint8_t *a = (uint8_t *)(uintptr_t)address;
|
||||||
fail_if(locked, "Attempting to write to a locked FLASH");
|
fail_if(locked, "Attempting to write to a locked FLASH");
|
||||||
if ((address >= WOLFBOOT_PARTITION_SWAP_ADDRESS) &&
|
if ((address >= WOLFBOOT_PARTITION_SWAP_ADDRESS) &&
|
||||||
(address < WOLFBOOT_PARTITION_UPDATE_ADDRESS + WOLFBOOT_SECTOR_SIZE)) {
|
(address < WOLFBOOT_PARTITION_UPDATE_ADDRESS + WOLFBOOT_SECTOR_SIZE)) {
|
||||||
|
@ -62,7 +62,7 @@ int hal_flash_write(haladdr_t address, const uint8_t *data, int len)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#ifdef MOCK_KEYVAULT
|
#ifdef MOCK_KEYVAULT
|
||||||
if ((address >= vault_base) && (address < vault_base + keyvault_size)) {
|
if ((address >= (const uintptr_t)vault_base) && (address < (const uintptr_t)vault_base + keyvault_size)) {
|
||||||
for (i = 0; i < len; i++) {
|
for (i = 0; i < len; i++) {
|
||||||
a[i] = data[i];
|
a[i] = data[i];
|
||||||
}
|
}
|
||||||
|
@ -76,7 +76,7 @@ int hal_flash_erase(haladdr_t address, int len)
|
||||||
if ((address >= WOLFBOOT_PARTITION_BOOT_ADDRESS) &&
|
if ((address >= WOLFBOOT_PARTITION_BOOT_ADDRESS) &&
|
||||||
(address < WOLFBOOT_PARTITION_BOOT_ADDRESS + WOLFBOOT_PARTITION_SIZE)) {
|
(address < WOLFBOOT_PARTITION_BOOT_ADDRESS + WOLFBOOT_PARTITION_SIZE)) {
|
||||||
erased_boot++;
|
erased_boot++;
|
||||||
memset(address, 0xFF, len);
|
memset((void*)(uintptr_t)address, 0xFF, len);
|
||||||
if (address >= WOLFBOOT_PARTITION_BOOT_ADDRESS + WOLFBOOT_PARTITION_SIZE - WOLFBOOT_SECTOR_SIZE) {
|
if (address >= WOLFBOOT_PARTITION_BOOT_ADDRESS + WOLFBOOT_PARTITION_SIZE - WOLFBOOT_SECTOR_SIZE) {
|
||||||
erased_nvm_bank0++;
|
erased_nvm_bank0++;
|
||||||
} else if (address >= WOLFBOOT_PARTITION_BOOT_ADDRESS + WOLFBOOT_PARTITION_SIZE - 2 * WOLFBOOT_SECTOR_SIZE) {
|
} else if (address >= WOLFBOOT_PARTITION_BOOT_ADDRESS + WOLFBOOT_PARTITION_SIZE - 2 * WOLFBOOT_SECTOR_SIZE) {
|
||||||
|
@ -85,7 +85,7 @@ int hal_flash_erase(haladdr_t address, int len)
|
||||||
} else if ((address >= WOLFBOOT_PARTITION_UPDATE_ADDRESS) &&
|
} else if ((address >= WOLFBOOT_PARTITION_UPDATE_ADDRESS) &&
|
||||||
(address < WOLFBOOT_PARTITION_UPDATE_ADDRESS + WOLFBOOT_PARTITION_SIZE)) {
|
(address < WOLFBOOT_PARTITION_UPDATE_ADDRESS + WOLFBOOT_PARTITION_SIZE)) {
|
||||||
erased_update++;
|
erased_update++;
|
||||||
memset(address, 0xFF, len);
|
memset((void *)(uintptr_t)address, 0xFF, len);
|
||||||
if (address >= WOLFBOOT_PARTITION_UPDATE_ADDRESS + WOLFBOOT_PARTITION_SIZE - WOLFBOOT_SECTOR_SIZE) {
|
if (address >= WOLFBOOT_PARTITION_UPDATE_ADDRESS + WOLFBOOT_PARTITION_SIZE - WOLFBOOT_SECTOR_SIZE) {
|
||||||
erased_nvm_bank0++;
|
erased_nvm_bank0++;
|
||||||
} else if (address >= WOLFBOOT_PARTITION_UPDATE_ADDRESS + WOLFBOOT_PARTITION_SIZE - 2 * WOLFBOOT_SECTOR_SIZE) {
|
} else if (address >= WOLFBOOT_PARTITION_UPDATE_ADDRESS + WOLFBOOT_PARTITION_SIZE - 2 * WOLFBOOT_SECTOR_SIZE) {
|
||||||
|
@ -94,12 +94,12 @@ int hal_flash_erase(haladdr_t address, int len)
|
||||||
} else if ((address >= WOLFBOOT_PARTITION_SWAP_ADDRESS) &&
|
} else if ((address >= WOLFBOOT_PARTITION_SWAP_ADDRESS) &&
|
||||||
(address < WOLFBOOT_PARTITION_SWAP_ADDRESS + WOLFBOOT_SECTOR_SIZE)) {
|
(address < WOLFBOOT_PARTITION_SWAP_ADDRESS + WOLFBOOT_SECTOR_SIZE)) {
|
||||||
erased_swap++;
|
erased_swap++;
|
||||||
memset(address, 0xFF, len);
|
memset((void *)(uintptr_t)address, 0xFF, len);
|
||||||
#ifdef MOCK_KEYVAULT
|
#ifdef MOCK_KEYVAULT
|
||||||
} else if ((address >= vault_base) && (address < vault_base + keyvault_size)) {
|
} else if ((address >= (uintptr_t)vault_base) && (address < (uintptr_t)vault_base + keyvault_size)) {
|
||||||
printf("Erasing vault from %p : %p bytes\n", address, len);
|
printf("Erasing vault from %p : %p bytes\n", address, len);
|
||||||
erased_vault++;
|
erased_vault++;
|
||||||
memset(address, 0xFF, len);
|
memset((void *)(uintptr_t)address, 0xFF, len);
|
||||||
#endif
|
#endif
|
||||||
} else {
|
} else {
|
||||||
fail("Invalid address\n");
|
fail("Invalid address\n");
|
||||||
|
@ -128,7 +128,7 @@ int ext_flash_erase(uintptr_t address, int len)
|
||||||
if ((address >= WOLFBOOT_PARTITION_BOOT_ADDRESS) &&
|
if ((address >= WOLFBOOT_PARTITION_BOOT_ADDRESS) &&
|
||||||
(address < WOLFBOOT_PARTITION_BOOT_ADDRESS + WOLFBOOT_PARTITION_SIZE)) {
|
(address < WOLFBOOT_PARTITION_BOOT_ADDRESS + WOLFBOOT_PARTITION_SIZE)) {
|
||||||
erased_update++;
|
erased_update++;
|
||||||
memset(address, 0xFF, len);
|
memset((void *)(uintptr_t)address, 0xFF, len);
|
||||||
if (address >= WOLFBOOT_PARTITION_BOOT_ADDRESS + WOLFBOOT_PARTITION_SIZE - WOLFBOOT_SECTOR_SIZE) {
|
if (address >= WOLFBOOT_PARTITION_BOOT_ADDRESS + WOLFBOOT_PARTITION_SIZE - WOLFBOOT_SECTOR_SIZE) {
|
||||||
erased_nvm_bank0++;
|
erased_nvm_bank0++;
|
||||||
} else if (address >= WOLFBOOT_PARTITION_BOOT_ADDRESS + WOLFBOOT_PARTITION_SIZE - 2 * WOLFBOOT_SECTOR_SIZE) {
|
} else if (address >= WOLFBOOT_PARTITION_BOOT_ADDRESS + WOLFBOOT_PARTITION_SIZE - 2 * WOLFBOOT_SECTOR_SIZE) {
|
||||||
|
@ -139,7 +139,7 @@ int ext_flash_erase(uintptr_t address, int len)
|
||||||
if ((address >= WOLFBOOT_PARTITION_UPDATE_ADDRESS) &&
|
if ((address >= WOLFBOOT_PARTITION_UPDATE_ADDRESS) &&
|
||||||
(address < WOLFBOOT_PARTITION_UPDATE_ADDRESS + WOLFBOOT_PARTITION_SIZE)) {
|
(address < WOLFBOOT_PARTITION_UPDATE_ADDRESS + WOLFBOOT_PARTITION_SIZE)) {
|
||||||
erased_update++;
|
erased_update++;
|
||||||
memset(address, 0xFF, len);
|
memset((void *)(uintptr_t)address, 0xFF, len);
|
||||||
if (address >= WOLFBOOT_PARTITION_UPDATE_ADDRESS + WOLFBOOT_PARTITION_SIZE - WOLFBOOT_SECTOR_SIZE) {
|
if (address >= WOLFBOOT_PARTITION_UPDATE_ADDRESS + WOLFBOOT_PARTITION_SIZE - WOLFBOOT_SECTOR_SIZE) {
|
||||||
erased_nvm_bank0++;
|
erased_nvm_bank0++;
|
||||||
} else if (address >= WOLFBOOT_PARTITION_UPDATE_ADDRESS + WOLFBOOT_PARTITION_SIZE - 2 * WOLFBOOT_SECTOR_SIZE) {
|
} else if (address >= WOLFBOOT_PARTITION_UPDATE_ADDRESS + WOLFBOOT_PARTITION_SIZE - 2 * WOLFBOOT_SECTOR_SIZE) {
|
||||||
|
@ -148,7 +148,7 @@ int ext_flash_erase(uintptr_t address, int len)
|
||||||
} else if ((address >= WOLFBOOT_PARTITION_SWAP_ADDRESS) &&
|
} else if ((address >= WOLFBOOT_PARTITION_SWAP_ADDRESS) &&
|
||||||
(address < WOLFBOOT_PARTITION_SWAP_ADDRESS + WOLFBOOT_SECTOR_SIZE)) {
|
(address < WOLFBOOT_PARTITION_SWAP_ADDRESS + WOLFBOOT_SECTOR_SIZE)) {
|
||||||
erased_swap++;
|
erased_swap++;
|
||||||
memset(address, 0xFF, len);
|
memset((void *)(uintptr_t)address, 0xFF, len);
|
||||||
} else {
|
} else {
|
||||||
fail("Invalid address: %p\n", address);
|
fail("Invalid address: %p\n", address);
|
||||||
return -1;
|
return -1;
|
||||||
|
|
|
@ -36,11 +36,8 @@
|
||||||
#if defined(ENCRYPT_WITH_CHACHA)
|
#if defined(ENCRYPT_WITH_CHACHA)
|
||||||
#define HAVE_CHACHA
|
#define HAVE_CHACHA
|
||||||
#endif
|
#endif
|
||||||
#define WC_NO_HARDEN
|
|
||||||
#define NVM_FLASH_WRITEONCE
|
#define NVM_FLASH_WRITEONCE
|
||||||
|
|
||||||
#define WOLFSSL_USER_SETTINGS
|
|
||||||
#define UNIT_TEST
|
|
||||||
#define MOCK_PARTITION_TRAILER
|
#define MOCK_PARTITION_TRAILER
|
||||||
#define MOCK_BLOB_TYPE
|
#define MOCK_BLOB_TYPE
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
@ -72,7 +69,7 @@ uint8_t image_backup(uint8_t part_id)
|
||||||
static int locked = 0;
|
static int locked = 0;
|
||||||
static int hal_flash_write_mock_called = 0;
|
static int hal_flash_write_mock_called = 0;
|
||||||
static uintptr_t hal_flash_write_mock_address = 0U;
|
static uintptr_t hal_flash_write_mock_address = 0U;
|
||||||
static uint8_t *hal_flash_write_mock_data = NULL;
|
static const uint8_t *hal_flash_write_mock_data = NULL;
|
||||||
static int hal_flash_write_mock_len = 0;
|
static int hal_flash_write_mock_len = 0;
|
||||||
|
|
||||||
static uintptr_t hal_flash_erase_mock_address = 0;
|
static uintptr_t hal_flash_erase_mock_address = 0;
|
||||||
|
@ -129,7 +126,7 @@ void hal_prepare_boot(void)
|
||||||
static int ext_locked = 1;
|
static int ext_locked = 1;
|
||||||
static int ext_flash_write_mock_called = 0;
|
static int ext_flash_write_mock_called = 0;
|
||||||
static uintptr_t ext_flash_write_mock_address = 0U;
|
static uintptr_t ext_flash_write_mock_address = 0U;
|
||||||
static uint8_t *ext_flash_write_mock_data = NULL;
|
static const uint8_t *ext_flash_write_mock_data = NULL;
|
||||||
static int ext_flash_write_mock_len = 0;
|
static int ext_flash_write_mock_len = 0;
|
||||||
|
|
||||||
static int ext_flash_read_mock_called = 0;
|
static int ext_flash_read_mock_called = 0;
|
||||||
|
|
|
@ -22,11 +22,11 @@
|
||||||
*/
|
*/
|
||||||
#define WOLFBOOT_HASH_SHA256
|
#define WOLFBOOT_HASH_SHA256
|
||||||
#define IMAGE_HEADER_SIZE 256
|
#define IMAGE_HEADER_SIZE 256
|
||||||
#define UNIT_TEST
|
|
||||||
#define WC_NO_HARDEN
|
|
||||||
#define MOCK_ADDRESS 0xCC000000
|
#define MOCK_ADDRESS 0xCC000000
|
||||||
#define MOCK_ADDRESS_BOOT 0xCD000000
|
#define MOCK_ADDRESS_BOOT 0xCD000000
|
||||||
#define MOCK_ADDRESS_SWAP 0xCE000000
|
#define MOCK_ADDRESS_SWAP 0xCE000000
|
||||||
|
#define WC_RSA_BLINDING
|
||||||
|
#define ECC_TIMING_RESISTANT
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include "libwolfboot.c"
|
#include "libwolfboot.c"
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
@ -52,18 +52,18 @@ START_TEST (test_nvm_select_fresh_sector)
|
||||||
uint32_t base_addr = WOLFBOOT_PARTITION_UPDATE_ADDRESS;
|
uint32_t base_addr = WOLFBOOT_PARTITION_UPDATE_ADDRESS;
|
||||||
uint32_t home_off = 0;
|
uint32_t home_off = 0;
|
||||||
|
|
||||||
ret = mmap_file("/tmp/wolfboot-unit-file.bin", MOCK_ADDRESS,
|
ret = mmap_file("/tmp/wolfboot-unit-file.bin", (void *)MOCK_ADDRESS,
|
||||||
WOLFBOOT_PARTITION_SIZE, NULL);
|
WOLFBOOT_PARTITION_SIZE, NULL);
|
||||||
fail_if(ret < 0);
|
fail_if(ret < 0);
|
||||||
#ifdef FLAGS_HOME
|
#ifdef FLAGS_HOME
|
||||||
ret = mmap_file("/tmp/wolfboot-unit-int-file.bin", MOCK_ADDRESS_BOOT,
|
ret = mmap_file("/tmp/wolfboot-unit-int-file.bin", (void *)MOCK_ADDRESS_BOOT,
|
||||||
WOLFBOOT_PARTITION_SIZE, NULL);
|
WOLFBOOT_PARTITION_SIZE, NULL);
|
||||||
fail_if(ret < 0);
|
fail_if(ret < 0);
|
||||||
part = PART_BOOT;
|
part = PART_BOOT;
|
||||||
base_addr = WOLFBOOT_PARTITION_BOOT_ADDRESS;
|
base_addr = WOLFBOOT_PARTITION_BOOT_ADDRESS;
|
||||||
home_off = PART_BOOT_ENDFLAGS - PART_UPDATE_ENDFLAGS;
|
home_off = PART_BOOT_ENDFLAGS - PART_UPDATE_ENDFLAGS;
|
||||||
#endif
|
#endif
|
||||||
ret = mmap_file("/tmp/wolfboot-unit-swap.bin", MOCK_ADDRESS_SWAP,
|
ret = mmap_file("/tmp/wolfboot-unit-swap.bin", (void *)MOCK_ADDRESS_SWAP,
|
||||||
WOLFBOOT_SECTOR_SIZE, NULL);
|
WOLFBOOT_SECTOR_SIZE, NULL);
|
||||||
fail_if(ret < 0);
|
fail_if(ret < 0);
|
||||||
|
|
||||||
|
@ -77,7 +77,7 @@ START_TEST (test_nvm_select_fresh_sector)
|
||||||
wolfBoot_erase_partition(PART_SWAP);
|
wolfBoot_erase_partition(PART_SWAP);
|
||||||
fail_if(erased_swap != 1);
|
fail_if(erased_swap != 1);
|
||||||
for (i = 0; i < WOLFBOOT_SECTOR_SIZE; i+=4) {
|
for (i = 0; i < WOLFBOOT_SECTOR_SIZE; i+=4) {
|
||||||
uint32_t *word = ((uint32_t *)(WOLFBOOT_PARTITION_SWAP_ADDRESS + i));
|
uint32_t *word = ((uint32_t *)((uintptr_t)WOLFBOOT_PARTITION_SWAP_ADDRESS + i));
|
||||||
fail_if(*word != 0xFFFFFFFF);
|
fail_if(*word != 0xFFFFFFFF);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -186,13 +186,13 @@ START_TEST (test_nvm_select_fresh_sector)
|
||||||
wolfBoot_set_update_sector_flag(1, SECT_FLAG_UPDATED);
|
wolfBoot_set_update_sector_flag(1, SECT_FLAG_UPDATED);
|
||||||
|
|
||||||
/* Copy flags from 0 to 1 */
|
/* Copy flags from 0 to 1 */
|
||||||
src = (uint8_t *)(base_addr + WOLFBOOT_PARTITION_SIZE - (8 + home_off));
|
src = (uint8_t *)((uintptr_t)base_addr + WOLFBOOT_PARTITION_SIZE - (8 + home_off));
|
||||||
dst = (uint8_t *)(base_addr + WOLFBOOT_PARTITION_SIZE - (8 + home_off + WOLFBOOT_SECTOR_SIZE));
|
dst = (uint8_t *)((uintptr_t)base_addr + WOLFBOOT_PARTITION_SIZE - (8 + home_off + WOLFBOOT_SECTOR_SIZE));
|
||||||
for (i = 0; i < 8; i++)
|
for (i = 0; i < 8; i++)
|
||||||
dst[i] = src[i];
|
dst[i] = src[i];
|
||||||
|
|
||||||
/* Force-erase 4B of sector flags in 0 */
|
/* Force-erase 4B of sector flags in 0 */
|
||||||
dst = (uint8_t *)(base_addr + WOLFBOOT_PARTITION_SIZE - (8 + home_off));
|
dst = (uint8_t *)((uintptr_t)base_addr + WOLFBOOT_PARTITION_SIZE - (8 + home_off));
|
||||||
for (i = 0; i < 4; i++)
|
for (i = 0; i < 4; i++)
|
||||||
dst[i] = 0xFF;
|
dst[i] = 0xFF;
|
||||||
|
|
||||||
|
@ -208,7 +208,7 @@ START_TEST (test_nvm_select_fresh_sector)
|
||||||
wolfBoot_set_update_sector_flag(3, SECT_FLAG_UPDATED);
|
wolfBoot_set_update_sector_flag(3, SECT_FLAG_UPDATED);
|
||||||
wolfBoot_set_update_sector_flag(4, SECT_FLAG_SWAPPING);
|
wolfBoot_set_update_sector_flag(4, SECT_FLAG_SWAPPING);
|
||||||
st = IMG_STATE_UPDATING;
|
st = IMG_STATE_UPDATING;
|
||||||
wolfBoot_set_partition_state(PART_UPDATE, &st);
|
wolfBoot_set_partition_state(PART_UPDATE, (uintptr_t)&st);
|
||||||
|
|
||||||
/* Current selected should now be 1 */
|
/* Current selected should now be 1 */
|
||||||
ret = nvm_select_fresh_sector(PART_UPDATE);
|
ret = nvm_select_fresh_sector(PART_UPDATE);
|
||||||
|
@ -231,13 +231,13 @@ START_TEST (test_nvm_select_fresh_sector)
|
||||||
fail_if(ret != 1, "Failed to select right sector after reading sector state\n");
|
fail_if(ret != 1, "Failed to select right sector after reading sector state\n");
|
||||||
|
|
||||||
/* Copy flags from 1 to 0 */
|
/* Copy flags from 1 to 0 */
|
||||||
src = (uint8_t *)(base_addr + WOLFBOOT_PARTITION_SIZE - (8 + home_off + WOLFBOOT_SECTOR_SIZE));
|
src = (uint8_t *)((uintptr_t)base_addr + WOLFBOOT_PARTITION_SIZE - (8 + home_off + WOLFBOOT_SECTOR_SIZE));
|
||||||
dst = (uint8_t *)(base_addr + WOLFBOOT_PARTITION_SIZE - (8 + home_off));
|
dst = (uint8_t *)((uintptr_t)base_addr + WOLFBOOT_PARTITION_SIZE - (8 + home_off));
|
||||||
for (i = 0; i < 8; i++)
|
for (i = 0; i < 8; i++)
|
||||||
dst[i] = src[i];
|
dst[i] = src[i];
|
||||||
|
|
||||||
/* Force to F0 last sector flag in 0, so that the sector '4' is 'updated' */
|
/* Force to F0 last sector flag in 0, so that the sector '4' is 'updated' */
|
||||||
dst = (uint8_t *)(base_addr + WOLFBOOT_PARTITION_SIZE - (8 + home_off));
|
dst = (uint8_t *)((uintptr_t)base_addr + WOLFBOOT_PARTITION_SIZE - (8 + home_off));
|
||||||
dst[0] = 0xF0;
|
dst[0] = 0xF0;
|
||||||
|
|
||||||
/* Check if still there */
|
/* Check if still there */
|
||||||
|
|
|
@ -26,8 +26,8 @@
|
||||||
/* Must also define DEBUG_WOLFSSL in user_settings.h */
|
/* Must also define DEBUG_WOLFSSL in user_settings.h */
|
||||||
#define WOLFBOOT_HASH_SHA256
|
#define WOLFBOOT_HASH_SHA256
|
||||||
#define IMAGE_HEADER_SIZE 256
|
#define IMAGE_HEADER_SIZE 256
|
||||||
#define UNIT_TEST
|
#define WC_RSA_BLINDING
|
||||||
#define WC_NO_HARDEN
|
#define ECC_TIMING_RESISTANT
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include "libwolfboot.c"
|
#include "libwolfboot.c"
|
||||||
#include <check.h>
|
#include <check.h>
|
||||||
|
|
|
@ -41,12 +41,8 @@
|
||||||
#endif
|
#endif
|
||||||
#define ECC_TIMING_RESISTANT
|
#define ECC_TIMING_RESISTANT
|
||||||
|
|
||||||
#define WOLFSSL_USER_SETTINGS
|
|
||||||
#define UNIT_TEST
|
|
||||||
#define WOLFBOOT_SIGN_ECC256
|
|
||||||
#define KEYSTORE_PUBKEY_SIZE KEYSTORE_PUBKEY_SIZE_ECC256
|
#define KEYSTORE_PUBKEY_SIZE KEYSTORE_PUBKEY_SIZE_ECC256
|
||||||
|
|
||||||
#define __WOLFBOOT
|
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <check.h>
|
#include <check.h>
|
||||||
|
@ -75,16 +71,16 @@ const uint32_t keyvault_size = KEYVAULT_OBJ_SIZE * KEYVAULT_MAX_ITEMS + 2 * WOLF
|
||||||
|
|
||||||
#include "txt_filler.h"
|
#include "txt_filler.h"
|
||||||
|
|
||||||
const char dante_filler[KEYVAULT_OBJ_SIZE] = DANTE_FILLER;
|
char dante_filler[KEYVAULT_OBJ_SIZE] = DANTE_FILLER;
|
||||||
|
|
||||||
START_TEST (test_store_and_load_objs) {
|
START_TEST (test_store_and_load_objs) {
|
||||||
CK_ULONG id_tok, id_obj;
|
CK_ULONG id_tok, id_obj;
|
||||||
int type;
|
int type;
|
||||||
int ret, readonly;
|
int ret, readonly;
|
||||||
void *store = NULL;
|
void *store = NULL;
|
||||||
const char secret1[] = "Everyone gets Friday off.";
|
char secret1[] = "Everyone gets Friday off.";
|
||||||
const char secret2[] = "This is just a test string.";
|
char secret2[] = "This is just a test string.";
|
||||||
const char short_string[] = "Short string";
|
char short_string[] = "Short string";
|
||||||
char secret_rd[KEYVAULT_OBJ_SIZE];
|
char secret_rd[KEYVAULT_OBJ_SIZE];
|
||||||
|
|
||||||
type = DYNAMIC_TYPE_ECC;
|
type = DYNAMIC_TYPE_ECC;
|
||||||
|
|
|
@ -30,13 +30,7 @@
|
||||||
#define EXT_FLASH 1
|
#define EXT_FLASH 1
|
||||||
#define PART_UPDATE_EXT 1
|
#define PART_UPDATE_EXT 1
|
||||||
#define PART_SWAP_EXT 1
|
#define PART_SWAP_EXT 1
|
||||||
|
|
||||||
|
|
||||||
#define WC_NO_HARDEN
|
|
||||||
|
|
||||||
#define WOLFSSL_USER_SETTINGS
|
|
||||||
#define ENCRYPT_KEY "123456789abcdef0123456789abcdef0123456789abcdef"
|
#define ENCRYPT_KEY "123456789abcdef0123456789abcdef0123456789abcdef"
|
||||||
#define UNIT_TEST
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <check.h>
|
#include <check.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
|
@ -20,14 +20,13 @@
|
||||||
* along with this program; if not, write to the Free Software
|
* along with this program; if not, write to the Free Software
|
||||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
|
||||||
*/
|
*/
|
||||||
#define WOLFBOOT_HASH_SHA256
|
#ifndef WOLFBOOT_HASH_SHA256
|
||||||
|
#define WOLFBOOT_HASH_SHA256
|
||||||
|
#endif
|
||||||
#define IMAGE_HEADER_SIZE 256
|
#define IMAGE_HEADER_SIZE 256
|
||||||
#define UNIT_TEST
|
|
||||||
#define WC_NO_HARDEN
|
|
||||||
#define MOCK_ADDRESS_UPDATE 0xCC000000
|
#define MOCK_ADDRESS_UPDATE 0xCC000000
|
||||||
#define MOCK_ADDRESS_BOOT 0xCD000000
|
#define MOCK_ADDRESS_BOOT 0xCD000000
|
||||||
#define MOCK_ADDRESS_SWAP 0xCE000000
|
#define MOCK_ADDRESS_SWAP 0xCE000000
|
||||||
|
|
||||||
#define TEST_SIZE_SMALL 5300
|
#define TEST_SIZE_SMALL 5300
|
||||||
#define TEST_SIZE_LARGE 9800
|
#define TEST_SIZE_LARGE 9800
|
||||||
|
|
||||||
|
@ -35,6 +34,7 @@
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include "user_settings.h"
|
||||||
#include "wolfboot/wolfboot.h"
|
#include "wolfboot/wolfboot.h"
|
||||||
#include "libwolfboot.c"
|
#include "libwolfboot.c"
|
||||||
#include "update_flash.c"
|
#include "update_flash.c"
|
||||||
|
@ -51,7 +51,7 @@ const char *argv0;
|
||||||
Suite *wolfboot_suite(void);
|
Suite *wolfboot_suite(void);
|
||||||
|
|
||||||
int wolfBoot_staged_ok = 0;
|
int wolfBoot_staged_ok = 0;
|
||||||
uint32_t *wolfBoot_stage_address = (uint32_t *) 0xFFFFFFFF;
|
const uint32_t *wolfBoot_stage_address = (uint32_t *) 0xFFFFFFFF;
|
||||||
|
|
||||||
void do_boot(const uint32_t *address)
|
void do_boot(const uint32_t *address)
|
||||||
{
|
{
|
||||||
|
@ -73,13 +73,13 @@ static void reset_mock_stats(void)
|
||||||
static void prepare_flash(void)
|
static void prepare_flash(void)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
ret = mmap_file("/tmp/wolfboot-unit-ext-file.bin", MOCK_ADDRESS_UPDATE,
|
ret = mmap_file("/tmp/wolfboot-unit-ext-file.bin", (void *)MOCK_ADDRESS_UPDATE,
|
||||||
WOLFBOOT_PARTITION_SIZE, NULL);
|
WOLFBOOT_PARTITION_SIZE, NULL);
|
||||||
fail_if(ret < 0);
|
fail_if(ret < 0);
|
||||||
ret = mmap_file("/tmp/wolfboot-unit-int-file.bin", MOCK_ADDRESS_BOOT,
|
ret = mmap_file("/tmp/wolfboot-unit-int-file.bin", (void *)MOCK_ADDRESS_BOOT,
|
||||||
WOLFBOOT_PARTITION_SIZE, NULL);
|
WOLFBOOT_PARTITION_SIZE, NULL);
|
||||||
fail_if(ret < 0);
|
fail_if(ret < 0);
|
||||||
ret = mmap_file("/tmp/wolfboot-unit-swap.bin", MOCK_ADDRESS_SWAP,
|
ret = mmap_file("/tmp/wolfboot-unit-swap.bin", (void *)MOCK_ADDRESS_SWAP,
|
||||||
WOLFBOOT_SECTOR_SIZE, NULL);
|
WOLFBOOT_SECTOR_SIZE, NULL);
|
||||||
fail_if(ret < 0);
|
fail_if(ret < 0);
|
||||||
hal_flash_unlock();
|
hal_flash_unlock();
|
||||||
|
@ -90,9 +90,9 @@ static void prepare_flash(void)
|
||||||
|
|
||||||
static void cleanup_flash(void)
|
static void cleanup_flash(void)
|
||||||
{
|
{
|
||||||
munmap(MOCK_ADDRESS_UPDATE, WOLFBOOT_PARTITION_SIZE);
|
munmap((void *)MOCK_ADDRESS_UPDATE, WOLFBOOT_PARTITION_SIZE);
|
||||||
munmap(MOCK_ADDRESS_BOOT, WOLFBOOT_PARTITION_SIZE);
|
munmap((void *)MOCK_ADDRESS_BOOT, WOLFBOOT_PARTITION_SIZE);
|
||||||
munmap(MOCK_ADDRESS_SWAP, WOLFBOOT_SECTOR_SIZE);
|
munmap((void *)MOCK_ADDRESS_SWAP, WOLFBOOT_SECTOR_SIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -102,7 +102,7 @@ static int add_payload(uint8_t part, uint32_t version, uint32_t size)
|
||||||
uint32_t word;
|
uint32_t word;
|
||||||
uint16_t word16;
|
uint16_t word16;
|
||||||
int i;
|
int i;
|
||||||
uint8_t *base = WOLFBOOT_PARTITION_BOOT_ADDRESS;
|
uint8_t *base = (uint8_t *)(uintptr_t)WOLFBOOT_PARTITION_BOOT_ADDRESS;
|
||||||
int ret;
|
int ret;
|
||||||
wc_Sha256 sha;
|
wc_Sha256 sha;
|
||||||
uint8_t digest[SHA256_DIGEST_SIZE];
|
uint8_t digest[SHA256_DIGEST_SIZE];
|
||||||
|
@ -113,27 +113,27 @@ static int add_payload(uint8_t part, uint32_t version, uint32_t size)
|
||||||
|
|
||||||
|
|
||||||
if (part == PART_UPDATE)
|
if (part == PART_UPDATE)
|
||||||
base = WOLFBOOT_PARTITION_UPDATE_ADDRESS;
|
base = (uint8_t *)(uintptr_t)WOLFBOOT_PARTITION_UPDATE_ADDRESS;
|
||||||
srandom(part); /* Ensure reproducible "random" image */
|
srandom(part); /* Ensure reproducible "random" image */
|
||||||
|
|
||||||
|
|
||||||
hal_flash_unlock();
|
hal_flash_unlock();
|
||||||
hal_flash_write(base, "WOLF", 4);
|
hal_flash_write((uintptr_t)base, "WOLF", 4);
|
||||||
printf("Written magic: \"WOLF\"\n");
|
printf("Written magic: \"WOLF\"\n");
|
||||||
|
|
||||||
hal_flash_write(base + 4, &size, 4);
|
hal_flash_write((uintptr_t)base + 4, (void *)&size, 4);
|
||||||
printf("Written size: %u\n", size);
|
printf("Written size: %u\n", size);
|
||||||
|
|
||||||
/* Headers */
|
/* Headers */
|
||||||
word = 4 << 16 | HDR_VERSION;
|
word = 4 << 16 | HDR_VERSION;
|
||||||
hal_flash_write(base + 8, &word, 4);
|
hal_flash_write((uintptr_t)base + 8, (void *)&word, 4);
|
||||||
hal_flash_write(base + 12, &version, 4);
|
hal_flash_write((uintptr_t)base + 12, (void *)&version, 4);
|
||||||
printf("Written version: %u\n", version);
|
printf("Written version: %u\n", version);
|
||||||
|
|
||||||
word = 2 << 16 | HDR_IMG_TYPE;
|
word = 2 << 16 | HDR_IMG_TYPE;
|
||||||
hal_flash_write(base + 16, &word, 4);
|
hal_flash_write((uintptr_t)base + 16, (void *)&word, 4);
|
||||||
word16 = HDR_IMG_TYPE_AUTH_NONE | HDR_IMG_TYPE_APP;
|
word16 = HDR_IMG_TYPE_AUTH_NONE | HDR_IMG_TYPE_APP;
|
||||||
hal_flash_write(base + 20, &word16, 2);
|
hal_flash_write((uintptr_t)base + 20, (void *)&word16, 2);
|
||||||
printf("Written img_type: %04X\n", word16);
|
printf("Written img_type: %04X\n", word16);
|
||||||
|
|
||||||
/* Add 28B header to sha calculation */
|
/* Add 28B header to sha calculation */
|
||||||
|
@ -145,7 +145,7 @@ static int add_payload(uint8_t part, uint32_t version, uint32_t size)
|
||||||
size += IMAGE_HEADER_SIZE;
|
size += IMAGE_HEADER_SIZE;
|
||||||
for (i = IMAGE_HEADER_SIZE; i < size; i+=4) {
|
for (i = IMAGE_HEADER_SIZE; i < size; i+=4) {
|
||||||
uint32_t word = (random() << 16) | random();
|
uint32_t word = (random() << 16) | random();
|
||||||
hal_flash_write(base + i, &word, 4);
|
hal_flash_write((uintptr_t)base + i, (void *)&word, 4);
|
||||||
}
|
}
|
||||||
for (i = IMAGE_HEADER_SIZE; i < size; i+= WOLFBOOT_SHA_BLOCK_SIZE) {
|
for (i = IMAGE_HEADER_SIZE; i < size; i+= WOLFBOOT_SHA_BLOCK_SIZE) {
|
||||||
int len = WOLFBOOT_SHA_BLOCK_SIZE;
|
int len = WOLFBOOT_SHA_BLOCK_SIZE;
|
||||||
|
@ -163,8 +163,8 @@ static int add_payload(uint8_t part, uint32_t version, uint32_t size)
|
||||||
wc_Sha256Free(&sha);
|
wc_Sha256Free(&sha);
|
||||||
|
|
||||||
word = SHA256_DIGEST_SIZE << 16 | HDR_SHA256;
|
word = SHA256_DIGEST_SIZE << 16 | HDR_SHA256;
|
||||||
hal_flash_write(base + DIGEST_TLV_OFF_IN_HDR, &word, 4);
|
hal_flash_write((uintptr_t)base + DIGEST_TLV_OFF_IN_HDR, (void *)&word, 4);
|
||||||
hal_flash_write(base + DIGEST_TLV_OFF_IN_HDR + 4, digest,
|
hal_flash_write((uintptr_t)base + DIGEST_TLV_OFF_IN_HDR + 4, digest,
|
||||||
SHA256_DIGEST_SIZE);
|
SHA256_DIGEST_SIZE);
|
||||||
printf("SHA digest written\n");
|
printf("SHA digest written\n");
|
||||||
for (i = 0; i < 32; i++) {
|
for (i = 0; i < 32; i++) {
|
||||||
|
@ -293,7 +293,7 @@ START_TEST (test_invalid_update_type) {
|
||||||
add_payload(PART_BOOT, 1, TEST_SIZE_SMALL);
|
add_payload(PART_BOOT, 1, TEST_SIZE_SMALL);
|
||||||
add_payload(PART_UPDATE, 2, TEST_SIZE_SMALL);
|
add_payload(PART_UPDATE, 2, TEST_SIZE_SMALL);
|
||||||
ext_flash_unlock();
|
ext_flash_unlock();
|
||||||
ext_flash_write(WOLFBOOT_PARTITION_UPDATE_ADDRESS + 20, &word16, 2);
|
ext_flash_write(WOLFBOOT_PARTITION_UPDATE_ADDRESS + 20, (void *)&word16, 2);
|
||||||
ext_flash_lock();
|
ext_flash_lock();
|
||||||
wolfBoot_update_trigger();
|
wolfBoot_update_trigger();
|
||||||
wolfBoot_start();
|
wolfBoot_start();
|
||||||
|
@ -311,7 +311,7 @@ START_TEST (test_update_toolarge) {
|
||||||
add_payload(PART_UPDATE, 2, TEST_SIZE_LARGE);
|
add_payload(PART_UPDATE, 2, TEST_SIZE_LARGE);
|
||||||
/* Change the size in the header to be larger than the actual size */
|
/* Change the size in the header to be larger than the actual size */
|
||||||
ext_flash_unlock();
|
ext_flash_unlock();
|
||||||
ext_flash_write(WOLFBOOT_PARTITION_UPDATE_ADDRESS + 4, &very_large, 4);
|
ext_flash_write(WOLFBOOT_PARTITION_UPDATE_ADDRESS + 4, (void *)&very_large, 4);
|
||||||
ext_flash_lock();
|
ext_flash_lock();
|
||||||
|
|
||||||
wolfBoot_update_trigger();
|
wolfBoot_update_trigger();
|
||||||
|
|
|
@ -20,17 +20,17 @@
|
||||||
* along with this program; if not, write to the Free Software
|
* along with this program; if not, write to the Free Software
|
||||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
|
||||||
*/
|
*/
|
||||||
#define WOLFBOOT_HASH_SHA256
|
#ifndef WOLFBOOT_HASH_SHA256
|
||||||
|
#define WOLFBOOT_HASH_SHA256
|
||||||
|
#endif
|
||||||
#define IMAGE_HEADER_SIZE 256
|
#define IMAGE_HEADER_SIZE 256
|
||||||
#define UNIT_TEST
|
|
||||||
#define WC_NO_HARDEN
|
|
||||||
#define MOCK_ADDRESS_UPDATE 0xCC000000
|
#define MOCK_ADDRESS_UPDATE 0xCC000000
|
||||||
#define MOCK_ADDRESS_BOOT 0xCD000000
|
#define MOCK_ADDRESS_BOOT 0xCD000000
|
||||||
#define MOCK_ADDRESS_SWAP 0xCE000000
|
#define MOCK_ADDRESS_SWAP 0xCE000000
|
||||||
#include "target.h"
|
#include "target.h"
|
||||||
static __thread unsigned char wolfboot_ram[2 * WOLFBOOT_PARTITION_SIZE + IMAGE_HEADER_SIZE];
|
static __thread unsigned char wolfboot_ram[2 * WOLFBOOT_PARTITION_SIZE + IMAGE_HEADER_SIZE];
|
||||||
|
|
||||||
#define WOLFBOOT_LOAD_ADDRESS ((wolfboot_ram + IMAGE_HEADER_SIZE))
|
#define WOLFBOOT_LOAD_ADDRESS (((uintptr_t)wolfboot_ram + IMAGE_HEADER_SIZE))
|
||||||
|
|
||||||
#define TEST_SIZE_SMALL 5300
|
#define TEST_SIZE_SMALL 5300
|
||||||
#define TEST_SIZE_LARGE 9800
|
#define TEST_SIZE_LARGE 9800
|
||||||
|
@ -39,6 +39,7 @@ static __thread unsigned char wolfboot_ram[2 * WOLFBOOT_PARTITION_SIZE + IMAGE_H
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include "user_settings.h"
|
||||||
#include "wolfboot/wolfboot.h"
|
#include "wolfboot/wolfboot.h"
|
||||||
#include "libwolfboot.c"
|
#include "libwolfboot.c"
|
||||||
#include "update_ram.c"
|
#include "update_ram.c"
|
||||||
|
@ -55,7 +56,7 @@ const char *argv0;
|
||||||
Suite *wolfboot_suite(void);
|
Suite *wolfboot_suite(void);
|
||||||
|
|
||||||
int wolfBoot_staged_ok = 0;
|
int wolfBoot_staged_ok = 0;
|
||||||
uint32_t *wolfBoot_stage_address = (uint32_t *) 0xFFFFFFFF;
|
const uint32_t *wolfBoot_stage_address = (uint32_t *) 0xFFFFFFFF;
|
||||||
|
|
||||||
void do_boot(const uint32_t *address)
|
void do_boot(const uint32_t *address)
|
||||||
{
|
{
|
||||||
|
@ -65,12 +66,12 @@ void do_boot(const uint32_t *address)
|
||||||
return;
|
return;
|
||||||
wolfBoot_staged_ok++;
|
wolfBoot_staged_ok++;
|
||||||
wolfBoot_stage_address = address;
|
wolfBoot_stage_address = address;
|
||||||
ck_assert_uint_eq(address, WOLFBOOT_LOAD_ADDRESS);
|
ck_assert_uint_eq((uintptr_t)address, WOLFBOOT_LOAD_ADDRESS);
|
||||||
memset(&boot_image, 0, sizeof(boot_image));
|
memset(&boot_image, 0, sizeof(boot_image));
|
||||||
printf("Called do_boot with address %p\n", address);
|
printf("Called do_boot with address %p\n", address);
|
||||||
ck_assert_uint_eq(0,wolfBoot_open_image_address(&boot_image, wolfboot_ram));
|
ck_assert_uint_eq(0,wolfBoot_open_image_address(&boot_image, wolfboot_ram));
|
||||||
boot_image.hdr = wolfboot_ram;
|
boot_image.hdr = wolfboot_ram;
|
||||||
boot_image.fw_base = WOLFBOOT_LOAD_ADDRESS;
|
boot_image.fw_base = (void *)(uintptr_t)WOLFBOOT_LOAD_ADDRESS;
|
||||||
boot_image.part = 0;
|
boot_image.part = 0;
|
||||||
boot_image.not_ext = 1;
|
boot_image.not_ext = 1;
|
||||||
ck_assert_uint_eq(0,wolfBoot_verify_integrity(&boot_image));
|
ck_assert_uint_eq(0,wolfBoot_verify_integrity(&boot_image));
|
||||||
|
@ -92,10 +93,10 @@ uint32_t get_version_ramloaded(void)
|
||||||
static void prepare_flash(void)
|
static void prepare_flash(void)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
ret = mmap_file("/tmp/wolfboot-unit-ext-file.bin", MOCK_ADDRESS_UPDATE,
|
ret = mmap_file("/tmp/wolfboot-unit-ext-file.bin", (void *)(uintptr_t)MOCK_ADDRESS_UPDATE,
|
||||||
WOLFBOOT_PARTITION_SIZE + IMAGE_HEADER_SIZE, NULL);
|
WOLFBOOT_PARTITION_SIZE + IMAGE_HEADER_SIZE, NULL);
|
||||||
fail_if(ret < 0);
|
fail_if(ret < 0);
|
||||||
ret = mmap_file("/tmp/wolfboot-unit-int-file.bin", MOCK_ADDRESS_BOOT,
|
ret = mmap_file("/tmp/wolfboot-unit-int-file.bin", (void *)(uintptr_t)MOCK_ADDRESS_BOOT,
|
||||||
WOLFBOOT_PARTITION_SIZE + IMAGE_HEADER_SIZE, NULL);
|
WOLFBOOT_PARTITION_SIZE + IMAGE_HEADER_SIZE, NULL);
|
||||||
fail_if(ret < 0);
|
fail_if(ret < 0);
|
||||||
ext_flash_unlock();
|
ext_flash_unlock();
|
||||||
|
@ -106,8 +107,8 @@ static void prepare_flash(void)
|
||||||
|
|
||||||
static void cleanup_flash(void)
|
static void cleanup_flash(void)
|
||||||
{
|
{
|
||||||
munmap(WOLFBOOT_PARTITION_BOOT_ADDRESS, WOLFBOOT_PARTITION_SIZE + IMAGE_HEADER_SIZE);
|
munmap((void *)WOLFBOOT_PARTITION_BOOT_ADDRESS, WOLFBOOT_PARTITION_SIZE + IMAGE_HEADER_SIZE);
|
||||||
munmap(WOLFBOOT_PARTITION_UPDATE_ADDRESS, WOLFBOOT_PARTITION_SIZE + IMAGE_HEADER_SIZE);
|
munmap((void *)WOLFBOOT_PARTITION_UPDATE_ADDRESS, WOLFBOOT_PARTITION_SIZE + IMAGE_HEADER_SIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -117,7 +118,7 @@ static int add_payload(uint8_t part, uint32_t version, uint32_t size)
|
||||||
uint32_t word;
|
uint32_t word;
|
||||||
uint16_t word16;
|
uint16_t word16;
|
||||||
int i;
|
int i;
|
||||||
uint8_t *base = WOLFBOOT_PARTITION_BOOT_ADDRESS;
|
uint8_t *base = (uint8_t *)WOLFBOOT_PARTITION_BOOT_ADDRESS;
|
||||||
int ret;
|
int ret;
|
||||||
wc_Sha256 sha;
|
wc_Sha256 sha;
|
||||||
uint8_t digest[SHA256_DIGEST_SIZE];
|
uint8_t digest[SHA256_DIGEST_SIZE];
|
||||||
|
@ -128,27 +129,27 @@ static int add_payload(uint8_t part, uint32_t version, uint32_t size)
|
||||||
|
|
||||||
|
|
||||||
if (part == PART_UPDATE)
|
if (part == PART_UPDATE)
|
||||||
base = WOLFBOOT_PARTITION_UPDATE_ADDRESS;
|
base = (uint8_t *)WOLFBOOT_PARTITION_UPDATE_ADDRESS;
|
||||||
srandom(part); /* Ensure reproducible "random" image */
|
srandom(part); /* Ensure reproducible "random" image */
|
||||||
|
|
||||||
|
|
||||||
ext_flash_unlock();
|
ext_flash_unlock();
|
||||||
ext_flash_write(base, "WOLF", 4);
|
ext_flash_write((uintptr_t)base, "WOLF", 4);
|
||||||
printf("Written magic: \"WOLF\"\n");
|
printf("Written magic: \"WOLF\"\n");
|
||||||
|
|
||||||
ext_flash_write(base + 4, &size, 4);
|
ext_flash_write((uintptr_t)base + 4, (void *)&size, 4);
|
||||||
printf("Written size: %u\n", size);
|
printf("Written size: %u\n", size);
|
||||||
|
|
||||||
/* Headers */
|
/* Headers */
|
||||||
word = 4 << 16 | HDR_VERSION;
|
word = 4 << 16 | HDR_VERSION;
|
||||||
ext_flash_write(base + 8, &word, 4);
|
ext_flash_write((uintptr_t)base + 8, (void *)&word, 4);
|
||||||
ext_flash_write(base + 12, &version, 4);
|
ext_flash_write((uintptr_t)base + 12, (void *)&version, 4);
|
||||||
printf("Written version: %u\n", version);
|
printf("Written version: %u\n", version);
|
||||||
|
|
||||||
word = 2 << 16 | HDR_IMG_TYPE;
|
word = 2 << 16 | HDR_IMG_TYPE;
|
||||||
ext_flash_write(base + 16, &word, 4);
|
ext_flash_write((uintptr_t)base + 16, (void *)&word, 4);
|
||||||
word16 = HDR_IMG_TYPE_AUTH_NONE | HDR_IMG_TYPE_APP;
|
word16 = HDR_IMG_TYPE_AUTH_NONE | HDR_IMG_TYPE_APP;
|
||||||
ext_flash_write(base + 20, &word16, 2);
|
ext_flash_write((uintptr_t)base + 20, (void *)&word16, 2);
|
||||||
printf("Written img_type: %04X\n", word16);
|
printf("Written img_type: %04X\n", word16);
|
||||||
|
|
||||||
/* Add 28B header to sha calculation */
|
/* Add 28B header to sha calculation */
|
||||||
|
@ -160,7 +161,7 @@ static int add_payload(uint8_t part, uint32_t version, uint32_t size)
|
||||||
size += IMAGE_HEADER_SIZE;
|
size += IMAGE_HEADER_SIZE;
|
||||||
for (i = IMAGE_HEADER_SIZE; i < size; i+=4) {
|
for (i = IMAGE_HEADER_SIZE; i < size; i+=4) {
|
||||||
uint32_t word = (random() << 16) | random();
|
uint32_t word = (random() << 16) | random();
|
||||||
ext_flash_write(base + i, &word, 4);
|
ext_flash_write((uintptr_t)base + i, (void *)&word, 4);
|
||||||
}
|
}
|
||||||
for (i = IMAGE_HEADER_SIZE; i < size; i+= WOLFBOOT_SHA_BLOCK_SIZE) {
|
for (i = IMAGE_HEADER_SIZE; i < size; i+= WOLFBOOT_SHA_BLOCK_SIZE) {
|
||||||
int len = WOLFBOOT_SHA_BLOCK_SIZE;
|
int len = WOLFBOOT_SHA_BLOCK_SIZE;
|
||||||
|
@ -178,8 +179,8 @@ static int add_payload(uint8_t part, uint32_t version, uint32_t size)
|
||||||
wc_Sha256Free(&sha);
|
wc_Sha256Free(&sha);
|
||||||
|
|
||||||
word = SHA256_DIGEST_SIZE << 16 | HDR_SHA256;
|
word = SHA256_DIGEST_SIZE << 16 | HDR_SHA256;
|
||||||
ext_flash_write(base + DIGEST_TLV_OFF_IN_HDR, &word, 4);
|
ext_flash_write((uintptr_t)base + DIGEST_TLV_OFF_IN_HDR, (void *)&word, 4);
|
||||||
ext_flash_write(base + DIGEST_TLV_OFF_IN_HDR + 4, digest,
|
ext_flash_write((uintptr_t)base + DIGEST_TLV_OFF_IN_HDR + 4, digest,
|
||||||
SHA256_DIGEST_SIZE);
|
SHA256_DIGEST_SIZE);
|
||||||
printf("SHA digest written\n");
|
printf("SHA digest written\n");
|
||||||
for (i = 0; i < 32; i++) {
|
for (i = 0; i < 32; i++) {
|
||||||
|
@ -302,7 +303,7 @@ START_TEST (test_invalid_update_type) {
|
||||||
add_payload(PART_BOOT, 1, TEST_SIZE_SMALL);
|
add_payload(PART_BOOT, 1, TEST_SIZE_SMALL);
|
||||||
add_payload(PART_UPDATE, 2, TEST_SIZE_SMALL);
|
add_payload(PART_UPDATE, 2, TEST_SIZE_SMALL);
|
||||||
ext_flash_unlock();
|
ext_flash_unlock();
|
||||||
ext_flash_write(WOLFBOOT_PARTITION_UPDATE_ADDRESS + 20, &word16, 2);
|
ext_flash_write(WOLFBOOT_PARTITION_UPDATE_ADDRESS + 20, (void *)&word16, 2);
|
||||||
ext_flash_lock();
|
ext_flash_lock();
|
||||||
wolfBoot_update_trigger();
|
wolfBoot_update_trigger();
|
||||||
wolfBoot_start();
|
wolfBoot_start();
|
||||||
|
@ -319,7 +320,7 @@ START_TEST (test_update_toolarge) {
|
||||||
add_payload(PART_UPDATE, 2, TEST_SIZE_LARGE);
|
add_payload(PART_UPDATE, 2, TEST_SIZE_LARGE);
|
||||||
/* Change the size in the header to be larger than the actual size */
|
/* Change the size in the header to be larger than the actual size */
|
||||||
ext_flash_unlock();
|
ext_flash_unlock();
|
||||||
ext_flash_write(WOLFBOOT_PARTITION_UPDATE_ADDRESS + 4, &very_large, 4);
|
ext_flash_write(WOLFBOOT_PARTITION_UPDATE_ADDRESS + 4, (void *)&very_large, 4);
|
||||||
ext_flash_lock();
|
ext_flash_lock();
|
||||||
|
|
||||||
wolfBoot_update_trigger();
|
wolfBoot_update_trigger();
|
||||||
|
|
Loading…
Reference in New Issue