Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[nrf toup][nrfconnect] Fix DAC migration for MRAM-based devices. #526

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/platform/nrfconnect/FactoryDataProvider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@
#include <psa/crypto.h>
#include <zephyr/drivers/flash.h>

#ifdef CONFIG_SOC_FLASH_NRF_MRAM
static const struct device * const kFlashDev = DEVICE_DT_GET_OR_NULL(DT_CHOSEN(zephyr_flash));
#else
static const struct device * const kFlashDev = DEVICE_DT_GET_OR_NULL(DT_CHOSEN(zephyr_flash_controller));
#endif // CONFIG_SOC_FLASH_NRF_MRAM
#endif

namespace chip {
Expand Down Expand Up @@ -188,7 +192,12 @@ CHIP_ERROR FactoryDataProvider<FlashFactoryData>::MoveDACPrivateKeyToSecureStora
// Check once again if the saved key has attributes set before removing it from the factory data set.
VerifyOrReturnError(psa_get_key_attributes(mDACPrivKeyId, &attributes) == PSA_SUCCESS, CHIP_ERROR_INTERNAL);

// Get the actual block size.
// Try to get the actual block size.
if (!device_is_ready(kFlashDev))
{
ChipLogError(DeviceLayer, "Flash device is not ready.");
return CHIP_ERROR_INTERNAL;
}
const flash_parameters * flashParameters = flash_get_parameters(kFlashDev);
VerifyOrReturnError(flashParameters, CHIP_ERROR_INTERNAL);

Expand Down
15 changes: 10 additions & 5 deletions src/platform/nrfconnect/FactoryDataProvider.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,10 @@
#include <zephyr/storage/flash_map.h>
#define FACTORY_DATA_SIZE DT_REG_SIZE(DT_ALIAS(factory_data))
#define FACTORY_DATA_LOCATION_ADDRESS DT_REG_ADDR(DT_ALIAS(factory_data_location))
#if FACTORY_DATA_LOCATION_ADDRESS
#define FACTORY_DATA_ADDRESS (DT_REG_ADDR(DT_ALIAS(factory_data)) + FACTORY_DATA_LOCATION_ADDRESS)
#else
#if defined(CONFIG_SOC_FLASH_NRF_MRAM) && !FACTORY_DATA_LOCATION_ADDRESS
#error factory_data_location alias must be defined while using device with MRAM memory.
#endif
#define FACTORY_DATA_ADDRESS DT_REG_ADDR(DT_ALIAS(factory_data))
#endif // if FACTORY_DATA_LOCATION_ADDRESS
#endif // if defined(USE_PARTITION_MANAGER) && USE_PARTITION_MANAGER == 1

#include <system/SystemError.h>
Expand All @@ -56,7 +55,13 @@ struct InternalFlashFactoryData
{
CHIP_ERROR GetFactoryDataPartition(uint8_t *& data, size_t & dataSize)
{
data = reinterpret_cast<uint8_t *>(FACTORY_DATA_ADDRESS);
data = reinterpret_cast<uint8_t *>(FACTORY_DATA_ADDRESS
#ifdef CONFIG_SOC_FLASH_NRF_MRAM
// For devices that use MRAM we need to point to the factory data partition as absolute
// address to get the proper value.
+ FACTORY_DATA_LOCATION_ADDRESS
#endif
);
dataSize = FACTORY_DATA_SIZE;
return CHIP_NO_ERROR;
}
Expand Down
Loading