Setting and using NVS and BT Settings with Static Partition Manager

Hi!
We are currently in the process of migrating our nrf5 SDK code to NCS, on nrf52833-based hardware.
After being stuck for a while on the basic init process of MCUBoot, I was finally able to get MCUBoot to run our app (see previous ticket RE: MCUBoot, Zephyr, and static partition manager - Thanks Sigurd for all your help!). 

My problem currently is that all the MCUBoot changes, most specifically the Static Partition Manager, have caused our app to consistently fail on boot with the following error:

 "bt_settings: settings_subsys_init failed (err -45)".

Reading up on this, err 45 = EDEADLK (https://docs.zephyrproject.org/apidoc/latest/group__system__errno.html#ga55cc70ce0ba661298f3c412095dfeeb6), which is "Resource deadlock avoided".

Before all the changes leading to MCUBoot + PM, I had been able to init and use the NVS without issues, as well as the BT settings init.

Pre-MCUBoot and PM, I had defined our flash like so (in overlay):

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/delete-node/ &storage_partition;
&flash0 {
partitions {
compatible = "fixed-partitions";
#address-cells = <1>;
#size-cells = <1>;
...
settings_partition: partition@77000 {
label = "settings";
reg = <0x00077000 0x00002000>;
};
storage_partition: partition@79000 {
label = "storage";
reg = <0x00079000 0x00007000>;
};
};
};
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

With chosen as follows (same overlay file):

Fullscreen
1
2
3
4
5
6
/{
chosen {
...
zephyr,settings-partition = &settings_partition;
};
};
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

And our NVS init code is as follows:

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#define NVS_PARTITION storage_partition
#define NVS_PARTITION_DEVICE FIXED_PARTITION_DEVICE(NVS_PARTITION)
#define NVS_PARTITION_OFFSET FIXED_PARTITION_OFFSET(NVS_PARTITION)
static struct nvs_fs fs;
void flash_manager_init()
{
int rc=0;
struct flash_pages_info info;
/* define the nvs file system by settings with:
* sector_size equal to the pagesize,
* 3 sectors
* starting at NVS_PARTITION_OFFSET
*/
fs.flash_device = NVS_PARTITION_DEVICE;
if (!device_is_ready(fs.flash_device)) {
printk("Flash device %s is not ready\n", fs.flash_device->name);
return;
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Our new pm_static.yml file is:

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
app:
address: 0x9200
end_address: 0x40000
region: flash_primary
size: 0x36e00
mcuboot:
address: 0x0
end_address: 0x9000
placement:
before:
- mcuboot_primary
region: flash_primary
size: 0x9000
mcuboot_pad:
address: 0x9000
end_address: 0x9200
placement:
align:
start: 0x1000
before:
- mcuboot_primary_app
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

I have tried to change the number of sectors to 7 to match the 7 sectors for storage_partition in the pm_static.yml, to no avail (same -45 error).

My questions are as follows:

  • How do I go about replacing the "zephyr,settings-partition = &settings_partition;" once I remove the flash0 override from our overlay file?
  • How do I go about pointing from my code (like the existing NVS_PARTITION define) to the PM partitions for nvs init, if possible?
  • If not possible - how do I go about initing and using nvs?

Thanks!

Roi