Skip to content

Commit 3f1c9b9

Browse files
simensrostadjtguggedal
authored andcommitted
net: fota_download: support DT-based B1 slot addresses
Add support for getting B1 slot addresses from devicetree `s0_partition`/`s1_partition` nodes as a fallback to the PM-based `PM_S0/S1_ADDRESS` macros. Introduce local `S0_ADDRESS`/`S1_ADDRESS` aliases to unify both sources and guard MCUBoot-specific code under `CONFIG_DFU_TARGET_MCUBOOT` instead of `PM_S1_ADDRESS`. Signed-off-by: Simen S. Røstad <simen.rostad@nordicsemi.no>
1 parent 8991479 commit 3f1c9b9

1 file changed

Lines changed: 24 additions & 11 deletions

File tree

subsys/net/lib/fota_download/src/fota_download.c

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,34 @@
1111
#include <net/downloader.h>
1212
#include <zephyr/net/socket.h>
1313
#include <zephyr/net/tls_credentials.h>
14+
#include <zephyr/devicetree.h>
1415

1516
#include "fota_download_util.h"
1617

1718
#ifdef CONFIG_PARTITION_MANAGER_ENABLED
1819
#include <pm_config.h>
1920
#endif
2021

21-
#if defined(PM_S1_ADDRESS) || defined(CONFIG_DFU_TARGET_MCUBOOT)
22-
/* MCUBoot support is required */
22+
#if defined(CONFIG_DFU_TARGET_MCUBOOT)
2323
#include <fw_info.h>
2424
#if CONFIG_TRUSTED_EXECUTION_NONSECURE
2525
#include <tfm/tfm_ioctl_api.h>
2626
#endif
2727
#include <dfu/dfu_target_mcuboot.h>
28+
29+
#if defined(PM_S0_ADDRESS) && defined(PM_S1_ADDRESS)
30+
#define S0_ADDRESS PM_S0_ADDRESS
31+
#define S1_ADDRESS PM_S1_ADDRESS
32+
#elif DT_NODE_EXISTS(DT_NODELABEL(s0_partition)) && DT_NODE_EXISTS(DT_NODELABEL(s1_partition))
33+
BUILD_ASSERT(DT_REG_SIZE(DT_NODELABEL(s0_partition)) != 0);
34+
BUILD_ASSERT(DT_REG_SIZE(DT_NODELABEL(s1_partition)) != 0);
35+
#define S0_ADDRESS DT_REG_ADDR(DT_NODELABEL(s0_partition))
36+
#define S1_ADDRESS DT_REG_ADDR(DT_NODELABEL(s1_partition))
37+
#endif
38+
#if defined(S0_ADDRESS) && defined(S1_ADDRESS)
39+
BUILD_ASSERT(S0_ADDRESS != S1_ADDRESS);
2840
#endif
41+
#endif /* CONFIG_DFU_TARGET_MCUBOOT */
2942

3043
LOG_MODULE_REGISTER(fota_download, CONFIG_FOTA_DOWNLOAD_LOG_LEVEL);
3144

@@ -425,7 +438,7 @@ static void download_with_offset(struct k_work *unused)
425438

426439
int fota_download_b1_file_parse(char *s0_s1_files)
427440
{
428-
#if !defined(PM_S1_ADDRESS)
441+
#if !defined(S1_ADDRESS)
429442
return -EOPNOTSUPP;
430443
#endif
431444
/* B1 upgrade is supported, check what B1 slot is active,
@@ -461,7 +474,7 @@ int fota_download_b1_file_parse(char *s0_s1_files)
461474
return 0;
462475
}
463476

464-
#if !defined(CONFIG_TRUSTED_EXECUTION_NONSECURE) && defined(PM_S1_ADDRESS)
477+
#if !defined(CONFIG_TRUSTED_EXECUTION_NONSECURE) && defined(S1_ADDRESS)
465478
static int read_s0_active(uint32_t s0_address, uint32_t s1_address,
466479
bool *const s0_active)
467480
{
@@ -492,18 +505,18 @@ static int read_s0_active(uint32_t s0_address, uint32_t s1_address,
492505

493506
int fota_download_s0_active_get(bool *const s0_active)
494507
{
495-
#ifdef PM_S1_ADDRESS
508+
#ifdef S1_ADDRESS
496509
int err;
497510

498511
#ifdef CONFIG_TRUSTED_EXECUTION_NONSECURE
499-
err = tfm_platform_s0_active(PM_S0_ADDRESS, PM_S1_ADDRESS, s0_active);
512+
err = tfm_platform_s0_active(S0_ADDRESS, S1_ADDRESS, s0_active);
500513
#else /* CONFIG_TRUSTED_EXECUTION_NONSECURE */
501-
err = read_s0_active(PM_S0_ADDRESS, PM_S1_ADDRESS, s0_active);
514+
err = read_s0_active(S0_ADDRESS, S1_ADDRESS, s0_active);
502515
#endif /* CONFIG_TRUSTED_EXECUTION_NONSECURE */
503516
return err;
504-
#else /* PM_S1_ADDRESS */
517+
#else /* S1_ADDRESS */
505518
return -ENOENT;
506-
#endif /* PM_S1_ADDRESS */
519+
#endif /* S1_ADDRESS */
507520
}
508521

509522
int fota_download_any(const char *host, const char *file, const int *sec_tag_list,
@@ -585,7 +598,7 @@ int fota_download(const char *host, const char *file,
585598

586599
socket_retries_left = CONFIG_FOTA_SOCKET_RETRIES;
587600

588-
#ifdef PM_S1_ADDRESS
601+
#ifdef S1_ADDRESS
589602
/* Need a modifiable copy of the filename for splitting */
590603
static char file_buf[CONFIG_FOTA_DOWNLOAD_RESOURCE_LOCATOR_LENGTH];
591604

@@ -600,7 +613,7 @@ int fota_download(const char *host, const char *file,
600613
atomic_clear_bit(&flags, FLAG_DOWNLOADING);
601614
return err;
602615
}
603-
#endif /* PM_S1_ADDRESS */
616+
#endif /* S1_ADDRESS */
604617

605618
img_type_expected = expected_type;
606619

0 commit comments

Comments
 (0)