Skip to content

Commit ccefb2a

Browse files
SebastianBoenordicjm
authored andcommitted
[nrf fromlist] soc: nordic: uicr: Add support for UICR.WDTSTART
Add support for UICR.WDTSTART. UICR.WDTSTART configures the automatic start of a local watchdog timer before the application core is booted. This provides early system protection ensuring that the system can recover from early boot failures. Upstream PR #: 97337 Signed-off-by: Sebastian Bøe <[email protected]>
1 parent c62a6c7 commit ccefb2a

File tree

4 files changed

+155
-6
lines changed

4 files changed

+155
-6
lines changed

scripts/ci/check_compliance.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1301,12 +1301,18 @@ def check_no_undef_outside_kconfig(self, kconf):
13011301
"FOO_SETTING_1",
13021302
"FOO_SETTING_2",
13031303
"GEN_UICR_GENERATE_PERIPHCONF", # Used in specialized build tool, not part of main Kconfig
1304-
"GEN_UICR_PROTECTEDMEM", # Used in specialized build tool, not part of main Kconfig
1305-
"GEN_UICR_PROTECTEDMEM_SIZE_BYTES", # Used in specialized build tool, not part of main Kconfig
1306-
"GEN_UICR_SECONDARY", # Used in specialized build tool, not part of main Kconfig
1307-
"GEN_UICR_SECONDARY_GENERATE_PERIPHCONF", # Used in specialized build tool, not part of main Kconfig
1308-
"GEN_UICR_SECONDARY_PROCESSOR_VALUE", # Used in specialized build tool, not part of main Kconfig
1309-
"GEN_UICR_SECURESTORAGE", # Used in specialized build tool, not part of main Kconfig
1304+
"GEN_UICR_PROTECTEDMEM",
1305+
"GEN_UICR_PROTECTEDMEM_SIZE_BYTES",
1306+
"GEN_UICR_SECONDARY",
1307+
"GEN_UICR_SECONDARY_GENERATE_PERIPHCONF",
1308+
"GEN_UICR_SECONDARY_PROCESSOR_VALUE",
1309+
"GEN_UICR_SECONDARY_WDTSTART",
1310+
"GEN_UICR_SECONDARY_WDTSTART_CRV",
1311+
"GEN_UICR_SECONDARY_WDTSTART_INSTANCE_CODE",
1312+
"GEN_UICR_SECURESTORAGE",
1313+
"GEN_UICR_WDTSTART",
1314+
"GEN_UICR_WDTSTART_CRV",
1315+
"GEN_UICR_WDTSTART_INSTANCE_CODE", # Used in specialized build tool, not part of main Kconfig
13101316
"HEAP_MEM_POOL_ADD_SIZE_", # Used as an option matching prefix
13111317
"HUGETLBFS", # Linux, in boards/xtensa/intel_adsp_cavs25/doc
13121318
"IAR_BUFFERED_WRITE",

soc/nordic/common/uicr/gen_uicr.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,36 @@ def main() -> None:
440440
type=int,
441441
help="Protected memory size in bytes (must be divisible by 4096)",
442442
)
443+
parser.add_argument(
444+
"--wdtstart",
445+
action="store_true",
446+
help="Enable watchdog timer start in UICR",
447+
)
448+
parser.add_argument(
449+
"--wdtstart-instance-code",
450+
type=lambda s: int(s, 0),
451+
help="Watchdog timer instance code (0xBD2328A8 for WDT0, 0x1730C77F for WDT1)",
452+
)
453+
parser.add_argument(
454+
"--wdtstart-crv",
455+
type=int,
456+
help="Initial Counter Reload Value (CRV) for watchdog timer (minimum: 0xF)",
457+
)
458+
parser.add_argument(
459+
"--secondary-wdtstart",
460+
action="store_true",
461+
help="Enable watchdog timer start in UICR.SECONDARY",
462+
)
463+
parser.add_argument(
464+
"--secondary-wdtstart-instance-code",
465+
type=lambda s: int(s, 0),
466+
help="Secondary watchdog timer instance code (0xBD2328A8 for WDT0, 0x1730C77F for WDT1)",
467+
)
468+
parser.add_argument(
469+
"--secondary-wdtstart-crv",
470+
type=int,
471+
help="Secondary initial Counter Reload Value (CRV) for watchdog timer (minimum: 0xF)",
472+
)
443473
parser.add_argument(
444474
"--secondary",
445475
action="store_true",
@@ -557,6 +587,12 @@ def main() -> None:
557587
uicr.PROTECTEDMEM.ENABLE = ENABLED_VALUE
558588
uicr.PROTECTEDMEM.SIZE4KB = args.protectedmem_size_bytes // KB_4
559589

590+
# Handle WDTSTART configuration
591+
if args.wdtstart:
592+
uicr.WDTSTART.ENABLE = ENABLED_VALUE
593+
uicr.WDTSTART.CRV = args.wdtstart_crv
594+
uicr.WDTSTART.INSTANCE = args.wdtstart_instance_code
595+
560596
# Process periphconf data first and configure UICR completely before creating hex objects
561597
periphconf_hex = IntelHex()
562598
secondary_periphconf_hex = IntelHex()
@@ -625,6 +661,12 @@ def main() -> None:
625661

626662
uicr.SECONDARY.PERIPHCONF.MAXCOUNT = args.secondary_periphconf_size // 8
627663

664+
# Handle secondary WDTSTART configuration
665+
if args.secondary_wdtstart:
666+
uicr.SECONDARY.WDTSTART.ENABLE = ENABLED_VALUE
667+
uicr.SECONDARY.WDTSTART.CRV = args.secondary_wdtstart_crv
668+
uicr.SECONDARY.WDTSTART.INSTANCE = args.secondary_wdtstart_instance_code
669+
628670
# Create UICR hex object with final UICR data
629671
uicr_hex = IntelHex()
630672
uicr_hex.frombytes(bytes(uicr), offset=args.uicr_address)

soc/nordic/common/uicr/gen_uicr/CMakeLists.txt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ endif()
7777

7878
set(protectedmem_args)
7979
set(periphconf_args)
80+
set(wdtstart_args)
8081
set(periphconf_elfs)
8182
set(merged_hex_file ${APPLICATION_BINARY_DIR}/zephyr/${CONFIG_KERNEL_BIN_NAME}.hex)
8283
set(secondary_periphconf_elfs)
@@ -120,6 +121,13 @@ if(CONFIG_GEN_UICR_PROTECTEDMEM)
120121
list(APPEND protectedmem_args --protectedmem-size-bytes ${CONFIG_GEN_UICR_PROTECTEDMEM_SIZE_BYTES})
121122
endif()
122123

124+
# Handle WDTSTART configuration
125+
if(CONFIG_GEN_UICR_WDTSTART)
126+
list(APPEND wdtstart_args --wdtstart)
127+
list(APPEND wdtstart_args --wdtstart-instance-code ${CONFIG_GEN_UICR_WDTSTART_INSTANCE_CODE})
128+
list(APPEND wdtstart_args --wdtstart-crv ${CONFIG_GEN_UICR_WDTSTART_CRV})
129+
endif()
130+
123131
if(CONFIG_GEN_UICR_GENERATE_PERIPHCONF)
124132
# gen_uicr.py parses all zephyr.elf files. To find these files (which
125133
# have not been built yet) we scan sibling build directories for
@@ -173,6 +181,13 @@ if(CONFIG_GEN_UICR_SECONDARY)
173181
--secondary-processor ${CONFIG_GEN_UICR_SECONDARY_PROCESSOR_VALUE}
174182
)
175183

184+
# Handle secondary WDTSTART configuration
185+
if(CONFIG_GEN_UICR_SECONDARY_WDTSTART)
186+
list(APPEND secondary_args --secondary-wdtstart)
187+
list(APPEND secondary_args --secondary-wdtstart-instance-code ${CONFIG_GEN_UICR_SECONDARY_WDTSTART_INSTANCE_CODE})
188+
list(APPEND secondary_args --secondary-wdtstart-crv ${CONFIG_GEN_UICR_SECONDARY_WDTSTART_CRV})
189+
endif()
190+
176191
if(CONFIG_GEN_UICR_SECONDARY_GENERATE_PERIPHCONF)
177192
# Compute SECONDARY_PERIPHCONF absolute address and size from this image's devicetree
178193
compute_partition_address_and_size("secondary_periphconf_partition" SECONDARY_PERIPHCONF_ADDRESS SECONDARY_PERIPHCONF_SIZE)
@@ -195,6 +210,7 @@ add_custom_command(
195210
--uicr-address ${UICR_ADDRESS}
196211
--out-merged-hex ${merged_hex_file}
197212
--out-uicr-hex ${uicr_hex_file}
213+
${wdtstart_args}
198214
${periphconf_args}
199215
${securestorage_args}
200216
${protectedmem_args}

soc/nordic/common/uicr/gen_uicr/Kconfig

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,91 @@ config GEN_UICR_PROTECTEDMEM_SIZE_BYTES
4646
Size of the protected memory region in bytes.
4747
This value must be divisible by 4096 (4 kiB).
4848

49+
config GEN_UICR_WDTSTART
50+
bool "Enable UICR.WDTSTART"
51+
help
52+
When enabled, the UICR generator will configure the
53+
watchdog timer to start automatically before the
54+
application core is booted.
55+
56+
choice GEN_UICR_WDTSTART_INSTANCE
57+
prompt "Watchdog timer instance"
58+
depends on GEN_UICR_WDTSTART
59+
help
60+
Select which watchdog timer instance to use.
61+
62+
config GEN_UICR_WDTSTART_INSTANCE_WDT0
63+
bool "WDT0"
64+
help
65+
Use watchdog timer instance 0.
66+
67+
config GEN_UICR_WDTSTART_INSTANCE_WDT1
68+
bool "WDT1"
69+
help
70+
Use watchdog timer instance 1.
71+
72+
endchoice
73+
74+
config GEN_UICR_WDTSTART_INSTANCE_CODE
75+
hex
76+
default 0xBD2328A8 if GEN_UICR_WDTSTART_INSTANCE_WDT0
77+
default 0x1730C77F if GEN_UICR_WDTSTART_INSTANCE_WDT1
78+
depends on GEN_UICR_WDTSTART
79+
80+
config GEN_UICR_WDTSTART_CRV
81+
int "Initial Counter Reload Value (CRV)"
82+
default 65535
83+
range 15 4294967295
84+
depends on GEN_UICR_WDTSTART
85+
help
86+
Initial Counter Reload Value (CRV) for the watchdog timer.
87+
This value determines the watchdog timeout period.
88+
Must be at least 15 (0xF) to ensure proper watchdog operation.
89+
Default value 65535 creates a 2-second timeout.
90+
91+
config GEN_UICR_SECONDARY_WDTSTART
92+
bool "Enable UICR.SECONDARY.WDTSTART"
93+
depends on GEN_UICR_SECONDARY
94+
help
95+
When enabled, the UICR generator will configure the
96+
watchdog timer to start automatically before the
97+
secondary firmware is booted.
98+
99+
choice GEN_UICR_SECONDARY_WDTSTART_INSTANCE
100+
prompt "Secondary watchdog timer instance"
101+
depends on GEN_UICR_SECONDARY_WDTSTART
102+
help
103+
Select which watchdog timer instance to use for secondary firmware.
104+
105+
config GEN_UICR_SECONDARY_WDTSTART_INSTANCE_WDT0
106+
bool "WDT0"
107+
help
108+
Use watchdog timer instance 0 for secondary firmware.
109+
110+
config GEN_UICR_SECONDARY_WDTSTART_INSTANCE_WDT1
111+
bool "WDT1"
112+
help
113+
Use watchdog timer instance 1 for secondary firmware.
114+
115+
endchoice
116+
117+
config GEN_UICR_SECONDARY_WDTSTART_INSTANCE_CODE
118+
hex
119+
default 0xBD2328A8 if GEN_UICR_SECONDARY_WDTSTART_INSTANCE_WDT0
120+
default 0x1730C77F if GEN_UICR_SECONDARY_WDTSTART_INSTANCE_WDT1
121+
depends on GEN_UICR_SECONDARY_WDTSTART
122+
123+
config GEN_UICR_SECONDARY_WDTSTART_CRV
124+
int "Secondary initial Counter Reload Value (CRV)"
125+
default 65535
126+
range 15 4294967295
127+
depends on GEN_UICR_SECONDARY_WDTSTART
128+
help
129+
Initial Counter Reload Value (CRV) for the secondary watchdog timer.
130+
This value determines the watchdog timeout period.
131+
Must be at least 15 (0xF) to ensure proper watchdog operation.
132+
Default value 65535 creates a 2-second timeout.
133+
49134
config GEN_UICR_SECONDARY
50135
bool "Enable UICR.SECONDARY.ENABLE"
51136

0 commit comments

Comments
 (0)