This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

pstorage_register() usage in bootloader_init().

I have a use for the pstorage module and while going over the implementations in the Nordic examples and libraries, I found a use-case of pstorage_register() in bootloader_init() (SDK11, file "nRF52_SDK\components\libraries\bootloader_dfu\bootloader.c").

Here's the relevant code:

uint32_t bootloader_init(void)
{ 
  uint32_t                err_code; 
  pstorage_module_param_t storage_params = {.cb = pstorage_callback_handler};     
  //
  err_code = pstorage_init();
  VERIFY_SUCCESS(err_code);
 //
  m_bootsettings_handle.block_id = BOOTLOADER_SETTINGS_ADDRESS;
  err_code = pstorage_register(&storage_params, &m_bootsettings_handle);
  return err_code;
}

I was looking into the pstorage docs and there are 2 things I do not understand:

  1. According to the API spec, the second argument is an output parameter BUT, "bootloader_init()" is setting the "block_id" parameter.
  2. For the first argument, the parameters "block_size" and "block_count" are not configured before calling register.

"dfu_init()" does something similar.

I am confused... Am I looking at this the wrong way?

Cheers, Dirk

Parents Reply Children
  • Hi Aryan, I could not find the answer to my question in the link you provided. Those docs point out that you have to use the raw APIs which is not done in bootloader_init(): Quote: "Dedicated APIs, register, store, and clear are provided to distinguish raw mode from the normal mode. Raw mode APIs have a similar signature to the normal mode. Because this is not a typical use case, raw mode is included for only a few applications like the DFU, and by default is disabled. It is included only if PSTORAGE_RAW_MODE_ENABLE is defined in the pstorage_platform.h header."

    So instead of pstorage_register(), pstorage_raw_register() should have been used if I understand correctly. Unfortunately that's all I could find on the "raw" mode. The "raw" APIs don't seem to have any documentation except for what I can find in the pstorage.h header file. Can I use "Raw" and "Regular" (?) mode at the same time? And back to my original question: the APIs are not used as documented. An [OUT] argument is assigned prior to the function call and an [IN] argument is only partially configured. Could you point me to the correct docs?

    Can you elaborate?

  • Hi The documentation was for a different raw mode within pstorage.c. That is not what you are looking for. There is a separate file pstorage_raw.c (check what file is added into the project, pstorage.c or pstorage_raw.c?) both the files uses the same API pstorage.h but function differently. Unfortunately I do not see any documentation explaining how pstorage_raw.c functionality works.

Related