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

Restyle [nrfconnect] Enabled factory data protection from write in internal memory #20206

Closed
wants to merge 3 commits into from
Closed
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
1 change: 1 addition & 0 deletions config/nrfconnect/chip-module/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ config CHIP_DEBUG_SYMBOLS
config CHIP_FACTORY_DATA
bool "Enable Factory Data support"
select ZCBOR
select FPROTECT
help
Enables support for reading factory data from flash memory partition.
It requires factory_data partition to exist in the partition manager
Expand Down
6 changes: 6 additions & 0 deletions docs/guides/nrfconnect_factory_data_configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ For the nRF Connect platform, the factory data is stored by default in a
separate partition of the internal flash memory. This helps to keep the factory
data secure by applying hardware write protection.

> Note: Due to hardware limitations, in the nRF Connect platform, protection
> against writing can be applied only to the internal memory partition. The
> [Fprotect](https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrf/libraries/others/fprotect.html)
> is the hardware flash protection driver, and we used it to ensure write
> protection of the factory data partition in internal flash memory.
<p align="center">
<img src="../../examples/platform/nrfconnect/doc/images/Logo_RGB_H-small.png" alt="Nordic Semiconductor logo"/>
<img src="../../examples/platform/nrfconnect/doc/images/nRF52840-DK-small.png" alt="nRF52840 DK">
Expand Down
10 changes: 9 additions & 1 deletion src/platform/nrfconnect/FactoryDataProvider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,15 @@ CHIP_ERROR FactoryDataProvider<FlashFactoryData>::Init()
uint8_t * factoryData = nullptr;
size_t factoryDataSize;

CHIP_ERROR error = mFlashFactoryData.GetFactoryDataPartition(factoryData, factoryDataSize);
CHIP_ERROR error = mFlashFactoryData.ProtectFactoryDataPartitionAgainstWrite();

if (error != CHIP_NO_ERROR)
{
ChipLogError(DeviceLayer, "Failed to protect the factory data partition");
return error;
}

error = mFlashFactoryData.GetFactoryDataPartition(factoryData, factoryDataSize);

if (error != CHIP_NO_ERROR)
{
Expand Down
9 changes: 9 additions & 0 deletions src/platform/nrfconnect/FactoryDataProvider.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <platform/DeviceInstanceInfoProvider.h>

#include <drivers/flash.h>
#include <fprotect.h>
#include <pm_config.h>

#include "FactoryDataParser.h"
Expand All @@ -37,6 +38,12 @@ struct InternalFlashFactoryData
dataSize = PM_FACTORY_DATA_SIZE;
return CHIP_NO_ERROR;
}

CHIP_ERROR ProtectFactoryDataPartitionAgainstWrite()
{
int ret = fprotect_area(PM_FACTORY_DATA_ADDRESS, PM_FACTORY_DATA_SIZE);
return System::MapErrorZephyr(ret);
}
};

struct ExternalFlashFactoryData
Expand All @@ -56,6 +63,8 @@ struct ExternalFlashFactoryData
return CHIP_NO_ERROR;
}

CHIP_ERROR ProtectFactoryDataPartitionAgainstWrite() { return CHIP_ERROR_NOT_IMPLEMENTED; }

const struct device * mFlashDevice = DEVICE_DT_GET(DT_CHOSEN(zephyr_flash_controller));
uint8_t mFactoryDataBuffer[PM_FACTORY_DATA_SIZE];
};
Expand Down