Skip to content

Commit 0e3155a

Browse files
plskeggsmbolivar-nordic
authored andcommitted
net: lib: nrf_cloud: Add optional P-GPS data partition
Add a Kconfig choice for CONFIG_NRF_CLOUD_PGPS_STORAGE. Allow for three choices: a new dedicated P-GPS subsystem partition, the older reuse of the MCUboot secondary partition, or a custom option. Add a new partition manager configuration for P-GPS which is used if CONFIG_NRF_CLOUD_PGPS_STORAGE_PARTITION is enabled. Enable P-GPS partition by default if CONFIG_BUILD_S1_VARIANT is enabled. This defines new Kconfig symbols CONFIG_NRF_CLOUD_PGPS_PARTITION_ALIGN and CONFIG_NRF_CLOUD_PGPS_PARTITION_SIZE. Any application-specified values passed to the nrf_cloud_pgps_init() function are overridden with either the dedicated P-GPS partition location or the MCUboot secondary location, if CONFIG_NRF_CLOUD_PGPS_STORAGE_CUSTOM is not defined. CONFIG_NRF_CLOUD_PGPS_PARTITION_ALIGN accesses the device tree to look up the flash page size, and use that for aligning the P-GPS partition. Add BUILD_ASSERT to ensure partition size is large enough based on the configured number of predictions. Pass any prediction found during initialization with the PGPS_EVT_READY event, so callers can process injections sooner. Signed-off-by: Pete Skeggs <[email protected]>
1 parent aa9a8c8 commit 0e3155a

File tree

5 files changed

+93
-9
lines changed

5 files changed

+93
-9
lines changed

subsys/net/lib/nrf_cloud/Kconfig.nrf_cloud_pgps

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ choice NRF_CLOUD_PGPS_TRANSPORT
7272
default NRF_CLOUD_PGPS_TRANSPORT_NONE
7373

7474
config NRF_CLOUD_PGPS_TRANSPORT_NONE
75-
bool "No transport"
75+
bool "Application-provided transport"
7676
help
7777
Enabling this option will make the nRF Cloud P-GPS library not request
7878
data from nRF Cloud when its APIs are called. This will instead let
@@ -93,4 +93,59 @@ config NRF_CLOUD_PGPS_SOCKET_RETRIES
9393
help
9494
This sets the maximum number of times to retry a download.
9595

96+
choice NRF_CLOUD_PGPS_STORAGE
97+
prompt "nRF Cloud P-GPS persistent storage location"
98+
default NRF_CLOUD_PGPS_STORAGE_PARTITION if BUILD_S1_VARIANT
99+
default NRF_CLOUD_PGPS_STORAGE_MCUBOOT_SECONDARY if BOARD_THINGY91_NRF9160_NS
100+
help
101+
The P-GPS subsystem requires a contiguous section of flash memory in
102+
which to store predictions. The amount required is 2048 bytes times
103+
the number of predictions set by NRF_CLOUD_PGPS_NUM_PREDICTIONS.
104+
If mcuboot DFU is enabled, default to NRF_CLOUD_PGPS_STORAGE_PARTITION.
105+
Otherwise, P-GPS will prevent a successful mcuboot update, causing it
106+
to revert to the previous image.
107+
108+
config NRF_CLOUD_PGPS_STORAGE_PARTITION
109+
bool "Define P-GPS subsystem flash partition"
110+
select PM_SINGLE_IMAGE if !SPM
111+
help
112+
If set, allocates flash for storing predictions.
113+
114+
config NRF_CLOUD_PGPS_STORAGE_MCUBOOT_SECONDARY
115+
bool "Reuse MCUboot secondary partition for P-GPS storage"
116+
depends on BOOTLOADER_MCUBOOT
117+
depends on IMG_MANAGER
118+
depends on !BUILD_S1_VARIANT
119+
help
120+
If set, use the secondary MCUboot partition to also store P-GPS data.
121+
Note that when a FOTA job executes, this data will be lost and will
122+
have to be downloaded again after the FOTA job is complete. This is
123+
not compatible with FOTA updates of MUCboot itself, which is possible
124+
when SECURE_BOOT and BUILD_S1_VARIANT are enabled.
125+
126+
config NRF_CLOUD_PGPS_STORAGE_CUSTOM
127+
bool "Use application-provided location and size in flash"
128+
help
129+
The application is responsible for providing the location in flash
130+
in which to store P-GPS data. The location must be aligned to a
131+
flash page boundary (4096 bytes), and the size must be at least 2048
132+
bytes times NRF_COUND_PGPS_NUM_PREDICTIONS.
133+
134+
endchoice # NRF_CLOUD_PGPS_STORAGE
135+
136+
if NRF_CLOUD_PGPS_STORAGE_PARTITION
137+
138+
config NRF_CLOUD_PGPS_PARTITION_SIZE
139+
int "Size of flash partition for P-GPS data storage"
140+
default 86016
141+
help
142+
This must be >= NRF_CLOUD_PGPS_NUM_PREDICTIONS times 2048, which is
143+
the nRF9160 flash page size.
144+
145+
config NRF_CLOUD_PGPS_PARTITION_ALIGN
146+
hex "Align P-GPS partition to flash block boundary"
147+
default $(dt_node_int_prop_hex,$(DT_CHOSEN_ZEPHYR_FLASH),erase-block-size)
148+
149+
endif # NRF_CLOUD_PGPS_STORAGE_PARTITION
150+
96151
endif # NRF_CLOUD_PGPS

subsys/net/lib/nrf_cloud/src/nrf_cloud_agps.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,9 +219,10 @@ int nrf_cloud_agps_request(const struct nrf_modem_gnss_agps_data_frame *request)
219219

220220
int nrf_cloud_agps_request_all(void)
221221
{
222+
const uint32_t mask = IS_ENABLED(CONFIG_NRF_CLOUD_PGPS) ? 0u : 0xFFFFFFFFu;
222223
struct nrf_modem_gnss_agps_data_frame request = {
223-
.sv_mask_ephe = 0xFFFFFFFF,
224-
.sv_mask_alm = 0xFFFFFFFF,
224+
.sv_mask_ephe = mask,
225+
.sv_mask_alm = mask,
225226
.data_flags =
226227
NRF_MODEM_GNSS_AGPS_GPS_UTC_REQUEST |
227228
NRF_MODEM_GNSS_AGPS_KLOBUCHAR_REQUEST |

subsys/net/lib/nrf_cloud/src/nrf_cloud_pgps.c

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <settings/settings.h>
1919
#include <sys/reboot.h>
2020
#include <logging/log_ctrl.h>
21+
#include <pm_config.h>
2122

2223
#include <logging/log.h>
2324

@@ -1341,6 +1342,7 @@ static int consume_pgps_data(uint8_t pnum, const char *buf, size_t buf_len)
13411342
if (evt_handler) {
13421343
struct nrf_cloud_pgps_event evt = {
13431344
.type = PGPS_EVT_READY,
1345+
.prediction = NULL
13441346
};
13451347

13461348
evt_handler(&evt);
@@ -1480,8 +1482,25 @@ int nrf_cloud_pgps_init(struct nrf_cloud_pgps_init_param *param)
14801482
.type = PGPS_EVT_INIT,
14811483
};
14821484

1485+
#if defined(CONFIG_NRF_CLOUD_PGPS_STORAGE_PARTITION)
1486+
BUILD_ASSERT(CONFIG_NRF_CLOUD_PGPS_PARTITION_SIZE >=
1487+
(CONFIG_NRF_CLOUD_PGPS_NUM_PREDICTIONS * BLOCK_SIZE),
1488+
"P-GPS partition size is too small");
1489+
if (param->storage_base || param->storage_size) {
1490+
LOG_WRN("Overriding P-GPS storage with P-GPS partition");
1491+
}
1492+
param->storage_base = PM_PGPS_ADDRESS;
1493+
param->storage_size = PM_PGPS_SIZE;
1494+
#elif defined(CONFIG_NRF_CLOUD_PGPS_STORAGE_MCUBOOT_SECONDARY)
1495+
if (param->storage_base || param->storage_size) {
1496+
LOG_WRN("Overriding P-GPS storage with MCUboot secondary partition");
1497+
}
1498+
param->storage_base = PM_MCUBOOT_SECONDARY_ADDRESS;
1499+
param->storage_size = PM_MCUBOOT_SECONDARY_SIZE;
1500+
#endif
1501+
14831502
__ASSERT(param != NULL, "param must be provided");
1484-
__ASSERT(param->storage_base != 0, "storage must be provided");
1503+
__ASSERT(param->storage_base != 0u, "P-GPS flash storage must be provided");
14851504
__ASSERT((param->storage_size >= (NUM_BLOCKS * BLOCK_SIZE)),
14861505
"insufficient storage provided; need at least %u bytes",
14871506
(NUM_BLOCKS * BLOCK_SIZE));
@@ -1558,20 +1577,20 @@ int nrf_cloud_pgps_init(struct nrf_cloud_pgps_init_param *param)
15581577
num_valid = validate_stored_predictions(&gps_day, &gps_time_of_day);
15591578
}
15601579

1561-
struct nrf_cloud_pgps_prediction *test_prediction;
1580+
struct nrf_cloud_pgps_prediction *found_prediction = NULL;
15621581
int pnum = -1;
15631582

15641583
LOG_DBG("num_valid:%u, count:%u", num_valid, count);
15651584
if (num_valid) {
15661585
LOG_INF("Checking if P-GPS data is expired...");
1567-
err = nrf_cloud_pgps_find_prediction(&test_prediction);
1586+
err = nrf_cloud_pgps_find_prediction(&found_prediction);
15681587
if (err == -ETIMEDOUT) {
15691588
LOG_WRN("Predictions expired. Requesting predictions...");
15701589
num_valid = 0;
15711590
} else if (err >= 0) {
15721591
LOG_INF("Found valid prediction, day:%u, time:%u",
1573-
test_prediction->time.date_day,
1574-
test_prediction->time.time_full_s);
1592+
found_prediction->time.date_day,
1593+
found_prediction->time.time_full_s);
15751594
pnum = err;
15761595
}
15771596
}
@@ -1620,7 +1639,7 @@ int nrf_cloud_pgps_init(struct nrf_cloud_pgps_init_param *param)
16201639
LOG_INF("P-GPS data is up to date.");
16211640
if (evt_handler) {
16221641
evt.type = PGPS_EVT_READY;
1623-
1642+
evt.prediction = found_prediction;
16241643
evt_handler(&evt);
16251644
}
16261645
err = 0;

subsys/partition_manager/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ if (CONFIG_MEMFAULT_NCS_INTERNAL_FLASH_BACKED_COREDUMP)
9393
ncs_add_partition_manager_config(pm.yml.memfault)
9494
endif()
9595

96+
if(CONFIG_NRF_CLOUD_PGPS_STORAGE_PARTITION)
97+
ncs_add_partition_manager_config(pm.yml.pgps)
98+
endif()
9699

97100
# We are using partition manager if we are a child image or if we are
98101
# the root image and the 'partition_manager' target exists.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#include <autoconf.h>
2+
3+
pgps:
4+
placement: {before: [tfm_storage, end]}
5+
size: CONFIG_NRF_CLOUD_PGPS_PARTITION_SIZE
6+
align: {start: CONFIG_NRF_CLOUD_PGPS_PARTITION_ALIGN}

0 commit comments

Comments
 (0)