Skip to content

Commit eade7d7

Browse files
[nrf mergeup] Merge upstream to commit 1e1be9b
Bring in additional upstream changes since v1.3.1. (This is being done in a separate mergeup to provide an additional convenient bisection point for this repository.) Signed-off-by: Marti Bolivar <[email protected]>
2 parents 5402bbe + 1e1be9b commit eade7d7

File tree

25 files changed

+1204
-347
lines changed

25 files changed

+1204
-347
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ matrix:
2323
# separated by ',' and each list of values is run sequentially in the
2424
# defined order.
2525
- os: linux
26-
env: MULTI_FEATURES="sig-rsa overwrite-only,sig-ecdsa overwrite-only" TEST=sim
26+
env: MULTI_FEATURES="sig-rsa overwrite-only,sig-ecdsa overwrite-only,multiimage overwrite-only" TEST=sim
2727
- os: linux
2828
env: MULTI_FEATURES="sig-rsa validate-primary-slot,sig-ecdsa validate-primary-slot" TEST=sim
2929
- os: linux

NOTICE

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,6 @@ The Apache Software Foundation (http://www.apache.org/).
66

77
Portions of this software were developed at
88
Runtime Inc, copyright 2015.
9+
10+
Portions of this software were developed at
11+
Arm Limited, copyright 2019.

boot/bootutil/include/bootutil/enc_key.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ int boot_enc_set_key(uint8_t slot, uint8_t *enckey);
5353
int boot_enc_load(const struct image_header *hdr, const struct flash_area *fap,
5454
uint8_t *enckey);
5555
bool boot_enc_valid(const struct flash_area *fap);
56+
void boot_enc_mark_keys_invalid(void);
5657
void boot_encrypt(const struct flash_area *fap, uint32_t off, uint32_t sz,
5758
uint32_t blk_off, uint8_t *buf);
5859
void boot_enc_zeroize(void);

boot/bootutil/include/bootutil/image.h

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
* under the License.
1818
*/
1919

20+
/*
21+
* Modifications are Copyright (c) 2019 Arm Limited.
22+
*/
23+
2024
#ifndef H_IMAGE_
2125
#define H_IMAGE_
2226

@@ -76,6 +80,7 @@ struct flash_area;
7680
#define IMAGE_TLV_ED25519 0x24 /* ed25519 of hash output */
7781
#define IMAGE_TLV_ENC_RSA2048 0x30 /* Key encrypted with RSA-OAEP-2048 */
7882
#define IMAGE_TLV_ENC_KW128 0x31 /* Key encrypted with AES-KW-128 */
83+
#define IMAGE_TLV_DEPENDENCY 0x40 /* Image depends on other image */
7984

8085
struct image_version {
8186
uint8_t iv_major;
@@ -84,16 +89,24 @@ struct image_version {
8489
uint32_t iv_build_num;
8590
};
8691

92+
struct image_dependency {
93+
uint8_t image_id; /* Image index (from 0) */
94+
struct image_version image_min_version; /* Indicates at minimum which
95+
* version of firmware must be
96+
* available to satisfy compliance
97+
*/
98+
};
99+
87100
/** Image header. All fields are in little endian byte order. */
88101
struct image_header {
89102
uint32_t ih_magic;
90103
uint32_t ih_load_addr;
91-
uint16_t ih_hdr_size; /* Size of image header (bytes). */
92-
uint16_t _pad1;
93-
uint32_t ih_img_size; /* Does not include header. */
94-
uint32_t ih_flags; /* IMAGE_F_[...]. */
104+
uint16_t ih_hdr_size; /* Size of image header (bytes). */
105+
uint16_t ih_protect_tlv_size; /* Size of protected TLV area (bytes). */
106+
uint32_t ih_img_size; /* Does not include header. */
107+
uint32_t ih_flags; /* IMAGE_F_[...]. */
95108
struct image_version ih_ver;
96-
uint32_t _pad2;
109+
uint32_t _pad1;
97110
};
98111

99112
/** Image TLV header. All fields in little endian. */

boot/bootutil/src/bootutil_misc.c

Lines changed: 69 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
* under the License.
1818
*/
1919

20+
/*
21+
* Modifications are Copyright (c) 2019 Arm Limited.
22+
*/
23+
2024
#include <assert.h>
2125
#include <string.h>
2226
#include <inttypes.h>
@@ -168,13 +172,12 @@ boot_magic_off(const struct flash_area *fap)
168172
int
169173
boot_status_entries(const struct flash_area *fap)
170174
{
171-
switch (fap->fa_id) {
172-
case FLASH_AREA_IMAGE_PRIMARY:
173-
case FLASH_AREA_IMAGE_SECONDARY:
174-
return BOOT_STATUS_STATE_COUNT * BOOT_STATUS_MAX_ENTRIES;
175-
case FLASH_AREA_IMAGE_SCRATCH:
175+
if (fap->fa_id == FLASH_AREA_IMAGE_SCRATCH) {
176176
return BOOT_STATUS_STATE_COUNT;
177-
default:
177+
} else if ((fap->fa_id == FLASH_AREA_IMAGE_PRIMARY) ||
178+
(fap->fa_id == FLASH_AREA_IMAGE_SECONDARY)) {
179+
return BOOT_STATUS_STATE_COUNT * BOOT_STATUS_MAX_ENTRIES;
180+
} else {
178181
return BOOT_EBADARGS;
179182
}
180183
}
@@ -194,7 +197,7 @@ boot_status_off(const struct flash_area *fap)
194197
}
195198

196199
uint32_t
197-
boot_swap_type_off(const struct flash_area *fap)
200+
boot_swap_info_off(const struct flash_area *fap)
198201
{
199202
return fap->fa_size - BOOT_MAGIC_SZ - BOOT_MAX_ALIGN * 3;
200203
}
@@ -232,6 +235,7 @@ boot_read_swap_state(const struct flash_area *fap,
232235
{
233236
uint32_t magic[BOOT_MAGIC_ARR_SZ];
234237
uint32_t off;
238+
uint8_t swap_info;
235239
int rc;
236240

237241
off = boot_magic_off(fap);
@@ -245,14 +249,19 @@ boot_read_swap_state(const struct flash_area *fap,
245249
state->magic = boot_magic_decode(magic);
246250
}
247251

248-
off = boot_swap_type_off(fap);
249-
rc = flash_area_read_is_empty(fap, off, &state->swap_type,
250-
sizeof state->swap_type);
252+
off = boot_swap_info_off(fap);
253+
rc = flash_area_read_is_empty(fap, off, &swap_info, sizeof swap_info);
251254
if (rc < 0) {
252255
return BOOT_EFLASH;
253256
}
257+
258+
/* Extract the swap type and image number */
259+
state->swap_type = BOOT_GET_SWAP_TYPE(swap_info);
260+
state->image_num = BOOT_GET_IMAGE_NUM(swap_info);
261+
254262
if (rc == 1 || state->swap_type > BOOT_SWAP_TYPE_REVERT) {
255263
state->swap_type = BOOT_SWAP_TYPE_NONE;
264+
state->image_num = 0;
256265
}
257266

258267
off = boot_copy_done_off(fap);
@@ -291,16 +300,14 @@ boot_read_swap_state_by_id(int flash_area_id, struct boot_swap_state *state)
291300
const struct flash_area *fap;
292301
int rc;
293302

294-
switch (flash_area_id) {
295-
case FLASH_AREA_IMAGE_SCRATCH:
296-
case FLASH_AREA_IMAGE_PRIMARY:
297-
case FLASH_AREA_IMAGE_SECONDARY:
303+
if (flash_area_id == FLASH_AREA_IMAGE_SCRATCH ||
304+
flash_area_id == FLASH_AREA_IMAGE_PRIMARY ||
305+
flash_area_id == FLASH_AREA_IMAGE_SECONDARY) {
298306
rc = flash_area_open(flash_area_id, &fap);
299307
if (rc != 0) {
300308
return BOOT_EFLASH;
301309
}
302-
break;
303-
default:
310+
} else {
304311
return BOOT_EBADARGS;
305312
}
306313

@@ -494,14 +501,18 @@ boot_write_image_ok(const struct flash_area *fap)
494501
* resume in case of an unexpected reset.
495502
*/
496503
int
497-
boot_write_swap_type(const struct flash_area *fap, uint8_t swap_type)
504+
boot_write_swap_info(const struct flash_area *fap, uint8_t swap_type,
505+
uint8_t image_num)
498506
{
499507
uint32_t off;
500-
501-
off = boot_swap_type_off(fap);
502-
BOOT_LOG_DBG("writing swap_type; fa_id=%d off=0x%x (0x%x), swap_type=0x%x",
503-
fap->fa_id, off, fap->fa_off + off, swap_type);
504-
return boot_write_trailer_byte(fap, off, swap_type);
508+
uint8_t swap_info;
509+
510+
BOOT_SET_SWAP_INFO(swap_info, image_num, swap_type);
511+
off = boot_swap_info_off(fap);
512+
BOOT_LOG_DBG("writing swap_info; fa_id=%d off=0x%x (0x%x), swap_type=0x%x"
513+
" image_num=0x%x",
514+
fap->fa_id, off, fap->fa_off + off, swap_type, image_num);
515+
return boot_write_trailer_byte(fap, off, swap_info);
505516
}
506517

507518
int
@@ -648,7 +659,7 @@ boot_set_pending(int permanent)
648659
} else {
649660
swap_type = BOOT_SWAP_TYPE_TEST;
650661
}
651-
rc = boot_write_swap_type(fap, swap_type);
662+
rc = boot_write_swap_info(fap, swap_type, 0);
652663
}
653664

654665
flash_area_close(fap);
@@ -730,3 +741,38 @@ boot_set_confirmed(void)
730741
flash_area_close(fap);
731742
return rc;
732743
}
744+
745+
#if (BOOT_IMAGE_NUMBER > 1)
746+
/**
747+
* Check if the version of the image is not older than required.
748+
*
749+
* @param req Required minimal image version.
750+
* @param ver Version of the image to be checked.
751+
*
752+
* @return 0 if the version is sufficient, nonzero otherwise.
753+
*/
754+
int
755+
boot_is_version_sufficient(struct image_version *req,
756+
struct image_version *ver)
757+
{
758+
if (ver->iv_major > req->iv_major) {
759+
return 0;
760+
}
761+
if (ver->iv_major < req->iv_major) {
762+
return BOOT_EBADVERSION;
763+
}
764+
/* The major version numbers are equal. */
765+
if (ver->iv_minor > req->iv_minor) {
766+
return 0;
767+
}
768+
if (ver->iv_minor < req->iv_minor) {
769+
return BOOT_EBADVERSION;
770+
}
771+
/* The minor version numbers are equal. */
772+
if (ver->iv_revision < req->iv_revision) {
773+
return BOOT_EBADVERSION;
774+
}
775+
776+
return 0;
777+
}
778+
#endif /* BOOT_IMAGE_NUMBER > 1 */

0 commit comments

Comments
 (0)