Skip to content

Commit

Permalink
[nrf noup][nrfconnect] Fix DAC migration for MRAM-based devices.
Browse files Browse the repository at this point in the history
A wrong device type was used for MRAM-based devices and
inappropriate factory data addresses.

Signed-off-by: Arkadiusz Balys <[email protected]>
  • Loading branch information
ArekBalysNordic committed Jan 3, 2025
1 parent 2340e0a commit ad8ba68
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
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

0 comments on commit ad8ba68

Please sign in to comment.