Skip to content
Merged
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
4 changes: 4 additions & 0 deletions doc/nrf-bm/release_notes/release_notes_changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ Libraries
* All instances of ``pm_failure_evt_t`` to struct :c:struct:`pm_failure_evt` and removed the ``pm_failure_evt_t`` type.
* All instances of ``pm_evt_t`` to struct :c:struct:`pm_evt` and removed the ``pm_evt_t`` type.

* Storage library:

* Updated to use errno instead of nrf_errors.

Samples
=======

Expand Down
87 changes: 40 additions & 47 deletions include/bm/storage/bm_storage.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ struct bm_storage_evt {
/* Specifies if the operation was performed synchronously or asynchronously. */
enum bm_storage_evt_dispatch_type dispatch_type;
/* Result of the operation.
* NRF_SUCCESS on success.
* A positive NRF error otherwise.
* 0 on success.
* A negative errno otherwise.
*/
uint32_t result;
int result;
/* Destination address where the operation was performed. */
uint32_t addr;
/* Pointer to the data that was written to non-volatile memory.
Expand Down Expand Up @@ -143,12 +143,12 @@ struct bm_storage {
*
* @param[in] storage Storage instance to initialize.
*
* @retval NRF_SUCCESS on success.
* @retval NRF_ERROR_NULL If @p storage is @c NULL.
* @retval NRF_ERROR_BUSY If the implementation-specific resource is busy.
* @retval NRF_ERROR_INTERNAL If an implementation-specific internal error occurred.
* @retval 0 on success.
* @retval -EFAULT If @p storage is @c NULL.
Copy link
Contributor

@MirkoCovizzi MirkoCovizzi Nov 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

EINVAL? I prefer to use EINVAL here, but I know that we don't really have a standard for this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the standard in the repo.

Copy link
Contributor

@MirkoCovizzi MirkoCovizzi Nov 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it is not a standard. Some libraries in this repo do it this way. But it's ok, it can stay like this, it's not a big deal.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I'll leave it as is, as it is like this in many other libraries. If we see the need we can align this treewide in a separate PR.

* @retval -EBUSY If the implementation-specific resource is busy.
* @retval -EIO If an implementation-specific internal error occurred.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would use EFAULT for generic failures. IO is more for read/write and such.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We use EFAULT for NULL checks.

Copy link
Contributor

@MirkoCovizzi MirkoCovizzi Nov 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, not in every library. It is not a standard. For user-space, the standard is -EINVAL for invalid parameters, including NULL pointers.

*/
uint32_t bm_storage_init(struct bm_storage *storage);
int bm_storage_init(struct bm_storage *storage);

/**
* @brief Uninitialize a storage instance.
Expand All @@ -158,13 +158,13 @@ uint32_t bm_storage_init(struct bm_storage *storage);
*
* @param[in] storage Storage instance to uninitialize.
*
* @retval NRF_SUCCESS on success.
* @retval NRF_ERROR_NULL If @p storage is @c NULL.
* @retval NRF_ERROR_INVALID_STATE If @p storage is in an invalid state.
* @retval NRF_ERROR_BUSY If the implementation-specific backend is busy with an ongoing operation.
* @retval NRF_ERROR_NOT_SUPPORTED If the backend does not support uninitialization.
* @retval 0 on success.
* @retval -EFAULT If @p storage is @c NULL.
* @retval -EPERM If @p storage is in an invalid state.
* @retval -EBUSY If the implementation-specific backend is busy with an ongoing operation.
* @retval -ENOTSUP If the backend does not support uninitialization.
*/
uint32_t bm_storage_uninit(struct bm_storage *storage);
int bm_storage_uninit(struct bm_storage *storage);

/**
* @brief Read data from a storage instance.
Expand All @@ -174,16 +174,14 @@ uint32_t bm_storage_uninit(struct bm_storage *storage);
* @param[out] dest Destination where the data will be copied to.
* @param[in] len Length of the data to copy (in bytes).
*
* @retval NRF_SUCCESS on success.
* @retval NRF_ERROR_NULL If @p storage is @c NULL.
* @retval NRF_ERROR_INVALID_STATE If @p storage is in an invalid state.
* @retval NRF_ERROR_INVALID_LENGTH If @p len is zero or not a multiple of
* @ref bm_storage_info.program_unit.
* @retval NRF_ERROR_INVALID_ADDR If @p dest or @p src are not 32-bit word aligned, or if they are
* outside the bounds of the memory region configured in @p storage.
* @retval NRF_ERROR_FORBIDDEN If the implementation-specific backend has not been initialized.
* @retval 0 on success.
* @retval -EFAULT If @p storage is @c NULL or if @p dest or @p src are not 32-bit word aligned,
* or if they are outside the bounds of the memory region configured in @p storage.
* @retval -EPERM If @p storage is in an invalid state or if the implementation-specific backend
* has not been initialized.
* @retval -EINVAL If @p len is zero or not a multiple of @ref bm_storage_info.program_unit.
*/
uint32_t bm_storage_read(const struct bm_storage *storage, uint32_t src, void *dest, uint32_t len);
int bm_storage_read(const struct bm_storage *storage, uint32_t src, void *dest, uint32_t len);

/**
* @brief Write data to a storage instance.
Expand All @@ -195,19 +193,17 @@ uint32_t bm_storage_read(const struct bm_storage *storage, uint32_t src, void *d
* @param[in] ctx Pointer to user data, passed to the implementation-specific API function call.
* Can be NULL.
*
* @retval NRF_SUCCESS on success.
* @retval NRF_ERROR_NULL If @p storage is @c NULL.
* @retval NRF_ERROR_INVALID_STATE If @p storage is in an invalid state.
* @retval NRF_ERROR_INVALID_LENGTH If @p len is zero or not a multiple of
* @ref bm_storage_info.program_unit.
* @retval NRF_ERROR_INVALID_ADDR If @p dest or @p src are not 32-bit word aligned, or if they are
* outside the bounds of the memory region configured in @p storage.
* @retval NRF_ERROR_FORBIDDEN If the implementation-specific backend has not been initialized.
* @retval NRF_ERROR_BUSY If the implementation-specific backend is busy with an ongoing operation.
* @retval NRF_ERROR_INTERNAL If an implementation-specific internal error occurred.
* @retval 0 on success.
* @retval -EFAULT If @p storage is @c NULL or if @p dest or @p src are not 32-bit word aligned,
* or if they are outside the bounds of the memory region configured in @p storage.
* @retval -EPERM If @p storage is in an invalid state or if the implementation-specific backend
* has not been initialized.
* @retval -EINVAL If @p len is zero or not a multiple of @ref bm_storage_info.program_unit.
* @retval -EBUSY If the implementation-specific backend is busy with an ongoing operation.
* @retval -EIO If an implementation-specific internal error occurred.
*/
uint32_t bm_storage_write(const struct bm_storage *storage, uint32_t dest, const void *src,
uint32_t len, void *ctx);
int bm_storage_write(const struct bm_storage *storage, uint32_t dest, const void *src,
uint32_t len, void *ctx);

/**
* @brief Erase data in a storage instance.
Expand All @@ -216,19 +212,16 @@ uint32_t bm_storage_write(const struct bm_storage *storage, uint32_t dest, const
* @param[in] ctx Pointer to user data, passed to the implementation-specific API function call.
* Can be NULL.
*
* @retval NRF_SUCCESS on success.
* @retval NRF_ERROR_NULL If @p storage is @c NULL.
* @retval NRF_ERROR_INVALID_STATE If @p storage is in an invalid state.
* @retval NRF_ERROR_INVALID_LENGTH If @p len is zero or not a multiple of
* @ref bm_storage_info.erase_unit.
* @retval NRF_ERROR_INVALID_ADDR If @p addr is outside the bounds of the memory region configured
* in @p storage.
* @retval NRF_ERROR_FORBIDDEN If the implementation-specific backend has not been initialized.
* @retval NRF_ERROR_BUSY If the implementation-specific backend is busy with an ongoing operation.
* @retval NRF_ERROR_NOT_SUPPORTED If the implementation-specific backend does not implement this
* function.
* @retval 0 on success.
* @retval -EFAULT If @p storage is @c NULL or if @p addr is outside the bounds of the memory region
* configured in @p storage.
* @retval -EPERM If @p storage is in an invalid state or if the implementation-specific backend
* has not been initialized.
* @retval -EINVAL If @p len is zero or not a multiple of @ref bm_storage_info.erase_unit.
* @retval -EBUSY If the implementation-specific backend is busy with an ongoing operation.
* @retval -ENOTSUP If the implementation-specific backend does not implement this function.
*/
uint32_t bm_storage_erase(const struct bm_storage *storage, uint32_t addr, uint32_t len, void *ctx);
int bm_storage_erase(const struct bm_storage *storage, uint32_t addr, uint32_t len, void *ctx);

/**
* @brief Query the status of a storage instance.
Expand Down
54 changes: 28 additions & 26 deletions include/bm/storage/bm_storage_backend.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,57 +24,59 @@ extern "C" {
*
* @note This function must be defined by the backend.
*
* @retval NRF_SUCCESS on success.
* @retval NRF_ERROR_BUSY If the implementation-specific resource is busy.
* @retval NRF_ERROR_INTERNAL If an implementation-specific internal error occurred.
* @retval 0 on success.
* @retval -EBUSY If the implementation-specific resource is busy.
* @retval -EIO If an implementation-specific internal error occurred.
*/
uint32_t bm_storage_backend_init(struct bm_storage *storage);
int bm_storage_backend_init(struct bm_storage *storage);
/**
* @brief Uninitialize the storage peripheral.
*
* @note This function is optional. If not defined in the backend, a weak implementation will return
* NRF_ERROR_NOT_SUPPORTED.
* -ENOTSUP.
*
* @retval NRF_SUCCESS on success.
* @retval NRF_ERROR_BUSY If the implementation-specific backend is busy with an ongoing operation.
* @retval NRF_ERROR_NOT_SUPPORTED If the backend does not support uninitialization.
* @retval 0 on success.
* @retval -EBUSY If the implementation-specific backend is busy with an ongoing operation.
* @retval -ENOTSUP If the backend does not support uninitialization.
*/
uint32_t bm_storage_backend_uninit(struct bm_storage *storage);
int bm_storage_backend_uninit(struct bm_storage *storage);
/**
* @brief Read data from non-volatile memory.
*
* @note This function must be defined by the backend.
*
* @retval NRF_SUCCESS on success.
* @retval NRF_ERROR_FORBIDDEN If the implementation-specific backend has not been initialized.
* @retval 0 on success.
* @retval -EPERM If the implementation-specific backend has not been initialized.
* @retval -EFAULT if @p src is not 32-bit aligned.
*/
uint32_t bm_storage_backend_read(const struct bm_storage *storage, uint32_t src, void *dest,
uint32_t len);
int bm_storage_backend_read(const struct bm_storage *storage, uint32_t src, void *dest,
uint32_t len);
/**
* @brief Write bytes to non-volatile memory.
*
* @note This function must be defined by the backend.
*
* @retval NRF_SUCCESS on success.
* @retval NRF_ERROR_FORBIDDEN If the implementation-specific backend has not been initialized.
* @retval NRF_ERROR_BUSY If the implementation-specific backend is busy with an ongoing operation.
* @retval NRF_ERROR_INTERNAL If an implementation-specific internal error occurred.
* @retval 0 on success.
* @retval -EPERM If the implementation-specific backend has not been initialized.
* @retval -EBUSY If the implementation-specific backend is busy with an ongoing operation.
* @retval -EIO If an implementation-specific internal error occurred.
* @retval -EFAULT if @p src is not 32-bit aligned.
*/
uint32_t bm_storage_backend_write(const struct bm_storage *storage, uint32_t dest, const void *src,
uint32_t len, void *ctx);
int bm_storage_backend_write(const struct bm_storage *storage, uint32_t dest, const void *src,
uint32_t len, void *ctx);
/**
* @brief Erase the non-volatile memory.
*
* @note This function is optional. If not defined in the backend, a weak implementation will return
* NRF_ERROR_NOT_SUPPORTED.
* -ENOTSUP.
*
* @retval NRF_SUCCESS on success.
* @retval NRF_ERROR_FORBIDDEN If the implementation-specific backend has not been initialized.
* @retval NRF_ERROR_BUSY If the implementation-specific backend is busy with an ongoing operation.
* @retval NRF_ERROR_NOT_SUPPORTED If the backend does not support erase.
* @retval 0 on success.
* @retval -EPERM If the implementation-specific backend has not been initialized.
* @retval -EBUSY If the implementation-specific backend is busy with an ongoing operation.
* @retval -ENOTSUP If the backend does not support erase.
*/
uint32_t bm_storage_backend_erase(const struct bm_storage *storage, uint32_t addr, uint32_t len,
void *ctx);
int bm_storage_backend_erase(const struct bm_storage *storage, uint32_t addr, uint32_t len,
void *ctx);
/**
* @brief Check if there are any pending operations.
*
Expand Down
Loading