Skip to content

Commit 808d60f

Browse files
de-nordicFrancescoSer
authored andcommitted
tests/bootloader/bl_validation_neg: Reworking test internals
Use PARTITION_ macros to get partition information. Remove part that checks for existence of bl_storage/provision at specified address, as tests missing the part would not pass anyway, due to regex requirements in testcase.yaml. Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
1 parent 1c5db87 commit 808d60f

1 file changed

Lines changed: 18 additions & 14 deletions

File tree

  • tests/subsys/bootloader/bl_validation_neg/src

tests/subsys/bootloader/bl_validation_neg/src/main.c

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@
1212
#include <zephyr/sys/reboot.h>
1313
#include <zephyr/sys/util.h>
1414
#include <bl_storage.h>
15-
#include <fw_info.h>
16-
1715

16+
#define S0_SLOT_ADDRESS PARTITION_ADDRESS(s0_image)
17+
#define S0_SLOT_SIZE PARTITION_SIZE(s0_image)
18+
#define S1_SLOT_ADDRESS PARTITION_ADDRESS(s1_image)
1819

1920
/* These symbols are defined in linker scripts. */
2021
extern const uint32_t _ext_apis_size[];
@@ -30,11 +31,11 @@ ZTEST(test_bl_validation_neg, test_validation_neg1)
3031
uint32_t copy_len = ROUND_UP((uint32_t)_flash_used, 4);
3132

3233
/* Round up to at least the next SPU region. */
33-
uint32_t new_addr = ROUND_UP(PM_ADDRESS + (PM_SIZE / 2), 0x8000);
34+
uint32_t new_addr = ROUND_UP(S0_SLOT_ADDRESS + (S0_SLOT_SIZE / 2), 0x8000);
3435

3536
const struct fw_info s1_info = {
3637
.magic = {FIRMWARE_INFO_MAGIC},
37-
.total_size = PM_S0_ADDRESS - PM_S1_ADDRESS,
38+
.total_size = S0_SLOT_ADDRESS - S1_SLOT_ADDRESS,
3839
.size = ((uint32_t)_flash_used),
3940
.version = CONFIG_FW_INFO_FIRMWARE_VERSION + 1,
4041
.address = new_addr,
@@ -45,15 +46,15 @@ ZTEST(test_bl_validation_neg, test_validation_neg1)
4546
.ext_api_request_num = 0,
4647
};
4748

48-
const struct fw_info *s1_info_copied = fw_info_find(PM_S1_ADDRESS);
49+
const struct fw_info *s1_info_copied = fw_info_find(S1_SLOT_ADDRESS);
4950

5051
if (s1_info_copied) {
5152
/* Second boot */
5253
zassert_not_equal(CONFIG_FW_INFO_VALID_VAL,
5354
s1_info_copied->valid, "Failed to invalidate S1.\r\n");
54-
zassert_equal((uint32_t)s1_info_copied, PM_S1_ADDRESS,
55+
zassert_equal((uint32_t)s1_info_copied, S1_SLOT_ADDRESS,
5556
"S1 info found at wrong address.\r\n");
56-
int ret = nrfx_nvmc_page_erase(PM_S1_ADDRESS);
57+
int ret = nrfx_nvmc_page_erase(S1_SLOT_ADDRESS);
5758

5859
zassert_equal(0, ret, "Erase failed.\r\n");
5960
} else {
@@ -68,22 +69,22 @@ ZTEST(test_bl_validation_neg, test_validation_neg1)
6869

6970
zassert_equal(0, ret, "Erase failed.\r\n");
7071
}
71-
nrfx_nvmc_words_write(new_addr, (const uint32_t *)PM_ADDRESS,
72+
nrfx_nvmc_words_write(new_addr, (const uint32_t *)S0_SLOT_ADDRESS,
7273
copy_len / 4);
7374

7475
/* Write to S1 */
75-
nrfx_nvmc_words_write(PM_S1_ADDRESS, &s1_info,
76+
nrfx_nvmc_words_write(S1_SLOT_ADDRESS, &s1_info,
7677
ROUND_UP(sizeof(s1_info), 4) / 4);
7778

78-
zassert_mem_equal(&s1_info, (void *)PM_S1_ADDRESS,
79+
zassert_mem_equal(&s1_info, (void *)S1_SLOT_ADDRESS,
7980
sizeof(s1_info), "Failed to copy S1 info.\r\n");
8081

81-
s1_info_copied = fw_info_find(PM_S1_ADDRESS);
82-
zassert_equal((uint32_t)s1_info_copied, PM_S1_ADDRESS,
82+
s1_info_copied = fw_info_find(S1_SLOT_ADDRESS);
83+
zassert_equal((uint32_t)s1_info_copied, S1_SLOT_ADDRESS,
8384
"S1 info wrongly copied.\r\n");
8485

8586
/* Modify copied app's validation info */
86-
memcpy(val_info_buf, (const uint32_t *)(PM_ADDRESS + copy_len),
87+
memcpy(val_info_buf, (const uint32_t *)(S0_SLOT_ADDRESS + copy_len),
8788
VAL_INFO_MAX_SIZE);
8889

8990
struct __packed {
@@ -111,7 +112,8 @@ ZTEST(test_bl_validation_neg, test_validation_neg1)
111112

112113
ZTEST(test_bl_validation_neg, test_validation_neg2)
113114
{
114-
#if PM_PROVISION_ADDRESS > 0xF00000
115+
/* testcase.yaml nrf52 variant of test does not catch below regex */
116+
#ifndef CONFIG_SOC_SERIES_NRF52
115117
uint32_t num_public_keys = num_public_keys_read();
116118
bool any_valid = false;
117119

@@ -133,6 +135,8 @@ ZTEST(test_bl_validation_neg, test_validation_neg2)
133135
"keys.");
134136
sys_reboot(0);
135137
zassert_true(false, "should not come here.");
138+
#else
139+
ztest_test_skip();
136140
#endif
137141
}
138142

0 commit comments

Comments
 (0)