From 4db7728a82611e4ff1c59a044436bd013905787e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Ga=C5=82at?= Date: Thu, 22 Aug 2024 10:39:22 +0000 Subject: [PATCH] fprotect: fix minimal fprotect area MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit on nrf53 the minimal size of fprotect is bigger than size of mfg_storage Signed-off-by: Robert Gałat --- .../pm_static_nrf52840dk_nrf52840.yml | 9 ++++ .../pm_static_nrf52840dk_nrf52840_release.yml | 9 ++++ .../pm_static_nrf5340dk_nrf5340_cpuapp.yml | 53 +++++++++++++------ ...tatic_nrf5340dk_nrf5340_cpuapp_release.yml | 53 +++++++++++++------ .../pm_static_nrf54l15pdk_nrf54l15_cpuapp.yml | 9 ++++ ...ic_nrf54l15pdk_nrf54l15_cpuapp_release.yml | 9 ++++ .../pm_static_thingy53_nrf5340_cpuapp.yml | 53 +++++++++++++------ subsys/sal/sid_pal/src/sid_mfg_storage.c | 6 +-- 8 files changed, 146 insertions(+), 55 deletions(-) diff --git a/samples/sid_end_device/pm_static_nrf52840dk_nrf52840.yml b/samples/sid_end_device/pm_static_nrf52840dk_nrf52840.yml index 10bf45af8a..c884e9dad5 100644 --- a/samples/sid_end_device/pm_static_nrf52840dk_nrf52840.yml +++ b/samples/sid_end_device/pm_static_nrf52840dk_nrf52840.yml @@ -51,6 +51,15 @@ mcuboot_secondary: share_size: - mcuboot_primary size: 0xf6000 +mfg_fprotect: + address: 0xff000 + align: + start: CONFIG_FPROTECT_BLOCK_SIZE + end_address: 0x100000 + region: flash_primary + size: 0x1000 + span: + - mfg_storage mfg_storage: address: 0xff000 end_address: 0x100000 diff --git a/samples/sid_end_device/pm_static_nrf52840dk_nrf52840_release.yml b/samples/sid_end_device/pm_static_nrf52840dk_nrf52840_release.yml index 10bf45af8a..c884e9dad5 100644 --- a/samples/sid_end_device/pm_static_nrf52840dk_nrf52840_release.yml +++ b/samples/sid_end_device/pm_static_nrf52840dk_nrf52840_release.yml @@ -51,6 +51,15 @@ mcuboot_secondary: share_size: - mcuboot_primary size: 0xf6000 +mfg_fprotect: + address: 0xff000 + align: + start: CONFIG_FPROTECT_BLOCK_SIZE + end_address: 0x100000 + region: flash_primary + size: 0x1000 + span: + - mfg_storage mfg_storage: address: 0xff000 end_address: 0x100000 diff --git a/samples/sid_end_device/pm_static_nrf5340dk_nrf5340_cpuapp.yml b/samples/sid_end_device/pm_static_nrf5340dk_nrf5340_cpuapp.yml index 5764ee5a3e..af1596b695 100644 --- a/samples/sid_end_device/pm_static_nrf5340dk_nrf5340_cpuapp.yml +++ b/samples/sid_end_device/pm_static_nrf5340dk_nrf5340_cpuapp.yml @@ -1,21 +1,21 @@ EMPTY_0: - address: 0xfe000 - end_address: 0xff000 + address: 0xfa000 + end_address: 0xfc000 placement: after: - settings_storage region: flash_primary - size: 0x1000 + size: 0x2000 app: address: 0x8200 - end_address: 0xfc000 + end_address: 0xf8000 region: flash_primary - size: 0xf3e00 + size: 0xefe00 external_flash: - address: 0x134000 + address: 0x130000 end_address: 0x800000 region: external_flash - size: 0x6cc000 + size: 0x6d0000 mcuboot: address: 0x0 end_address: 0x8000 @@ -33,12 +33,12 @@ mcuboot_pad: size: 0x200 mcuboot_primary: address: 0x8000 - end_address: 0xfc000 + end_address: 0xf8000 orig_span: &id001 - mcuboot_pad - app region: flash_primary - size: 0xf4000 + size: 0xf0000 span: *id001 mcuboot_primary_1: address: 0x0 @@ -48,34 +48,53 @@ mcuboot_primary_1: size: 0x40000 mcuboot_primary_app: address: 0x8200 - end_address: 0xfc000 + end_address: 0xf8000 orig_span: &id002 - app region: flash_primary - size: 0xf3e00 + size: 0xefe00 span: *id002 mcuboot_secondary: address: 0x0 device: DT_CHOSEN(nordic_pm_ext_flash) - end_address: 0xf4000 + end_address: 0xf0000 placement: align: start: 0x4 region: external_flash share_size: - mcuboot_primary - size: 0xf4000 + size: 0xf0000 mcuboot_secondary_1: - address: 0xf4000 + address: 0xf0000 device: DT_CHOSEN(nordic_pm_ext_flash) - end_address: 0x134000 + end_address: 0x130000 region: external_flash size: 0x40000 +mfg_fprotect: + address: 0xfc000 + align: + start: CONFIG_FPROTECT_BLOCK_SIZE + end_address: 0x100000 + region: flash_primary + size: 0x4000 + span: + - mfg_storage_pad + - mfg_storage mfg_storage: address: 0xff000 end_address: 0x100000 region: flash_primary size: 0x1000 +mfg_storage_pad: + address: 0xfc000 + end_address: 0xff000 + placement: + align: + start: CONFIG_FPROTECT_BLOCK_SIZE + before: mfg_storage + region: flash_primary + size: 0x3000 otp: address: 0xff8100 end_address: 0xff83fc @@ -103,8 +122,8 @@ rpmsg_nrf53_sram: region: sram_primary size: 0x10000 settings_storage: - address: 0xfc000 - end_address: 0xfe000 + address: 0xf8000 + end_address: 0xfa000 placement: align: start: 0x4000 diff --git a/samples/sid_end_device/pm_static_nrf5340dk_nrf5340_cpuapp_release.yml b/samples/sid_end_device/pm_static_nrf5340dk_nrf5340_cpuapp_release.yml index 5764ee5a3e..af1596b695 100644 --- a/samples/sid_end_device/pm_static_nrf5340dk_nrf5340_cpuapp_release.yml +++ b/samples/sid_end_device/pm_static_nrf5340dk_nrf5340_cpuapp_release.yml @@ -1,21 +1,21 @@ EMPTY_0: - address: 0xfe000 - end_address: 0xff000 + address: 0xfa000 + end_address: 0xfc000 placement: after: - settings_storage region: flash_primary - size: 0x1000 + size: 0x2000 app: address: 0x8200 - end_address: 0xfc000 + end_address: 0xf8000 region: flash_primary - size: 0xf3e00 + size: 0xefe00 external_flash: - address: 0x134000 + address: 0x130000 end_address: 0x800000 region: external_flash - size: 0x6cc000 + size: 0x6d0000 mcuboot: address: 0x0 end_address: 0x8000 @@ -33,12 +33,12 @@ mcuboot_pad: size: 0x200 mcuboot_primary: address: 0x8000 - end_address: 0xfc000 + end_address: 0xf8000 orig_span: &id001 - mcuboot_pad - app region: flash_primary - size: 0xf4000 + size: 0xf0000 span: *id001 mcuboot_primary_1: address: 0x0 @@ -48,34 +48,53 @@ mcuboot_primary_1: size: 0x40000 mcuboot_primary_app: address: 0x8200 - end_address: 0xfc000 + end_address: 0xf8000 orig_span: &id002 - app region: flash_primary - size: 0xf3e00 + size: 0xefe00 span: *id002 mcuboot_secondary: address: 0x0 device: DT_CHOSEN(nordic_pm_ext_flash) - end_address: 0xf4000 + end_address: 0xf0000 placement: align: start: 0x4 region: external_flash share_size: - mcuboot_primary - size: 0xf4000 + size: 0xf0000 mcuboot_secondary_1: - address: 0xf4000 + address: 0xf0000 device: DT_CHOSEN(nordic_pm_ext_flash) - end_address: 0x134000 + end_address: 0x130000 region: external_flash size: 0x40000 +mfg_fprotect: + address: 0xfc000 + align: + start: CONFIG_FPROTECT_BLOCK_SIZE + end_address: 0x100000 + region: flash_primary + size: 0x4000 + span: + - mfg_storage_pad + - mfg_storage mfg_storage: address: 0xff000 end_address: 0x100000 region: flash_primary size: 0x1000 +mfg_storage_pad: + address: 0xfc000 + end_address: 0xff000 + placement: + align: + start: CONFIG_FPROTECT_BLOCK_SIZE + before: mfg_storage + region: flash_primary + size: 0x3000 otp: address: 0xff8100 end_address: 0xff83fc @@ -103,8 +122,8 @@ rpmsg_nrf53_sram: region: sram_primary size: 0x10000 settings_storage: - address: 0xfc000 - end_address: 0xfe000 + address: 0xf8000 + end_address: 0xfa000 placement: align: start: 0x4000 diff --git a/samples/sid_end_device/pm_static_nrf54l15pdk_nrf54l15_cpuapp.yml b/samples/sid_end_device/pm_static_nrf54l15pdk_nrf54l15_cpuapp.yml index 2aae80fef6..1cd6552041 100644 --- a/samples/sid_end_device/pm_static_nrf54l15pdk_nrf54l15_cpuapp.yml +++ b/samples/sid_end_device/pm_static_nrf54l15pdk_nrf54l15_cpuapp.yml @@ -49,6 +49,15 @@ mcuboot_secondary: share_size: - mcuboot_primary size: 0xb7000 +mfg_fprotect: + address: 0x17c000 + align: + start: CONFIG_FPROTECT_BLOCK_SIZE + end_address: 0x17d000 + region: flash_primary + size: 0x1000 + span: + - mfg_storage mfg_storage: address: 0x17c000 end_address: 0x17d000 diff --git a/samples/sid_end_device/pm_static_nrf54l15pdk_nrf54l15_cpuapp_release.yml b/samples/sid_end_device/pm_static_nrf54l15pdk_nrf54l15_cpuapp_release.yml index 2aae80fef6..1cd6552041 100644 --- a/samples/sid_end_device/pm_static_nrf54l15pdk_nrf54l15_cpuapp_release.yml +++ b/samples/sid_end_device/pm_static_nrf54l15pdk_nrf54l15_cpuapp_release.yml @@ -49,6 +49,15 @@ mcuboot_secondary: share_size: - mcuboot_primary size: 0xb7000 +mfg_fprotect: + address: 0x17c000 + align: + start: CONFIG_FPROTECT_BLOCK_SIZE + end_address: 0x17d000 + region: flash_primary + size: 0x1000 + span: + - mfg_storage mfg_storage: address: 0x17c000 end_address: 0x17d000 diff --git a/samples/sid_end_device/pm_static_thingy53_nrf5340_cpuapp.yml b/samples/sid_end_device/pm_static_thingy53_nrf5340_cpuapp.yml index c28ba886ec..1c8b639fab 100644 --- a/samples/sid_end_device/pm_static_thingy53_nrf5340_cpuapp.yml +++ b/samples/sid_end_device/pm_static_thingy53_nrf5340_cpuapp.yml @@ -1,21 +1,21 @@ EMPTY_0: - address: 0xfe000 - end_address: 0xff000 + address: 0xfa000 + end_address: 0xfc000 placement: after: - settings_storage region: flash_primary - size: 0x1000 + size: 0x2000 app: address: 0x8200 - end_address: 0xfc000 + end_address: 0xf8000 region: flash_primary - size: 0xf3e00 + size: 0xefe00 external_flash: - address: 0x134000 + address: 0x130000 end_address: 0x800000 region: external_flash - size: 0x6cc000 + size: 0x6d0000 mcuboot: address: 0x0 end_address: 0x8000 @@ -33,12 +33,12 @@ mcuboot_pad: size: 0x200 mcuboot_primary: address: 0x8000 - end_address: 0xfc000 + end_address: 0xf8000 orig_span: &id001 - app - mcuboot_pad region: flash_primary - size: 0xf4000 + size: 0xf0000 span: *id001 mcuboot_primary_1: address: 0x0 @@ -48,34 +48,53 @@ mcuboot_primary_1: size: 0x40000 mcuboot_primary_app: address: 0x8200 - end_address: 0xfc000 + end_address: 0xf8000 orig_span: &id002 - app region: flash_primary - size: 0xf3e00 + size: 0xefe00 span: *id002 mcuboot_secondary: address: 0x0 device: DT_CHOSEN(nordic_pm_ext_flash) - end_address: 0xf4000 + end_address: 0xf0000 placement: align: start: 0x4 region: external_flash share_size: - mcuboot_primary - size: 0xf4000 + size: 0xf0000 mcuboot_secondary_1: - address: 0xf4000 + address: 0xf0000 device: DT_CHOSEN(nordic_pm_ext_flash) - end_address: 0x134000 + end_address: 0x130000 region: external_flash size: 0x40000 +mfg_fprotect: + address: 0xfc000 + align: + start: CONFIG_FPROTECT_BLOCK_SIZE + end_address: 0x100000 + region: flash_primary + size: 0x4000 + span: + - mfg_storage_pad + - mfg_storage mfg_storage: address: 0xff000 end_address: 0x100000 region: flash_primary size: 0x1000 +mfg_storage_pad: + address: 0xfc000 + end_address: 0xff000 + placement: + align: + start: CONFIG_FPROTECT_BLOCK_SIZE + before: mfg_storage + region: flash_primary + size: 0x3000 otp: address: 0xff8100 end_address: 0xff83fc @@ -103,8 +122,8 @@ rpmsg_nrf53_sram: region: sram_primary size: 0x10000 settings_storage: - address: 0xfc000 - end_address: 0xfe000 + address: 0xf8000 + end_address: 0xfa000 placement: align: start: 0x4000 diff --git a/subsys/sal/sid_pal/src/sid_mfg_storage.c b/subsys/sal/sid_pal/src/sid_mfg_storage.c index 9b923b1463..c74a769a61 100644 --- a/subsys/sal/sid_pal/src/sid_mfg_storage.c +++ b/subsys/sal/sid_pal/src/sid_mfg_storage.c @@ -158,8 +158,7 @@ static bool sid_pal_mfg_store_search_for_tag(uint16_t tag, } /* Go to the next TLV */ - address += (MFG_STORE_TLV_HEADER_SIZE + - ROUND_UP(length, WORD_SIZE)); + address += (MFG_STORE_TLV_HEADER_SIZE + ROUND_UP(length, WORD_SIZE)); if ((uintptr_t)(address + MFG_STORE_TLV_HEADER_SIZE + WORD_SIZE) > nrf_mfg_store_region.addr_end) { @@ -202,8 +201,7 @@ void sid_pal_mfg_store_init(sid_pal_mfg_store_region_t mfg_store_region) #ifdef CONFIG_SIDEWALK_CRYPTO_PSA_KEY_STORAGE sid_mfg_storage_secure_init(); #endif /* CONFIG_SIDEWALK_CRYPTO_PSA_KEY_STORAGE */ - - int err = fprotect_area(PM_MFG_STORAGE_ADDRESS, PM_MFG_STORAGE_SIZE); + int err = fprotect_area(PM_MFG_FPROTECT_ADDRESS, PM_MFG_FPROTECT_SIZE); if (err) { LOG_ERR("Flash protect failed %d", err); }